OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_c/] [synfull/] [traffic-generator/] [src/] [ModelRead.cpp] - Blame information for rev 54

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 54 alirezamon
/*
2
Copyright (c) 2014, Mario Badr
3
All rights reserved.
4
 
5
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
 
7
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
 
9
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10
 
11
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12
*/
13
/*
14
 * ModelRead.cpp
15
 *
16
 *  Created on: 2013-01-13
17
 *      Author: mario
18
 */
19
 
20
#include <string>
21
#include <iostream>
22
#include <sstream>
23
 
24
 
25
#include "ModelRead.h"
26
#include "Global.h"
27
 
28
using namespace std;
29
 
30
/**
31
 * Returns true if the next line equals 'header'.
32
 *
33
 * @param file The file to peak in
34
 * @param header The string to find in the next line
35
 *
36
 */
37
bool PeekForHeader(ifstream& file, string header) {
38
        // Get current position
39
        int len = file.tellg();
40
 
41
        // Read line
42
        std::string line;
43
        getline(file, line); //Finish reading the last line
44
        getline(file, line);
45
 
46
        // Return to position before "Read line".
47
        file.seekg(len ,std::ios_base::beg);
48
 
49
        return(line.compare(header) == 0);
50
}
51
 
52
/**
53
 * Parse the hierarchical parameters of the model
54
 *
55
 * @param modelFile The model file stream
56
 */
57
void ReadHierarchy(ifstream& modelFile) {
58
        string header;
59
 
60
        modelFile >> header;
61
        modelFile >> g_hierClasses;
62
        modelFile >> header;
63
        modelFile >> g_timeSpan;
64
 
65
        //Hierarchical Markov Model
66
        double transition;
67
 
68
        modelFile >> header;
69
        for(int i = 1; i <= g_hierClasses; i++) {
70
                for(int j = 0; j < g_hierClasses; j++) {
71
                        modelFile >> transition;
72
                        g_hierState[i].Add(transition);
73
                }
74
        }
75
        modelFile >> header;
76
 
77
        //Read steady state
78
        modelFile >> header;
79
        for(int i = 0; i < g_hierClasses; i++) {
80
                modelFile >> transition;
81
                g_hierSState.push_back(transition);
82
        }
83
        modelFile >> header;
84
}
85
 
86
/**
87
 * Read the parameters of the model
88
 *
89
 * @param modelFile The model file stream
90
 *
91
 */
92
void ReadParameters(ifstream& modelFile) {
93
        string header;
94
 
95
        modelFile >> header;
96
        modelFile >> g_memory;
97
 
98
        modelFile >> header;
99
        modelFile >> g_numNodes;
100
 
101
        modelFile >> header;
102
        modelFile >> g_numClasses;
103
 
104
        modelFile >> header;
105
        modelFile >> g_resolution;
106
}
107
 
108
/**
109
 * Read in the Markov probability matrix
110
 *
111
 * @param modelFile The model file stream
112
 */
113
void ReadMarkov1(ifstream& modelFile) {
114
        string header;
115
        double transition;
116
 
117
        modelFile >> header;
118
        for(int i = 1; i <= g_numClasses; i++) {
119
                for(int j = 0; j < g_numClasses; j++) {
120
                        modelFile >> transition;
121
                        g_states1[g_hierClass][i].Add(transition);
122
                }
123
        }
124
        modelFile >> header;
125
 
126
        //Read steady state
127
        modelFile >> header;
128
        for(int i = 0; i < g_numClasses; i++) {
129
                modelFile >> transition;
130
                g_steadyState[g_hierClass].push_back(transition);
131
        }
132
        modelFile >> header;
133
}
134
 
135
/**
136
 * Read in the spatial injection probabilities for each message type.
137
 *
138
 * @param modelFile The model file stream
139
 */
