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 48

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
 
154
 
155
        smartflit_chanel_t chan_in_all  [NE-1 : 0];
156
        smartflit_chanel_t chan_out_all [NE-1 : 0];
157
 
158
 
159
 
160
 
161
 
162
        wire [NE-1      :   0]  hdr_flit_sent;
163
        wire [EAw-1     :   0]  dest_e_addr             [NE-1           :0];
164
        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
 
172
 
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
                        .chan_out_all(chan_out_all)
214
                );
215
 
216
 
217
 
218
        always @ (posedge clk or posedge reset)begin
219
                if          (reset  ) begin clk_counter  <= 0;  end
220
                else  begin
221
                        if  (count_en) clk_counter  <= clk_counter+1'b1;
222
 
223
                end
224
        end
225
 
226
 
227
 
228
        function integer addrencode;
229
                input integer pos,k,n,kw;
230
                integer pow,i,tmp;begin
231
                        addrencode=0;
232
                        pow=1;
233
                        for (i = 0; i 
234
                                tmp=(pos/pow);
235
                                tmp=tmp%k;
236
                                tmp=tmp<
237
                                addrencode=addrencode | tmp;
238
                                pow=pow * k;
239
                        end
240
                end
241
        endfunction
242
 
243
 
244
        genvar i;
245
    wire [NE-1 : 0] valid_dst;
246
 
247
        generate
248
        for(i=0; i< NE; i=i+1) begin : endpoints
249
 
250
                wire [EAw-1 : 0] current_e_addr [NE-1 : 0];
251
 
252
                        endp_addr_encoder #(
253
                                .TOPOLOGY(TOPOLOGY),
254
                                .T1(T1),
255
                                .T2(T2),
256
                                .T3(T3),
257
                                .EAw(EAw),
258
                                .NE(NE)
259
                        )
260
                        encoder
261
                        (
262
                                .id(i[NEw-1 : 0]),
263
                                .code(current_e_addr[i])
264
                        );
265
 
266
 
267
 
268
 
269
                        traffic_gen_top #(
270
                                .MAX_RATIO(100)
271
                        )
272
                        the_traffic_gen
273
                        (
274
                        .ratio (ratio),
275
                                .pck_size_in(pck_size_in[i]),
276
                                .current_e_addr(current_e_addr[i]),
277
                                .dest_e_addr(dest_e_addr[i]),
278
                                .pck_class_in(pck_class_in[i]),
279
                                .init_weight({{(WEIGHTw-1){1'b0}},1'b1}),
280
                                .hdr_flit_sent(hdr_flit_sent[i]),
281
                                .pck_number(pck_counter[i]),
282
                                .reset(reset),
283
                                .clk(clk),
284
                                .start(start),
285
                                .stop(stop | ~valid_dst[i]),
286
                                .sent_done(),
287
                                .update(update[i]),
288
                                .time_stamp_h2h(time_stamp_h2h[i]),
289
                                .time_stamp_h2t(time_stamp_h2t[i]),
290
                                .distance(distance[i]),
291
                                .src_e_addr(src_e_addr[i] ),
292
                                .pck_class_out(pck_class_out[i]),
293
                                .report (1'b0),
294
                                .pck_size_o(pck_size_o[i]),
295
                                .chan_in(chan_out_all[i]),
296
                                .chan_out(chan_in_all[i]),
297
                                .start_delay(start_delay[i]),
298
                .flit_out_class(flit_out_class[i]),
299
                                .flit_out_wr(),
300
                                .flit_in_wr()
301
 
302
                        );
303
 
304
                        endp_addr_decoder #(
305
                                .TOPOLOGY(TOPOLOGY),
306
                                .T1(T1),
307
                                .T2(T2),
308
                                .T3(T3),
309
                                .EAw(EAw),
310
                                .NE(NE)
311
                        )
312
                        decoder
313
                        (
314
                                .id(src_id[i]),
315
                                .code(src_e_addr[i])
316
                        );
317
 
318
 
319
                        pck_class_in_gen #(
320
                                .C(C),
321
                                .C0_p(C0_p),
322
                                .C1_p(C1_p),
323
                                .C2_p(C2_p),
324
                                .C3_p(C3_p)
325
                        )
326
                        the_pck_class_in_gen
327
                        (
328
                                .en(hdr_flit_sent[i]),
329
                                .pck_class_o(pck_class_in[i]),
330
                                .reset(reset),
331
                                .clk(clk)
332
                        );
333
 
334
 
335
 
336
 
337
                        pck_dst_gen #(
338
                                .NE(NE),
339
                                .MAX_PCK_NUM(MAX_PCK_NUM),
340
                                .TRAFFIC(TRAFFIC),
341
                                .HOTSPOT_NODE_NUM(HOTSPOT_NODE_NUM)
342
                        )
