-
Notifications
You must be signed in to change notification settings - Fork 2
/
ScoreFeedbackGraph.h
162 lines (127 loc) · 4.86 KB
/
ScoreFeedbackGraph.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
//////////////////////////////////////////////////////////////////////////////
//
// 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.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef ScoreFeedbackGraph_h__
#define ScoreFeedbackGraph_h__
#include "LEDA/core/list.h"
#include "LEDA/core/string.h"
#include <stdio.h>
#include <string.h>
#include <map>
using leda::list;
using leda::string;
class ScoreGraphNode;
typedef enum { NODE_TYPE_PAGE, NODE_TYPE_SEGMENT, NODE_TYPE_ERROR } ScoreFeedbackNodeType;
class ScoreFeedbackGraphNode {
public:
ScoreFeedbackGraphNode() :
_kind(NODE_TYPE_ERROR),
_numInputs(0),
_numOutputs(0),
_nodeTag(0xffffffff) {}
ScoreFeedbackGraphNode(ScoreFeedbackNodeType kind,
string myname,
int numIns,
int numOuts,
size_t nodeTag,
ScoreGraphNode *scoreNode) :
_kind(kind), _numInputs(numIns), _numOutputs(numOuts),
_nodeTag(nodeTag), _scoreNode(scoreNode) {
_name = new char[strlen(myname)+1];
strcpy(_name, myname);
}
~ScoreFeedbackGraphNode() {
if (_name)
delete _name;
}
// records consumption in the _inputConsumption vector.
// from the array provided
void recordConsumption (const unsigned int *inCons, int size);
// records production in the _outputProduction vector.
// from the array provided
void recordProduction (const unsigned int *outProd, int size);
void recordFireCount(const int fire);
void writeTab(FILE *f);
// write/read the text file in our feedback format
void writeText(FILE *f);
int readText(FILE *f);
int readUntil(FILE *f, char theChar);
typedef list<unsigned int> Vector_1d;
typedef list<Vector_1d> Vector_2d;
int readVector2(FILE *f, Vector_2d &vec, int count, int count2);
template <class C> int readVector(FILE *f, list<C> &vec, int count);
void writeHistoryVector(FILE *f, Vector_2d &);
size_t getTag() const { return _nodeTag; }
void getStatInfo(unsigned int **consumption, unsigned int **production,
unsigned int *fireCount);
// emit node descriptions for the sched template
void outputSchedNodes(FILE *f);
static void resetCPUio() { _cpuInputs = _cpuOutputs = 0; }
private:
// these vectors record the history of the cons/prod
// thus to access mth record about nth input/output
// one should _inputConsumption[m][n]
Vector_2d _inputConsumption;
Vector_2d _outputProduction;
Vector_1d _fireCount;
ScoreFeedbackNodeType _kind;
char *_name;
int _numInputs, _numOutputs;
size_t _nodeTag;
static const char *node_kinds[];
ScoreGraphNode *_scoreNode;
static int _cpuInputs;
static int _cpuOutputs;
};
class ScoreFeedbackGraph {
public:
ScoreFeedbackGraph(const char *userDir);
~ScoreFeedbackGraph();
// adds a node to the graph and returns a pointer to its
// entry in the dictionary
ScoreFeedbackGraphNode *addNode(size_t nodeTag, ScoreGraphNode* node);
// removes the node from the dictionary, and destroys
// the node
void removeNode(size_t nodeTag);
void writeTab(FILE *f);
// write/read the text fiule in our feedback format
void writeText(FILE *f);
int readText(FILE *f);
// given a nodeTag, return the pointer to the entry
ScoreFeedbackGraphNode *getNodePtr(size_t nodeTag);
// obtains a "status" of this data structure
// true if everything is ok (no errors)
// false if there are errors
bool getStatus() const { return _status; }
// emit node descriptions for the sched template
void outputSchedNodes(FILE *f);
private:
std::map<size_t, ScoreFeedbackGraphNode*> _nodes;
const char *_userDir;
// the following is true iff the graph needs to be written on
// disk on destruction. if the graph was constructed dynamically
// this will be true. however, if it was constructed by reading
// the feedback file, this will be false.
bool _needWrite;
bool _status;
};
#endif // ifndef ScoreFeedbackGraph_h__