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 43

Go to most recent revision | 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
#include "topology.h"
6
 
7
 
8
extern int TRAFFIC_TYPE;
9
extern int HOTSPOT_NUM;
10
extern char * TRAFFIC;
11
extern unsigned char  NEw;
12
 
13
 
14
 
15
typedef struct HOTSPOT_NODE {
16
        int  ip_num;
17
        char send_enable;
18
        int  percentage; // x10 
19
} hotspot_st;
20
 
21
hotspot_st * hotspots;
22
 
23
 
24
 
25
// number, b:bit location  W: number width log2(num)
26
int getBit(int num, int b, int W)
27
{
28
        while(b<0) b+=W;
29
        b%=W;
30
        return (num >> b) & 0x1;
31
}
32
 
33
// number; b:bit location;  W: number width log2(num); v: 1 assert the bit, 0 deassert the bit; 
34
void setBit(int *num, int b,   int W, int v)
35
{
36
    while(b<0) b+=W;
37
        b%=W;
38
    int mask = 1 << b;
39
    //printf("b=%d\n", b);
40
        if (v == 0)*num  = *num & ~mask; // assert bit
41
    else *num = *num | mask; // deassert bit
42
 
43
}
44
 
45
 
46
 
47
 
48
 
49
unsigned int pck_dst_gen_2D (unsigned int core_num){
50
        //for mesh-tori
51
        unsigned int current_l,current_x, current_y;
52
        unsigned int dest_l,dest_x,dest_y;
53
        mesh_tori_addrencod_sep(core_num,&current_x,&current_y,&current_l);
54
 
55
        unsigned int rnd=0;
56
        unsigned int rnd100=0;
57
        unsigned int max_percent=100/HOTSPOT_NUM;
58
        int i;
59
 
60
        if((strcmp (TRAFFIC,"RANDOM")==0) || (strcmp (TRAFFIC,"random")==0)){
61
                do{
62
                        rnd=rand()%NE;
63
                }while (rnd==core_num); // get a random IP core, make sure its not same as sender core
64
       return endp_addr_encoder(rnd);
65
        }
66
 
67
        if ((strcmp(TRAFFIC,"HOTSPOT")==0) || (strcmp (TRAFFIC,"hot spot")==0)){
68
                unsigned int rnd1000=0;
69
                do{
70
                        rnd=rand()%NE;
71
                }while (rnd==core_num); // get a random IP core, make sure its not same as sender core
72
                rnd1000=rand()%1000; // generate a random number between 0 & 1000
73
                for (i=0;i<HOTSPOT_NUM; i++){
74
                        if ( hotspots[i].send_enable == 0 && core_num ==hotspots[i].ip_num){
75
                                rnd = core_num; // turn off the core
76
                                return endp_addr_encoder(rnd);
77
                        }
78
                }
79
                for (i=0;i<HOTSPOT_NUM; i++){
80
                        if (rnd1000 < hotspots[i].percentage && core_num !=hotspots[i].ip_num) {
81
                                rnd = hotspots[i].ip_num;
82
                                return endp_addr_encoder(rnd);
83
                        }
84
                }
85
                return endp_addr_encoder(rnd);
86
        }
87
 
88
        if(( strcmp(TRAFFIC ,"TRANSPOSE1")==0)|| (strcmp (TRAFFIC,"transposed 1")==0)){
89
                 dest_x = T1-current_y-1;
90
                 dest_y = T2-current_x-1;
91
                 dest_l = T3-current_l-1;
92
                 return mesh_tori_addr_join(dest_x,dest_y,dest_l);
93
        }
94
 
95
        if(( strcmp(TRAFFIC ,"TRANSPOSE2")==0)|| (strcmp (TRAFFIC,"transposed 2")==0)){
96
                dest_x = current_y;
97
                dest_y = current_x;
98
                dest_l = current_l;
99
                return mesh_tori_addr_join(dest_x,dest_y,dest_l);
100
        }
101
 
102
        if(( strcmp(TRAFFIC ,"BIT_REVERSE")==0)|| (strcmp (TRAFFIC,"bit reverse")==0)){
103
                //di = sb−i−1
104
                int tmp=0;
105
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, NEw-i-1, NEw));
106
                return endp_addr_encoder(tmp);