343
                        the_pck_dst_gen
344
                        (
345
                                .reset(reset),
346
                                .clk(clk),
347
                                .en(hdr_flit_sent[i]),
348
                                .core_num(i[NEw-1  :   0]),
349
                                .pck_number(pck_counter[i]),
350
                                .current_e_addr(current_e_addr[i]),
351
                                .dest_e_addr(dest_e_addr[i]),
352
                                .valid_dst(valid_dst[i]),
353
                                .hotspot_info(hotspot_info),
354
                                .custom_traffic_t(custom_traffic_t[i]),  // defined in sim_param.sv
355
                                .custom_traffic_en(custom_traffic_en[i])  // defined in sim_param.sv
356
                        );
357
 
358
                        pck_size_gen #(
359
                                .PCK_SIZw(PCK_SIZw),
360
                                .MIN(MIN_PACKET_SIZE),
361
                                .MAX(MAX_PACKET_SIZE),
362
                                .PCK_SIZ_SEL(PCK_SIZ_SEL),
363
                                .DISCRETE_PCK_SIZ_NUM(DISCRETE_PCK_SIZ_NUM)
364
                        )
365
                        the_pck_siz_gen
366
                        (
367
                                .reset(reset),
368
                                .clk(clk),
369
                                .en(hdr_flit_sent[i]),
370
                                .pck_size( pck_size_in[i]) ,
371
                                .rnd_discrete(rnd_discrete)
372
                        );
373
 
374
        end
375
        endgenerate
376
 
377
 
378
 
379
 
380
 
381
 
382
 
383
 
384
        real                            sum_clk_h2h,sum_clk_h2t;
385
        real                            sum_clk_pow2;
386
        real                            sum_clk_pow2_per_class [C-1 : 0];
387
        real                            sum_clk_per_hop;
388
        integer             total_rsv_pck_num_per_class         [C-1    :   0];
389
        real                            sum_clk_h2h_per_class                   [C-1    :   0];
390
        real                            sum_clk_h2t_per_class                   [C-1    :   0];
391
        real                            sum_clk_per_hop_per_class               [C-1    :       0];
392
        integer                         rsvd_core_total_rsv_pck_num                     [NE-1   :   0];
393
        integer                         rsvd_core_worst_delay                   [NE-1   :   0];
394
        integer             sent_core_worst_delay           [NE-1   :   0];
395
        integer                         total_active_endp;
396
        integer             total_rsv_pck_num,total_rsv_flit_number;
397
        integer                         total_sent_pck_num,total_sent_flit_number;
398
 
399
        integer core_num,k;
400
        always @(posedge clk or posedge reset)begin
401
                if (reset) begin
402
                        total_rsv_pck_num=0;
403
                        total_sent_pck_num=0;
404
                        sum_clk_h2h=0;
405
                        sum_clk_h2t=0;
406
                        sum_clk_pow2=0;
407
                        sum_clk_per_hop=0;
408
                        total_sent_flit_number=0;
409
                        total_rsv_flit_number=0;
410
                        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
                                if (C>1) sent_stat [core_num][flit_out_class[core_num]].flit_num++;
431
                                else     sent_stat [core_num][0].flit_num++;
432
                                if(chan_in_all[core_num].flit_chanel.flit[Fw-1])begin
433
                                        total_sent_pck_num+=1;
434
                                        if (C>1) sent_stat [core_num][flit_out_class[core_num]].pck_num++;
