OpenASIP  2.0
SchedulingResource.hh
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 SchedulingResource.hh
26  *
27  * Declaration of prototype of Resource Model:
28  * declaration of the SchedulingResource class.
29  *
30  * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 
35 #ifndef TTA_SCHEDULING_RESOURCE_HH
36 #define TTA_SCHEDULING_RESOURCE_HH
37 
38 #include <string>
39 #include <vector>
40 #include <set>
41 
42 #include "Exception.hh"
43 
44 //#define NO_OVERCOMMIT
45 
46 class MoveNode;
47 
48 /**
49  * An interface for scheduling resources of Resource Model
50  * The base class SchedulingResource
51  */
53 public:
54  virtual ~SchedulingResource();
55  SchedulingResource(const std::string& name, const unsigned int ii = 0);
56 
57  virtual bool isInUse(const int cycle) const = 0;
58  virtual bool isAvailable(const int cycle) const = 0;
59  virtual bool canAssign(const int cycle, const MoveNode& node) const = 0;
60  virtual void assign(const int cycle, MoveNode& node) = 0;
61  virtual void unassign(const int cycle, MoveNode& node) = 0;
62 
63  virtual int relatedResourceGroupCount() const;
64  virtual int dependentResourceGroupCount() const;
65  inline int relatedResourceCount(
66  const int group) const;
67  inline int dependentResourceCount(
68  const int group) const;
69  virtual void addToRelatedGroup(
70  const int group,
71  SchedulingResource& resource);
72  virtual void addToDependentGroup(
73  const int group,
74  SchedulingResource& resource);
76  const int group,
77  const int index) const;
79  const int group,
80  const int index) const;
81  virtual bool hasRelatedResource(
82  const SchedulingResource& sResource)const;
83  virtual bool hasDependentResource(
84  const SchedulingResource& sResource)const;
85  virtual const std::string& name() const;
86  virtual int useCount() const;
87  virtual void increaseUseCount();
88  virtual void decreaseUseCount();
89 
90  // Determine if resource is InputPSocketResource
91  virtual bool isInputPSocketResource() const;
92  // Determine if resource is OutputPSocketResource
93  virtual bool isOutputPSocketResource() const;
94  // Determine if resource is OutputPSocketResource
95  virtual bool isShortImmPSocketResource() const;
96  // Determine if resource is InputFUResource
97  virtual bool isInputFUResource() const;
98  // Determine if resource is OutputFUResource
99  virtual bool isOutputFUResource() const;
100  // Determine if resource is ExecutionPipelineResource
101  virtual bool isExecutionPipelineResource() const;
102  // Determine if resource is BusResource
103  virtual bool isBusResource() const;
104  // Determine if resource is SegmentResource
105  virtual bool isSegmentResource() const;
106  // Determine if resource is IUResource
107  virtual bool isIUResource() const;
108  // Determine if resource is ITemplateResource
109  virtual bool isITemplateResource() const;
110 
111  // Get instruction index for resource
112  inline int instructionIndex(int cycle) const;
113 
114  // Set initiation interval for resource
115  void setInitiationInterval(unsigned int ii);
116  int initiationInterval() const;
117 
118  friend class ResourceBroker;
119 
120  virtual bool operator < (const SchedulingResource& other) const;
121  virtual void clear();
122  virtual void setMaxCycle(unsigned int) {};
123 protected:
124  // Tests if all referenced resources in dependent groups are of correct
125  // type
126  virtual bool validateDependentGroups() ;
127  // Tests if all referenced resources in related groups are of correct
128  // type
129  virtual bool validateRelatedGroups() ;
130 
131  // initiation interval used for modulo scheduler
133 
134 private:
135  // A vector type that stores SchedulingResource pointers
136  typedef std::vector<SchedulingResource*> SchedulingResourceVector;
137  // A container storing SchedulingResourceVectors
138  typedef std::vector<SchedulingResourceVector> SchedulingResourceGroup;
139  // Copying forbidden (it is abstract class but anyway)
141  //Assignment forbidden (it is abstract class but anyway)
143 
144  // The related resource group
146  // The dependent resource group
148  // Defines name of the resource
149  std::string name_;
150 
151  typedef std::set<const SchedulingResource*> SchedulingResourceSet;
153 
154  // Counts number of times particular resource was used
156 };
157 
158 /**
159  * Set of scheduling resources.
160  */
162 public:
166  int count() const;
167  SchedulingResource& resource(int index) const;
170  void sort();
171  void clear();
172  bool hasResource(SchedulingResource& res);
173 private:
174  // List for resources.
175  typedef std::vector<SchedulingResource*> ResourceList;
176 
177  struct less_name {
179  return *x < *y;
180  }
181  };
182 
183  // Scheduling resources in the set.
185 };
186 
187 #include "SchedulingResource.icc"
188 
189 #endif
SchedulingResource::~SchedulingResource
virtual ~SchedulingResource()
Definition: SchedulingResource.cc:43
SchedulingResource::relatedResourceGroup_
SchedulingResourceGroup relatedResourceGroup_
Definition: SchedulingResource.hh:145
SchedulingResource::addToDependentGroup
virtual void addToDependentGroup(const int group, SchedulingResource &resource)
Definition: SchedulingResource.cc:101
SchedulingResource::SchedulingResourceVector
std::vector< SchedulingResource * > SchedulingResourceVector
Definition: SchedulingResource.hh:136
SchedulingResource::dependentResourceGroupCount
virtual int dependentResourceGroupCount() const
Definition: SchedulingResource.cc:71
SchedulingResource::clear
virtual void clear()
Definition: SchedulingResource.cc:397
SchedulingResource::validateRelatedGroups
virtual bool validateRelatedGroups()
SchedulingResourceSet::hasResource
bool hasResource(SchedulingResource &res)
Definition: SchedulingResource.cc:297
SchedulingResource::hasDependentResource
virtual bool hasDependentResource(const SchedulingResource &sResource) const
Definition: SchedulingResource.cc:207
SchedulingResource::SchedulingResource
SchedulingResource(const std::string &name, const unsigned int ii=0)
Definition: SchedulingResource.cc:51
SchedulingResource::SchedulingResourceGroup
std::vector< SchedulingResourceVector > SchedulingResourceGroup
Definition: SchedulingResource.hh:138
Exception.hh
SchedulingResource::unassign
virtual void unassign(const int cycle, MoveNode &node)=0
SchedulingResource::isITemplateResource
virtual bool isITemplateResource() const
ResourceBroker
Definition: ResourceBroker.hh:61
MoveNode
Definition: MoveNode.hh:65
SchedulingResource::initiationInterval_
int initiationInterval_
Definition: SchedulingResource.hh:132
SchedulingResource::isOutputFUResource
virtual bool isOutputFUResource() const
SchedulingResource::isInputPSocketResource
virtual bool isInputPSocketResource() const
SchedulingResourceSet::clear
void clear()
Definition: SchedulingResource.cc:336
SchedulingResourceSet
Definition: SchedulingResource.hh:161
SchedulingResourceSet::SchedulingResourceSet
SchedulingResourceSet()
Definition: SchedulingResource.cc:222
SchedulingResource::dependentResource
virtual SchedulingResource & dependentResource(const int group, const int index) const
Definition: SchedulingResource.cc:158
SchedulingResource::dependentResourceCount
int dependentResourceCount(const int group) const
SchedulingResourceSet::~SchedulingResourceSet
~SchedulingResourceSet()
Definition: SchedulingResource.cc:227
SchedulingResource::relatedResource
virtual SchedulingResource & relatedResource(const int group, const int index) const
Definition: SchedulingResource.cc:120
SchedulingResource::assign
virtual void assign(const int cycle, MoveNode &node)=0
SchedulingResource::isBusResource
virtual bool isBusResource() const
SchedulingResource::addToRelatedGroup
virtual void addToRelatedGroup(const int group, SchedulingResource &resource)
Definition: SchedulingResource.cc:82
SchedulingResource::setMaxCycle
virtual void setMaxCycle(unsigned int)
Definition: SchedulingResource.hh:122
SchedulingResource::useCount
virtual int useCount() const
Definition: SchedulingResource.cc:346
SchedulingResource
Definition: SchedulingResource.hh:52
SchedulingResourceSet::operator=
SchedulingResourceSet & operator=(const SchedulingResourceSet &newSet)
Definition: SchedulingResource.cc:315
SchedulingResource::name_
std::string name_
Definition: SchedulingResource.hh:149
SchedulingResource::operator<
virtual bool operator<(const SchedulingResource &other) const
SchedulingResource::isOutputPSocketResource
virtual bool isOutputPSocketResource() const
SchedulingResource::isExecutionPipelineResource
virtual bool isExecutionPipelineResource() const
SchedulingResource::instructionIndex
int instructionIndex(int cycle) const
SchedulingResource::isInUse
virtual bool isInUse(const int cycle) const =0
SchedulingResource::isSegmentResource
virtual bool isSegmentResource() const
SchedulingResource::isInputFUResource
virtual bool isInputFUResource() const
SchedulingResourceSet::less_name
Definition: SchedulingResource.hh:177
SchedulingResource::initiationInterval
int initiationInterval() const
Definition: SchedulingResource.cc:385
SchedulingResource::hasRelatedResource
virtual bool hasRelatedResource(const SchedulingResource &sResource) const
Definition: SchedulingResource.cc:194
SchedulingResource::relatedResourceCount
int relatedResourceCount(const int group) const
SchedulingResource::SchedulingResourceSet
std::set< const SchedulingResource * > SchedulingResourceSet
Definition: SchedulingResource.hh:151
SchedulingResource::isIUResource
virtual bool isIUResource() const
SchedulingResourceSet::ResourceList
std::vector< SchedulingResource * > ResourceList
Definition: SchedulingResource.hh:175
SchedulingResource::setInitiationInterval
void setInitiationInterval(unsigned int ii)
Definition: SchedulingResource.cc:374
SchedulingResource::isAvailable
virtual bool isAvailable(const int cycle) const =0
SchedulingResource::validateDependentGroups
virtual bool validateDependentGroups()
SchedulingResource.icc
SchedulingResourceSet::remove
void remove(SchedulingResource &resource)
Definition: SchedulingResource.cc:279
SchedulingResource::canAssign
virtual bool canAssign(const int cycle, const MoveNode &node) const =0
SchedulingResourceSet::count
int count() const
Definition: SchedulingResource.cc:251
SchedulingResource::operator=
SchedulingResource & operator=(const SchedulingResource &)
SchedulingResourceSet::resources_
ResourceList resources_
Definition: SchedulingResource.hh:184
SchedulingResource::decreaseUseCount
virtual void decreaseUseCount()
Definition: SchedulingResource.cc:364
SchedulingResourceSet::less_name::operator()
bool operator()(SchedulingResource *x, SchedulingResource *y)
Definition: SchedulingResource.hh:178
SchedulingResourceSet::resource
SchedulingResource & resource(int index) const
Definition: SchedulingResource.cc:263
SchedulingResource::name
virtual const std::string & name() const
SchedulingResource::dependentResourceGroup_
SchedulingResourceGroup dependentResourceGroup_
Definition: SchedulingResource.hh:147
SchedulingResource::relatedResourceGroupCount
virtual int relatedResourceGroupCount() const
Definition: SchedulingResource.cc:61
SchedulingResource::useCount_
int useCount_
Definition: SchedulingResource.hh:155
SchedulingResource::isShortImmPSocketResource
virtual bool isShortImmPSocketResource() const
SchedulingResourceSet::insert
void insert(SchedulingResource &resource)
Definition: SchedulingResource.cc:236
SchedulingResource::relatedResourceSet_
SchedulingResourceSet relatedResourceSet_
Definition: SchedulingResource.hh:152
SchedulingResource::increaseUseCount
virtual void increaseUseCount()
Definition: SchedulingResource.cc:355
SchedulingResourceSet::sort
void sort()
Definition: SchedulingResource.cc:328