-
Notifications
You must be signed in to change notification settings - Fork 2
/
ScoreGraphNode.cc
292 lines (246 loc) · 7.54 KB
/
ScoreGraphNode.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 1999 The Regents of the University of California
// Permission to use, copy, modify, and distribute this software and
// its documentation for any purpose, without fee, and without a
// written agreement is hereby granted, provided that the above copyright
// notice and this paragraph and the following two paragraphs appear in
// all copies.
//
// IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
// LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
// EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
// THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
// AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
// PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
//
//////////////////////////////////////////////////////////////////////////////
//
// BRASS source file
//
// SCORE runtime support
// $Revision: 1.29 $
//
//////////////////////////////////////////////////////////////////////////////
#include "ScorePage.h"
#include "ScoreSegment.h"
#include "ScoreStream.h"
#include "ScoreGraphNode.h"
#include "ScoreConfig.h"
ScoreGraphNode::ScoreGraphNode() {
inputs = 0;
outputs = 0;
sim_unstallTime = 0;
sim_unstallTimeIsInfinity = 0;
sched_isDone = 0;
sched_isResident = 0;
sched_isScheduled = 0;
sched_residentLoc = 0;
sched_parentProcess = NULL;
sched_parentCluster = NULL;
sched_parentOperator = NULL;
sched_dependentOnInputBuffer = NULL;
sched_dependentOnOutputBuffer = NULL;
sched_inputConsumption = NULL;
sched_outputProduction = NULL;
sched_inputConsumptionOffset = NULL;
sched_outputProductionOffset = NULL;
sched_lastKnownInputFIFONumTokens = NULL;
sched_expectedInputConsumption = NULL;
sched_expectedOutputProduction = NULL;
sim_runnableNodeListItem = NULL; // no such thing as nil_item
#if 0
sim_stalledNodeQueueItem = nil_item;
#endif
sim_checkNodeListItem = NULL; // nil+item
sched_potentiallyDidNotFireLastResident = 0;
#ifdef RANDOM_SCHEDULER
// this is to indicate that this node was never scheduled before
// the reason, why -1 is not appropriate is that on the first
// timeslice (currentTimeslice == 0), the value -1 (=currentTimeslice-1)
// indicates that this node was scheduled on the previous timeslice
// and thus must be removed from the array (which is not accurate).
sched_lastTimesliceScheduled = (unsigned int)(-2);
#endif
#if GET_FEEDBACK
feedbackNode = 0;
stat_consumption = 0;
stat_production = 0;
stat_fireCount = 0;
#endif
}
ScoreGraphNode::~ScoreGraphNode() {
int i;
for (i = 0; i < inputs; i++) {
SCORE_STREAM currentStream = in[i];
if(errno) {
errno=0;
perror("Crazy mofo");
}
if (currentStream != NULL) {
cout << "Who are you??" << endl;
STREAM_FREE_HW(currentStream);
}
}
for (i = 0; i < outputs; i++) {
SCORE_STREAM currentStream = out[i];
if (currentStream != NULL) {
cout << "And, who are you??" << endl;
STREAM_CLOSE_HW(currentStream);
}
}
delete(in);
delete(out);
delete(sched_in);
delete(sched_out);
delete(in_types);
delete(out_types);
delete(sched_in_types);
delete(sched_out_types);
delete(sched_dependentOnInputBuffer);
delete(sched_dependentOnOutputBuffer);
delete(sched_inputConsumption);
delete(sched_outputProduction);
delete(sched_inputConsumptionOffset);
delete(sched_outputProductionOffset);
delete(sched_lastKnownInputFIFONumTokens);
delete(sched_expectedInputConsumption);
delete(sched_expectedOutputProduction);
#if GET_FEEDBACK
if (stat_consumption)
delete stat_consumption;
if (stat_production)
delete stat_production;
#endif
}
void ScoreGraphNode::recalculateUnstallTime() {
int i;
ScoreIOMaskType currentConsumes = 0;
unsigned long long mostFutureInputTime = 0;
char missingInputs = 0;
if (isPage()) {
ScorePage *currentPage = (ScorePage *) this;
int currentState = currentPage->get_state();
currentConsumes = currentPage->inputs_consumed(currentState);
} else if (isSegment()) {
ScoreSegment *currentSegment = (ScoreSegment *) this;
currentConsumes = currentSegment->sim_segmentInputMask;
}
for (i = 0; i < inputs; i++) {
ScoreStream *currentInput = in[i];
char needInput = (currentConsumes>>i)&1;
if (needInput) {
if (currentInput->stream_data_any()) {
unsigned long long currentHeadTokenTime =
currentInput->stream_head_futuretime();
if (currentHeadTokenTime > mostFutureInputTime) {
mostFutureInputTime = currentHeadTokenTime;
}
} else {
missingInputs = 1;
break;
}
}
}
if (missingInputs) {
sim_unstallTime = 0;
sim_unstallTimeIsInfinity = 1;
} else {
sim_unstallTime = mostFutureInputTime;
sim_unstallTimeIsInfinity = 0;
}
}
char ScoreGraphNode::isStalledOnInput() {
int i;
ScoreIOMaskType currentConsumes = 0;
if (isPage()) {
ScorePage *currentPage = (ScorePage *) this;
int currentState = currentPage->get_state();
currentConsumes = currentPage->inputs_consumed(currentState);
} else if (isSegment()) {
ScoreSegment *currentSegment = (ScoreSegment *) this;
currentConsumes = currentSegment->sim_segmentInputMask;
}
for (i = 0; i < inputs; i++) {
ScoreStream *currentInput = in[i];
char needInput = (currentConsumes>>i)&1;
if (needInput) {
if (!(currentInput->stream_data())) {
return(1);
}
}
}
return(0);
}
void ScoreGraphNode::syncSchedToReal() {
int i;
for (i = 0; i < inputs; i++) {
in[i] = sched_in[i];
in_types[i] = sched_in_types[i];
}
for (i = 0; i < outputs; i++) {
out[i] = sched_out[i];
out_types[i] = sched_out_types[i];
}
}
// required by LEDA for use with lists/etc.
// provides comparison operation between ScoreGraphNodes.
// NOTE: Right now, we only say 2 nodes are equal if their pointers
// are equal. Otherwise, less than/greater than is determined
// simply by their pointer values.
int compare(ScoreGraphNode * const & left, ScoreGraphNode * const & right) {
if (left == right) {
return(0);
} else if (left < right) {
return(-1);
} else {
return(1);
}
}
void ScoreGraphNode::print(FILE *f, bool printShort)
{
static char *node_names[] = {"Page", "Segment", "Stitch", "Operator" };
int node_names_index = -1;
if (_isPage) {
node_names_index = 0;
} else if (_isOperator) {
node_names_index = 3;
} else if (_isSegment) {
ScoreSegment *seg = (ScoreSegment*) this;
if (seg->sched_isStitch) {
node_names_index = 2;
} else {
node_names_index = 1;
}
}
#if GET_FEEDBACK
fprintf(f, "%s %d [%d] %s:\n", node_names[node_names_index],
uniqTag, (long) this,
_isPage ? ((ScorePage*)this)->getSource() : "");
#endif
if (!printShort) {
for (int i = 0; i < getInputs(); i ++) {
fprintf(f, "INPUT%d: ", i);
ScoreGraphNode *src = getSchedInput(i)->src;
if (src) {
src->print(f, true);
} else {
fprintf(f, "NULL\n");
}
}
for (int i = 0; i < getOutputs(); i ++) {
fprintf(f, "OUTPUT%d: ", i);
ScoreGraphNode *sink = getSchedOutput(i)->sink;
if (sink) {
sink->print(f, true);
} else {
fprintf(f, "NULL\n");
}
}
}
}