OpenASIP  2.0
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
TTAMachine::ResourceVector Class Reference

#include <ResourceVector.hh>

Collaboration diagram for TTAMachine::ResourceVector:
Collaboration graph

Public Types

typedef std::set< std::string > ResourceSet
 Resources are stored in a set as strings. Normal pipeline resource usages are prefixed with "res:", port usages with "port:". More...
 

Public Member Functions

 ResourceVector ()
 
 ResourceVector (const TTAMachine::ExecutionPipeline &pipeline)
 
virtual ~ResourceVector ()
 
const ResourceSetresourcesUsedAtCycle (unsigned cycle) const
 
std::size_t width () const
 
std::string toString () const
 
virtual bool conflictsWith (const ResourceVector &other, unsigned cycle) const
 
virtual void mergeWith (const ResourceVector &other, unsigned cycle)
 
virtual void shiftLeft ()
 
virtual void clear ()
 
virtual bool operator== (const ResourceVector &rightHand) const
 

Private Types

typedef std::deque< ResourceSetResourceUsageIndex
 Each resource usage is stored as a string. More...
 

Private Attributes

ResourceUsageIndex resources_
 The storage for the resource usages. More...
 

Detailed Description

Represents a resource vector used in building the states in case of an function unit FSA.

Definition at line 53 of file ResourceVector.hh.

Member Typedef Documentation

◆ ResourceSet

typedef std::set<std::string> TTAMachine::ResourceVector::ResourceSet

Resources are stored in a set as strings. Normal pipeline resource usages are prefixed with "res:", port usages with "port:".

Definition at line 57 of file ResourceVector.hh.

◆ ResourceUsageIndex

Each resource usage is stored as a string.

Definition at line 82 of file ResourceVector.hh.

Constructor & Destructor Documentation

◆ ResourceVector() [1/2]

TTAMachine::ResourceVector::ResourceVector ( )
inline

Definition at line 59 of file ResourceVector.hh.

59 {};

◆ ResourceVector() [2/2]

TTAMachine::ResourceVector::ResourceVector ( const TTAMachine::ExecutionPipeline pipeline)

Constructor.

Builds the resource vector out of MOM ExecutionPipeline.

Parameters
pipelineThe ExecutionPipeline to build the resource vector for.

Definition at line 52 of file ResourceVector.cc.

52  {
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 }

References TTAMachine::FUPort::bindingString(), TTAMachine::ExecutionPipeline::latency(), TTAMachine::ExecutionPipeline::parentOperation(), TTAMachine::HWOperation::port(), TTAMachine::ExecutionPipeline::readOperands(), resources_, TTAMachine::ExecutionPipeline::resourceUsages(), and TTAMachine::ExecutionPipeline::writtenOperands().

Here is the call graph for this function:

◆ ~ResourceVector()

TTAMachine::ResourceVector::~ResourceVector ( )
virtual

Destructor.

Definition at line 93 of file ResourceVector.cc.

93  {
94 }

Member Function Documentation

◆ clear()

void TTAMachine::ResourceVector::clear ( )
virtual

Clears the resource vector.

Result is an empty resource vector with no columns

Definition at line 220 of file ResourceVector.cc.

220  {
221  resources_.clear();
222 }

References resources_.

Referenced by ResourceVectorFUResourceConflictDetector::reset().

◆ conflictsWith()

bool TTAMachine::ResourceVector::conflictsWith ( const ResourceVector other,
unsigned  cycle 
) const
virtual

Returns true if the given resource vector has conflicting resource usages when issued after given count of cycles.

Parameters
otherThe another resource vector.
cycleThe count of cycles after which the operation is issued.
Returns
True iff there is a conflict.

Definition at line 154 of file ResourceVector.cc.

155  {
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 }

References resources_, resourcesUsedAtCycle(), and width().

Referenced by ResourceVectorFUResourceConflictDetector::issueOperation().

Here is the call graph for this function:

◆ mergeWith()

void TTAMachine::ResourceVector::mergeWith ( const ResourceVector other,
unsigned  cycle 
)
virtual

Merges the resource vector with the given resource vector starting from the given cycle.