435
                                        else     sent_stat [core_num][0].pck_num++;
436
 
437
                                end
438
                        end
439
 
440
                        if(chan_out_all[core_num].flit_chanel.flit_wr)begin
441
                                total_rsv_flit_number+=1;
442
                                if (C>1) rsvd_stat [core_num][pck_class_out[core_num]].flit_num++;
443
                                else     rsvd_stat [core_num][0].flit_num++;
444
                        end
445
 
446
 
447
                        if( update [core_num] ) begin
448
                                total_rsv_pck_num = total_rsv_pck_num+1;
449
 
450
                                if (AVG_LATENCY_METRIC == "HEAD_2_TAIL")
451
                                update_statistic (
452
                                        core_num,
453
                                        pck_class_out[core_num],
454
                                         $itor(time_stamp_h2h[core_num]),
455
                                         $itor(time_stamp_h2t[core_num]),
456
                                        src_id[core_num],
457
                                        time_stamp_h2t[core_num],
458
                                        distance[core_num]
459
                                );
460
                                else
461
                                update_statistic (
462
                                        core_num,
463
                                        pck_class_out[core_num],
464
                                        $itor(time_stamp_h2h[core_num]),
465
                                        $itor(time_stamp_h2t[core_num]),
466
                                        src_id[core_num],
467
                                        time_stamp_h2h[core_num],
468
                                        distance[core_num]
469
                                );
470
 
471
 
472
                                if((total_rsv_pck_num & 'hffff )==0 ) $display(" packet received total=%0d",total_rsv_pck_num);
473
                                sum_clk_h2h +=  time_stamp_h2h[core_num];
474
                                sum_clk_h2t +=  time_stamp_h2t[core_num];
475
                                `ifdef STND_DEV_EN
476
                                        sum_clk_pow2+=time_stamp_h2h[core_num] * time_stamp_h2h[core_num];
477
                                        sum_clk_pow2_per_class[pck_class_out[core_num]]+=time_stamp_h2h[core_num] * time_stamp_h2h[core_num];
478
                                `endif
479
                                sum_clk_per_hop+= $itor(time_stamp_h2h[core_num])/$itor(distance[core_num]);
480
                                total_rsv_pck_num_per_class[pck_class_out[core_num]]+=1;
481
                                sum_clk_h2h_per_class[pck_class_out[core_num]]+=time_stamp_h2h[core_num] ;
482
                                sum_clk_h2t_per_class[pck_class_out[core_num]]+=time_stamp_h2t[core_num] ;
483
                                sum_clk_per_hop_per_class[pck_class_out[core_num]]+= $itor(time_stamp_h2h[core_num])/$itor(distance[core_num]);
484
                                rsvd_core_total_rsv_pck_num[core_num]+=1;
485
                                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];
486
                                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];
487
                                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;
488
 
489
 
490
 
491
 
492
 
493
 
494
 
495
 
496
 
497
 
498
 
499
 
500
 
501
 
502
 
503
 
504
 
505
                        end
506
                end
507
        end//always
508
 
509
 
510
 
511
 
512
 
513
 
514
    integer rsv_ideal_cnt,total_rsv_flit_number_old;
515
        reg all_done_reg;
516
        wire all_done_in;
517
        assign all_done_in = (clk_counter > STOP_SIM_CLK) || ( total_sent_pck_num >  STOP_PCK_NUM );
518
        assign sent_done = all_done_in & ~ all_done_reg;
519
        always @(posedge clk or posedge reset)begin
520
                if(reset) begin
521
                        all_done_reg <= 1'b0;
522
                        rsv_ideal_cnt<=0;
523
                        done<=1'b0;
524
                        total_rsv_flit_number_old<=0;
525
                end  else  begin
526
                        all_done_reg <= all_done_in;
527
                        total_rsv_flit_number_old<=total_rsv_flit_number;
528
                        if(all_done_in) begin //All injectors stopped injecting packets
529
                                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
530
                                else rsv_ideal_cnt=0;
531
                                if(total_sent_flit_number == total_rsv_flit_number) begin // All injected packets are consumed
