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_verilator/] [traffic_synthetic.h] - Blame information for rev 54

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 43 alirezamon
#ifndef TRAFFIC_SYNTHETIC_H
2
#define TRAFFIC_SYNTHETIC_H
3
 
4
 
5 48 alirezamon
#define INJECT_OFF -1
6 43 alirezamon
 
7 48 alirezamon
//#include "topology.h"
8 43 alirezamon
 
9 48 alirezamon
 
10 43 alirezamon
extern int TRAFFIC_TYPE;
11
extern int HOTSPOT_NUM;
12
extern char * TRAFFIC;
13
extern unsigned char  NEw;
14
 
15 48 alirezamon
int custom_traffic_table[NE];
16 43 alirezamon
 
17
typedef struct HOTSPOT_NODE {
18
        int  ip_num;
19
        char send_enable;
20
        int  percentage; // x10 
21
} hotspot_st;
22
 
23
hotspot_st * hotspots;
24
 
25 54 alirezamon
unsigned int pck_dst_gen_1D (unsigned int, unsigned char *);
26 43 alirezamon
 
27
// number, b:bit location  W: number width log2(num)
28
int getBit(int num, int b, int W)
29
{
30
        while(b<0) b+=W;
31
        b%=W;
32
        return (num >> b) & 0x1;
33
}
34
 
35
// number; b:bit location;  W: number width log2(num); v: 1 assert the bit, 0 deassert the bit; 
36
void setBit(int *num, int b,   int W, int v)
37
{
38
    while(b<0) b+=W;
39
        b%=W;
40
    int mask = 1 << b;
41
    //printf("b=%d\n", b);
42
        if (v == 0)*num  = *num & ~mask; // assert bit
43
    else *num = *num | mask; // deassert bit
44
 
45
}
46
 
47
 
48 48 alirezamon
unsigned int get_rnd_ip (unsigned int core_num){
49
        unsigned int rnd=rand()%NE;
50
        if(IS_SELF_LOOP_EN) return rnd;
51
        //make sure its not same as sender core
52
        while (rnd==core_num)   rnd=rand()%NE;
53
        return rnd;
54
}
55 43 alirezamon
 
56 48 alirezamon
#if (defined (IS_MESH) || defined (IS_TORUS) || defined (IS_LINE) || defined (IS_RING) )
57 43 alirezamon
 
58 54 alirezamon
unsigned int pck_dst_gen_2D (unsigned int core_num, unsigned char * inject_en){
59 43 alirezamon
        //for mesh-tori
60
        unsigned int current_l,current_x, current_y;
61
        unsigned int dest_l,dest_x,dest_y;
62
        mesh_tori_addrencod_sep(core_num,&current_x,&current_y,&current_l);
63 54 alirezamon
        * inject_en=1;
64 43 alirezamon
        unsigned int rnd=0;
65
        unsigned int rnd100=0;
66
        unsigned int max_percent=100/HOTSPOT_NUM;
67
        int i;
68
 
69
        if((strcmp (TRAFFIC,"RANDOM")==0) || (strcmp (TRAFFIC,"random")==0)){
70 48 alirezamon
                //get a random IP core
71
            return endp_addr_encoder(get_rnd_ip(core_num));
72 43 alirezamon
        }
73
 
74
        if ((strcmp(TRAFFIC,"HOTSPOT")==0) || (strcmp (TRAFFIC,"hot spot")==0)){
75
                unsigned int rnd1000=0;
76 48 alirezamon
                rnd=get_rnd_ip(core_num);
77
 
78 43 alirezamon
                rnd1000=rand()%1000; // generate a random number between 0 & 1000
79
                for (i=0;i<HOTSPOT_NUM; i++){
80
                        if ( hotspots[i].send_enable == 0 && core_num ==hotspots[i].ip_num){
81 48 alirezamon
                                //rnd = core_num; // turn off the core
82
                                //return endp_addr_encoder(rnd);
83 54 alirezamon
                                *inject_en=0;
84 48 alirezamon
                                return INJECT_OFF;
85 43 alirezamon
                        }
86
                }
87
                for (i=0;i<HOTSPOT_NUM; i++){
88
                        if (rnd1000 < hotspots[i].percentage && core_num !=hotspots[i].ip_num) {
89
                                rnd = hotspots[i].ip_num;
90
                                return endp_addr_encoder(rnd);
91
                        }
92
                }
93
                return endp_addr_encoder(rnd);
94
        }
95
 
96
        if(( strcmp(TRAFFIC ,"TRANSPOSE1")==0)|| (strcmp (TRAFFIC,"transposed 1")==0)){
97
                 dest_x = T1-current_y-1;
98
                 dest_y = T2-current_x-1;
99
                 dest_l = T3-current_l-1;
100
                 return mesh_tori_addr_join(dest_x,dest_y,dest_l);
101
        }
102
 
103
        if(( strcmp(TRAFFIC ,"TRANSPOSE2")==0)|| (strcmp (TRAFFIC,"transposed 2")==0)){
104
                dest_x = current_y;
105
                dest_y = current_x;
106
                dest_l = current_l;
107
                return mesh_tori_addr_join(dest_x,dest_y,dest_l);
108
        }
109
 
110
        if(( strcmp(TRAFFIC ,"BIT_REVERSE")==0)|| (strcmp (TRAFFIC,"bit reverse")==0)){
111
                //di = sb−i−1
112
                int tmp=0;
113
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, NEw-i-1, NEw));
114
                return endp_addr_encoder(tmp);