This method is used for producing the composite vector for simulation. The resulting resource vector is "stretched" in case there are no enough cycle elements in to contain the merged elements.

Parameters
otherThe another resource vector.
cycleThe count of cycles after which the operation is issued.

Definition at line 194 of file ResourceVector.cc.

194  {
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 }

References resources_, resourcesUsedAtCycle(), and width().

Referenced by ResourceVectorFUResourceConflictDetector::issueOperation().

Here is the call graph for this function:

◆ operator==()

bool TTAMachine::ResourceVector::operator== ( const ResourceVector rightHand) const
virtual

Compares two ResourceVectors.

Parameters
rightHandRight hand operand.
Returns
True is the two vectors match false otherwise.

Definition at line 232 of file ResourceVector.cc.

232  {
233 
234  if (toString() != rightHand.toString()) {
235  return false;
236  }
237  return true;
238 }

References toString().

Here is the call graph for this function:

◆ resourcesUsedAtCycle()

const ResourceVector::ResourceSet & TTAMachine::ResourceVector::resourcesUsedAtCycle ( unsigned  cycle) const

Returns the set that contains the resources used at the given cycle.

Parameters
cycleThe cycle.
Returns
The set of resources.
Exceptions
OutOfRangeIf the cycle is out of range.

Definition at line 104 of file ResourceVector.cc.

104  {
105  if (cycle > resources_.size())
106  throw OutOfRange(__FILE__, __LINE__, __func__);
107  return resources_.at(cycle);
108 }

References __func__, and resources_.

Referenced by conflictsWith(), and mergeWith().

◆ shiftLeft()

void TTAMachine::ResourceVector::shiftLeft ( )
virtual

Shifts the resource vector one step left, i.e., deletes the first column.

Definition at line 209 of file ResourceVector.cc.

209  {
210  if (resources_.size() > 0)
211  resources_.pop_front();
212 }

References resources_.

Referenced by ResourceVectorFUResourceConflictDetector::advanceCycle().

◆ toString()

std::string TTAMachine::ResourceVector::toString ( ) const

Returns a textual description of the resource vector.

Returns
A string describing the vector.

Definition at line 116 of file ResourceVector.cc.

116  {
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 }

References resources_, and Conversion::toString().

Referenced by operator==().

Here is the call graph for this function:

◆ width()

std::size_t TTAMachine::ResourceVector::width ( ) const

Returns the width of the resource vector.

Returns
The width.

Definition at line 141 of file ResourceVector.cc.

141  {
142  return resources_.size();
143 }

References resources_.

Referenced by conflictsWith(), mergeWith(), and TTAMachine::ResourceVectorSet::ResourceVectorSet().

Member Data Documentation

◆ resources_

ResourceUsageIndex TTAMachine::ResourceVector::resources_
private

The storage for the resource usages.

Definition at line 84 of file ResourceVector.hh.

Referenced by clear(), conflictsWith(), mergeWith(), resourcesUsedAtCycle(), ResourceVector(), shiftLeft(), toString(), and width().


The documentation for this class was generated from the following files:
OutOfRange
Definition: Exception.hh:320
TTAMachine::ExecutionPipeline::writtenOperands
OperandSet writtenOperands(int cycle) const
Definition: ExecutionPipeline.cc:429
TTAMachine::ExecutionPipeline::readOperands
OperandSet readOperands(int cycle) const
Definition: ExecutionPipeline.cc:408
Conversion::toString
static std::string toString(const T &source)
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::FUPort::bindingString
std::string bindingString() const
Definition: FUPort.cc:280
TTAMachine::ResourceVector::toString
std::string toString() const
Definition: ResourceVector.cc:116
__func__
#define __func__
Definition: Application.hh:67
TTAMachine::ExecutionPipeline::OperandSet
std::set< int > OperandSet
Set for operand indexes.
Definition: ExecutionPipeline.hh:58
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
TTAMachine::ExecutionPipeline::resourceUsages
ResourceSet resourceUsages(int cycle) const
Definition: ExecutionPipeline.cc:327
TTAMachine::ExecutionPipeline::latency
int latency() const
Definition: ExecutionPipeline.cc:482