OpenASIP  2.0
FUResource.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 FUResource.cc
26  *
27  * Implementation of prototype of Resource Model:
28  * implementation of the abstract FUResource.
29  *
30  * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "FUResource.hh"
35 #include "Application.hh"
36 #include "Conversion.hh"
37 #include "InputPSocketResource.hh"
38 
39 /**
40  * Constructor defining resource name
41  * @param name Name of resource
42  */
43 FUResource::FUResource(const std::string& name, int opCount,
44  int nopSlotWeight, unsigned int initiationInterval) :
45  SchedulingResource(name, initiationInterval) , opCount_(opCount),
46  nopSlotWeight_(nopSlotWeight) {
47 }
48 
49 /**
50  * Empty destructor
51  */
53 
54 /**
55  * Test if resource FUResource is used in given cycle, meaning
56  * InputPSocket or OutputPSocket is in use or ExecutionPipeline
57  * is inUse.
58  * @param cycle Cycle which to test
59  * @return True if FUResource is already used in cycle
60  */
61 bool
62 FUResource::isInUse(const int cycle) const {
63  for (int i = 0; i < dependentResourceGroupCount(); i++) {
64  for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
65  if (dependentResource(i, j).isInUse(cycle)) {
66  return true;
67  }
68  }
69  }
70  return false;
71 }
72 
73 /**
74  * Test if resource FUResource is available.
75  * Not all of the PSocket are inUse.
76  * @param cycle Cycle which to test
77  * @return True if FUResource is available in cycle
78  */
79 bool
80 FUResource::isAvailable(const int cycle) const {
81  for (int i = 0; i < dependentResourceGroupCount(); i++) {
82  for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
85  if (dependentResource(i, j).isAvailable(cycle)) {
86  return true;
87  }
88  }
89  }
90  }
91  return false;
92 }
93 
94 /**
95  * Assign resource to given node for given cycle
96  * @param cycle Cycle to assign
97  * @param node MoveNode assigned
98  */
99 void
101 
102  // Implemented in derived classes
103  abortWithError("assign of FUResource called!");
104 }
105 
106 /**
107  * Unassign resource from given node for given cycle
108  * @param cycle Cycle to remove assignment from
109  * @param node MoveNode to remove assignment from
110  */
111 void
113 
114  // Implemented in derived classes
115  abortWithError("unassign of FUResource called!");
116 }
117 
118 /**
119  * Return true if resource can be assigned for given resource in given cycle
120  * @param cycle Cycle to test
121  * @param node MoveNode to test
122  * @return true if node can be assigned to cycle
123  */
124 bool
125 FUResource::canAssign(const int, const MoveNode&) const {
126  // Implemented in derived classes
127  abortWithError("canAssign of FUResource called!");
128  return false;
129 }
130 
131 /**
132  * Comparison operator.
133  *
134  * Favours least used FU's and FU's with less operations.
135  */
136 bool
138 
139  const FUResource *fur = static_cast<const FUResource*>(&other);
140  if (fur == NULL) {
141  return false;
142  }
143 
144  if (nopSlotWeight_ < fur->nopSlotWeight_) {
145  return true;
146  }
147 
148  if (nopSlotWeight_ > fur->nopSlotWeight_) {
149  return false;
150  }
151 
152  if (opCount_ < fur->opCount_) {
153  return true;
154  }
155  if (opCount_ > fur->opCount_) {
156  return false;
157  }
158 
159  // favours FU's with connections to less busses.
160  int connCount = 0;
161  int connCount2 = 0;
162 
163  // count the connections.
164  for (int i = 0; i < dependentResourceCount(0); i++) {
166  if (dynamic_cast<InputPSocketResource*>(&r)) {
167  connCount += r.relatedResourceCount(1);
168  } else {
169  connCount += r.relatedResourceCount(2);
170  }
171  }
172 
173  for (int i = 0; i < other.dependentResourceCount(0); i++) {
174  SchedulingResource& r = other.dependentResource(0,i);
175  if (dynamic_cast<InputPSocketResource*>(&r)) {
176  connCount2 += r.relatedResourceCount(1);
177  } else {
178  connCount2 += r.relatedResourceCount(2);
179  }
180  }
181 
182  if (connCount < connCount2) {
183  return true;
184  }
185  if (connCount > connCount2) {
186  return false;
187  }
188 
189  // then use count
190  if (useCount() < other.useCount()) {
191  return true;
192  }
193  if (useCount() > other.useCount()) {
194  return false;
195  }
196 
197  return name() < other.name();
198 }
SchedulingResource::dependentResourceGroupCount
virtual int dependentResourceGroupCount() const
Definition: SchedulingResource.cc:71
FUResource::unassign
virtual void unassign(const int cycle, MoveNode &node) override
Definition: FUResource.cc:112
MoveNode
Definition: MoveNode.hh:65
SchedulingResource::isInputPSocketResource
virtual bool isInputPSocketResource() const
FUResource::~FUResource
virtual ~FUResource()
Definition: FUResource.cc:52
FUResource::assign
virtual void assign(const int cycle, MoveNode &node) override
Definition: FUResource.cc:100
SchedulingResource::dependentResource
virtual SchedulingResource & dependentResource(const int group, const int index) const
Definition: SchedulingResource.cc:158
SchedulingResource::dependentResourceCount
int dependentResourceCount(const int group) const
InputPSocketResource
Definition: InputPSocketResource.hh:47
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
SchedulingResource::useCount
virtual int useCount() const
Definition: SchedulingResource.cc:346
SchedulingResource
Definition: SchedulingResource.hh:52
Conversion.hh
InputPSocketResource.hh
Application.hh
FUResource
Definition: FUResource.hh:46
FUResource::opCount_
int opCount_
Definition: FUResource.hh:65
FUResource::canAssign
virtual bool canAssign(const int cycle, const MoveNode &node) const override
Definition: FUResource.cc:125
FUResource::operator<
virtual bool operator<(const SchedulingResource &other) const override
Definition: FUResource.cc:137
SchedulingResource::isOutputPSocketResource
virtual bool isOutputPSocketResource() const
SchedulingResource::isInUse
virtual bool isInUse(const int cycle) const =0
FUResource::FUResource
FUResource(const std::string &name, int operationCount, int nopSlotWeight, unsigned int initiationInterval=0)
Definition: FUResource.cc:43
SchedulingResource::relatedResourceCount
int relatedResourceCount(const int group) const
SchedulingResource::isAvailable
virtual bool isAvailable(const int cycle) const =0
FUResource.hh
SchedulingResource::name
virtual const std::string & name() const
FUResource::isInUse
virtual bool isInUse(const int cycle) const override
Definition: FUResource.cc:62
FUResource::nopSlotWeight_
int nopSlotWeight_
Definition: FUResource.hh:66
FUResource::isAvailable
virtual bool isAvailable(const int cycle) const override
Definition: FUResource.cc:80