115
        }
116
 
117
        if(( strcmp(TRAFFIC ,"BIT_COMPLEMENT") ==0)|| (strcmp (TRAFFIC,"bit complement")==0)){
118
                int tmp=0;
119
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i, NEw)==0);
120
                return endp_addr_encoder(tmp);
121
        }
122
 
123
        if(( strcmp(TRAFFIC ,"TORNADO") == 0)|| (strcmp (TRAFFIC,"tornado")==0)){
124
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
125
                        dest_x = ((current_x + ((T1/2)-1))%T1);
126
                        dest_y = ((current_y + ((T2/2)-1))%T2);
127
                        dest_l = current_l;
128
                        return mesh_tori_addr_join(dest_x,dest_y,dest_l);
129
     }
130
 
131
    if(( strcmp(TRAFFIC ,"SHUFFLE") == 0)|| (strcmp (TRAFFIC,"shuffle")==0)){
132
                //di = si−1 mod b
133
                int tmp=0;
134
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i-1, NEw));
135
                return endp_addr_encoder(tmp);
136
     }
137
 
138
    if(( strcmp(TRAFFIC ,"BIT_ROTATION") == 0)|| (strcmp (TRAFFIC,"bit rotation")==0)){
139
                //di = si+1 mod b
140
                int tmp=0;
141
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i+1, NEw));
142
                return endp_addr_encoder(tmp);
143
     }
144
 
145
    if(( strcmp(TRAFFIC ,"NEIGHBOR") == 0)|| (strcmp (TRAFFIC,"neighbor")==0)){
146
                //dx = sx + 1 mod k
147
                 dest_x = (current_x + 1)%T1;
148
                 dest_y = (current_y + 1)%T2;
149
                 dest_l = current_l;
150
                 return mesh_tori_addr_join(dest_x,dest_y,dest_l);
151
     }
152
 
153 48 alirezamon
     if(( strcmp(TRAFFIC ,"CUSTOM") == 0)|| (strcmp (TRAFFIC,"custom")==0)){
154 54 alirezamon
         if (custom_traffic_table[core_num]== INJECT_OFF){
155
                 *inject_en=0;
156
                 return INJECT_OFF;
157
         }
158 48 alirezamon
                 return endp_addr_encoder(custom_traffic_table[core_num]);
159 43 alirezamon
 
160
     }
161
 
162 48 alirezamon
         fprintf (stderr,"ERROR: traffic %s is an unsupported traffic pattern\n",TRAFFIC);
163 54 alirezamon
         *inject_en=0;
164 48 alirezamon
         return INJECT_OFF;
165
 
166 43 alirezamon
}
167
 
168 48 alirezamon
#else
169 43 alirezamon
 
170 54 alirezamon
        unsigned int pck_dst_gen_2D (unsigned int core_num, unsigned char * inject_en){
171
                return pck_dst_gen_1D (core_num,inject_en );
172 48 alirezamon
        }
173 43 alirezamon
 
174 48 alirezamon
#endif
175 43 alirezamon
 
176 48 alirezamon
 
