OpenASIP  2.0
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
OutputPSocketResource Class Reference

#include <OutputPSocketResource.hh>

Inheritance diagram for OutputPSocketResource:
Inheritance graph
Collaboration diagram for OutputPSocketResource:
Collaboration graph

Public Member Functions

virtual ~OutputPSocketResource ()
 
 OutputPSocketResource (const std::string &name, unsigned int initiationInterval=0)
 
virtual bool isAvailable (const int cycle) const override
 
virtual bool isOutputPSocketResource () const override
 
virtual void assign (const int cycle, MoveNode &node) override
 
virtual void unassign (const int cycle, MoveNode &node) override
 
virtual bool canAssign (const int cycle, const MoveNode &node) const override
 
virtual bool operator< (const SchedulingResource &other) const override
 
void clear () override
 
- Public Member Functions inherited from PSocketResource
virtual ~PSocketResource ()
 
 PSocketResource (const std::string &name, unsigned int initiationInterval=0)
 
virtual bool isInUse (const int cycle) const override
 
void clear () override
 
- Public Member Functions inherited from SchedulingResource
virtual ~SchedulingResource ()
 
 SchedulingResource (const std::string &name, const unsigned int ii=0)
 
virtual int relatedResourceGroupCount () const
 
virtual int dependentResourceGroupCount () const
 
int relatedResourceCount (const int group) const
 
int dependentResourceCount (const int group) const
 
virtual void addToRelatedGroup (const int group, SchedulingResource &resource)
 
virtual void addToDependentGroup (const int group, SchedulingResource &resource)
 
virtual SchedulingResourcerelatedResource (const int group, const int index) const
 
virtual SchedulingResourcedependentResource (const int group, const int index) const
 
virtual bool hasRelatedResource (const SchedulingResource &sResource) const
 
virtual bool hasDependentResource (const SchedulingResource &sResource) const
 
virtual const std::string & name () const
 
virtual int useCount () const
 
virtual void increaseUseCount ()
 
virtual void decreaseUseCount ()
 
virtual bool isInputPSocketResource () const
 
virtual bool isShortImmPSocketResource () const
 
virtual bool isInputFUResource () const
 
virtual bool isOutputFUResource () const
 
virtual bool isExecutionPipelineResource () const
 
virtual bool isBusResource () const
 
virtual bool isSegmentResource () const
 
virtual bool isIUResource () const
 
virtual bool isITemplateResource () const
 
int instructionIndex (int cycle) const
 
void setInitiationInterval (unsigned int ii)
 
int initiationInterval () const
 
virtual void setMaxCycle (unsigned int)
 

Protected Member Functions

virtual bool validateDependentGroups () override
 
virtual bool validateRelatedGroups () override
 

Private Member Functions

 OutputPSocketResource (const OutputPSocketResource &)
 
OutputPSocketResourceoperator= (const OutputPSocketResource &)
 

Private Attributes

int activeCycle_
 
std::map< int, std::pair< const TTAMachine::Port *, int > > storedPorts_
 

Additional Inherited Members

- Protected Types inherited from PSocketResource
typedef std::map< int, std::set< MoveNode * > > ResourceRecordType
 
- Protected Attributes inherited from PSocketResource
ResourceRecordType resourceRecord_
 
- Protected Attributes inherited from SchedulingResource
int initiationInterval_
 

Detailed Description

An interface for scheduling resources of Resource Model The derived class OutputPSocketResource

Definition at line 52 of file OutputPSocketResource.hh.

Constructor & Destructor Documentation

◆ ~OutputPSocketResource()

OutputPSocketResource::~OutputPSocketResource ( )
virtual

Destructor.

Definition at line 54 of file OutputPSocketResource.cc.

54 {}

◆ OutputPSocketResource() [1/2]

OutputPSocketResource::OutputPSocketResource ( const std::string &  name,
unsigned int  initiationInterval = 0 
)

Constructor.

Parameters
nameName of resource.

Definition at line 48 of file OutputPSocketResource.cc.

◆ OutputPSocketResource() [2/2]

OutputPSocketResource::OutputPSocketResource ( const OutputPSocketResource )
private

Member Function Documentation

◆ assign()

void OutputPSocketResource::assign ( const int  cycle,
MoveNode node 
)
overridevirtual

Assign resource to given node for given cycle.

Parameters
cycleCycle to assign
nodeMoveNode to assign

Reimplemented from PSocketResource.

Definition at line 83 of file OutputPSocketResource.cc.

