OpenASIP  2.0
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 
43 namespace 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  */
94 }
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  */
115 std::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  */
140 std::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  */
153 bool
154 ResourceVector::conflictsWith(const ResourceVector& other, unsigned cycle)
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  */
193 void
194 ResourceVector::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  */
208 void
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  */
219 void
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  */
231 bool
233 
234  if (toString() != rightHand.toString()) {
235  return false;
236  }
237  return true;
238 }
239 
240 }
TTAMachine::ResourceVector::clear
virtual void clear()
Definition: ResourceVector.cc:220
ExecutionPipeline.hh
OutOfRange
Definition: Exception.hh:320
TTAMachine::ResourceVector::width
std::size_t width() const
Definition: ResourceVector.cc:141
TTAMachine::ResourceVector
Definition: ResourceVector.hh:53
TTAMachine::ExecutionPipeline::writtenOperands
OperandSet writtenOperands(int cycle) const
Definition: ExecutionPipeline.cc:429
TTAMachine::ExecutionPipeline::readOperands
OperandSet readOperands(int cycle) const
Definition: ExecutionPipeline.cc:408
TTAMachine::ResourceVector::operator==
virtual bool operator==(const ResourceVector &rightHand) const
Definition: ResourceVector.cc:232
Conversion::toString
static std::string toString(const T &source)
TTAMachine::ResourceVector::~ResourceVector
virtual ~ResourceVector()
Definition: ResourceVector.cc:93
TTAMachine::ResourceVector::ResourceSet
std::set< std::string > ResourceSet
Resources are stored in a set as strings. Normal pipeline resource usages are prefixed with "res:",...
Definition: ResourceVector.hh:57
TTAMachine::HWOperation::port
virtual FUPort * port(int operand) const
Definition: HWOperation.cc:320
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAMachine::ResourceVector::ResourceVector
ResourceVector()
Definition: ResourceVector.hh:59
TTAMachine::FUPort::bindingString
std::string bindingString() const
Definition: FUPort.cc:280
HWOperation.hh
TTAMachine::ResourceVector::toString
std::string toString() const
Definition: ResourceVector.cc:116
Conversion.hh
Application.hh
__func__
#define __func__
Definition: Application.hh:67
ResourceVector.hh
TTAMachine::ResourceVector::mergeWith
virtual void mergeWith(const ResourceVector &other, unsigned cycle)
Definition: ResourceVector.cc:194
TTAMachine::ResourceVector::resourcesUsedAtCycle
const ResourceSet & resourcesUsedAtCycle(unsigned cycle) const
Definition: ResourceVector.cc:104
TTAMachine::ExecutionPipeline::OperandSet
std::set< int > OperandSet
Set for operand indexes.
Definition: ExecutionPipeline.hh:58
TTAMachine::ResourceVector::conflictsWith
virtual bool conflictsWith(const ResourceVector &other, unsigned cycle) const
Definition: ResourceVector.cc:154
TTAMachine::ResourceVector::shiftLeft
virtual void shiftLeft()
Definition: ResourceVector.cc:209
TTAMachine::ExecutionPipeline::ResourceSet
std::set< PipelineElement *, PipelineElement::Comparator > ResourceSet
Set for pipeline elements.
Definition: ExecutionPipeline.hh:60
TTAMachine::ResourceVector::resources_
ResourceUsageIndex resources_
The storage for the resource usages.
Definition: ResourceVector.hh:84
TTAMachine::ExecutionPipeline::parentOperation
const HWOperation * parentOperation() const
Definition: ExecutionPipeline.cc:89
AssocTools.hh
FUPort.hh
PipelineElement.hh
TTAMachine::ExecutionPipeline
Definition: ExecutionPipeline.hh:55
TTAMachine::ExecutionPipeline::resourceUsages
ResourceSet resourceUsages(int cycle) const
Definition: ExecutionPipeline.cc:327
TTAMachine
Definition: Assembler.hh:48
TTAMachine::ExecutionPipeline::latency
int latency() const
Definition: ExecutionPipeline.cc:482
FunctionUnit.hh