140
void ReadSpatial(ifstream& modelFile) {
141
        string header;
142
        int value;
143
 
144
        modelFile >> header;
145
        while(!PeekForHeader(modelFile, "END")) {
146
                for(int cl  = 1; cl <= g_numClasses; cl++) {
147
                        modelFile >> value;
148
 
149
                        g_writeSpat[g_hierClass][cl].Add(value);
150
                }
151
        }
152
        modelFile >> header;
153
 
154
        modelFile >> header;
155
        while(!PeekForHeader(modelFile, "END")) {
156
                for(int cl  = 1; cl <= g_numClasses; cl++) {
157
                        modelFile >> value;
158
 
159
                        g_readSpat[g_hierClass][cl].Add(value);
160
                }
161
        }
162
        modelFile >> header;
163
 
164
        modelFile >> header;
165
        while(!PeekForHeader(modelFile, "END")) {
166
                for(int cl  = 1; cl <= g_numClasses; cl++) {
167
                        modelFile >> value;
168
 
169
                        g_ccrSpat[g_hierClass][cl].Add(value);
170
                }
171
        }
172
        modelFile >> header;
173
 
174
        modelFile >> header;
175
        while(!PeekForHeader(modelFile, "END")) {
176
                for(int cl  = 1; cl <= g_numClasses; cl++) {
177
                        modelFile >> value;
178
 
179
                        g_dcrSpat[g_hierClass][cl].Add(value);
180
                }
181
        }
182
        modelFile >> header;
183
}
184
 
185
/**
186
 * Read in the flows probabilities to determine destinations for each message
187
 * type.
188
 *
189
 * @param modelFile The model file stream
190
 */
191
void ReadFlows2(ifstream& modelFile) {
192
        string header;
193
        int value, s, d, cl;
194
 
195
        modelFile >> header;
196
        while(!PeekForHeader(modelFile, "END")) {
197
                modelFile >> s >> d >> cl >> value;
198
 
199
                g_writeDest[g_hierClass][cl][s].Add(value);
200
        }
201
        modelFile >> header;
202
 
203
        modelFile >> header;
204
        while(!PeekForHeader(modelFile, "END")) {
205
                modelFile >> s >> d >> cl >> value;
206
 
207
                g_readDest[g_hierClass][cl][s].Add(value);
208
        }
209
        modelFile >> header;
210
 
211
        modelFile >> header;
212
        while(!PeekForHeader(modelFile, "END")) {
213
                modelFile >> s >> d >> cl >> value;
214
 
215
                g_ccrDest[g_hierClass][cl][s].Add(value);
216
        }
217
        modelFile >> header;
218
 
219
        modelFile >> header;
220
 
221
        while(!PeekForHeader(modelFile, "END")) {
222
                modelFile >> s >> d >> cl >> value;
223
 
224
                g_dcrDest[g_hierClass][cl][s].Add(value);
225
        }
226
        modelFile >> header;
227
 
228
}
229
 
230
/**
231
 * Read the injection rates for each message type.
232
 *
233
 * @param modelFile The model file stream
234
 */
235
void ReadInjections2(ifstream& modelFile) {
236
        int value;
237
        string header;
238
 
239
        modelFile >> header;
240
 
241
        while(!PeekForHeader(modelFile, "END")) {
242
                for(int cl  = 1; cl <= g_numClasses; cl++) {
243
                        modelFile >> value;
244
 
245
                        g_writes[g_hierClass][cl].Add(value);
246
                }
247
        }
248
        modelFile >> header;
249
 
250
 
251
        modelFile >> header;
252
 
253
        while(!PeekForHeader(modelFile, "END")) {
254
                for(int cl  = 1; cl <= g_numClasses; cl++) {
255
                        modelFile >> value;
256
 
257
                        g_reads[g_hierClass][cl].Add(value);
258
                }
259
        }
260
        modelFile >> header;
261
 
262
 
263
        modelFile >> header;
264
 
265
        while(!PeekForHeader(modelFile, "END")) {
266
                for(int cl  = 1; cl <= g_numClasses; cl++) {
267
                        modelFile >> value;
268
 
269
                        g_ccrs[g_hierClass][cl].Add(value);
270
                }
271
        }
272
        modelFile >> header;
273
 
274
 
275
        modelFile >> header;
276
 
277
        while(!PeekForHeader(modelFile, "END")) {
278
                for(int cl  = 1; cl <= g_numClasses; cl++) {
279
                        modelFile >> value;
280
 
281
                        g_dcrs[g_hierClass][cl].Add(value);
282
                }
283
        }
284
        modelFile >> header;
285
 
286
}
287
 
