-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathScoreGraphNode.h
452 lines (388 loc) · 14.2 KB
/
ScoreGraphNode.h
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
//////////////////////////////////////////////////////////////////////////////
//
// 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.35 $
//
//////////////////////////////////////////////////////////////////////////////
#ifndef _ScoreGraphNode_H
#define _ScoreGraphNode_H
#include "LEDA/graph/graph.h"
#include "LEDA/core/list.h"
#include "ScoreStreamType.h"
#include "ScoreStream.h"
#include <assert.h>
using leda::node;
using leda::list_item;
#if GET_FEEDBACK
class ScoreFeedbackGraphNode;
#endif
typedef enum {
ScoreGraphNodeTag,
ScoreOperatorTag,
ScorePageTag,
ScoreProcessorNodeTag,
ScoreSegmentTag,
ScoreSegmentStitchTag
} NodeTags;
// the definition of the type for the mask of IOs produced or consumed
typedef unsigned long long ScoreIOMaskType;
// prototypes to avoid circular includes.
class ScoreProcess;
class ScoreCluster;
class ScoreOperatorInstance;
class ScoreGraphNode {
public:
ScoreGraphNode();
virtual ~ScoreGraphNode();
int getInputs() {return(inputs);}
int getOutputs() {return(outputs);}
SCORE_STREAM getInput(int which) { return(in[which]); }
SCORE_STREAM getOutput(int which) { return(out[which]); }
SCORE_STREAM getSchedInput(int which) { return(sched_in[which]); }
SCORE_STREAM getSchedOutput(int which) { return(sched_out[which]); }
ScoreStreamType *inputType(int which) { return(in_types[which]); }
ScoreStreamType *outputType(int which) { return(out_types[which]); }
ScoreStreamType *schedInputType(int which) { return(sched_in_types[which]); }
ScoreStreamType *schedOutputType(int which) { return(sched_out_types[which]); }
// added by Nachiket on 1/20/2010 to store name of operator..
char* getName() {
return name;
}
void declareIO(int new_inputs, int new_outputs, char* base=NULL) {
// name added by Nachiket on 1/20/2010
/*
if(base!=NULL) {
name=(char *)malloc(strlen(base));
sprintf(name,"%s",base);
//memcpy(name,base,strlen(base));
} else {
//name=NULL;
char* newbase="nullname";
name=(char *)malloc(strlen(newbase));
sprintf(name,"%s",newbase);
}
*/
int i;
inputs=new_inputs;
if (inputs > 0) {
in=new SCORE_STREAM[inputs];
sched_in=new SCORE_STREAM[inputs];
inConsumption=new unsigned int[inputs];
// Nachiket: gcc4 rules
in_types=new ScoreStreamType*[inputs];
sched_in_types=new ScoreStreamType*[inputs];
sched_dependentOnInputBuffer=new char[inputs];
sched_inputConsumption=new unsigned int[inputs];
sched_inputConsumptionOffset=new int[inputs];
sched_lastKnownInputFIFONumTokens=new unsigned int[inputs];
sched_expectedInputConsumption=new unsigned int[inputs];
for (i = 0; i < inputs; i++) {
in[i] = NULL;
sched_in[i] = NULL;
inConsumption[i] = 0;
in_types[i] = NULL;
sched_in_types[i] = NULL;
sched_dependentOnInputBuffer[i] = 0;
sched_inputConsumption[i] = 0;
sched_inputConsumptionOffset[i] = 0;
sched_lastKnownInputFIFONumTokens[i] = 0;
sched_expectedInputConsumption[i] = 0;
}
} else {
in=NULL;
sched_in=NULL;
inConsumption=NULL;
in_types=NULL;
sched_in_types=NULL;
sched_dependentOnInputBuffer=NULL;
sched_inputConsumption=NULL;
sched_inputConsumptionOffset=NULL;
sched_lastKnownInputFIFONumTokens=NULL;
sched_expectedInputConsumption=NULL;
}
outputs=new_outputs;
if (outputs > 0) {
out=new SCORE_STREAM[outputs];
sched_out=new SCORE_STREAM[outputs];
outProduction=new unsigned int[outputs];
out_types=new ScoreStreamType*[outputs];
sched_out_types=new ScoreStreamType*[outputs];
sched_dependentOnOutputBuffer=new char[outputs];
sched_outputProduction=new unsigned int[outputs];
sched_outputProductionOffset=new int[outputs];
sched_expectedOutputProduction=new unsigned int[outputs];
for (i = 0; i < outputs; i++) {
out[i] = NULL;
sched_out[i] = NULL;
outProduction[i] = 0;
out_types[i] = NULL;
sched_out_types[i] = NULL;
sched_dependentOnOutputBuffer[i] = 0;
sched_outputProduction[i] = 0;
sched_outputProductionOffset[i] = 0;
sched_expectedOutputProduction[i] = 0;
}
} else {
out=NULL;
sched_out=NULL;
outProduction=NULL;
out_types=NULL;
sched_out_types=NULL;
sched_dependentOnOutputBuffer=NULL;
sched_outputProduction=NULL;
sched_outputProductionOffset=NULL;
sched_expectedOutputProduction=NULL;
}
}
void bindInput(int which, SCORE_STREAM strm,
ScoreStreamType *stype) {
in[which]=strm;
sched_in[which]=strm;
strm->snkNum = which; // input of a graph node is a stram sink
strm->sched_snkNum = which; // input of a graph node is a stram sink
in_types[which]=stype;
sched_in_types[which]=stype;
if (_isPage) {
STREAM_BIND_SINK(strm,this,stype,STREAM_PAGE_TYPE);
} else if (_isSegment) {
STREAM_BIND_SINK(strm,this,stype,STREAM_SEGMENT_TYPE);
} else if (_isOperator) {
STREAM_BIND_SINK(strm,this,stype,STREAM_OPERATOR_TYPE);
}
}
void bindOutput(int which, SCORE_STREAM strm,
ScoreStreamType *stype) {
out[which]=strm;
// cout << "which=" << which << endl;
sched_out[which]=strm;
strm->srcNum = which; // output of a graph node is a stream source
strm->sched_srcNum = which; // output of a graph node is a stream source
out_types[which]=stype;
sched_out_types[which]=stype;
if (_isPage) {
STREAM_BIND_SRC(strm,this,stype,STREAM_PAGE_TYPE);
} else if (_isSegment) {
STREAM_BIND_SRC(strm,this,stype,STREAM_SEGMENT_TYPE);
} else if (_isOperator) {
STREAM_BIND_SRC(strm,this,stype,STREAM_OPERATOR_TYPE);
}
// cout << "out[which]=" << out[which] << endl;
}
// this is used by the scheduler when building a processor node which does
// not really want to have streams point to it.
void bindInput_localbind(int which, SCORE_STREAM strm) {
in[which]=strm;
sched_in[which]=strm;
}
// this is used by the scheduler when building a processor node which does
// not really want to have streams point to it.
void bindOutput_localbind(int which, SCORE_STREAM strm) {
out[which]=strm;
sched_out[which]=strm;
}
void unbindInput(int which) {
STREAM_UNBIND_SINK(in[which]);
in[which]->snkNum = -1;
sched_in[which]->sched_snkNum = -1;
in[which]=NULL;
sched_in[which]=NULL;
in_types[which]=NULL;
sched_in_types[which]=NULL;
}
void unbindOutput(int which) {
STREAM_UNBIND_SRC(out[which]);
out[which]->srcNum = -1;
sched_out[which]->srcNum = -1;
out[which]=NULL;
sched_out[which]=NULL;
out_types[which]=NULL;
sched_out_types[which]=NULL;
}
void bindSchedInput(int which, SCORE_STREAM strm,
ScoreStreamType *stype) {
sched_in[which]=strm;
strm->sched_snkNum = which; // input of a graph node is a stram sink
sched_in_types[which]=stype;
if (_isPage) {
STREAM_SCHED_BIND_SINK(strm,this,stype,STREAM_PAGE_TYPE);
} else if (_isSegment) {
STREAM_SCHED_BIND_SINK(strm,this,stype,STREAM_SEGMENT_TYPE);
} else if (_isOperator) {
STREAM_SCHED_BIND_SINK(strm,this,stype,STREAM_OPERATOR_TYPE);
}
}
void bindSchedOutput(int which, SCORE_STREAM strm,
ScoreStreamType *stype) {
sched_out[which]=strm;
strm->sched_srcNum = which; // output of a graph node is a stream source
sched_out_types[which]=stype;
if (_isPage) {
STREAM_SCHED_BIND_SRC(strm,this,stype,STREAM_PAGE_TYPE);
} else if (_isSegment) {
STREAM_SCHED_BIND_SRC(strm,this,stype,STREAM_SEGMENT_TYPE);
} else if (_isOperator) {
STREAM_SCHED_BIND_SRC(strm,this,stype,STREAM_OPERATOR_TYPE);
}
}
// this is used by the scheduler when building a processor node which does
// not really want to have streams point to it.
void bindSchedInput_localbind(int which, SCORE_STREAM strm) {
sched_in[which]=strm;
}
// this is used by the scheduler when building a processor node which does
// not really want to have streams point to it.
void bindSchedOutput_localbind(int which, SCORE_STREAM strm) {
sched_out[which]=strm;
}
void unbindSchedInput(int which) {
STREAM_SCHED_UNBIND_SINK(sched_in[which]);
sched_in[which]->sched_snkNum = -1;
sched_in[which]=NULL;
sched_in_types[which]=NULL;
}
void unbindSchedOutput(int which) {
STREAM_SCHED_UNBIND_SRC(sched_out[which]);
sched_out[which]->sched_srcNum = -1;
sched_out[which]=NULL;
sched_out_types[which]=NULL;
}
int getFire() {return(fire);}
int getStall() {return(stall);}
void setStall(int stall_t) {stall=stall_t;}
int getDoneCount() { return (doneCount); }
void incrementInputConsumption(int which) {inConsumption[which]++;}
void incrementOutputProduction(int which) {outProduction[which]++;}
unsigned int getInputConsumption(int which) {return(inConsumption[which]);}
unsigned int getOutputProduction(int which) {return(outProduction[which]);}
int isPage() {return(_isPage);}
int isOperator() {return(_isOperator);}
int isSegment() {return(_isSegment);}
virtual NodeTags getTag() { return ScoreGraphNodeTag; }
virtual void print(FILE *f, bool printShort = false);
void recalculateUnstallTime();
char isStalledOnInput();
void syncSchedToReal();
unsigned long long sim_unstallTime;
char sim_unstallTimeIsInfinity;
int _isPage, _isSegment, _isOperator;
//////////////////////////////////////////////////////
// BEGIN SCHEDULER VARIABLES
//////////////////////////////////////////////////////
// stores what status the node is in.
char sched_isDone;
char sched_isResident;
char sched_isScheduled;
// stores the location where the node is resident (only valid when
// this node is resident).
unsigned int sched_residentLoc;
// stores a pointer to the parent process.
ScoreProcess *sched_parentProcess;
// stores a pointer to the parent cluster.
ScoreCluster *sched_parentCluster;
// stores a pointer to the parent operator.
ScoreOperatorInstance *sched_parentOperator;
// used by scheduler for clustering and graph operations.
node sched_graphNode;
// used by graph algorithms to mark this node visited.
char sched_visited;
char sched_visited2;
// used by scheduler for bufferlock detection.
char *sched_dependentOnInputBuffer;
char *sched_dependentOnOutputBuffer;
// stores the scheduler-known input/output consumption/production rates.
unsigned int *sched_inputConsumption;
unsigned int *sched_outputProduction;
// offsets so that the scheduler can effectively reset the rates.
// NOTE: This will be automatically applied by the scheduler.
int *sched_inputConsumptionOffset;
int *sched_outputProductionOffset;
// stores the last known input number of tokens.
unsigned int *sched_lastKnownInputFIFONumTokens;
// stores the expected input/output consumption/production amount.
unsigned int *sched_expectedInputConsumption;
unsigned int *sched_expectedOutputProduction;
SCORE_STREAM *sched_in;
SCORE_STREAM *sched_out;
ScoreStreamType **sched_in_types;
ScoreStreamType **sched_out_types;
// stores whether or not this node did not fire in its last timeslice
// resident.
// FIX ME! PERHAPS WE WOULD WANT TO CONSIDER ADDING SOME HYSTERISIS
// WITH A COUNTER THAT ALLOWS A PAGE TO NOT CONSUME/PRODUCE
// FOR MORE THAN 1 TIMESLICE BEFORE WE CONSIDER IT STALLED.
// (WE WOULD UP THE TRIGGER NUMBER AFTER WE RUN A DEADLOCK DETECTION
// AND DETERMINE, BY EXAMINING STATE, THAT IT IS STILL "ALIVE").
char sched_potentiallyDidNotFireLastResident;
#ifdef RANDOM_SCHEDULER
// contains the timeslice when this node was scheduled last
// i.e. if (sched_lastTimesliceScheduled == currentTimeslice) then
// this node was selected to be scheduled during this timeslice
private:
unsigned int sched_lastTimesliceScheduled;
public:
void setLastTimesliceScheduled(unsigned int val) {
sched_lastTimesliceScheduled = val;
}
unsigned int getLastTimesliceScheduled() const {
return sched_lastTimesliceScheduled;
}
#endif
//////////////////////////////////////////////////////
// END SCHEDULER VARIABLES
//////////////////////////////////////////////////////
list_item sim_runnableNodeListItem;
#if 0
pq_item sim_stalledNodeQueueItem;
#endif
list_item sim_checkNodeListItem;
#if GET_FEEDBACK
unsigned int *getConsumptionVector() { return inConsumption; }
unsigned int *getProductionVector() { return outProduction; }
ScoreFeedbackGraphNode *feedbackNode;
size_t uniqTag;
// this is where statistical information will be placed
unsigned int *stat_consumption;
unsigned int *stat_production;
unsigned int stat_fireCount;
#endif
protected:
char* name; // added by Nachiket on 1/20/2010 to support dumping out stream connectivity information..
int inputs;
int outputs;
SCORE_STREAM *in;
SCORE_STREAM *out;
unsigned int *inConsumption;
unsigned int *outProduction;
ScoreStreamType **in_types;
ScoreStreamType **out_types;
int fire;
int stall;
int doneCount;
};
// needed by LEDA for use with lists/etc.
int compare(ScoreGraphNode * const & left, ScoreGraphNode * const & right);
typedef enum _feedbackMode { NOTHING, MAKEFEEDBACK, READFEEDBACK, SAMPLERATES } ScoreFeedbackMode;
#endif