177 54 alirezamon
unsigned int pck_dst_gen_1D (unsigned int core_num, unsigned char  *inject_en){
178 43 alirezamon
 
179
        unsigned int rnd=0;
180
        unsigned int rnd100=0;
181
        unsigned int max_percent=100/HOTSPOT_NUM;
182
        int i;
183
 
184 54 alirezamon
        *inject_en=1;
185 43 alirezamon
        if((strcmp (TRAFFIC,"RANDOM")==0) || (strcmp (TRAFFIC,"random")==0)){
186 48 alirezamon
                 return endp_addr_encoder(get_rnd_ip(core_num));
187 43 alirezamon
        }
188
 
189
        if ((strcmp(TRAFFIC,"HOTSPOT")==0) || (strcmp (TRAFFIC,"hot spot")==0)){
190
                unsigned int rnd1000=0;
191
                int i;
192 48 alirezamon
                rnd=get_rnd_ip(core_num);
193 43 alirezamon
                rnd1000=rand()%1000; // generate a random number between 0 & 1000
194
                for (i=0;i<HOTSPOT_NUM; i++){
195
                        if ( hotspots[i].send_enable == 0 && core_num ==hotspots[i].ip_num){
196 54 alirezamon
                                *inject_en=0;
197 48 alirezamon
                                return INJECT_OFF;
198 43 alirezamon
                        }
199
                }
200
 
201
                for (i=0;i<HOTSPOT_NUM; i++){
202
                        if (rnd1000 < hotspots[i].percentage && core_num !=hotspots[i].ip_num) {
203
                                rnd = hotspots[i].ip_num;
204
                                return endp_addr_encoder(rnd % NE );
205
                        }
206
                }
207
                return endp_addr_encoder(rnd % NE );
208
        }
209
 
210
 
211
        if(( strcmp(TRAFFIC ,"TRANSPOSE1")==0)|| (strcmp (TRAFFIC,"transposed 1")==0)){
212
                  return endp_addr_encoder(NE-core_num-1);
213
        }
214
        if(( strcmp(TRAFFIC ,"TRANSPOSE2")==0)|| (strcmp (TRAFFIC,"transposed 2")==0)){
215
                 return endp_addr_encoder(NE-core_num-1);
216
        }
217
 
218
        if(( strcmp(TRAFFIC ,"BIT_REVERSE")==0)|| (strcmp (TRAFFIC,"bit reverse")==0)){
219
                int tmp=0;
220
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, NEw-i-1, NEw));
221
                return endp_addr_encoder(tmp);
222
         }
223
 
224
         if(( strcmp(TRAFFIC ,"BIT_COMPLEMENT") ==0)|| (strcmp (TRAFFIC,"bit complement")==0)){
225
                 int tmp=0;
226
                 for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i, NEw)==0);
227
                 return endp_addr_encoder(tmp%NE);
228
         }
229
 
230
         if(( strcmp(TRAFFIC ,"TORNADO") == 0)|| (strcmp (TRAFFIC,"tornado")==0)){
231
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
232
                 return endp_addr_encoder((core_num + ((NE/2)-1))%NE);
233
     }
234
 
235
     if(( strcmp(TRAFFIC ,"SHUFFLE") == 0)|| (strcmp (TRAFFIC,"shuffle")==0)){
236
                //di = si−1 mod b
237
                int tmp=0;
238
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i-1, NEw));
239
                return endp_addr_encoder(tmp%NE);
240
         }
241
 
242
     if(( strcmp(TRAFFIC ,"BIT_ROTATION") == 0)|| (strcmp (TRAFFIC,"bit rotation")==0)){
243
                //di = si+1 mod b
244
                int tmp=0;
245
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i+1, NEw));
246
                return endp_addr_encoder(tmp%NE);
247
 
248
     }
249
 
250
     if(( strcmp(TRAFFIC ,"NEIGHBOR") == 0)|| (strcmp (TRAFFIC,"neighbor")==0)){
251
                //dx = sx + 1 mod k
252
         return endp_addr_encoder((core_num + 1)%NE);
253
         }
254
 
255 48 alirezamon
     if(( strcmp(TRAFFIC ,"CUSTOM") == 0)|| (strcmp (TRAFFIC,"custom")==0)){
256 54 alirezamon
         if (custom_traffic_table[core_num]== INJECT_OFF){
257
                 *inject_en=0;
258
                 return INJECT_OFF;
259
         }
260 48 alirezamon
         return endp_addr_encoder(custom_traffic_table[core_num]);
261 43 alirezamon
 
262 48 alirezamon
     }