107
        }
108
 
109
        if(( strcmp(TRAFFIC ,"BIT_COMPLEMENT") ==0)|| (strcmp (TRAFFIC,"bit complement")==0)){
110
                int tmp=0;
111
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i, NEw)==0);
112
                return endp_addr_encoder(tmp);
113
        }
114
 
115
        if(( strcmp(TRAFFIC ,"TORNADO") == 0)|| (strcmp (TRAFFIC,"tornado")==0)){
116
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
117
                        dest_x = ((current_x + ((T1/2)-1))%T1);
118
                        dest_y = ((current_y + ((T2/2)-1))%T2);
119
                        dest_l = current_l;
120
                        return mesh_tori_addr_join(dest_x,dest_y,dest_l);
121
     }
122
 
123
    if(( strcmp(TRAFFIC ,"SHUFFLE") == 0)|| (strcmp (TRAFFIC,"shuffle")==0)){
124
                //di = si−1 mod b
125
                int tmp=0;
126
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i-1, NEw));
127
                return endp_addr_encoder(tmp);
128
     }
129
 
130
    if(( strcmp(TRAFFIC ,"BIT_ROTATION") == 0)|| (strcmp (TRAFFIC,"bit rotation")==0)){
131
                //di = si+1 mod b
132
                int tmp=0;
133
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i+1, NEw));
134
                return endp_addr_encoder(tmp);
135
     }
136
 
137
    if(( strcmp(TRAFFIC ,"NEIGHBOR") == 0)|| (strcmp (TRAFFIC,"neighbor")==0)){
138
                //dx = sx + 1 mod k
139
                 dest_x = (current_x + 1)%T1;
140
                 dest_y = (current_y + 1)%T2;
141
                 dest_l = current_l;
142
                 return mesh_tori_addr_join(dest_x,dest_y,dest_l);
143
     }
144
 
145
     if( strcmp(TRAFFIC ,"CUSTOM") == 0){
146
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
147
                if(current_x ==0 && current_y == 0 && current_l==0 ){
148
           // dest_x =  T1-1;
149
           // dest_y =  T2-1;
150
           // dest_l =  T3-1;
151
                         dest_x =  0;
152
                         dest_y =  0;
153
                         dest_l =  1;
154
            return mesh_tori_addr_join(dest_x,dest_y,dest_l);
155
                }// make it invalid
156
        dest_x = current_x;
157
        dest_y = current_y;
158
        dest_l = current_l;
159
        return mesh_tori_addr_join(dest_x,dest_y,dest_l);
160
 
161
     }
162
 
163
                 printf ("traffic %s is an unsupported traffic pattern\n",TRAFFIC);
164
                 dest_x = current_x;
165
                 dest_y = current_y;
166
                 dest_l = current_l;
167
                 return mesh_tori_addr_join(dest_x,dest_y,dest_l);
168
}
169
 
170
 
171
 
172
 
