OpenASIP  2.0
InputFUResource.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 InputFUResource.cc
26  *
27  * Implementation of prototype of Resource Model:
28  * implementation of the InputFUResource.
29  *
30  * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "InputFUResource.hh"
35 #include "FUPort.hh"
36 #include "Application.hh"
37 #include "Exception.hh"
38 #include "MoveNode.hh"
40 #include "ResourceManager.hh"
41 #include "InputPSocketResource.hh"
42 
44 using TTAMachine::FUPort;
45 using TTAMachine::Port;
46 
47 /**
48  * Constructor defining name of resource.
49  *
50  * @param name Name of resource
51  */
53  const std::string& name, int opCount, int nopSlotWeight,
54  unsigned int initiationInterval) :
55  FUResource(name, opCount, nopSlotWeight, initiationInterval) {
56 }
57 
58 /**
59  * Empty destructor
60  */
62 }
63 
64 /**
65  * Not to be used, aborts!
66  *
67  * Use version with third InputPSocket operand!
68  */
69 bool
70 InputFUResource::canAssign(const int, const MoveNode&) const {
71  abortWithError("Wrong method. Use canAssign with PSocket!");
72  return false;
73 }
74 
75 /**
76  * Assign resource to given node for given cycle
77  * as a side effect, assign also execution pipeline for triggering moves.
78  *
79  * @param cycle Cycle to assign
80  * @param node MoveNode assigned
81  * @param pSocket InputPSocket used for writting operand
82  * @throw In case the assignment is impossible, should have been tested
83  * with canAssing first.
84  */
85 void
87  const int cycle,
88  MoveNode& node) {
89 
90  for (int i = 0; i < dependentResourceGroupCount(); i++) {
91  for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
95  dynamic_cast<ExecutionPipelineResource*>(res);
96  epRes->assignDestination(cycle, node);
98  return;
99  }
100  }
101  }
102  abortWithError("InputFUResource has no execution pipeline registered!");
103 }
104 
105 /**
106  * Unassign resource from given node for given cycle,
107  * for triggering moves also unassign execution pipeline.
108  *
109  * @param cycle Cycle to remove assignment from
110  * @param node MoveNode to remove assignment from
111  * @param pSocket InputPSocket used for writting operand
112  * @throw In case PSocket is not connected to FU
113  */
114 void
116  const int cycle,
117  MoveNode& node) {
118 
119  for (int i = 0; i < dependentResourceGroupCount(); i++) {
120  for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
124  dynamic_cast<ExecutionPipelineResource*>(res);
125  epRes->unassignDestination(cycle, node);
127  return;
128  }
129  }
130  }
131  abortWithError("InputFUResource has no execution pipeline registered!");
132 }
133 
134 /**
135  * Return true if resource can be assigned for given node in given cycle.
136  *
137  * @param cycle Cycle to test
138  * @param node MoveNode to test
139  * @param pSocket InputPSocket used for writting operand
140  * @return true if node can be assigned to cycle
141  * @throw Internal error, PSocket is not conencted to FU or ExecutionPipeline
142  */
143 bool
145  const int cycle,
146  const MoveNode& node,
147  const InputPSocketResource& pSocket,
148  const bool triggers) const {
149 
150  if (!hasDependentResource(pSocket)) {
151  std::string msg = "InputPSocket ";
152  msg += pSocket.name();
153  msg += " is not connected to ";
154  msg += name();
155  msg += "!";
156  throw ModuleRunTimeError(__FILE__, __LINE__, __func__, msg);
157  return false;
158  }
159 
160  if (!pSocket.canAssign(cycle, node)) {
161  debugLogRM("cannot assign pSocket");
162  return false;
163  }
164 
165  for (int i = 0; i < dependentResourceGroupCount(); i++) {
166  for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
167  SchedulingResource& depRes = dependentResource(i, j);
168  if (depRes.isExecutionPipelineResource()) {
170  static_cast<ExecutionPipelineResource*>(&depRes);
171  if (!(epRes->canAssignDestination(cycle, node, triggers))) {
172  debugLogRM("cannot assign execution pipeline resource");
173  return false;
174  } else {
175  return true;
176  }
177  }
178  }
179  }
180  debugLogRM("could not find a depedent resource I could assign");
181  return false;
182 }
183 
184 /**
185  * Test if resource InputFUResource is available.
186  *
187  * Not all the PSocket are inUse and there is some operation possible for
188  * triggering moves.
189  *
190  * @param cycle Cycle which to test
191  * @return True if FUResource is available in cycle
192  */
193 bool
194 InputFUResource::isAvailable(const int cycle) const {
195  // Test availability of PSockets using parent class
196  if (!FUResource::isAvailable(cycle)) {
197  return false;
198  }
199  for (int i = 0; i < dependentResourceGroupCount(); i++) {
200  for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
202  dependentResource(i, j).isAvailable(cycle)) {
203  return true;
204  }
205  }
206  }
207  return false;
208 }
209 
210 /**
211  * Test if resource InputFUResource is used in given cycle.
212  *
213  * True if some of InputPSockets are already used or there is
214  * operation already in execution pipeline.
215  *
216  * @param cycle Cycle which to test
217  * @return True if InputFUResource is already used in cycle
218  */
219 bool
220 InputFUResource::isInUse(const int cycle) const {
221  // Test isInUse of PSockets using parent class
222  if (FUResource::isInUse(cycle)) {
223  return true;
224  }
225  for (int i = 0; i < dependentResourceGroupCount(); i++) {
226  for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
228  dependentResource(i, j).isInUse(cycle)) {
229  return true;
230  }
231  }
232  }
233  return false;
234 }
235 
236 /**
237  * Allways return true
238  *
239  * @return true
240  */
241 bool
243  return true;
244 }
245 
246 /**
247  * Tests if all referred resource in dependent groups are of
248  * proper types.
249  *
250  * @return true If all resources in dependent groups are
251  * input or output PSockets or executionPipeline
252  */
253 bool
255  for (int i = 0; i < dependentResourceGroupCount(); i++) {
256  for (int j = 0, count = dependentResourceCount(i); j < count; j++) {
260  return false;
261  }
262  }
263  }
264  return true;
265 }
266 
267 /**
268  * Tests if related resource groups are empty.
269  *
270  * @return true If all related resource groups are
271  * empty
272  */
273 bool
275  for (int i = 0; i < relatedResourceGroupCount(); i++) {
276  if (relatedResourceCount(i) > 0) {
277  return false;
278  }
279  }
280  return true;
281 }
ExecutionPipelineResource
Definition: ExecutionPipelineResource.hh:64
SchedulingResource::dependentResourceGroupCount
virtual int dependentResourceGroupCount() const
Definition: SchedulingResource.cc:71
SchedulingResource::hasDependentResource
virtual bool hasDependentResource(const SchedulingResource &sResource) const
Definition: SchedulingResource.cc:207
InputFUResource::validateRelatedGroups
virtual bool validateRelatedGroups() override
Definition: InputFUResource.cc:274
Exception.hh
TTAMachine::BaseFUPort
Definition: BaseFUPort.hh:44
InputFUResource::InputFUResource
InputFUResource(const std::string &name, int opCount, int nopSlotWeight, unsigned int initiationInterval=0)
Definition: InputFUResource.cc:52
MoveNode
Definition: MoveNode.hh:65
InputFUResource.hh
SchedulingResource::isInputPSocketResource
virtual bool isInputPSocketResource() const
InputFUResource::unassign
virtual void unassign(const int cycle, MoveNode &node) override
Definition: InputFUResource.cc:115
debugLogRM
#define debugLogRM(__X)
Definition: ResourceManager.hh:123
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
TTAMachine::FUPort
Definition: FUPort.hh:46
InputFUResource::isInUse
virtual bool isInUse(const int cycle) const override
Definition: InputFUResource.cc:220
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
ExecutionPipelineResource::unassignDestination
virtual void unassignDestination(const int cycle, MoveNode &node)
Definition: ExecutionPipelineResource.cc:676
SchedulingResource
Definition: SchedulingResource.hh:52
TTAMachine::Port
Definition: Port.hh:54
InputPSocketResource.hh
Application.hh
__func__
#define __func__
Definition: Application.hh:67
InputFUResource::assign
virtual void assign(const int cycle, MoveNode &node) override
Definition: InputFUResource.cc:86
FUResource
Definition: FUResource.hh:46
SchedulingResource::isOutputPSocketResource
virtual bool isOutputPSocketResource() const
SchedulingResource::isExecutionPipelineResource
virtual bool isExecutionPipelineResource() const
SchedulingResource::isInUse
virtual bool isInUse(const int cycle) const =0
InputFUResource::validateDependentGroups
virtual bool validateDependentGroups() override
Definition: InputFUResource.cc:254
ModuleRunTimeError
Definition: Exception.hh:1043
SchedulingResource::relatedResourceCount
int relatedResourceCount(const int group) const
SchedulingResource::isAvailable
virtual bool isAvailable(const int cycle) const =0
ExecutionPipelineResource::canAssignDestination
virtual bool canAssignDestination(const int cycle, const MoveNode &node, const bool triggering=false) const
Definition: ExecutionPipelineResource.cc:990
ExecutionPipelineResource.hh
InputPSocketResource::canAssign
virtual bool canAssign(const int cycle, const MoveNode &node) const override
Definition: InputPSocketResource.cc:102
InputFUResource::~InputFUResource
virtual ~InputFUResource()
Definition: InputFUResource.cc:61
FUPort.hh
SchedulingResource::decreaseUseCount
virtual void decreaseUseCount()
Definition: SchedulingResource.cc:364
ExecutionPipelineResource::assignDestination
virtual void assignDestination(const int cycle, MoveNode &node)
Definition: ExecutionPipelineResource.cc:487
SchedulingResource::name
virtual const std::string & name() const
SchedulingResource::relatedResourceGroupCount
virtual int relatedResourceGroupCount() const
Definition: SchedulingResource.cc:61
MoveNode.hh
InputFUResource::isInputFUResource
virtual bool isInputFUResource() const override
Definition: InputFUResource.cc:242
FUResource::isInUse
virtual bool isInUse(const int cycle) const override
Definition: FUResource.cc:62
InputFUResource::canAssign
virtual bool canAssign(const int cycle, const MoveNode &node) const override
Definition: InputFUResource.cc:70
ResourceManager.hh
SchedulingResource::increaseUseCount
virtual void increaseUseCount()
Definition: SchedulingResource.cc:355
InputFUResource::isAvailable
virtual bool isAvailable(const int cycle) const override
Definition: InputFUResource.cc:194
FUResource::isAvailable
virtual bool isAvailable(const int cycle) const override
Definition: FUResource.cc:80