OpenASIP 2.2
Loading...
Searching...
No Matches
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
41namespace 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++) {
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 */
101void
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 }
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 */
138void
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
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
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 */
184void
188
#define __func__
std::map< const TTAMachine::FunctionUnit *, ExecutionPipelineResourceTable * > ResourceTableMap
std::map< std::string, int > operationSupported_
Operations supported, name - index to operation pipeline vector.
void setLatency(const std::string &opName, const int output, const int latency)
static const ExecutionPipelineResourceTable & resourceTable(const TTAMachine::FunctionUnit &fu)
void setResourceUse(const std::string &opName, const int cycle, const int resIndex)
ExecutionPipelineResourceTable(const TTAMachine::FunctionUnit &fu)
std::vector< ResourceVector > ResourceTable
Type for resource reservation table, resource vector x latency.
std::vector< std::map< int, int > > operationLatencies_
int numberOfResources_
Resource and ports vector width, depends on particular FU.
std::vector< ResourceTable > operationPipelines_
Pipelines for operations.
unsigned int maximalLatency_
Maximal latency of operation in FU.
static ResourceTableMap allResourceTables_
Contains these tables for all FU's.
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)
static void deleteAllValues(MapType &aMap)
static bool containsKey(const MapType &aMap, const KeyType &aKey)
static std::string stringToUpper(const std::string &source)
OperandSet writtenOperands(int cycle) const
bool isPortWritten(const FUPort &port, int cycle) const
bool isPortRead(const FUPort &port, int cycle) const
bool isResourceUsed(const std::string &name, int cycle) const
virtual int pipelineElementCount() const
virtual HWOperation * operation(const std::string &name) const
virtual int operationCount() const
virtual FUPort * operationPort(const std::string &name) const
virtual PipelineElement * pipelineElement(int index) const
virtual int operationPortCount() const
ExecutionPipeline * pipeline() const
const std::string & name() const
const std::string & name() const