OpenASIP  2.0
ExecutionPipelineResourceTable.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2011 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file ExecutionPipelineResourceTable.cc
26  *
27  * Implementation of prototype of ExecutionPipelineResourceTable class.
28  *
29  * @author Heikki Kultala 2009 (heikki.kultala-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include "StringTools.hh"
34 
36 #include "FunctionUnit.hh"
37 #include "HWOperation.hh"
38 #include "ExecutionPipeline.hh"
39 #include "PipelineElement.hh"
40 
41 namespace TTAMachine {
42  class FUPort;
43 }
44 
48 
49 
51  const TTAMachine::FunctionUnit& fu) :
52  name_(fu.name()),
53  numberOfResources_(fu.pipelineElementCount() + fu.operationPortCount()),
54  maximalLatency_(fu.maxLatency()) {
55 
56  for (int j = 0; j < fu.operationCount(); j++) {
57  HWOperation& hwop = *fu.operation(j);
58  ExecutionPipeline* ep = hwop.pipeline();
59  std::string opName = StringTools::stringToUpper(
60  fu.operation(j)->name());
61 
62  for (int l = 0; l < ep->latency(); l++ ) {
63  for (int k = 0; k < fu.pipelineElementCount(); k++) {
64  PipelineElement *pe = fu.pipelineElement(k);
65  if (ep->isResourceUsed(pe->name(),l)){
66  setResourceUse(opName, l, k);
67  }
68  }
69  for (int k = 0; k < fu.operationPortCount(); k++) {
70  TTAMachine::FUPort* fuPort = fu.operationPort(k);
71  if (ep->isPortWritten(*fuPort,l)) {
73  opName, l,fu.pipelineElementCount()+k);
74  }
75  if (ep->isPortRead(*fuPort,l)) {
77  opName, -1, fu.pipelineElementCount()+k);
78  }
79  }
80  }
81 
82  // set operation latencies
83  ExecutionPipeline::OperandSet writes = ep->writtenOperands();
84  for (ExecutionPipeline::OperandSet::iterator iter =
85  writes.begin(); iter != writes.end(); iter++) {
86  int index = *iter;
87  int latency = hwop.latency(index);
88  setLatency(opName, index, latency);
89  }
90  }
91 }
92 
93 /**
94  * Sets usage of resource/port to true for given cycle and resource number
95  * and particular pipeline.
96  *
97  * @param opName Name of operation to set resource for
98  * @param cycle Cycle in which to set usage
99  * @param index Index of resource/port in resource vector
100  */
101 void
103  const std::string& opName,
104  const int cycle,
105  const int resIndex) {
106 
107  if (cycle > (signed)maximalLatency_) {
108  throw InvalidData(__FILE__, __LINE__, __func__,
109  "Trying to set resource use to cycle out of scope of "
110  "FU pipeline!");
111  }
112  if (resIndex >= numberOfResources_ || resIndex < 0){
113  throw InvalidData(__FILE__, __LINE__, __func__,
114  "Trying to set resource use for resource out of scope of "
115  "FU pipeline!");
116  }
117 
119  ResourceTable newOp(
120  maximalLatency_, std::vector<bool>(numberOfResources_, false));
121  operationPipelines_.push_back(newOp);
122  operationSupported_[opName] = operationPipelines_.size() - 1;
123  }
124  int pIndex = MapTools::valueForKey<int>(operationSupported_, opName);
125  if(cycle > -1) {
126  operationPipelines_[pIndex][cycle][resIndex] = true;
127  }
128 }
129 
130 /**
131  * Sets latency of an output of an operation.
132  * The resource usage of the operation has to be set before calling this.
133  * @param opName operation to set the latency
134  * @param output index of the output operand(stating from
135  * numberofinputoperand, not 0/1)
136  * @param latency latency of the output of the operation
137  */
138 void
140  const std::string& opName,
141  const int output,
142  const int latency) {
143 
145  ResourceTable newOp(maximalLatency_, std::vector<bool>(0, false));
146  operationPipelines_.push_back(newOp);
147  operationSupported_[opName] = operationPipelines_.size() - 1;
148  }
149 
150  int pIndex = MapTools::valueForKey<int>(operationSupported_, opName);
151  while (static_cast<int>(operationLatencies_.size()) <= pIndex) {
152  operationLatencies_.push_back(std::map<int,int>());
153  }
154  operationLatencies_[pIndex][output] = latency;
155 }
156 
157 /**
158  * Gives an resource table for given FU.
159  * If no existing found, creates a new one.
160  *
161  * @param fu function unit whose resource table we are asking for.
162  */
165  const TTAMachine::FunctionUnit& fu) {
166 
167  ResourceTableMap::iterator i = allResourceTables_.find(&fu);
168 
169  if (i != allResourceTables_.end()) {
170  return *i->second;
171  }
172 
173  ExecutionPipelineResourceTable* newTable =
175  allResourceTables_[&fu] = newTable;
176  return *newTable;
177 }
178 
179 /**
180  * Delete all the resource tables.
181  * This can be called after scheduling is done,
182  * when resource managers are longer used.
183  */
184 void
187 }
188 
ExecutionPipelineResourceTable::finalize
static void finalize()
Definition: ExecutionPipelineResourceTable.cc:185
ExecutionPipelineResourceTable::operationLatencies_
std::vector< std::map< int, int > > operationLatencies_
Definition: ExecutionPipelineResourceTable.hh:95
TTAMachine::HWOperation
Definition: HWOperation.hh:52
ExecutionPipeline.hh
MapTools::deleteAllValues
static void deleteAllValues(MapType &aMap)
ExecutionPipelineResourceTable::setResourceUse
void setResourceUse(const std::string &opName, const int cycle, const int resIndex)
Definition: ExecutionPipelineResourceTable.cc:102
ExecutionPipelineResourceTable::ExecutionPipelineResourceTable
ExecutionPipelineResourceTable(const TTAMachine::FunctionUnit &fu)
Definition: ExecutionPipelineResourceTable.cc:50
TTAMachine::ExecutionPipeline::writtenOperands
OperandSet writtenOperands(int cycle) const
Definition: ExecutionPipeline.cc:429
TTAMachine::PipelineElement::name
const std::string & name() const
StringTools::stringToUpper
static std::string stringToUpper(const std::string &source)
Definition: StringTools.cc:143
StringTools.hh
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::FUPort
Definition: FUPort.hh:46
ExecutionPipelineResourceTable::allResourceTables_
static ResourceTableMap allResourceTables_
Contains these tables for all FU's.
Definition: ExecutionPipelineResourceTable.hh:100
HWOperation.hh
TTAMachine::HWOperation::name
const std::string & name() const
Definition: HWOperation.cc:141
InvalidData
Definition: Exception.hh:149
TTAMachine::FunctionUnit::pipelineElement
virtual PipelineElement * pipelineElement(int index) const
Definition: FunctionUnit.cc:523
ExecutionPipelineResourceTable::maximalLatency_
unsigned int maximalLatency_
Maximal latency of operation in FU.
Definition: ExecutionPipelineResourceTable.hh:91
TTAMachine::ExecutionPipeline::isPortWritten
bool isPortWritten(const FUPort &port, int cycle) const
Definition: ExecutionPipeline.cc:386
__func__
#define __func__
Definition: Application.hh:67
ExecutionPipelineResourceTable::ResourceTable
std::vector< ResourceVector > ResourceTable
Type for resource reservation table, resource vector x latency.
Definition: ExecutionPipelineResourceTable.hh:83
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
ExecutionPipelineResourceTable::numberOfResources_
int numberOfResources_
Resource and ports vector width, depends on particular FU.
Definition: ExecutionPipelineResourceTable.hh:89
TTAMachine::FunctionUnit::operationPortCount
virtual int operationPortCount() const
Definition: FunctionUnit.cc:182
TTAMachine::FunctionUnit::pipelineElementCount
virtual int pipelineElementCount() const
Definition: FunctionUnit.cc:507
TTAMachine::ExecutionPipeline::isPortRead
bool isPortRead(const FUPort &port, int cycle) const
Definition: ExecutionPipeline.cc:362
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
ExecutionPipelineResourceTable::ResourceTableMap
std::map< const TTAMachine::FunctionUnit *, ExecutionPipelineResourceTable * > ResourceTableMap
Definition: ExecutionPipelineResourceTable.hh:86
ExecutionPipelineResourceTable::operationPipelines_
std::vector< ResourceTable > operationPipelines_
Pipelines for operations.
Definition: ExecutionPipelineResourceTable.hh:97
TTAMachine::PipelineElement
Definition: PipelineElement.hh:46
ExecutionPipelineResourceTable::setLatency
void setLatency(const std::string &opName, const int output, const int latency)
Definition: ExecutionPipelineResourceTable.cc:139
PipelineElement.hh
TTAMachine::HWOperation::pipeline
ExecutionPipeline * pipeline() const
Definition: HWOperation.cc:201
TTAMachine::ExecutionPipeline
Definition: ExecutionPipeline.hh:55
ExecutionPipelineResourceTable::resourceTable
static const ExecutionPipelineResourceTable & resourceTable(const TTAMachine::FunctionUnit &fu)
Definition: ExecutionPipelineResourceTable.cc:164
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
TTAMachine::HWOperation::latency
int latency() const
Definition: HWOperation.cc:216
ExecutionPipelineResourceTable::operationSupported_
std::map< std::string, int > operationSupported_
Operations supported, name - index to operation pipeline vector.
Definition: ExecutionPipelineResourceTable.hh:93
TTAMachine::FunctionUnit::operationPort
virtual FUPort * operationPort(const std::string &name) const
Definition: FunctionUnit.cc:224
ExecutionPipelineResourceTable
Definition: ExecutionPipelineResourceTable.hh:44
TTAMachine
Definition: Assembler.hh:48
TTAMachine::ExecutionPipeline::latency
int latency() const
Definition: ExecutionPipeline.cc:482
ExecutionPipelineResourceTable.hh
TTAMachine::ExecutionPipeline::isResourceUsed
bool isResourceUsed(const std::string &name, int cycle) const
Definition: ExecutionPipeline.cc:300
FunctionUnit.hh