OpenASIP  2.0
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
ResourceBroker Class Referenceabstract

#include <ResourceBroker.hh>

Inheritance diagram for ResourceBroker:
Inheritance graph
Collaboration diagram for ResourceBroker:
Collaboration graph

Public Types

typedef std::set< SchedulingResource * > ResourceSet
 

Public Member Functions

 ResourceBroker (std::string, unsigned int initiationInterval=0)
 
virtual ~ResourceBroker ()
 
virtual bool isAnyResourceAvailable (int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const
 
virtual SchedulingResourceavailableResource (int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const
 
virtual SchedulingResourceSet allAvailableResources (int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const
 
virtual bool isAvailable (SchedulingResource &des, const MoveNode &node, int cycle, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const
 
virtual int earliestCycle (int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const =0
 
virtual int latestCycle (int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const =0
 
virtual bool isAlreadyAssigned (int cycle, const MoveNode &node, const TTAMachine::Bus *preassignedBus) const =0
 
virtual bool isApplicable (const MoveNode &node, const TTAMachine::Bus *preassignedBus) const =0
 
virtual void assign (int cycle, MoveNode &node, SchedulingResource &res, int immWriteCycle, int immRegIndex)=0
 
virtual void unassign (MoveNode &node)=0
 
virtual void buildResources (const TTAMachine::Machine &target)=0
 
virtual void setupResourceLinks (const ResourceMapper &mapper)=0
 
SchedulingResourceresourceOf (const TTAMachine::MachinePart &mp) const
 
virtual const TTAMachine::MachinePartmachinePartOf (const SchedulingResource &r) const
 
bool hasResourceOf (const TTAMachine::MachinePart &mp) const
 
bool hasResource (const SchedulingResource &r) const
 
int resourceCount () const
 
virtual bool isBusBroker () const
 
virtual bool isITemplateBroker () const
 
virtual bool isIUBroker () const
 
virtual bool isExecutionPipelineBroker () const
 
void validateResources () const
 
virtual std::string brokerName () const
 
void resources (ResourceSet &contents)
 
virtual void setInitiationInterval (unsigned int cycles)
 
virtual void clear ()
 
virtual void setMaxCycle (unsigned int)
 

Protected Types

typedef std::map< const TTAMachine::MachinePart *, SchedulingResource *, TTAMachine::MachinePart::ComparatorResourceMap
 
typedef std::map< const MoveNode *, SchedulingResource *, MoveNode::ComparatorMoveResMap
 

Protected Member Functions

void setResourceMapper (const ResourceMapper &mapper)
 
const ResourceMapperresourceMapper () const
 
unsigned int instructionIndex (unsigned int) const
 
void addResource (const TTAMachine::MachinePart &mp, SchedulingResource *res)
 

Protected Attributes

unsigned int initiationInterval_
 
ResourceMap resMap_
 
const ResourceMapperresourceMapper_
 
MoveResMap assignedResources_
 
std::string brokerName_
 

Detailed Description

Base interface for resource brokers.

Definition at line 61 of file ResourceBroker.hh.

Member Typedef Documentation

◆ MoveResMap

Definition at line 154 of file ResourceBroker.hh.

◆ ResourceMap

Definition at line 147 of file ResourceBroker.hh.

◆ ResourceSet

Definition at line 66 of file ResourceBroker.hh.

Constructor & Destructor Documentation

◆ ResourceBroker()

ResourceBroker::ResourceBroker ( std::string  name,
unsigned int  initiationInterval = 0 
)

Constructor.

Definition at line 49 of file ResourceBroker.cc.

50  :
51  initiationInterval_(initiationInterval),
52  resourceMapper_(NULL),
53  brokerName_(name){
54 }

◆ ~ResourceBroker()

ResourceBroker::~ResourceBroker ( )
virtual

Destructor.

Definition at line 59 of file ResourceBroker.cc.

59  {
61 }

References MapTools::deleteAllValues(), and resMap_.

Here is the call graph for this function:

Member Function Documentation

◆ addResource()

void ResourceBroker::addResource ( const TTAMachine::MachinePart mp,
SchedulingResource res 
)
protected

Add resource - machine part pair to the broker.

Parameters
mpMachine part.
resCorresponding resource.

Definition at line 265 of file ResourceBroker.cc.

267  {
268 
269  resMap_.insert(
270  pair<const TTAMachine::MachinePart*, SchedulingResource*>(&mp, res));
271 }

References resMap_.

Referenced by ExecutionPipelineBroker::buildResources(), OutputFUBroker::buildResources(), InputPSocketBroker::buildResources(), InputFUBroker::buildResources(), OutputPSocketBroker::buildResources(), ITemplateBroker::buildResources(), IUBroker::buildResources(), and BusBroker::buildResources().

◆ allAvailableResources()

SchedulingResourceSet ResourceBroker::allAvailableResources ( int  cycle,
const MoveNode node,
const TTAMachine::Bus bus,
const TTAMachine::FunctionUnit srcFU,
const TTAMachine::FunctionUnit dstFU,
int  immWriteCycle,
const TTAMachine::ImmediateUnit immu,
int  immRegIndex 
) const
virtual

Return all resources managed by this broker that can be assigned to the given node in the given cycle.

Returns
All resources managed by this broker that can be assigned to the given node in the given cycle.
Parameters
cycleCycle.
nodeNode.
Note
This default implementation always returns an empty set.

Reimplemented in ITemplateBroker, IUBroker, BusBroker, OutputPSocketBroker, InputFUBroker, InputPSocketBroker, and OutputFUBroker.

Definition at line 143 of file ResourceBroker.cc.

149  {
150  SchedulingResourceSet resourceSet;
151  return resourceSet;
152 }

Referenced by PendingAssignment::isAssignmentPossible(), and isAvailable().

◆ assign()

virtual void ResourceBroker::assign ( int  cycle,
MoveNode node,
SchedulingResource res,
int  immWriteCycle,
int  immRegIndex 
)
pure virtual

◆ availableResource()

SchedulingResource & ResourceBroker::availableResource ( int  cycle,
const MoveNode node,
const TTAMachine::Bus bus,
const TTAMachine::FunctionUnit srcFU,
const TTAMachine::FunctionUnit dstFU,
int  immWriteCycle,
const TTAMachine::ImmediateUnit immu,
int  immRegIndex 
) const
virtual

Return one (any) resource managed by this broker that can be assigned to the given node in the given cycle.

If no change occurs to the state of the resources, the broker should always return the same object. If a resource of the type managed by this broker is already assigned to the node, it is returned.

Parameters
cycleCycle.
nodeNode.
Returns
One (any) resource managed by this broker that can be assigned to the given node in the given cycle.
Exceptions
InstanceNotFoundIf no available resource is found.

Reimplemented in BusBroker, and IUBroker.

Definition at line 111 of file ResourceBroker.cc.

116  {
117 
118  for (ResourceMap::const_iterator resIter = resMap_.begin();
119  resIter != resMap_.end(); resIter++) {
120 
121  SchedulingResource* res = (*resIter).second;
122  if (res->isAvailable(cycle)
123  && res->canAssign(cycle, node)) {
124  return *res;
125  }
126  }
127 
128  string msg = "No available resource found.";
129  throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
130 }

References __func__, SchedulingResource::canAssign(), SchedulingResource::isAvailable(), and resMap_.

Here is the call graph for this function:

◆ brokerName()

std::string ResourceBroker::brokerName ( ) const
virtual

Returns the name of particular broker. Used for debugging mainly.

Returns
Name of a broker.

Definition at line 356 of file ResourceBroker.cc.

356  {
357  return brokerName_;
358 }

References brokerName_.

Referenced by validateResources().

◆ buildResources()

virtual void ResourceBroker::buildResources ( const TTAMachine::Machine target)
pure virtual

◆ clear()

void ResourceBroker::clear ( )
virtual

Clears all resources managed by the broker so that the broker can be reused.

Reimplemented in BusBroker, and ITemplateBroker.

Definition at line 365 of file ResourceBroker.cc.

365  {
366  // Call clear for all resources.
367  for (ResourceMap::iterator i = resMap_.begin(); i != resMap_.end(); i++) {
368  i->second->clear();
369  }
370  assignedResources_.clear();
371 }

References assignedResources_, and resMap_.

Referenced by ITemplateBroker::clear(), and BusBroker::clear().

◆ earliestCycle()

virtual int ResourceBroker::earliestCycle ( int  cycle,
const MoveNode node,
const TTAMachine::Bus bus,
const TTAMachine::FunctionUnit srcFU,
const TTAMachine::FunctionUnit dstFU,
int  immWriteCycle,
const TTAMachine::ImmediateUnit immu,
int  immRegIndex 
) const
pure virtual

◆ hasResource()

bool ResourceBroker::hasResource ( const SchedulingResource r) const

Return true if this broker holds given resource instance.

Parameters
rScheduling resource.
Returns
True if this broker holds given resource instance.

Definition at line 214 of file ResourceBroker.cc.

214  {
215  return MapTools::containsValue(resMap_, &r);
216 }

References MapTools::containsValue(), and resMap_.

Referenced by OutputFUBroker::assign(), InputPSocketBroker::assign(), OutputPSocketBroker::assign(), InputFUBroker::assign(), IUBroker::assign(), and BusBroker::assign().

Here is the call graph for this function:

◆ hasResourceOf()

bool ResourceBroker::hasResourceOf ( const TTAMachine::MachinePart mp) const

Return true if this broker holds a resource instance that models given machine part.

Parameters
mpMachine part.
Returns
True if this broker holds a resource instance that models given machine part.

Definition at line 203 of file ResourceBroker.cc.

203  {
204  return MapTools::containsKey(resMap_, &mp);
205 }

References MapTools::containsKey(), and resMap_.

Referenced by FUBroker::findDstFUOfMove(), FUBroker::findFUOfPO(), OutputFUBroker::isAlreadyAssigned(), InputFUBroker::isAlreadyAssigned(), and BusBroker::isInUse().

Here is the call graph for this function:

◆ instructionIndex()

unsigned int ResourceBroker::instructionIndex ( unsigned int  cycle) const
protected

◆ isAlreadyAssigned()

virtual bool ResourceBroker::isAlreadyAssigned ( int  cycle,
const MoveNode node,
const TTAMachine::Bus preassignedBus 
) const
pure virtual

◆ isAnyResourceAvailable()

bool ResourceBroker::isAnyResourceAvailable ( int  cycle,
const MoveNode node,
const TTAMachine::Bus bus,
const TTAMachine::FunctionUnit srcFU,
const TTAMachine::FunctionUnit dstFU,
int  immWriteCycle,
const TTAMachine::ImmediateUnit immu,
int  immRegIndex 
) const
virtual

Return true if one of the resources managed by this broker is suitable for the request contained in the node and can be assigned to it in given cycle.

Parameters
cycleCycle.
nodeNode.
Returns
True if one of the resources managed by this broker is suitable for the request contained in the node and can be assigned to it in given cycle.

Reimplemented in ITemplateBroker, IUBroker, BusBroker, and OutputPSocketBroker.

Definition at line 75 of file ResourceBroker.cc.

80  {
81 
82  for (ResourceMap::const_iterator resIter = resMap_.begin();
83  resIter != resMap_.end(); resIter++) {
84 
85  // IUBroker overrides this so no need for immu check
86  const SchedulingResource* res = (*resIter).second;
87  if (res->isAvailable(cycle) && res->canAssign(cycle, node)) {
88  return true;
89  }
90  }
91 
92  return false;
93 }

References SchedulingResource::canAssign(), SchedulingResource::isAvailable(), and resMap_.

Here is the call graph for this function:

◆ isApplicable()

virtual bool ResourceBroker::isApplicable ( const MoveNode node,
const TTAMachine::Bus preassignedBus 
) const
pure virtual

◆ isAvailable()

bool ResourceBroker::isAvailable ( SchedulingResource res,
const MoveNode node,
int  cycle,
const TTAMachine::Bus bus,
const TTAMachine::FunctionUnit srcFU,
const TTAMachine::FunctionUnit dstFU,
int  immWriteCycle,
const TTAMachine::ImmediateUnit immu,
int  immRegIndex 
) const
virtual

Tells whether the given resource is available for given node at given cycle.

Reimplemented in BusBroker.

Definition at line 158 of file ResourceBroker.cc.

165  {
167  allAvailableResources(cycle, node, bus, srcFU, dstFU,
168  immWriteCycle, immu, immRegIndex);
169  return resources.hasResource(res);
170 }

References allAvailableResources(), and resources().

Here is the call graph for this function:

◆ isBusBroker()

bool ResourceBroker::isBusBroker ( ) const
virtual

Reimplemented in BusBroker.

Definition at line 303 of file ResourceBroker.cc.

303  {
304  return false;
305 }

Referenced by SimpleBrokerDirector::busBroker().

◆ isExecutionPipelineBroker()

bool ResourceBroker::isExecutionPipelineBroker ( ) const
virtual

Reimplemented in ExecutionPipelineBroker.

Definition at line 318 of file ResourceBroker.cc.

318  {
319  return false;
320 }

Referenced by SimpleBrokerDirector::executionPipelineBroker().

◆ isITemplateBroker()

bool ResourceBroker::isITemplateBroker ( ) const
virtual

Reimplemented in ITemplateBroker.

Definition at line 308 of file ResourceBroker.cc.

308  {
309  return false;
310 }

Referenced by SimpleBrokerDirector::instructionTemplateBroker().

◆ isIUBroker()

bool ResourceBroker::isIUBroker ( ) const
virtual

Reimplemented in IUBroker.

Definition at line 313 of file ResourceBroker.cc.

313  {
314  return false;
315 }

Referenced by SimpleBrokerDirector::immediateUnitBroker().

◆ latestCycle()

virtual int ResourceBroker::latestCycle ( int  cycle,
const MoveNode node,
const TTAMachine::Bus bus,
const TTAMachine::FunctionUnit srcFU,
const TTAMachine::FunctionUnit dstFU,
int  immWriteCycle,
const TTAMachine::ImmediateUnit immu,
int  immRegIndex 
) const
pure virtual

◆ machinePartOf()

const TTAMachine::MachinePart & ResourceBroker::machinePartOf ( const SchedulingResource r) const
virtual

Return the machine part that models the given resource.

Parameters
rScheduling resource.
Returns
The machine part that models the given resource.
Exceptions
KeyNotFoundIf no corresponding machine part is found or r is not one of the primary resources of this broker.

Definition at line 181 of file ResourceBroker.cc.

181  {
182  const TTAMachine::MachinePart* machinePart = NULL;
183  try {
184  machinePart = MapTools::keyForValue<const MachinePart*>(resMap_, &r);
185  } catch (const Exception& e) {
186  string msg = "Machine part of for resource ";
187  msg += r.name();
188  msg += " not found!";
189  throw KeyNotFound(__FILE__, __LINE__, __func__, msg);
190  }
191  return *machinePart;
192 }

References __func__, SchedulingResource::name(), and resMap_.

Referenced by IUBroker::allAvailableResources(), BusBroker::allAvailableResources(), OutputFUBroker::assign(), InputPSocketBroker::assign(), OutputPSocketBroker::assign(), ITemplateBroker::assign(), InputFUBroker::assign(), IUBroker::assign(), BusBroker::assign(), ITemplateBroker::assignImmediate(), BusBroker::hasGuard(), ITemplateBroker::instruction(), BusBroker::isAvailable(), ITemplateBroker::reselectTemplate(), and OutputFUBroker::unassign().

Here is the call graph for this function:

◆ resourceCount()

int ResourceBroker::resourceCount ( ) const

Definition at line 298 of file ResourceBroker.cc.

298  {
299  return resMap_.size();
300 }

References resMap_.

◆ resourceMapper()

const ResourceMapper & ResourceBroker::resourceMapper ( ) const
protected

Return the resource mapper set for this broker.

Returns
The resource mapper set for this broker.

Definition at line 234 of file ResourceBroker.cc.

234  {
235  return *resourceMapper_;
236 }

References resourceMapper_.

Referenced by InputFUBroker::allAvailableResources().

◆ resourceOf()

SchedulingResource* ResourceBroker::resourceOf ( const TTAMachine::MachinePart mp) const
inline

◆ resources()

void ResourceBroker::resources ( ResourceSet contents)

Get resources

Parameters
contentsSet to which resources are copied to.

Definition at line 279 of file ResourceBroker.cc.

279  {
280  for (ResourceMap::iterator i = resMap_.begin(); i != resMap_.end(); ++i ) {
281  contents.insert(i->second);
282  }
283 }

References resMap_.

Referenced by ITemplateBroker::assignImmediate(), isAvailable(), and ITemplateBroker::reselectTemplate().

◆ setInitiationInterval()

void ResourceBroker::setInitiationInterval ( unsigned int  ii)
virtual

Set initiation interval, if ii = 0 then initiation interval is not used.

Parameters
iiinitiation interval

Reimplemented in ExecutionPipelineBroker.

Definition at line 292 of file ResourceBroker.cc.

293 {
294  initiationInterval_ = ii;
295 }

References initiationInterval_.

Referenced by ExecutionPipelineBroker::ExecutionPipelineBroker().

◆ setMaxCycle()

virtual void ResourceBroker::setMaxCycle ( unsigned int  )
inlinevirtual

Reimplemented in ExecutionPipelineBroker.

Definition at line 147 of file ResourceBroker.hh.

147 {};

◆ setResourceMapper()

void ResourceBroker::setResourceMapper ( const ResourceMapper mapper)
protected

◆ setupResourceLinks()

virtual void ResourceBroker::setupResourceLinks ( const ResourceMapper mapper)
pure virtual

◆ unassign()

virtual void ResourceBroker::unassign ( MoveNode node)
pure virtual

◆ validateResources()

void ResourceBroker::validateResources ( ) const

Tests if is each resource has correct related and dependent groups.

Exceptions
ModuleRunTimeErrorin case resource does not have correct related or dependent resources.

Definition at line 329 of file ResourceBroker.cc.

329  {
330  ResourceMap::const_iterator itr = resMap_.begin();
331  while (itr != resMap_.end()) {
332  if (!(*itr).second->validateDependentGroups()) {
333  std::string msg = (boost::format(
334  "Broker '%s' failed to validate DependentGroup for '%s'!") %
335  brokerName() % (*itr).second->name()).str();
336  throw ModuleRunTimeError(__FILE__, __LINE__, __func__, msg);
337  }
338  if (!(*itr).second->validateRelatedGroups()){
339  std::string msg = (boost::format(
340  "Broker '%s' failed to validate RelatedGroup for '%s'!") %
341  brokerName() % (*itr).second->name()).str();
342  throw ModuleRunTimeError(__FILE__, __LINE__, __func__, msg);
343  }
344  ++itr;
345  }
346  return;
347 }

References __func__, brokerName(), and resMap_.

Here is the call graph for this function:

Member Data Documentation

◆ assignedResources_

MoveResMap ResourceBroker::assignedResources_
protected

◆ brokerName_

std::string ResourceBroker::brokerName_
protected

Definition at line 168 of file ResourceBroker.hh.

Referenced by brokerName().

◆ initiationInterval_

unsigned int ResourceBroker::initiationInterval_
protected

◆ resMap_

ResourceMap ResourceBroker::resMap_
protected

◆ resourceMapper_

const ResourceMapper* ResourceBroker::resourceMapper_
protected

Definition at line 166 of file ResourceBroker.hh.

Referenced by resourceMapper(), and setResourceMapper().


The documentation for this class was generated from the following files:
ResourceBroker::allAvailableResources
virtual SchedulingResourceSet allAvailableResources(int cycle, const MoveNode &node, const TTAMachine::Bus *bus, const TTAMachine::FunctionUnit *srcFU, const TTAMachine::FunctionUnit *dstFU, int immWriteCycle, const TTAMachine::ImmediateUnit *immu, int immRegIndex) const
Definition: ResourceBroker.cc:143
ResourceBroker::initiationInterval_
unsigned int initiationInterval_
Definition: ResourceBroker.hh:158
ResourceBroker::resMap_
ResourceMap resMap_
Definition: ResourceBroker.hh:165
MapTools::deleteAllValues
static void deleteAllValues(MapType &aMap)
ResourceBroker::assignedResources_
MoveResMap assignedResources_
Definition: ResourceBroker.hh:167
ResourceBroker::brokerName
virtual std::string brokerName() const
Definition: ResourceBroker.cc:356
SchedulingResourceSet
Definition: SchedulingResource.hh:161
ResourceBroker::resources
void resources(ResourceSet &contents)
Definition: ResourceBroker.cc:279
SchedulingResource
Definition: SchedulingResource.hh:52
__func__
#define __func__
Definition: Application.hh:67
TTAMachine::MachinePart
Definition: MachinePart.hh:57
Exception
Definition: Exception.hh:54
ModuleRunTimeError
Definition: Exception.hh:1043
SchedulingResource::isAvailable
virtual bool isAvailable(const int cycle) const =0
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
SchedulingResource::canAssign
virtual bool canAssign(const int cycle, const MoveNode &node) const =0
MapTools::containsValue
static bool containsValue(const MapType &aMap, const ValueType &aValue)
KeyNotFound
Definition: Exception.hh:285
SchedulingResource::name
virtual const std::string & name() const
ResourceBroker::resourceMapper_
const ResourceMapper * resourceMapper_
Definition: ResourceBroker.hh:166
InstanceNotFound
Definition: Exception.hh:304
ResourceBroker::brokerName_
std::string brokerName_
Definition: ResourceBroker.hh:168