OpenASIP 2.2
Loading...
Searching...
No Matches
ResourceVector.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 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 ResourceVector.cc
26 *
27 * Definition of ResourceVector class.
28 *
29 * @author Pekka J��skel�inen 2006 (pekka.jaaskelainen-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include "ResourceVector.hh"
34#include "Application.hh"
35#include "FunctionUnit.hh"
36#include "PipelineElement.hh"
37#include "FUPort.hh"
38#include "HWOperation.hh"
39#include "Conversion.hh"
40#include "AssocTools.hh"
41#include "ExecutionPipeline.hh"
42
43namespace TTAMachine {
44
45/**
46 * Constructor.
47 *
48 * Builds the resource vector out of MOM ExecutionPipeline.
49 *
50 * @param pipeline The ExecutionPipeline to build the resource vector for.
51 */
53
54 resources_.resize(pipeline.latency(), ResourceSet());
55
56 for (int i = 0; i < pipeline.latency(); ++i) {
58 pipeline.resourceUsages(i);
59 TTAMachine::ExecutionPipeline::ResourceSet::const_iterator res =
60 resourceUsages.begin();
61 while (res != resourceUsages.end()) {
62 resources_.at(i).insert(std::string("res:") + (*res)->name());
63 ++res;
64 }
66 pipeline.readOperands(i);
68 pipeline.writtenOperands(i);
69 TTAMachine::ExecutionPipeline::OperandSet::const_iterator op =
70 readOperands.begin();
71 while (op != readOperands.end()) {
72 const TTAMachine::FUPort* fuPort =
73 pipeline.parentOperation()->port(*op);
74 resources_.at(i).insert(
75 std::string("port:") + fuPort->bindingString());
76 ++op;
77 }
78
79 op = writtenOperands.begin();
80 while (op != writtenOperands.end()) {
81 const TTAMachine::FUPort* fuPort =
82 pipeline.parentOperation()->port(*op);
83 resources_.at(i).insert(
84 std::string("port:") + fuPort->bindingString());
85 ++op;
86 }
87 }
88}
89
90/**
91 * Destructor.
92 */
95
96/**
97 * Returns the set that contains the resources used at the given cycle.
98 *
99 * @param cycle The cycle.
100 * @return The set of resources.
101 * @exception OutOfRange If the cycle is out of range.
102 */
105 if (cycle > resources_.size())
106 throw OutOfRange(__FILE__, __LINE__, __func__);
107 return resources_.at(cycle);
108}
109
110/**
111 * Returns a textual description of the resource vector.
112 *
113 * @return A string describing the vector.
114 */
115std::string
117
118 std::string theString = "";
119 for (unsigned cycle = 0; cycle < resources_.size(); ++cycle) {
120 theString += std::string("[") + Conversion::toString(cycle) + ":{";
121
122 const ResourceSet& resSet = resources_.at(cycle);
123 for (ResourceSet::const_iterator i = resSet.begin();
124 i != resSet.end();) {
125 theString += *i;
126 ++i;
127 if (i != resSet.end())
128 theString += ",";
129 }
130 theString += "}]";
131 }
132 return theString;
133}
134
135/**
136 * Returns the width of the resource vector.
137 *
138 * @return The width.
139 */
140std::size_t
142 return resources_.size();
143}
144
145/**
146 * Returns true if the given resource vector has conflicting resource usages
147 * when issued after given count of cycles.
148 *
149 * @param other The another resource vector.
150 * @param cycle The count of cycles after which the operation is issued.
151 * @return True iff there is a conflict.
152 */
153bool
155 const {
156
157 for (std::size_t c = cycle; c < resources_.size(); ++c) {
158
159 if (other.width() <= c - cycle)
160 return false;
161
162 ResourceSet conflictingResources;
163 const ResourceSet& thisResources = resources_.at(c);
164 const ResourceSet& otherResources =
165 other.resourcesUsedAtCycle(c - cycle);
166
167 if (thisResources.size() == 0 || otherResources.size() == 0)
168 return false;
169
170 // check if any of the resources in another resource set is
171 // found in the another
172 ResourceSet::const_iterator i = thisResources.begin();
173 while (i != thisResources.end()) {
174 if (otherResources.find(*i) != otherResources.end())
175 return true;
176 ++i;
177 }
178 }
179 return false;
180}
181
182/**
183 * Merges the resource vector with the given resource vector starting from the
184 * given cycle.
185 *
186 * This method is used for producing the composite vector for simulation.
187 * The resulting resource vector is "stretched" in case there are no enough
188 * cycle elements in to contain the merged elements.
189 *
190 * @param other The another resource vector.
191 * @param cycle The count of cycles after which the operation is issued.
192 */
193void
194ResourceVector::mergeWith(const ResourceVector& other, unsigned cycle) {
195
196 resources_.resize(std::max(resources_.size(), cycle + other.width()));
197
198 for (std::size_t i = 0; i < other.width(); ++i) {
199 const ResourceSet& otherResources = other.resourcesUsedAtCycle(i);
200 resources_[cycle + i].insert(
201 otherResources.begin(), otherResources.end());
202 }
203}
204
205/**
206 * Shifts the resource vector one step left, i.e., deletes the first column.
207 */
208void
210 if (resources_.size() > 0)
211 resources_.pop_front();
212}
213
214/**
215 * Clears the resource vector.
216 *
217 * Result is an empty resource vector with no columns
218 */
219void
221 resources_.clear();
222}
223
224
225/**
226 * Compares two ResourceVectors.
227 *
228 * @param rightHand Right hand operand.
229 * @return True is the two vectors match false otherwise.
230 */
231bool
233
234 if (toString() != rightHand.toString()) {
235 return false;
236 }
237 return true;
238}
239
240}
#define __func__
static std::string toString(const T &source)
OperandSet writtenOperands(int cycle) const
OperandSet readOperands(int cycle) const
std::set< int > OperandSet
Set for operand indexes.
ResourceSet resourceUsages(int cycle) const
std::set< PipelineElement *, PipelineElement::Comparator > ResourceSet
Set for pipeline elements.
const HWOperation * parentOperation() const
std::string bindingString() const
Definition FUPort.cc:280
virtual FUPort * port(int operand) const
ResourceUsageIndex resources_
The storage for the resource usages.
std::set< std::string > ResourceSet
Resources are stored in a set as strings. Normal pipeline resource usages are prefixed with "res:",...
const ResourceSet & resourcesUsedAtCycle(unsigned cycle) const
std::string toString() const
virtual bool conflictsWith(const ResourceVector &other, unsigned cycle) const
std::size_t width() const
virtual bool operator==(const ResourceVector &rightHand) const
virtual void mergeWith(const ResourceVector &other, unsigned cycle)