532
                                        done<=1'b1;
533
                                end
534
                                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.
535
                                        $display ("ERROR: The number of sent (%d) & received flits (%d) were not equal at the end of simulation",total_sent_flit_number ,total_rsv_flit_number);
536
 
537
                                        $stop;
538
                                end
539
                        end
540
                end
541
        end
542
 
543
        initial total_active_endp=0;
544
 
545
 
546
        real avg_throughput,avg_latency_flit,avg_latency_pck,std_dev,avg_latency_per_hop,min_avg_latency_per_class;
547
 
548
 
549
        initial begin
550
                for(m=0;m
551
        end
552
 
553
 
554
 
555
 
556
        //report
557
        always @( posedge done) begin
558
 
559
                for (core_num=0; core_num
560
                        if(pck_counter[core_num]>0) total_active_endp           =       total_active_endp +1;
561
                end
562
 
563
                avg_throughput= ((total_sent_flit_number*100)/total_active_endp )/clk_counter;
564
                avg_latency_flit =sum_clk_h2h/$itor(total_rsv_pck_num);
565
                avg_latency_pck  =sum_clk_h2t/$itor(total_rsv_pck_num);
566
                avg_latency_per_hop    = sum_clk_per_hop/$itor(total_rsv_pck_num);
567
                $display("simulation results-------------------");
568
                $display("\tSimulation clock cycles:%0d",clk_counter);
569
/*
570
                $display(" total sent/received packets:%d/%d",total_sent_pck_num,total_rsv_pck_num);
571
                $display(" total sent/received flits:%d/%d",total_sent_flit_number,total_rsv_flit_number);
572
                $display(" Total active Endpoint: %d \n",total_active_endp);
573
                $display(" Avg throughput is: %f (flits/clk/Total active Endpoint %%)",   avg_throughput);
574
 
575
 
576
 
577
                $display("\nall : ");
578
                $display(" Total number of packet = %d \n average latency per hop = %f ",total_rsv_pck_num,avg_latency_per_hop);
579
                $display(" average packet latency = %f \n average flit latency = %f ",avg_latency_pck, avg_latency_flit);
580
*/
581
                $display("\n\tTotal injected packet in different size:");
582
                for (m=0;m<=(MAX_PACKET_SIZE - MIN_PACKET_SIZE);m++) begin
583
                        $write("\tflit_size,");
584
                        if(rsv_size_array[m]>0)$write("%0d,",m+ MIN_PACKET_SIZE);
585
                end
586
                for (m=0;m<=(MAX_PACKET_SIZE - MIN_PACKET_SIZE);m++) begin
587
                        $write("\n\t#pck,");
588
                        if(rsv_size_array[m]>0)$write("%0d,",rsv_size_array[m]);
589
                end
590
 
591
                //              if(ratio==RATIO_INIT) first_avg_latency_flit=avg_latency_flit;
592
                //`ifdef STND_DEV_EN
593
                                //std_dev= standard_dev( sum_clk_pow2,total_rsv_pck_num, avg_latency_flit);
594
                                //$display(" standard_dev = %f",std_dev);
595
                //`endif
596
 
597
                $write("\n\n\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,");
598
`ifdef STND_DEV_EN
599
                $write("avg.std_dev");
600
`endif
601
                $write("\n");
602
 
603
 
604
 
605
 
606
 
607
                for (m=0; m
608
                        for (c=0; c
609
                                merge_statistic (rsvd_stat_class[m],rsvd_stat[m][c],rsvd_stat_class[m]);
610
                                merge_statistic (sent_stat_class[m],sent_stat[m][c],sent_stat_class[m]);
611
                                if(C>1) begin
612
                                        merge_statistic (rsvd_stat_per_class[c],rsvd_stat[m][c],rsvd_stat_per_class[c]);
613
                                        merge_statistic (sent_stat_per_class[c],sent_stat[m][c],sent_stat_per_class[c]);
614
                                end
615
                        end
616
                end
617
 
618
 
619
 
620
 
621
 
622
 
623
 
624
 
625
 
626
        for (m=0; m
627
 
628
                merge_statistic (rsvd_stat_total,rsvd_stat_class[m],rsvd_stat_total);
629
                merge_statistic (sent_stat_total,sent_stat_class[m],sent_stat_total);
630
 
631
        end
632
 
633
        $write("\ttotal,");
634
        print_st_single (clk_counter, rsvd_stat_total,sent_stat_total);
635
 
636
        if(C>1)begin
637
                for (c=0; c
638
                        $write("\ttotal_class%0d,",c);
639
                        print_st_single (clk_counter, rsvd_stat_per_class[c],sent_stat_per_class[c]);
640
                end
641
        end
642
 
643
    for (m=0; m
644
        $write("\t%0d,",m);
645
                if(C>1) begin
646
                        print_st_single (clk_counter, rsvd_stat_class[m],sent_stat_class[m] );
647
                end else begin
648
                        print_st_single (clk_counter, rsvd_stat[m][0],sent_stat[m][0] );
649
                end
650
    end
651
 
652
 
653
 
654
 
655
 
656
 
657
 
658
 
659
/*
660
                min_avg_latency_per_class=1000000;
661
                for(m=0;m
662
                        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;
663
                        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;
664
                        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;
665
                        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;
666
                        if(AVG_LATENCY_METRIC == "HEAD_2_TAIL") begin
667
                                                $display ("\nclass : %d  ",m);
668
                                                $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);
669
 
670
                        end else begin
671
 
672
                                                $display ("\nclass : %d  ",m);
673
                                                $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);
674
                        end
675
                        if(min_avg_latency_per_class > avg_latency_flit) min_avg_latency_per_class=avg_latency_flit;
676
 
677
                                        //#if (STND_DEV_EN)
678
                                        //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;
679
                                        // sprintf(file_name,"%s_std%u.txt",out_file_name,i);
680
                                        // update_file( file_name,avg_throughput,std_dev);
681
 
682
                                        //#endif
683
                end//for
684
 
685
 
686
 
687
                for (m=0;m
688
                        $display         ("\n\nEndpoint %d",m);
689
                        $display         ("\n\ttotal number of received packets: %d",rsvd_core_total_rsv_pck_num[m]);
690
                        $display         ("\n\tworst-case-delay of received packets (clks): %d",rsvd_core_worst_delay[m] );
691
                        $display         ("\n\ttotal number of sent packets: %d",pck_counter[m]);
692
                        $display         ("\n\tworst-case-delay of sent packets (clks): %d",sent_core_worst_delay[m] );
693
                end
694
 
695
*/
696
 
697
        end
698
 
699
 
700
 
701
 
702
 
703
        initial begin
704
 
705
                //print_parameter
706
                $display ("NoC parameters:----------------");
707
                $display ("\tTopology: %s",TOPOLOGY);
708
                $display ("\tRouting algorithm: %s",ROUTE_NAME);
709
                $display ("\tVC_per port: %0d", V);
710
                $display ("\tNon-local port buffer_width per VC: %0d", B);
711
                $display ("\tLocal port buffer_width per VC: %0d", LB);
712
                if(TOPOLOGY=="MESH" || TOPOLOGY=="TORUS")begin
713
                        $display ("\tRouter num in row: %0d",T1);
714
                        $display ("\tRouter num in column: %0d",T2);
715
                        $display ("\tEndpoint num per router: %0d",T3);
716
                end else if (TOPOLOGY=="RING" || TOPOLOGY == "LINE") begin
717
                        $display ("\tTotal Router num: %0d",T1);
718
                        $display ("\tEndpoint num per router: %0d",T3);
719
                end else if (TOPOLOGY == "TREE" ||  TOPOLOGY == "FATTREE")begin
720
                        $display ("\tK: %0d",T1);
721
                        $display ("\tL: %0d",T2);
722
                end else begin //CUSTOM
723
                        $display ("\tTotal Endpoints number: %0d",T1);
724
                        $display ("\tTotal Routers number: %0d",T2);
725
                end
726
                $display ("\tNumber of Class: %0d", C);
727
                $display ("\tFlit data width: %0d", Fpay);
728
                $display ("\tVC reallocation mechanism: %s",  VC_REALLOCATION_TYPE);
729
                $display ("\tVC/sw combination mechanism: %s", COMBINATION_TYPE);
730
                $display ("\tAVC_ATOMIC_EN:%0d", AVC_ATOMIC_EN);
731
                $display ("\tCongestion Index:%0d",CONGESTION_INDEX);
732
                $display ("\tADD_PIPREG_AFTER_CROSSBAR:%0d",ADD_PIPREG_AFTER_CROSSBAR);
733
                $display ("\tSSA_EN enabled:%s",SSA_EN);
734
                $display ("\tSwitch allocator arbitration type:%s",SWA_ARBITER_TYPE);
735
                $display ("\tMinimum supported packet size:%0d flit(s)",MIN_PCK_SIZE);
736
                $display ("\tLoop back is enabled:%s",SELF_LOOP_EN);
737
                $display ("\tNumber of multihop bypass (SMART max):%0d",SMART_MAX);
738
                $display ("NoC parameters:----------------");
739
                $display ("Simulation parameters-------------");
740
                if(DEBUG_EN)
741
                        $display ("\tDebuging is enabled");
742
                else
743
                        $display ("\tDebuging is disabled");
744
 
745
                //if( AVG_LATENCY_METRIC == "HEAD_2_TAIL")  $display ("\tOutput is the average latency on sending the packet header until receiving tail");
746
                //else $display ("\tOutput is the average latency on sending the packet header until receiving header flit at destination node");
747
                $display ("\tTraffic pattern:%s",TRAFFIC);
748
                if(C>0) $display ("\ttraffic percentage of class 0 is : %0d", C0_p);
749
                if(C>1) $display ("\ttraffic percentage of class 1 is : %0d", C1_p);
750
                if(C>2) $display ("\ttraffic percentage of class 2 is : %0d", C2_p);
751
                if(C>3) $display ("\ttraffic percentage of class 3 is : %0d", C3_p);
752
                if(TRAFFIC == "HOTSPOT")begin
753
                        //$display ("\tHot spot percentage: %u\n", HOTSPOT_PERCENTAGE);
754
                        $display ("\tNumber of hot spot cores: %0d", HOTSPOT_NODE_NUM);
755
                end
756
                //$display ("\tTotal packets sent by one router: %u\n", TOTAL_PKT_PER_ROUTER);
757
                $display ("\tSimulation timeout =%0d", STOP_SIM_CLK);
758
                $display ("\tSimulation ends on total packet num of =%0d", STOP_PCK_NUM);
759
                $display ("\tPacket size (min,max,average) in flits: (%0d,%0d,%0d)",MIN_PACKET_SIZE,MAX_PACKET_SIZE,AVG_PCK_SIZ);
760
                $display ("\tPacket injector FIFO width in flit:%0d\n\n",TIMSTMP_FIFO_NUM);
761
                $display ("\tFlit injection ratio per router is =%f (flits/clk/Total Endpoint %%)",ratio);
762
 
763
                $display ("Simulation parameters-------------");
764
 
765
        end//initial
766
 
767
 
768
 
769
 
770
 
771
        task update_statistic;
772
                input integer core_num;
773
                input [Cw-1 : 0] class_num;
774
                input real clk_num_h2h;
775
                input real clk_num_h2t;
776
                input [NEw-1     :   0]  src;
777
                input real latency;
778
                input [DISTw-1         :0] distance     ;
779
                begin
780
 
781
 
782
                if(C>1) begin
783
 
784
                        rsvd_stat[core_num][class_num].pck_num ++;
785
                        rsvd_stat[core_num][class_num].sum_clk_h2h +=clk_num_h2h;
786
                        rsvd_stat[core_num][class_num].sum_clk_h2t +=clk_num_h2t;
787
                        rsvd_stat[core_num][class_num].sum_clk_per_hop+= (clk_num_h2h/$itor(distance));
788
                        if (rsvd_stat[core_num][class_num].worst_latency < latency ) rsvd_stat[core_num][class_num].worst_latency =latency;
789
                        if (rsvd_stat[core_num][class_num].min_latency==0          ) rsvd_stat[core_num][class_num].min_latency   =latency;
790
                        if (rsvd_stat[core_num][class_num].min_latency   > latency ) rsvd_stat[core_num][class_num].min_latency   =latency;
791
                        if (sent_stat[src     ][class_num].worst_latency < latency ) sent_stat[src     ][class_num].worst_latency =latency;
792
                        if (sent_stat[src     ][class_num].min_latency==0          ) sent_stat[src     ][class_num].min_latency   =latency;
793
                        if (sent_stat[src     ][class_num].min_latency   > latency ) sent_stat[src     ][class_num].min_latency   =latency;
794
 
795
                        `ifdef STND_DEV_EN
796
                        rsvd_stat[core_num][class_num].sum_clk_pow2 += clk_num_h2h * clk_num_h2h;
797
                        `endif
798
                end else begin
799
                        rsvd_stat[core_num][0].pck_num ++;
800
                    rsvd_stat[core_num][0].sum_clk_h2h +=clk_num_h2h;
801
                    rsvd_stat[core_num][0].sum_clk_h2t +=clk_num_h2t;
802
                    rsvd_stat[core_num][0].sum_clk_per_hop+= (clk_num_h2h/$itor(distance));
803
                    if (rsvd_stat[core_num][0].worst_latency < latency ) rsvd_stat[core_num][0].worst_latency=latency;
804
                    if (rsvd_stat[core_num][0].min_latency==0          ) rsvd_stat[core_num][0].min_latency  =latency;
805
                    if (rsvd_stat[core_num][0].min_latency   > latency ) rsvd_stat[core_num][0].min_latency  =latency;
806
                    if (sent_stat[src     ][0].worst_latency < latency ) sent_stat[src     ][0].worst_latency=latency;
807
                    if (sent_stat[src     ][0].min_latency==0          ) sent_stat[src     ][0].min_latency  =latency;
808
                    if (sent_stat[src     ][0].min_latency   > latency ) sent_stat[src     ][0].min_latency  =latency;
809
 
810
                        `ifdef STND_DEV_EN
811
                        rsvd_stat[core_num][0].sum_clk_pow2 += clk_num_h2h * clk_num_h2h;
812
                        `endif
813
                end
814
 
815
        end
816
        endtask
817
 
818
 
819
 
820
 
821
        task merge_statistic;
822
        input statistic_t merge_stat;
823
        input statistic_t stat_in;
824
        output statistic_t stat_out;
825
        begin
826
                stat_out.pck_num =    merge_stat.pck_num+stat_in.pck_num;
827
                stat_out.flit_num =   merge_stat.flit_num+stat_in.flit_num;
828
                if(merge_stat.worst_latency <  stat_in.worst_latency) stat_out.worst_latency= stat_in.worst_latency;
829
                if(merge_stat.min_latency   == 0                       ) stat_out.min_latency  = stat_in.min_latency;
830
                if(merge_stat.min_latency   > stat_in.min_latency  && stat_in.min_latency!=0   ) stat_out.min_latency  = stat_in.min_latency;
831
                stat_out.sum_clk_h2h = merge_stat.sum_clk_h2h      +stat_in.sum_clk_h2h    ;
832
                stat_out.sum_clk_h2t = merge_stat.sum_clk_h2t      +stat_in.sum_clk_h2t    ;
833
                stat_out.sum_clk_per_hop =   merge_stat.sum_clk_per_hop  +stat_in.sum_clk_per_hop;
834
                `ifdef STND_DEV_EN
835
                        stat_out.sum_clk_pow2 = merge_stat.sum_clk_pow2 +stat_in.sum_clk_pow2;
836
        `endif
837
 
838
        end
839
        endtask
840
 
841
 
842
 
843
 
844
 
845
 
846
        task print_st_single;
847
                input [CLK_CNTw-1 : 0]total_clk;
848
                input statistic_t rsvd_stat;
849
                input statistic_t sent_stat;
850
                begin
851
 
852
 
853
 
854
                avg_st_t avg;
855
                finilize_statistic (total_clk,  rsvd_stat, avg);
856
 
857
                $write("%0d,",sent_stat.pck_num);
858
                $write("%0d,",rsvd_stat.pck_num);
859
                $write("%0d,",sent_stat.flit_num);
860
                $write("%0d,",rsvd_stat.flit_num);
861
                $write("%0d,",sent_stat.worst_latency);
862
                $write("%0d,",rsvd_stat.worst_latency);
863
                $write("%0d,",sent_stat.min_latency);
864
                $write("%0d,",rsvd_stat.min_latency);
865
                $write("%f,",avg.avg_latency_per_hop);
866
                $write("%f,",avg.avg_latency_flit);
867
                $write("%f,",avg.avg_latency_pck);
868
                $write("%f,",avg.avg_throughput);
869
                $write("%f,",avg.avg_pck_siz);
870
        `ifdef STND_DEV_EN
871
                $write("%f,",avg.std_dev);
872
        `endif
873
                $write("\n");
874
        //      printf("\n");
875
                end
876
        endtask
877
 
878
 
879
 
880
        task finilize_statistic;
881
                input [CLK_CNTw-1 : 0]total_clk;
882
                input statistic_t rsvd_stat;
883
                output avg_st_t avg_statistic;
884
                begin
885
 
886
 
887
                 avg_statistic.avg_throughput = ($itor(rsvd_stat.flit_num*100)/NE )/total_clk;
888
                 avg_statistic.avg_latency_flit =(rsvd_stat.pck_num>0)? rsvd_stat.sum_clk_h2h/rsvd_stat.pck_num : 0;
889
                 avg_statistic.avg_latency_pck = (rsvd_stat.pck_num>0)? rsvd_stat.sum_clk_h2t/rsvd_stat.pck_num :0;
890
                 avg_statistic.avg_latency_per_hop = ( rsvd_stat.pck_num==0)? 0 : rsvd_stat.sum_clk_per_hop/rsvd_stat.pck_num;
891
                 avg_statistic.avg_pck_siz  = ( rsvd_stat.pck_num==0)? 0 : $itor(rsvd_stat.flit_num) / $itor(rsvd_stat.pck_num);
892
                 `ifdef STND_DEV_EN
893
                        standard_dev( rsvd_stat.sum_clk_pow2,rsvd_stat.pck_num, avg_statistic.avg_latency_flit,avg_statistic.std_dev);
894
                 `endif
895
        end
896
        endtask
897
 
898
 
899
 
900
        `ifdef STND_DEV_EN
901
        /************************
902
         * std_dev = sqrt[(B-A^2/N)/N]  = sqrt [(B/N)- (A/N)^2] = sqrt [B/N - mean^2]
903
         * A = sum of the values
904
         * B = sum of the squarded values
905
         * *************/
906
 
907
        task standard_dev;
908
                input real sum_pow2;
909
                input [PCK_CNTw-1     :0]  total_num;
910
                input real average;
911
                output real std_dev;
912
                begin
913
                /*
914
                double  A, B, N;
915
                N= total_num;
916
                A= average * N;
917
                B= sum_pow2;
918
 
919
                A=(A*A)/N;
920
                std_dev = (B-A)/N;
921
                std_dev = sqrt(std_dev);
922
        */
923
                if(total_num==0) std_dev= 0;
924
                else begin
925
                        std_dev = sum_pow2/$itor(total_num); //B/N
926
                        std_dev -= (average*average);// (B/N) - mean^2
927
                        std_dev = $sqrt(std_dev);// sqrt [B/N - mean^2]
928
 
929
                end
930
        end
931
        endtask
932
 
933
        `endif
934
 
935
 
936
 
937
        /*
938
        start_delay_gen #(
939
                        .NC(NE)
940
                )
941
                delay_gen
942
                (
943
                        .clk(clk),
944
                        .reset(reset),
945
                        .start_i(start),
946
                        .start_o(start_o)
947
                );
948
         */
949
 
950
endmodule
951
// synthesis translate_on
952
 

powered by: WebSVN 2.1.0

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