84 {
85  PSocketResource::assign(cycle, node);
86  auto i = storedPorts_.find(instructionIndex(cycle));
87  if (i == storedPorts_.end()) {
88  const TTAMachine::Port* newPort = &node.move().source().port();
90  std::make_pair(newPort,1);
91  } else {
92  i->second.second++;
93  }
94 }

References PSocketResource::assign(), SchedulingResource::instructionIndex(), MoveNode::move(), TTAProgram::Terminal::port(), TTAProgram::Move::source(), and storedPorts_.

Here is the call graph for this function:

◆ canAssign()

bool OutputPSocketResource::canAssign ( const int  cycle,
const MoveNode node 
) const
overridevirtual

Return true if resource can be assigned for given resource in given cycle.

Parameters
cycleCycle to test
nodeMoveNode to test
Returns
true if node can be assigned to cycle

Reimplemented from PSocketResource.

Definition at line 124 of file OutputPSocketResource.cc.

125  {
126  MoveNode& mNode = const_cast<MoveNode&>(node);
127  auto i = storedPorts_.find(instructionIndex(cycle));
128  if (mNode.move().source().isFUPort()) {
129  if (i != storedPorts_.end()) {
130  const TTAMachine::Port* storedP = i->second.first;
131  if (&mNode.move().source().port() != storedP) {
132  return false;
133  }
134  }
135  }
136  if (mNode.move().source().isImmediateRegister()) {
137  if (i != storedPorts_.end()) {
138  return false;
139  }
140  }
141  if (node.move().source().isGPR()) {
142  if (i != storedPorts_.end()) {
143  const TTAMachine::Port* storedP =
144  i->second.first;
145  if (mNode.move().source().port().parentUnit() !=
146  storedP->parentUnit()) {
147  return false;
148  }
149  }
150 
151  ResourceRecordType::const_iterator iter = resourceRecord_.find(cycle);
152  if (iter != resourceRecord_.end()) {
153  std::set<MoveNode*> movesInCycle = iter->second;
154  for (std::set<MoveNode*>::iterator it = movesInCycle.begin();
155  it != movesInCycle.end(); it++) {
156 #ifdef NO_OVERCOMMIT
157  return false;
158 #else
159  MoveNode* mn = *it;
160  if (node.move().isUnconditional() ||
161  mn->move().isUnconditional()) {
162  if (node.move().source().port().parentUnit() !=
163  mn->move().source().port().parentUnit() ||
164  node.move().source().index() !=
165  mn->move().source().index()) {
166  return false;
167  } else {
168  continue;
169  }
170 
171  }
172  if (!node.move().guard().guard().isOpposite(
173  mn->move().guard().guard())) {
174  if (!node.move().source().equals(
175  mn->move().source())) {
176  return false;
177  }
178  }
179 #endif
180  }
181  }
182  }
183  activeCycle_ = cycle;
184  return true;
185 }

References activeCycle_, TTAProgram::Terminal::equals(), TTAProgram::MoveGuard::guard(), TTAProgram::Move::guard(), TTAProgram::Terminal::index(), SchedulingResource::instructionIndex(), TTAProgram::Terminal::isFUPort(), TTAProgram::Terminal::isGPR(), TTAProgram::Terminal::isImmediateRegister(), TTAMachine::Guard::isOpposite(), TTAProgram::Move::isUnconditional(), MoveNode::move(), TTAMachine::Port::parentUnit(), TTAProgram::Terminal::port(), PSocketResource::resourceRecord_, TTAProgram::Move::source(), and storedPorts_.

Here is the call graph for this function:

◆ clear()

void OutputPSocketResource::clear ( )
overridevirtual

Clears bookkeeping of the scheduling resource.

After this call the state of the resource should be identical to a newly-created and initialized resource.

Reimplemented from SchedulingResource.

Definition at line 305 of file OutputPSocketResource.cc.

305  {
307  storedPorts_.clear();
308 }

References PSocketResource::clear(), and storedPorts_.

Here is the call graph for this function:

◆ isAvailable()

bool OutputPSocketResource::isAvailable ( const int  cycle) const
overridevirtual

Test if resource OutputPSocketResource is available.

Parameters
cycleCycle which to test.
Returns
Always true, multiple reads are possible.

Reimplemented from PSocketResource.

Definition at line 63 of file OutputPSocketResource.cc.

63  {
64  return true;
65 }

◆ isOutputPSocketResource()

bool OutputPSocketResource::isOutputPSocketResource ( ) const
overridevirtual

Return true always.

Returns
True always.

Reimplemented from SchedulingResource.

