OpenASIP 2.2
Loading...
Searching...
No Matches
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"
38
39/**
40 * Constructor defining resource name
41 * @param name Name of resource
42 */
43FUResource::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 */
61bool
62FUResource::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 */
79bool
80FUResource::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 */
99void
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 */
111void
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 */
124bool
125FUResource::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 */
136bool
137FUResource::operator< (const SchedulingResource& other) const {
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++) {
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}
#define abortWithError(message)
virtual bool canAssign(const int cycle, const MoveNode &node) const override
virtual bool isAvailable(const int cycle) const override
Definition FUResource.cc:80
virtual bool isInUse(const int cycle) const override
Definition FUResource.cc:62
virtual void assign(const int cycle, MoveNode &node) override
virtual ~FUResource()
Definition FUResource.cc:52
virtual bool operator<(const SchedulingResource &other) const override
virtual void unassign(const int cycle, MoveNode &node) override
int nopSlotWeight_
Definition FUResource.hh:66
FUResource(const std::string &name, int operationCount, int nopSlotWeight, unsigned int initiationInterval=0)
Definition FUResource.cc:43
int relatedResourceCount(const int group) const
virtual SchedulingResource & dependentResource(const int group, const int index) const
virtual bool isInputPSocketResource() const
virtual const std::string & name() const
virtual bool isOutputPSocketResource() const
int dependentResourceCount(const int group) const
virtual bool isAvailable(const int cycle) const =0
virtual int useCount() const
virtual int dependentResourceGroupCount() const
virtual bool isInUse(const int cycle) const =0