173
unsigned int pck_dst_gen_1D (unsigned int core_num){
174
 
175
        unsigned int rnd=0;
176
        unsigned int rnd100=0;
177
        unsigned int max_percent=100/HOTSPOT_NUM;
178
        int i;
179
 
180
 
181
        if((strcmp (TRAFFIC,"RANDOM")==0) || (strcmp (TRAFFIC,"random")==0)){
182
                do{
183
                        rnd=rand()%NE;
184
                }while (rnd==core_num); // get a random IP core, make sure its not same as sender core
185
 
186
                return endp_addr_encoder(rnd);
187
        }
188
 
189
        if ((strcmp(TRAFFIC,"HOTSPOT")==0) || (strcmp (TRAFFIC,"hot spot")==0)){
190
                unsigned int rnd1000=0;
191
                int i;
192
                do{
193
                        rnd=rand()%NE;
194
                }while (rnd==core_num); // get a random IP core, make sure its not same as sender core
195
                rnd1000=rand()%1000; // generate a random number between 0 & 1000
196
                for (i=0;i<HOTSPOT_NUM; i++){
197
                        if ( hotspots[i].send_enable == 0 && core_num ==hotspots[i].ip_num){
198
                                rnd = core_num; // turn off the core
199
                                return endp_addr_encoder(rnd);
200
                        }
201
                }
202
 
203
                for (i=0;i<HOTSPOT_NUM; i++){
204
                        if (rnd1000 < hotspots[i].percentage && core_num !=hotspots[i].ip_num) {
205
                                rnd = hotspots[i].ip_num;
206
                                return endp_addr_encoder(rnd % NE );
207
                        }
208
                }
209
                return endp_addr_encoder(rnd % NE );
210
        }
211
 
212
 
213
        if(( strcmp(TRAFFIC ,"TRANSPOSE1")==0)|| (strcmp (TRAFFIC,"transposed 1")==0)){
214
                  return endp_addr_encoder(NE-core_num-1);
215
        }
216
        if(( strcmp(TRAFFIC ,"TRANSPOSE2")==0)|| (strcmp (TRAFFIC,"transposed 2")==0)){
217
                 return endp_addr_encoder(NE-core_num-1);
218
        }
219
 
220
        if(( strcmp(TRAFFIC ,"BIT_REVERSE")==0)|| (strcmp (TRAFFIC,"bit reverse")==0)){
221
                int tmp=0;
222
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, NEw-i-1, NEw));
223
                return endp_addr_encoder(tmp);
224
         }
225
 
226
         if(( strcmp(TRAFFIC ,"BIT_COMPLEMENT") ==0)|| (strcmp (TRAFFIC,"bit complement")==0)){
227
                 int tmp=0;
228
                 for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i, NEw)==0);
229
                 return endp_addr_encoder(tmp%NE);
230
         }
231
 
232
         if(( strcmp(TRAFFIC ,"TORNADO") == 0)|| (strcmp (TRAFFIC,"tornado")==0)){
233
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
234
                 return endp_addr_encoder((core_num + ((NE/2)-1))%NE);
235
     }
236
 
237
     if(( strcmp(TRAFFIC ,"SHUFFLE") == 0)|| (strcmp (TRAFFIC,"shuffle")==0)){
238
                //di = si−1 mod b
239
                int tmp=0;
240
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i-1, NEw));
241
                return endp_addr_encoder(tmp%NE);
242
         }
243
 
244
     if(( strcmp(TRAFFIC ,"BIT_ROTATION") == 0)|| (strcmp (TRAFFIC,"bit rotation")==0)){
245
                //di = si+1 mod b
246
                int tmp=0;
247
                for(i=0; i< NEw; i++)  setBit(&tmp , i, NEw, getBit(core_num, i+1, NEw));
248
                return endp_addr_encoder(tmp%NE);
249
 
250
     }
251
 
252
     if(( strcmp(TRAFFIC ,"NEIGHBOR") == 0)|| (strcmp (TRAFFIC,"neighbor")==0)){
253
                //dx = sx + 1 mod k
254
         return endp_addr_encoder((core_num + 1)%NE);
255
         }
256
 
257
     if( strcmp(TRAFFIC ,"CUSTOM") == 0){
258
                //[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
259
                if(core_num ==2  )       return  endp_addr_encoder(6);
260
                return endp_addr_encoder(core_num);
261
         }
262
 
263
         printf ("traffic %s is an unsupported traffic pattern\n",TRAFFIC);
264
         return  endp_addr_encoder(core_num);
265
}
266
 
267
 
268
unsigned int rnd_between (unsigned int a, unsigned int b){
269
        unsigned int rnd,diff,min;
270
        if(a==b) return a;
271
        diff= (a<b) ?  b-a+1 : a-b+1;
272
        min= (a<b) ?  a : b;
273
        rnd = (rand() % diff) +  min;
274
        return rnd;
275
}
276
 
277
 
278
 
279
 
280
 
281
 
282
#endif

powered by: WebSVN 2.1.0

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