Definition at line 73 of file OutputPSocketResource.cc.

73  {
74  return true;
75 }

◆ operator<()

bool OutputPSocketResource::operator< ( const SchedulingResource other) const
overridevirtual

Comparison operator.

Favours sockets which have less connections.

TODO: precalc/cache these to optimize scheduling time?

Reimplemented from SchedulingResource.

Definition at line 232 of file OutputPSocketResource.cc.

232  {
233  const OutputPSocketResource *opsr =
234  dynamic_cast<const OutputPSocketResource*>(&other);
235  if (opsr == NULL) {
236  return false;
237  }
238 
239  // first priority is to put reads from same source to same psocket.
240  // so favour the one with most moves in current cycle.
241  int myCount = 0;
242  int otherCount = 0;
243  ResourceRecordType::const_iterator myIter = resourceRecord_.find(activeCycle_);
244  if (myIter != resourceRecord_.end()) {
245  myCount = myIter->second.size();
246  }
247 
248  ResourceRecordType::const_iterator otherIter = opsr->resourceRecord_.find(opsr->activeCycle_);
249  if (otherIter != opsr->resourceRecord_.end()) {
250  otherCount = otherIter->second.size();
251  }
252  if (myCount < otherCount) {
253  return false;
254  } else if (myCount > otherCount) {
255  return true;
256  }
257 
258  // favour sockets which have connections to busses with fewest connections
259  // calculate the connections..
260  int connCount = 0;
261  int connCount2 = 0;
262 
263  int rrCount2 = relatedResourceCount(2);
264  for (int i = 0; i < rrCount2; i++) {
266  connCount += r.relatedResourceCount(0);
267  }
268 
269  int oRRCount2 = other.relatedResourceCount(2);
270 
271  for (int i = 0; i < oRRCount2; i++) {
272  SchedulingResource& r = other.relatedResource(2,i);
273  connCount2 += r.relatedResourceCount(0);
274  }
275 
276  // then the comparison.
277  if (connCount < connCount2) {
278  return true;
279  }
280 
281  if (connCount > connCount2) {
282  return false;
283  }
284 
285  // favour sockets with less buses.
286  if (rrCount2 < oRRCount2) {
287  return true;
288  }
289  if (rrCount2 > oRRCount2) {
290  return false;
291  }
292 
293  // then use the default use count, name comparison,
294  // but in opposite direction, facouring already used
295  return other.SchedulingResource::operator<(*this);
296 }

References activeCycle_, SchedulingResource::relatedResource(), SchedulingResource::relatedResourceCount(), and PSocketResource::resourceRecord_.

Here is the call graph for this function:

◆ operator=()

OutputPSocketResource& OutputPSocketResource::operator= ( const OutputPSocketResource )
private

◆ unassign()

void OutputPSocketResource::unassign ( const int  cycle,
MoveNode node 
)
overridevirtual

Unassign resource from given node for given cycle.

Parameters
cycleCycle to remove assignment from
nodeMoveNode to remove assignment from

Reimplemented from PSocketResource.

Definition at line 103 of file OutputPSocketResource.cc.

104 {
105  PSocketResource::unassign(cycle, node);
106  auto i = storedPorts_.find(instructionIndex(cycle));
107  if (i != storedPorts_.end()) {
108  if (i->second.second == 1) {
109  storedPorts_.erase(i);
110  } else {
111  i->second.second--;
112  }
113  }
114 }

References SchedulingResource::instructionIndex(), storedPorts_, and PSocketResource::unassign().

Here is the call graph for this function:

◆ validateDependentGroups()

bool OutputPSocketResource::validateDependentGroups ( )
overrideprotectedvirtual

Tests if all referred resources in dependent groups are of proper types.

Returns
True if all dependent groups are empty.

Reimplemented from SchedulingResource.

Definition at line 194 of file OutputPSocketResource.cc.

194  {
195  for (int i = 0; i < dependentResourceGroupCount(); i++) {
196  if (dependentResourceCount(i) > 0) {
197  return false;
198  }
199  }
200  return true;
201 }

References SchedulingResource::dependentResourceCount(), and SchedulingResource::dependentResourceGroupCount().

Here is the call graph for this function:

◆ validateRelatedGroups()

bool OutputPSocketResource::validateRelatedGroups ( )
overrideprotectedvirtual

Tests if all referred resources in related groups are of proper types.

Returns
True if all resources in related groups are Segment or OutputFU or IU resources.

Reimplemented from SchedulingResource.

Reimplemented in ShortImmPSocketResource.