263
 
264
     fprintf (stderr,"ERROR: traffic %s is an unsupported traffic pattern\n",TRAFFIC);
265 54 alirezamon
     *inject_en=0;
266 48 alirezamon
         return  INJECT_OFF;
267 43 alirezamon
}
268
 
269
 
270
unsigned int rnd_between (unsigned int a, unsigned int b){
271
        unsigned int rnd,diff,min;
272
        if(a==b) return a;
273
        diff= (a<b) ?  b-a+1 : a-b+1;
274
        min= (a<b) ?  a : b;
275
        rnd = (rand() % diff) +  min;
276
        return rnd;
277
}
278
 
279 54 alirezamon
char mcast_list[1024];
280 43 alirezamon
 
281 54 alirezamon
void reverse(char str1[], int index, int size)
282
{
283
    char temp;
284 43 alirezamon
 
285 54 alirezamon
    temp = str1[index];
286
    str1[index] = str1[size - index];
287
    str1[size - index] = temp;
288 43 alirezamon
 
289 54 alirezamon
    if (index == size / 2)
290
    {
291
        return;
292
    }
293
    reverse(str1, index + 1, size);
294
}
295 43 alirezamon
 
296 54 alirezamon
char * mcast_list_array;
297
unsigned int MCAST_PRTLw=0;
298 43 alirezamon
 
299 54 alirezamon
void mcast_init(){
300
        mcast_list_array = (char *) malloc(NE * sizeof(char));
301
        if (IS_MCAST_FULL){
302
        for(int i=0; i< NE; i++) {
303
                mcast_list_array[i]=1;
304
                MCAST_PRTLw=NE;
305
        }
306
        return;
307
    }
308
        //partial
309
 
310
        int hex=0;
311
        int bin=0;
312
        char * temp_str;
313
        temp_str = (char *) malloc(strlen(MCAST_ENDP_LIST) * sizeof(char));
314
        sscanf(MCAST_ENDP_LIST,"%s",temp_str );
315
 
316
        char * t = strstr(temp_str, "\'h");
317
        if(t) hex=1;
318
        else  t = strstr(temp_str, "\'b");
319
        if(t) bin=1;
320
        if(hex==0 && bin == 0){
321
                fprintf (stderr,"ERROR: MCAST_ENDP_LIST (%s) is given in wrong format. Only hex ('h) and bin ('b) format is accepted. \n",MCAST_ENDP_LIST);
322
                exit(1);
323
        }
324
 
325
        t+=2;
326
        int size = strlen(t);
327
        reverse(t, 0, size - 1);
328
 
329
        int i=0;
330
    char u [2];
331
    u [1] =0;
332
 
333
    if(hex){
334
                for(i=0; i< size; i++) {
335
                        unsigned int ch ;
336
                        u[0] = t[i];
337
                        sscanf(u , "%x", &ch);
338
                        ch&=0xf;
339
                        mcast_list_array[i*4  ] = (ch & 0x1);
340
                        mcast_list_array[i*4+1] = (ch & 0x2)>>1;
341
                        mcast_list_array[i*4+2] = (ch & 0x4)>>2;
342
                        mcast_list_array[i*4+3] = (ch & 0x8)>>3;
343
                }
344
        }else if(bin){
345
                for(i=0; i< size; i++) {
346
                        unsigned int ch ;
347
                        u[0] = t[i];
348
                        sscanf(u , "%x", &ch);
349
                        ch&=0xf;
350
                        mcast_list_array[i  ] = ch;
351
                }
352
 
353
        }
354
 
355
        for (i=0;i<NE;i++){
356
                if(mcast_list_array[i] ==1) MCAST_PRTLw++;
357
//      printf("mcast_list_array[%u]=%u\n",i,mcast_list_array[i]);
358
        }
359
//      printf("mcastw=%u\n",MCAST_PRTLw);
360
 
361
}
362
 
363
 
364
unsigned int  endp_id_to_mcast_id (unsigned int  endp_id){
365
 
366
        int i=0;
367
        if (IS_MCAST_FULL) return endp_id;
368
        int  id=0;
369
        for (i=0;i<endp_id;i++) {
370
                if( mcast_list_array[i]==1) id++;
371
        }
372
        return id;
373
}
374
 
375
 
376 43 alirezamon
#endif

powered by: WebSVN 2.1.0

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