288
/**
289
 * Read the forwarding probabilities for node directories.
290
 *
291
 * @param modelFile The model file stream
292
 */
293
void ReadForwards(ifstream& modelFile) {
294
        int index;
295
        double value1, value2;
296
        string header;
297
 
298
        modelFile >> header;
299
        while(!PeekForHeader(modelFile, "END")) {
300
                modelFile >> index >> value1 >> value2;
301
                g_toForward[g_hierClass][index][WRITE].Add(value1);
302
                g_toForward[g_hierClass][index][WRITE].Add(1 - value1);
303
                g_toForward[g_hierClass][index][READ].Add(value2);
304
                g_toForward[g_hierClass][index][READ].Add(1 - value2);
305
        }
306
        modelFile >> header;
307
 
308
        int cl, source, destination, value;
309
        //map<int, map<int, map<int, int> > > iteration;
310
        modelFile >> header;
311
        while(!PeekForHeader(modelFile, "END")) {
312
                modelFile >> source >> destination >> cl >> value;
313
 
314
                g_forwardDest[g_hierClass][cl][source].Add(value);
315
        }
316
        modelFile >> header;
317
 
318
}
319
 
320
/**
321
 * Read in the probabilities for number of invalidates and their respective
322
 * destinations for each source node.
323
 *
324
 * @param modelFile The model file stream
325
 */
326
void ReadInvalidates(ifstream& modelFile) {
327
        string header;
328
        int cl, source, number, freq;
329
 
330
        modelFile >> header;
331
        while(!PeekForHeader(modelFile, "END")) {
332
                for(int i = 0; i < g_numNodes/2; i++) {
333
                        modelFile >> cl >> source >> number >> freq;
334
 
335
                        if(i != number) {
336
                                cerr << "Invalid model file. Reading invalidate probabilities."
337
                                                << endl;
338
                                return;
339
                        }
340
 
341
                        g_numInv[g_hierClass][cl][source].Add(freq);
342
                }
343
        }
344
        modelFile >> header;
345
 
346
        int destination, value;
347
        map<int, map<int, map<int, int> > > iteration;
348
        modelFile >> header;
349
        while(!PeekForHeader(modelFile, "END")) {
350
                modelFile >> source >> destination >> cl >> value;
351
 
352
                g_invDest[g_hierClass][cl][source].Add(value);
353
        }
354
        modelFile >> header;
355
}
356
 
357
/**
358
 * Parse the modelFile given and store all information in the global variables.
359
 *
360
 * @param modelFile The model file stream
361
 */
362
void ReadModel(ifstream& modelFile) {
363
        cout << "Reading model\n";
364
        ReadHierarchy(modelFile);
365
        string header;
366
 
367
        for(int i = 0; i < g_hierClasses; i++) {
368
                modelFile >> header;
369
                modelFile >> g_hierClass;
370
                ReadParameters(modelFile);
371
 
372
                //Active Model
373
                ReadMarkov1(modelFile);
374
                cout << ".\n";
375
                ReadSpatial(modelFile);
376
                cout << ".\n";
377
 
378
                ReadFlows2(modelFile);
379
                cout << ".\n";
380
 
381
                ReadInjections2(modelFile);
382
                cout << ".\n";
383
 
384
                //Reactive Model
385
                ReadForwards(modelFile);
386
                cout << ".\n";
387
                ReadInvalidates(modelFile);
388
                cout << ".\n";
389
 
390
                modelFile >> header;
391
                cout << "*\n";
392
        }
393
        g_hierClass = 1;
394
 
395
        cout << " Done!" << endl;
396
}
397
 
398
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.