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/] [rtl/] [src_modelsim/] [testbench_noc.sv] - Blame information for rev 54

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
// synthesis translate_off
2
`timescale   1ns/1ns
3
 
4
`define STND_DEV_EN
5
 
6
module testbench_noc;
7
 
8
        import pronoc_pkg::*;
9
        `define INCLUDE_SIM_PARAM
10
        `include "sim_param.sv" //will be generated by ProNoC GUI
11
        // simulation parameter setting
12
        // injected packet class percentage
13
        localparam
14
                C0_p=100,
15
                C1_p=0,
16
                C2_p=0,
17
                C3_p=0;
18
 
19
 
20
        localparam RATIOw=$clog2(100);
21
 
22
 
23
        reg     reset ,clk;
24
        reg     start,stop;
25
        wire    sent_done;
26
        reg    done;
27
        reg [RATIOw-1:0] ratio;
28
 
29
 
30
 
31
 
32
        initial begin
33
                clk = 1'b0;
34
                forever clk = #10 ~clk;
35
        end
36
 
37
 
38
 
39
        initial begin
40
                reset = 1'b1;
41
                start = 1'b0;
42
                stop  = 1'b0;
43
                ratio =INJRATIO;
44
                #80
45
                @(posedge clk) reset = 1'b0;
46
                #200
47
                @(posedge clk) start = 1'b1;
48
                @(posedge clk) start = 1'b0;
49
                @(posedge sent_done)
50
                stop=1;//stop all packet injectprs
51
                @(posedge done) //wait for all sent flits to be received at their destination
52
                #450
53
                @(posedge clk)
54
                $stop;
55
        end
56
 
57
 
58
        localparam
59
        /* verilator lint_off WIDTH */
60
 
61
 
62
                DISTw = (TOPOLOGY=="FATTREE" || TOPOLOGY == "TREE") ? $clog2(2*L+1): $clog2(NR+1),
63
                /* verilator lint_on WIDTH */
64
 
65
                Cw      =   (C>1)? $clog2(C): 1,
66
                // NEw     =   log2(NE),
67
 
68
                NEV     =   NE  * V,
69
                NEFw    =   NE  * Fw,
70
                PCK_CNTw=   $clog2(MAX_PCK_NUM+1),
71
                CLK_CNTw=   $clog2(MAX_SIM_CLKs+1),
72
                PCK_SIZw=   $clog2(MAX_PCK_SIZ+1),
73
                AVG_PCK_SIZ = (MAX_PACKET_SIZE + MIN_PACKET_SIZE)/2 ;
74
 
75
 
76
    typedef struct  {
77
                logic [PCK_CNTw-1     :0] pck_num;
78
                integer flit_num;
79
                integer worst_latency;
80
                integer min_latency;
81
                real sum_clk_h2h;
82
                real sum_clk_h2t;
83
                real sum_clk_per_hop;
84
`ifdef STND_DEV_EN
85
                real sum_clk_pow2;
86
`endif
87
        } statistic_t;
88
 
89
 
90
        typedef struct  {
91
                real avg_latency_per_hop;
92
                real avg_latency_flit;
93
                real avg_latency_pck;
94
                real avg_throughput;
95
                real avg_pck_siz;
96
`ifdef STND_DEV_EN
97
                real std_dev;
98
`endif
99
        } avg_st_t;
100
 
101
        integer m,c;
102
        localparam STAT_NUM= (C==0)? 1 : C;
103
        statistic_t sent_stat [NE][STAT_NUM];
104
        statistic_t rsvd_stat [NE][STAT_NUM];
105
        statistic_t sent_stat_class [NE];
106
        statistic_t rsvd_stat_class [NE];
107
        statistic_t sent_stat_per_class [STAT_NUM];
108
        statistic_t rsvd_stat_per_class [STAT_NUM];
109
        statistic_t rsvd_stat_total;
110
        statistic_t sent_stat_total;
111
 
112
        initial begin
113
                reset_st (rsvd_stat_total);
114
                reset_st (sent_stat_total);