Definition at line 211 of file OutputPSocketResource.cc.

211  {
212  for (int i = 0; i < relatedResourceGroupCount(); i++) {
213  for (int j = 0, count = relatedResourceCount(i); j < count; j++) {
214  if (!(relatedResource(i, j).isOutputFUResource() ||
215  relatedResource(i, j).isBusResource() ||
216  relatedResource(i, j).isIUResource())) {
217  return false;
218  }
219  }
220  }
221  return true;
222 }

References SchedulingResource::isBusResource(), SchedulingResource::isIUResource(), SchedulingResource::isOutputFUResource(), SchedulingResource::relatedResource(), SchedulingResource::relatedResourceCount(), and SchedulingResource::relatedResourceGroupCount().

Here is the call graph for this function:

Member Data Documentation

◆ activeCycle_

int OutputPSocketResource::activeCycle_
mutableprivate

Definition at line 69 of file OutputPSocketResource.hh.

Referenced by canAssign(), and operator<().

◆ storedPorts_

std::map<int, std::pair<const TTAMachine::Port*, int> > OutputPSocketResource::storedPorts_
private

Definition at line 75 of file OutputPSocketResource.hh.

Referenced by assign(), canAssign(), clear(), and unassign().


The documentation for this class was generated from the following files:
TTAProgram::Terminal::isFUPort
virtual bool isFUPort() const
Definition: Terminal.cc:118
SchedulingResource::dependentResourceGroupCount
virtual int dependentResourceGroupCount() const
Definition: SchedulingResource.cc:71
OutputPSocketResource::activeCycle_
int activeCycle_
Definition: OutputPSocketResource.hh:69
TTAProgram::Terminal::index
virtual int index() const
Definition: Terminal.cc:274
PSocketResource::assign
virtual void assign(const int cycle, MoveNode &node) override
Definition: PSocketResource.cc:105
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
MoveNode
Definition: MoveNode.hh:65
SchedulingResource::isOutputFUResource
virtual bool isOutputFUResource() const
PSocketResource::unassign
virtual void unassign(const int cycle, MoveNode &node) override
Definition: PSocketResource.cc:120
SchedulingResource::dependentResourceCount
int dependentResourceCount(const int group) const
TTAProgram::Terminal::isImmediateRegister
virtual bool isImmediateRegister() const
Definition: Terminal.cc:97
SchedulingResource::relatedResource
virtual SchedulingResource & relatedResource(const int group, const int index) const
Definition: SchedulingResource.cc:120
SchedulingResource::isBusResource
virtual bool isBusResource() const
OutputPSocketResource
Definition: OutputPSocketResource.hh:52
SchedulingResource
Definition: SchedulingResource.hh:52
TTAMachine::Port
Definition: Port.hh:54
TTAProgram::Move::guard
MoveGuard & guard() const
Definition: Move.cc:345
OutputPSocketResource::storedPorts_
std::map< int, std::pair< const TTAMachine::Port *, int > > storedPorts_
Definition: OutputPSocketResource.hh:75
TTAProgram::Terminal::isGPR
virtual bool isGPR() const
Definition: Terminal.cc:107
PSocketResource::PSocketResource
PSocketResource(const std::string &name, unsigned int initiationInterval=0)
Definition: PSocketResource.cc:46
SchedulingResource::instructionIndex
int instructionIndex(int cycle) const
PSocketResource::clear
void clear() override
Definition: PSocketResource.cc:171
SchedulingResource::initiationInterval
int initiationInterval() const
Definition: SchedulingResource.cc:385
SchedulingResource::relatedResourceCount
int relatedResourceCount(const int group) const
TTAMachine::Guard::isOpposite
virtual bool isOpposite(const Guard &guard) const =0
SchedulingResource::isIUResource
virtual bool isIUResource() const
MoveNode::move
TTAProgram::Move & move()
TTAProgram::Terminal::equals
virtual bool equals(const Terminal &other) const =0
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
TTAProgram::Terminal::port
virtual const TTAMachine::Port & port() const
Definition: Terminal.cc:378
SchedulingResource::name
virtual const std::string & name() const
TTAProgram::MoveGuard::guard
const TTAMachine::Guard & guard() const
Definition: MoveGuard.cc:86
SchedulingResource::relatedResourceGroupCount
virtual int relatedResourceGroupCount() const
Definition: SchedulingResource.cc:61
PSocketResource::resourceRecord_
ResourceRecordType resourceRecord_
Definition: PSocketResource.hh:63
TTAMachine::Port::parentUnit
Unit * parentUnit() const