115
                for(m=0;m
116
                        for (c=0;c
117
                                reset_st(sent_stat[m][c]);
118
                                reset_st(rsvd_stat[m][c]);
119
                        end
120
                        reset_st(rsvd_stat_class[m]);
121
                        reset_st(sent_stat_class[m]);
122
                end
123
                for (c=0; c
124
                        reset_st(sent_stat_per_class [c]);
125
                        reset_st(rsvd_stat_per_class [c]);
126
                end
127
        end
128
 
129
 
130
 
131
 
132
 
133
 
134
 
135
        task  reset_st;
136
                output  statistic_t stat_in;
137
                begin
138
                        stat_in.pck_num={PCK_CNTw{1'b0}};
139
                        stat_in.flit_num=0;
140
                        stat_in.worst_latency=0;
141
                        stat_in.min_latency=0;
142
                        stat_in.sum_clk_h2h=0;
143
                        stat_in.sum_clk_h2t=0;
144
                        stat_in.sum_clk_per_hop=0;
145
        `ifdef STND_DEV_EN
146
                        stat_in.sum_clk_pow2=0;
147
        `endif
148
                end
149
        endtask
150
 
151
 
152
 
153 54 alirezamon
    reg print_router_st;
154 48 alirezamon
 
155
        smartflit_chanel_t chan_in_all  [NE-1 : 0];
156
        smartflit_chanel_t chan_out_all [NE-1 : 0];
157 54 alirezamon
        router_event_t router_event [NR-1 : 0] [MAX_P-1 : 0];
158 48 alirezamon
 
159
 
160
 
161
 
162
        wire [NE-1      :   0]  hdr_flit_sent;
163 54 alirezamon
        wire [DAw-1     :   0]  dest_e_addr             [NE-1           :0];
164 48 alirezamon
        wire [EAw-1     :   0]  src_e_addr                              [NE-1           :0];
165
        wire [Cw-1      :   0]  pck_class_in            [NE-1           :0];
166
        wire [Cw-1      :   0]  flit_out_class          [NE-1           :0];
167
        wire [NEw-1     :   0]  src_id                                  [NE-1           :0];
168
 
169
        wire [PCK_SIZw-1:   0] pck_size_in [NE-1        :0];
170
        wire [PCK_SIZw-1:   0] pck_size_o  [NE-1        :0];
171 54 alirezamon
        wire [NEw-1 : 0] mcast_dst_num [NE-1        :0];
172 48 alirezamon
 
173
        //   wire    [NE-1           :0] report;
174
        reg     [CLK_CNTw-1             :0] clk_counter;
175
 
176
 
177
 
178
        wire    [PCK_CNTw-1     :0] pck_counter     [NE-1        :0];
179
        wire    [NE-1           :0] noc_report;
180
        wire    [NE-1           :0] update;
181
        wire    [CLK_CNTw-1     :0] time_stamp_h2t  [NE-1           :0];
182
        wire    [CLK_CNTw-1     :0] time_stamp_h2h  [NE-1           :0];
183
        wire    [DISTw-1         :0] distance        [NE-1           :0];
184
        wire    [Cw-1           :0] pck_class_out       [NE-1           :0];
185
 
186
        reg                         count_en;
187
        //reg [NE-1 : 0] start_o;
188
        logic [DELAYw-1 : 0] start_delay [NE-1 : 0];
189
 
190
 
191
 
192
 
193
        integer  rsv_size_array [MAX_PACKET_SIZE - MIN_PACKET_SIZE : 0];
194
 
195
 
196
 
197
        always @(posedge    clk or posedge reset) begin
198
                if (reset) begin
199
                        count_en <=1'b0;
200
                end else begin
201
                        if(start) count_en <=1'b1;
202
                        else if(noc_report) count_en <=1'b0;
203
                end
204
        end//always
205
 
206
 
207
        noc_top
208
                the_noc
209
                (
210
                        .reset(reset),
211
                        .clk(clk),
212
                        .chan_in_all(chan_in_all),
213 54 alirezamon
                        .chan_out_all(chan_out_all),
214
                        .router_event(router_event)
215 48 alirezamon
                );
216
 
217
 
218
 
219
        always @ (posedge clk or posedge reset)begin
220
                if          (reset  ) begin clk_counter  <= 0;  end
221
                else  begin
222
                        if  (count_en) clk_counter  <= clk_counter+1'b1;
223
 
224
                end
225
        end
226
 
227
 
228
 
229
        function integer addrencode;
230
                input integer pos,k,n,kw;
231
                integer pow,i,tmp;begin
232
                        addrencode=0;
233
                        pow=1;
234
                        for (i = 0; i 
235
                                tmp=(pos/pow);
236
                                tmp=tmp%k;
237
                                tmp=tmp<
238
                                addrencode=addrencode | tmp;
239
                                pow=pow * k;
240
                        end
241
                end
242
        endfunction
243
 
244
 
245
        genvar i;
246
    wire [NE-1 : 0] valid_dst;
247
 
248
        generate
249
        for(i=0; i< NE; i=i+1) begin : endpoints
250
 
251
                wire [EAw-1 : 0] current_e_addr [NE-1 : 0];
252
 
253
                        endp_addr_encoder #(
254
                                .TOPOLOGY(TOPOLOGY),
255
                                .T1(T1),
256
                                .T2(T2),
257
                                .T3(T3),
258
                                .EAw(EAw),
259
                                .NE(NE)
260
                        )
261
                        encoder
262
                        (
263
                                .id(i[NEw-1 : 0]),
264
                                .code(current_e_addr[i])
265
                        );
266
 
267
 
268
 
269
 
270
                        traffic_gen_top #(
271 54 alirezamon
                                .MAX_RATIO(100),
272
                                .ENDP_ID(i)
273 48 alirezamon
                        )
274
                        the_traffic_gen
275
                        (
276
                        .ratio (ratio),
277
                                .pck_size_in(pck_size_in[i]),
278
                                .current_e_addr(current_e_addr[i]),
279
                                .dest_e_addr(dest_e_addr[i]),
280
                                .pck_class_in(pck_class_in[i]),
281
                                .init_weight({{(WEIGHTw-1){1'b0}},1'b1}),
282
                                .hdr_flit_sent(hdr_flit_sent[i]),
283
                                .pck_number(pck_counter[i]),
284
                                .reset(reset),
285
                                .clk(clk),
286
                                .start(start),
287
                                .stop(stop | ~valid_dst[i]),
288
                                .sent_done(),
289
                                .update(update[i]),
290
                                .time_stamp_h2h(time_stamp_h2h[i]),
291
                                .time_stamp_h2t(time_stamp_h2t[i]),
292
                                .distance(distance[i]),
293
                                .src_e_addr(src_e_addr[i] ),
294
                                .pck_class_out(pck_class_out[i]),
295
                                .report (1'b0),
296
                                .pck_size_o(pck_size_o[i]),
297
                                .chan_in(chan_out_all[i]),
298
                                .chan_out(chan_in_all[i]),
299
                                .start_delay(start_delay[i]),
300
                .flit_out_class(flit_out_class[i]),
301
                                .flit_out_wr(),
302 54 alirezamon
                                .flit_in_wr(),
303
                                .mcast_dst_num_o(mcast_dst_num[i])
304 48 alirezamon
 
305
                        );
306
 
307
                        endp_addr_decoder #(
308
                                .TOPOLOGY(TOPOLOGY),
309
                                .T1(T1),
310
                                .T2(T2),
311
                                .T3(T3),
312
                                .EAw(EAw),
313
                                .NE(NE)
314
                        )
315
                        decoder
316
                        (
317
                                .id(src_id[i]),
318
                                .code(src_e_addr[i])
319
                        );
320
 
321
 
322
                        pck_class_in_gen #(
323
                                .C(C),
324
                                .C0_p(C0_p),
325
                                .C1_p(C1_p),
326
                                .C2_p(C2_p),
327
                                .C3_p(C3_p)
328
                        )
329
                        the_pck_class_in_gen
330
                        (
331
                                .en(hdr_flit_sent[i]),
332
                                .pck_class_o(pck_class_in[i]),
333
                                .reset(reset),
334
                                .clk(clk)
335
                        );
336
 
337
 
338
 
339
 
340
                        pck_dst_gen #(
341
                                .NE(NE),
342
                                .MAX_PCK_NUM(MAX_PCK_NUM),
343
                                .TRAFFIC(TRAFFIC),
344 54 alirezamon
                                .HOTSPOT_NODE_NUM(HOTSPOT_NODE_NUM),
345
                                .MCAST_TRAFFIC_RATIO(MCAST_TRAFFIC_RATIO),
346
                                .MCAST_PCK_SIZ_MIN(MCAST_PCK_SIZ_MIN),
347
                                .MCAST_PCK_SIZ_MAX(MCAST_PCK_SIZ_MAX),
348
                                .PCK_SIZw(PCK_SIZw),
349
                                .MIN_PACKET_SIZE(MIN_PACKET_SIZE),
350
                                .MAX_PACKET_SIZE(MAX_PACKET_SIZE),
351
                                .PCK_SIZ_SEL(PCK_SIZ_SEL),
352
                                .DISCRETE_PCK_SIZ_NUM(DISCRETE_PCK_SIZ_NUM)
353 48 alirezamon
                        )
354
                        the_pck_dst_gen
355
                        (
356
                                .reset(reset),
357
                                .clk(clk),
358
                                .en(hdr_flit_sent[i]),
359
                                .core_num(i[NEw-1  :   0]),
360
                                .pck_number(pck_counter[i]),
361
                                .current_e_addr(current_e_addr[i]),
362
                                .dest_e_addr(dest_e_addr[i]),
363
                                .valid_dst(valid_dst[i]),
364
                                .hotspot_info(hotspot_info),
365 54 alirezamon
                                .pck_size_o( pck_size_in[i]) ,
366
                                .rnd_discrete(rnd_discrete),
367 48 alirezamon
                                .custom_traffic_t(custom_traffic_t[i]),  // defined in sim_param.sv
368
                                .custom_traffic_en(custom_traffic_en[i])  // defined in sim_param.sv
369
                        );
370
 
371 54 alirezamon
 
372 48 alirezamon
 
373
        end
374
        endgenerate
375
 
376
 
377
 
378
 
379
 
380
 
381
 
382
 
383
        real                            sum_clk_h2h,sum_clk_h2t;
384
        real                            sum_clk_pow2;
385
        real                            sum_clk_pow2_per_class [C-1 : 0];
386
        real                            sum_clk_per_hop;
387
        integer             total_rsv_pck_num_per_class         [C-1    :   0];
388
        real                            sum_clk_h2h_per_class                   [C-1    :   0];
389
        real                            sum_clk_h2t_per_class                   [C-1    :   0];
390
        real                            sum_clk_per_hop_per_class               [C-1    :       0];
391
        integer                         rsvd_core_total_rsv_pck_num                     [NE-1   :   0];
392
        integer                         rsvd_core_worst_delay                   [NE-1   :   0];
393
        integer             sent_core_worst_delay           [NE-1   :   0];
394
        integer                         total_active_endp;
395
        integer             total_rsv_pck_num,total_rsv_flit_number;
396 54 alirezamon
        integer                         total_sent_pck_num,total_sent_flit_number,total_expect_rsv_flit_num;
397 48 alirezamon
 
398
        integer core_num,k;
399
        always @(posedge clk or posedge reset)begin
400
                if (reset) begin
401
                        total_rsv_pck_num=0;
402
                        total_sent_pck_num=0;
403
                        sum_clk_h2h=0;
404
                        sum_clk_h2t=0;
405
                        sum_clk_pow2=0;
406
                        sum_clk_per_hop=0;
407
                        total_sent_flit_number=0;
408
                        total_rsv_flit_number=0;
409 54 alirezamon
                        total_expect_rsv_flit_num=0;
410 48 alirezamon
                        for (k=0;k
411
                                        sum_clk_pow2_per_class[k]=0;
412
                                        total_rsv_pck_num_per_class[k]=0;
413
                                        sum_clk_h2h_per_class [k]=0;
414
                                        sum_clk_h2t_per_class [k]=0;
415
                                        sum_clk_per_hop_per_class[k]=0;
416
                        end
417
                        for (k=0;k
418
                                rsvd_core_total_rsv_pck_num[k]=0;
419
                                rsvd_core_worst_delay[k]=0;
420
                                sent_core_worst_delay[k]=0;
421
                        end
422
                        for (k=0; k<= MAX_PACKET_SIZE - MIN_PACKET_SIZE; k++)   rsv_size_array[k]=0;
423
 
424
                end
425
 
426
 
427
                for (core_num=0; core_num
428
                        if(chan_in_all[core_num].flit_chanel.flit_wr)begin
429
                                total_sent_flit_number+=1;
430 54 alirezamon
                                if (CAST_TYPE != "UNICAST") total_expect_rsv_flit_num+=mcast_dst_num[core_num];
431
                                else   total_expect_rsv_flit_num++;
432
 
433
 
434 48 alirezamon
                                if (C>1) sent_stat [core_num][flit_out_class[core_num]].flit_num++;
435
                                else     sent_stat [core_num][0].flit_num++;
436
                                if(chan_in_all[core_num].flit_chanel.flit[Fw-1])begin
437
                                        total_sent_pck_num+=1;
438
                                        if (C>1) sent_stat [core_num][flit_out_class[core_num]].pck_num++;
439
                                        else     sent_stat [core_num][0].pck_num++;
440
 
441
                                end
442
                        end
443
 
444
                        if(chan_out_all[core_num].flit_chanel.flit_wr)begin
445
                                total_rsv_flit_number+=1;
446
                                if (C>1) rsvd_stat [core_num][pck_class_out[core_num]].flit_num++;
447
                                else     rsvd_stat [core_num][0].flit_num++;
448
                        end
449
 
450
 
451
                        if( update [core_num] ) begin
452
                                total_rsv_pck_num = total_rsv_pck_num+1;
453
 
454
                                if (AVG_LATENCY_METRIC == "HEAD_2_TAIL")
455
                                update_statistic (
456
                                        core_num,
457
                                        pck_class_out[core_num],
458
                                         $itor(time_stamp_h2h[core_num]),
459
                                         $itor(time_stamp_h2t[core_num]),
460
                                        src_id[core_num],
461
                                        time_stamp_h2t[core_num],
462
                                        distance[core_num]
463
                                );
464
                                else
465
                                update_statistic (
466
                                        core_num,
467
                                        pck_class_out[core_num],
468
                                        $itor(time_stamp_h2h[core_num]),
469
                                        $itor(time_stamp_h2t[core_num]),
470
                                        src_id[core_num],
471
                                        time_stamp_h2h[core_num],
472
                                        distance[core_num]
473
                                );
474
 
475
 
476
                                if((total_rsv_pck_num & 'hffff )==0 ) $display(" packet received total=%0d",total_rsv_pck_num);
477
                                sum_clk_h2h +=  time_stamp_h2h[core_num];
478
                                sum_clk_h2t +=  time_stamp_h2t[core_num];
479
                                `ifdef STND_DEV_EN
480
                                        sum_clk_pow2+=time_stamp_h2h[core_num] * time_stamp_h2h[core_num];
481
                                        sum_clk_pow2_per_class[pck_class_out[core_num]]+=time_stamp_h2h[core_num] * time_stamp_h2h[core_num];
482
                                `endif
483 54 alirezamon
                                if(distance[core_num] > 0) sum_clk_per_hop+= $itor(time_stamp_h2h[core_num])/$itor(distance[core_num]);
484 48 alirezamon
                                total_rsv_pck_num_per_class[pck_class_out[core_num]]+=1;
485
                                sum_clk_h2h_per_class[pck_class_out[core_num]]+=time_stamp_h2h[core_num] ;
486
                                sum_clk_h2t_per_class[pck_class_out[core_num]]+=time_stamp_h2t[core_num] ;
487 54 alirezamon
                                if(distance[core_num]>0) sum_clk_per_hop_per_class[pck_class_out[core_num]]+= $itor(time_stamp_h2h[core_num])/$itor(distance[core_num]);
488 48 alirezamon
                                rsvd_core_total_rsv_pck_num[core_num]+=1;
489
                                if (rsvd_core_worst_delay[core_num] < time_stamp_h2t[core_num]) rsvd_core_worst_delay[core_num] = ( AVG_LATENCY_METRIC == "HEAD_2_TAIL")? time_stamp_h2t[core_num] : time_stamp_h2h[core_num];
490
                                if (sent_core_worst_delay[src_id[core_num]] < time_stamp_h2t[core_num]) sent_core_worst_delay[src_id[core_num]] = (AVG_LATENCY_METRIC == "HEAD_2_TAIL")?  time_stamp_h2t[core_num] : time_stamp_h2h[core_num];
491
                                if (pck_size_o[core_num] >= MIN_PACKET_SIZE && pck_size_o[core_num] <=MAX_PACKET_SIZE) rsv_size_array[pck_size_o[core_num]-MIN_PACKET_SIZE] = rsv_size_array[pck_size_o[core_num]-MIN_PACKET_SIZE]+1;
492
 
493
 
494
 
495
 
496
 
497
 
498
 
499
 
500
 
501
 
502
 
503
 
504
 
505
 
506
 
507
 
508
 
509
                        end
510
                end
511
        end//always
512
 
513
 
514
 
515
 
516
 
517
 
518
    integer rsv_ideal_cnt,total_rsv_flit_number_old;
519
        reg all_done_reg;
520
        wire all_done_in;
521
        assign all_done_in = (clk_counter > STOP_SIM_CLK) || ( total_sent_pck_num >  STOP_PCK_NUM );
522
        assign sent_done = all_done_in & ~ all_done_reg;
523
        always @(posedge clk or posedge reset)begin
524
                if(reset) begin
525
                        all_done_reg <= 1'b0;
526
                        rsv_ideal_cnt<=0;
527
                        done<=1'b0;
528
                        total_rsv_flit_number_old<=0;
529
                end  else  begin
530
                        all_done_reg <= all_done_in;
531
                        total_rsv_flit_number_old<=total_rsv_flit_number;
532
                        if(all_done_in) begin //All injectors stopped injecting packets
533
                                if(total_rsv_flit_number_old==total_rsv_flit_number) rsv_ideal_cnt<=rsv_ideal_cnt+1;//count the number of cycle when no flit is received by any injector
534
                                else rsv_ideal_cnt=0;
535 54 alirezamon
                                if(total_expect_rsv_flit_num == total_rsv_flit_number) begin // All injected packets are consumed
536 48 alirezamon
                                        done<=1'b1;
537
                                end
538
                                if(rsv_ideal_cnt >= 100) begin //  Injectors stopped sending packets, number of received and sent flits are not equal yet and for 100 cycles no flit is consumed.
539 54 alirezamon
                                        done<=1'b1;
540
                                        #100 $display ("ERROR: The number of expected (%d) & received flits (%d) were not equal at the end of simulation",total_expect_rsv_flit_num ,total_rsv_flit_number);
541 48 alirezamon
 
542
                                        $stop;
543
                                end
544
                        end
545
                end
546
        end
547
 
548
        initial total_active_endp=0;
549
 
550
 
551
        real avg_throughput,avg_latency_flit,avg_latency_pck,std_dev,avg_latency_per_hop,min_avg_latency_per_class;
552
 
553
 
554
        initial begin
555
                for(m=0;m
556
        end
557
 
558
 
559 54 alirezamon
        initial print_router_st=1'b0;
560 48 alirezamon
 
561
        //report
562
        always @( posedge done) begin
563 54 alirezamon
 
564
 
565 48 alirezamon
                for (core_num=0; core_num
566
                        if(pck_counter[core_num]>0) total_active_endp           =       total_active_endp +1;
567
                end
568
 
569
                avg_throughput= ((total_sent_flit_number*100)/total_active_endp )/clk_counter;
570
                avg_latency_flit =sum_clk_h2h/$itor(total_rsv_pck_num);
571
                avg_latency_pck  =sum_clk_h2t/$itor(total_rsv_pck_num);
572
                avg_latency_per_hop    = sum_clk_per_hop/$itor(total_rsv_pck_num);
573
                $display("simulation results-------------------");
574
                $display("\tSimulation clock cycles:%0d",clk_counter);
575 54 alirezamon
 
576
                print_router_st=1'b1;
577
                #1
578
 
579 48 alirezamon
/*
580
                $display(" total sent/received packets:%d/%d",total_sent_pck_num,total_rsv_pck_num);
581
                $display(" total sent/received flits:%d/%d",total_sent_flit_number,total_rsv_flit_number);
582
                $display(" Total active Endpoint: %d \n",total_active_endp);
583
                $display(" Avg throughput is: %f (flits/clk/Total active Endpoint %%)",   avg_throughput);
584
 
585
 
586
 
587
                $display("\nall : ");
588
                $display(" Total number of packet = %d \n average latency per hop = %f ",total_rsv_pck_num,avg_latency_per_hop);
589
                $display(" average packet latency = %f \n average flit latency = %f ",avg_latency_pck, avg_latency_flit);
590
*/
591
                $display("\n\tTotal injected packet in different size:");
592 54 alirezamon
                $write("\tflit_size,");
593
                for (m=0;m<=(MAX_PACKET_SIZE - MIN_PACKET_SIZE);m++) begin
594 48 alirezamon
                        if(rsv_size_array[m]>0)$write("%0d,",m+ MIN_PACKET_SIZE);
595
                end
596 54 alirezamon
                $write("\n\t#pck,");
597
                for (m=0;m<=(MAX_PACKET_SIZE - MIN_PACKET_SIZE);m++) begin
598 48 alirezamon
                        if(rsv_size_array[m]>0)$write("%0d,",rsv_size_array[m]);
599
                end
600
 
601
                //              if(ratio==RATIO_INIT) first_avg_latency_flit=avg_latency_flit;
602
                //`ifdef STND_DEV_EN
603
                                //std_dev= standard_dev( sum_clk_pow2,total_rsv_pck_num, avg_latency_flit);
604
                                //$display(" standard_dev = %f",std_dev);
605
                //`endif
606 54 alirezamon
                $display("\n\n\tEndpoints' statistics");
607
                $write("\t#node,sent_stat.pck_num,rsvd_stat.pck_num,sent_stat.flit_num,rsvd_stat.flit_num,sent_stat.worst_latency,rsvd_stat.worst_latency,sent_stat.min_latency,rsvd_stat.min_latency,avg_latency_per_hop,avg_latency_flit,avg_latency_pck,avg_throughput(%%),avg_pck_size,");
608 48 alirezamon
`ifdef STND_DEV_EN
609
                $write("avg.std_dev");
610
`endif
611 54 alirezamon
                $write("\n");
612 48 alirezamon
 
613
                for (m=0; m
614
                        for (c=0; c
615
                                merge_statistic (rsvd_stat_class[m],rsvd_stat[m][c],rsvd_stat_class[m]);
616
                                merge_statistic (sent_stat_class[m],sent_stat[m][c],sent_stat_class[m]);
617
                                if(C>1) begin
618
                                        merge_statistic (rsvd_stat_per_class[c],rsvd_stat[m][c],rsvd_stat_per_class[c]);
619
                                        merge_statistic (sent_stat_per_class[c],sent_stat[m][c],sent_stat_per_class[c]);
620
                                end
621
                        end
622
                end
623
 
624
 
625
 
626
 
627
 
628
 
629
 
630
 
631
 
632
        for (m=0; m
633
 
634
                merge_statistic (rsvd_stat_total,rsvd_stat_class[m],rsvd_stat_total);
635
                merge_statistic (sent_stat_total,sent_stat_class[m],sent_stat_total);
636
 
637
        end
638
 
639
        $write("\ttotal,");
640
        print_st_single (clk_counter, rsvd_stat_total,sent_stat_total);
641
 
642
        if(C>1)begin
643
                for (c=0; c
644
                        $write("\ttotal_class%0d,",c);
645
                        print_st_single (clk_counter, rsvd_stat_per_class[c],sent_stat_per_class[c]);
646
                end
647
        end
648
 
649
    for (m=0; m
650
        $write("\t%0d,",m);
651
                if(C>1) begin
652
                        print_st_single (clk_counter, rsvd_stat_class[m],sent_stat_class[m] );
653
                end else begin
654
                        print_st_single (clk_counter, rsvd_stat[m][0],sent_stat[m][0] );
655
                end
656
    end
657
 
658
 
659
 
660
 
661
 
662
 
663
 
664
 
665
/*
666
                min_avg_latency_per_class=1000000;
667
                for(m=0;m
668
                        avg_throughput           = (total_rsv_pck_num_per_class[m]>0)? ((total_rsv_pck_num_per_class[m]*AVG_PCK_SIZ*100)/total_active_endp )/clk_counter:0;
669
                        avg_latency_flit         = (total_rsv_pck_num_per_class[m]>0)? sum_clk_h2h_per_class[m]/total_rsv_pck_num_per_class[m]:0;
670
                        avg_latency_pck          = (total_rsv_pck_num_per_class[m]>0)? sum_clk_h2t_per_class[m]/total_rsv_pck_num_per_class[m]:0;
671
                        avg_latency_per_hop  = (total_rsv_pck_num_per_class[m]>0)? sum_clk_per_hop_per_class[m]/total_rsv_pck_num_per_class[m]:0;
672
                        if(AVG_LATENCY_METRIC == "HEAD_2_TAIL") begin
673
                                                $display ("\nclass : %d  ",m);
674
                                                $display (" Total number of packet  = %d \n avg_throughput = %f \n average latency per hop = %f \n average latency = %f",total_rsv_pck_num_per_class[m],avg_throughput,avg_latency_per_hop,avg_latency_pck);
675
 
676
                        end else begin
677
 
678
                                                $display ("\nclass : %d  ",m);
679
                                                $display (" Total number of packet  = %d \n avg_throughput = %f \n average latency per hop = %f \n average latency = %f",total_rsv_pck_num_per_class[m],avg_throughput,avg_latency_per_hop,avg_latency_flit);
680
                        end
681
                        if(min_avg_latency_per_class > avg_latency_flit) min_avg_latency_per_class=avg_latency_flit;
682
 
683
                                        //#if (STND_DEV_EN)
684
                                        //std_dev= (total_rsv_pck_num_per_class[i]>0)?  standard_dev( sum_clk_pow2_per_class[i],total_rsv_pck_num_per_class[i], avg_latency_flit):0;
685
                                        // sprintf(file_name,"%s_std%u.txt",out_file_name,i);
686
                                        // update_file( file_name,avg_throughput,std_dev);
687
 
688
                                        //#endif
689
                end//for
690
 
691
 
692
 
693
                for (m=0;m
694
                        $display         ("\n\nEndpoint %d",m);
695
                        $display         ("\n\ttotal number of received packets: %d",rsvd_core_total_rsv_pck_num[m]);
696
                        $display         ("\n\tworst-case-delay of received packets (clks): %d",rsvd_core_worst_delay[m] );
697
                        $display         ("\n\ttotal number of sent packets: %d",pck_counter[m]);
698
                        $display         ("\n\tworst-case-delay of sent packets (clks): %d",sent_core_worst_delay[m] );
699
                end
700
 
701
*/
702
 
703
        end
704
 
705
 
706
 
707
 
708
 
709
        initial begin
710 54 alirezamon
                display_noc_parameters();
711 48 alirezamon
                $display ("Simulation parameters-------------");
712
                if(DEBUG_EN)
713
                        $display ("\tDebuging is enabled");
714
                else
715
                        $display ("\tDebuging is disabled");
716
 
717
                //if( AVG_LATENCY_METRIC == "HEAD_2_TAIL")  $display ("\tOutput is the average latency on sending the packet header until receiving tail");
718
                //else $display ("\tOutput is the average latency on sending the packet header until receiving header flit at destination node");
719
                $display ("\tTraffic pattern:%s",TRAFFIC);
720
                if(C>0) $display ("\ttraffic percentage of class 0 is : %0d", C0_p);
721
                if(C>1) $display ("\ttraffic percentage of class 1 is : %0d", C1_p);
722
                if(C>2) $display ("\ttraffic percentage of class 2 is : %0d", C2_p);
723
                if(C>3) $display ("\ttraffic percentage of class 3 is : %0d", C3_p);
724
                if(TRAFFIC == "HOTSPOT")begin
725
                        //$display ("\tHot spot percentage: %u\n", HOTSPOT_PERCENTAGE);
726
                        $display ("\tNumber of hot spot cores: %0d", HOTSPOT_NODE_NUM);
727
                end
728 54 alirezamon
                if (CAST_TYPE != "UNICAST")begin
729
                        $display ("\tMULTICAST traffic ratio: %d(%%), min: %d, max: %d\n", MCAST_TRAFFIC_RATIO,MCAST_PCK_SIZ_MIN,MCAST_PCK_SIZ_MAX);
730
                end
731
 
732
 
733
 
734 48 alirezamon
                //$display ("\tTotal packets sent by one router: %u\n", TOTAL_PKT_PER_ROUTER);
735
                $display ("\tSimulation timeout =%0d", STOP_SIM_CLK);
736
                $display ("\tSimulation ends on total packet num of =%0d", STOP_PCK_NUM);
737
                $display ("\tPacket size (min,max,average) in flits: (%0d,%0d,%0d)",MIN_PACKET_SIZE,MAX_PACKET_SIZE,AVG_PCK_SIZ);
738
                $display ("\tPacket injector FIFO width in flit:%0d\n\n",TIMSTMP_FIFO_NUM);
739
                $display ("\tFlit injection ratio per router is =%f (flits/clk/Total Endpoint %%)",ratio);
740
 
741
                $display ("Simulation parameters-------------");
742
 
743
        end//initial
744
 
745
 
746
 
747
 
748
 
749
        task update_statistic;
750
                input integer core_num;
751
                input [Cw-1 : 0] class_num;
752
                input real clk_num_h2h;
753
                input real clk_num_h2t;
754
                input [NEw-1     :   0]  src;
755
                input real latency;
756
                input [DISTw-1         :0] distance     ;
757
                begin
758
 
759
 
760
                if(C>1) begin
761
 
762
                        rsvd_stat[core_num][class_num].pck_num ++;
763
                        rsvd_stat[core_num][class_num].sum_clk_h2h +=clk_num_h2h;
764
                        rsvd_stat[core_num][class_num].sum_clk_h2t +=clk_num_h2t;
765
                        rsvd_stat[core_num][class_num].sum_clk_per_hop+= (clk_num_h2h/$itor(distance));
766
                        if (rsvd_stat[core_num][class_num].worst_latency < latency ) rsvd_stat[core_num][class_num].worst_latency =latency;
767
                        if (rsvd_stat[core_num][class_num].min_latency==0          ) rsvd_stat[core_num][class_num].min_latency   =latency;
768
                        if (rsvd_stat[core_num][class_num].min_latency   > latency ) rsvd_stat[core_num][class_num].min_latency   =latency;
769
                        if (sent_stat[src     ][class_num].worst_latency < latency ) sent_stat[src     ][class_num].worst_latency =latency;
770
                        if (sent_stat[src     ][class_num].min_latency==0          ) sent_stat[src     ][class_num].min_latency   =latency;
771
                        if (sent_stat[src     ][class_num].min_latency   > latency ) sent_stat[src     ][class_num].min_latency   =latency;
772
 
773
                        `ifdef STND_DEV_EN
774
                        rsvd_stat[core_num][class_num].sum_clk_pow2 += clk_num_h2h * clk_num_h2h;
775
                        `endif
776
                end else begin
777
                        rsvd_stat[core_num][0].pck_num ++;
778
                    rsvd_stat[core_num][0].sum_clk_h2h +=clk_num_h2h;
779
                    rsvd_stat[core_num][0].sum_clk_h2t +=clk_num_h2t;
780 54 alirezamon
                    if(distance>0) rsvd_stat[core_num][0].sum_clk_per_hop+= (clk_num_h2h/$itor(distance));
781 48 alirezamon
                    if (rsvd_stat[core_num][0].worst_latency < latency ) rsvd_stat[core_num][0].worst_latency=latency;
782
                    if (rsvd_stat[core_num][0].min_latency==0          ) rsvd_stat[core_num][0].min_latency  =latency;
783
                    if (rsvd_stat[core_num][0].min_latency   > latency ) rsvd_stat[core_num][0].min_latency  =latency;
784
                    if (sent_stat[src     ][0].worst_latency < latency ) sent_stat[src     ][0].worst_latency=latency;
785
                    if (sent_stat[src     ][0].min_latency==0          ) sent_stat[src     ][0].min_latency  =latency;
786
                    if (sent_stat[src     ][0].min_latency   > latency ) sent_stat[src     ][0].min_latency  =latency;
787
 
788
                        `ifdef STND_DEV_EN
789
                        rsvd_stat[core_num][0].sum_clk_pow2 += clk_num_h2h * clk_num_h2h;
790
                        `endif
791
                end
792
 
793
        end
794
        endtask
795
 
796
 
797
 
798
 
799
        task merge_statistic;
800
        input statistic_t merge_stat;
801
        input statistic_t stat_in;
802
        output statistic_t stat_out;
803
        begin
804
                stat_out.pck_num =    merge_stat.pck_num+stat_in.pck_num;
805
                stat_out.flit_num =   merge_stat.flit_num+stat_in.flit_num;
806
                if(merge_stat.worst_latency <  stat_in.worst_latency) stat_out.worst_latency= stat_in.worst_latency;
807
                if(merge_stat.min_latency   == 0                       ) stat_out.min_latency  = stat_in.min_latency;
808
                if(merge_stat.min_latency   > stat_in.min_latency  && stat_in.min_latency!=0   ) stat_out.min_latency  = stat_in.min_latency;
809
                stat_out.sum_clk_h2h = merge_stat.sum_clk_h2h      +stat_in.sum_clk_h2h    ;
810
                stat_out.sum_clk_h2t = merge_stat.sum_clk_h2t      +stat_in.sum_clk_h2t    ;
811
                stat_out.sum_clk_per_hop =   merge_stat.sum_clk_per_hop  +stat_in.sum_clk_per_hop;
812
                `ifdef STND_DEV_EN
813
                        stat_out.sum_clk_pow2 = merge_stat.sum_clk_pow2 +stat_in.sum_clk_pow2;
814
        `endif
815
 
816
        end
817
        endtask
818
 
819
 
820
 
821
 
822
 
823
 
824
        task print_st_single;
825
                input [CLK_CNTw-1 : 0]total_clk;
826
                input statistic_t rsvd_stat;
827
                input statistic_t sent_stat;
828
                begin
829
 
830
 
831
 
832
                avg_st_t avg;
833
                finilize_statistic (total_clk,  rsvd_stat, avg);
834
 
835
                $write("%0d,",sent_stat.pck_num);
836
                $write("%0d,",rsvd_stat.pck_num);
837
                $write("%0d,",sent_stat.flit_num);
838
                $write("%0d,",rsvd_stat.flit_num);
839
                $write("%0d,",sent_stat.worst_latency);
840
                $write("%0d,",rsvd_stat.worst_latency);
841
                $write("%0d,",sent_stat.min_latency);
842
                $write("%0d,",rsvd_stat.min_latency);
843
                $write("%f,",avg.avg_latency_per_hop);
844
                $write("%f,",avg.avg_latency_flit);
845
                $write("%f,",avg.avg_latency_pck);
846
                $write("%f,",avg.avg_throughput);
847
                $write("%f,",avg.avg_pck_siz);
848
        `ifdef STND_DEV_EN
849
                $write("%f,",avg.std_dev);
850
        `endif
851
                $write("\n");
852
        //      printf("\n");
853
                end
854
        endtask
855
 
856
 
857
 
858
        task finilize_statistic;
859
                input [CLK_CNTw-1 : 0]total_clk;
860
                input statistic_t rsvd_stat;
861
                output avg_st_t avg_statistic;
862
                begin
863
 
864
 
865
                 avg_statistic.avg_throughput = ($itor(rsvd_stat.flit_num*100)/NE )/total_clk;
866
                 avg_statistic.avg_latency_flit =(rsvd_stat.pck_num>0)? rsvd_stat.sum_clk_h2h/rsvd_stat.pck_num : 0;
867
                 avg_statistic.avg_latency_pck = (rsvd_stat.pck_num>0)? rsvd_stat.sum_clk_h2t/rsvd_stat.pck_num :0;
868
                 avg_statistic.avg_latency_per_hop = ( rsvd_stat.pck_num==0)? 0 : rsvd_stat.sum_clk_per_hop/rsvd_stat.pck_num;
869
                 avg_statistic.avg_pck_siz  = ( rsvd_stat.pck_num==0)? 0 : $itor(rsvd_stat.flit_num) / $itor(rsvd_stat.pck_num);
870
                 `ifdef STND_DEV_EN
871
                        standard_dev( rsvd_stat.sum_clk_pow2,rsvd_stat.pck_num, avg_statistic.avg_latency_flit,avg_statistic.std_dev);
872
                 `endif
873
        end
874
        endtask
875
 
876
 
877
 
878
        `ifdef STND_DEV_EN
879
        /************************
880
         * std_dev = sqrt[(B-A^2/N)/N]  = sqrt [(B/N)- (A/N)^2] = sqrt [B/N - mean^2]
881
         * A = sum of the values
882
         * B = sum of the squarded values
883
         * *************/
884
 
885
        task standard_dev;
886
                input real sum_pow2;
887
                input [PCK_CNTw-1     :0]  total_num;
888
                input real average;
889
                output real std_dev;
890
                begin
891
                /*
892
                double  A, B, N;
893
                N= total_num;
894
                A= average * N;
895
                B= sum_pow2;
896
 
897
                A=(A*A)/N;
898
                std_dev = (B-A)/N;
899
                std_dev = sqrt(std_dev);
900
        */
901
                if(total_num==0) std_dev= 0;
902
                else begin
903
                        std_dev = sum_pow2/$itor(total_num); //B/N
904
                        std_dev -= (average*average);// (B/N) - mean^2
905
                        std_dev = $sqrt(std_dev);// sqrt [B/N - mean^2]
906
 
907
                end
908
        end
909
        endtask
910
 
911
        `endif
912
 
913
 
914
 
915
        /*
916
        start_delay_gen #(
917
                        .NC(NE)
918
                )
919
                delay_gen
920
                (
921
                        .clk(clk),
922
                        .reset(reset),
923
                        .start_i(start),
924
                        .start_o(start_o)
925
                );
926
         */
927 54 alirezamon
 
928
 
929
        routers_statistic_collector router_stat(
930
                .reset(reset),
931
                .clk(clk),
932
                .router_event(router_event),
933
                .print(print_router_st)
934
        );
935 48 alirezamon
 
936
endmodule
937
// synthesis translate_on
938
 

powered by: WebSVN 2.1.0

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