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_noc/] [routing.v] - Blame information for rev 56

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
`timescale     1ns/1ps
2
/**********************************************************************
3
**      File:  routing.v
4 56 alirezamon
**
5 48 alirezamon
**      Copyright (C) 2014-2017  Alireza Monemi
6
**
7 56 alirezamon
**      This file is part of ProNoC
8
**
9
**      ProNoC ( stands for Prototype Network-on-chip)  is free software:
10 48 alirezamon
**      you can redistribute it and/or modify it under the terms of the GNU
11
**      Lesser General Public License as published by the Free Software Foundation,
12
**      either version 2 of the License, or (at your option) any later version.
13
**
14
**      ProNoC is distributed in the hope that it will be useful, but WITHOUT
15
**      ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
**      or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
17
**      Public License for more details.
18
**
19
**      You should have received a copy of the GNU Lesser General Public
20
**      License along with ProNoC. If not, see <http:**www.gnu.org/licenses/>.
21
**
22
**
23 56 alirezamon
**      Description:
24 48 alirezamon
**      look-ahead and conventional routing algorithms for Mesh and Torus NoC
25
**
26
**
27
**************************************************************/
28
 
29
 
30
module conventional_routing #(
31 56 alirezamon
    parameter NOC_ID            = 0,
32
    parameter TOPOLOGY          = "MESH",
33 48 alirezamon
    parameter ROUTE_NAME        = "XY",
34 56 alirezamon
    parameter ROUTE_TYPE        = "DETERMINISTIC",
35 48 alirezamon
    parameter T1                = 4,
36
    parameter T2                = 4,
37
    parameter T3                = 4,
38 56 alirezamon
    parameter RAw               = 3,
39
    parameter EAw               = 3,
40 48 alirezamon
    parameter DSTPw             = 4,
41
    parameter LOCATED_IN_NI     = 1 // only needed for mesh and odd-even routing
42
)
43 56 alirezamon
(
44 48 alirezamon
    reset,
45
    clk,
46
    current_r_addr,
47
    src_e_addr,
48
    dest_e_addr,
49
    destport
50 56 alirezamon
);
51 48 alirezamon
 
52
    function integer log2;
53 56 alirezamon
    input integer number; begin
54
       log2=(number <=1) ? 1: 0;
55
       while(2**log2<number) begin
56
          log2=log2+1;
57
       end
58
    end
59
    endfunction // log2
60
 
61
    input  reset,clk;
62 48 alirezamon
    input   [RAw-1   :0] current_r_addr;
63
    input   [EAw-1   :0] src_e_addr;
64
    input   [EAw-1   :0] dest_e_addr;
65
    output  [DSTPw-1 :0] destport;
66 56 alirezamon
 
67
 generate
68
    /* verilator lint_off WIDTH */
69 48 alirezamon
    if(TOPOLOGY == "MESH" || TOPOLOGY == "FMESH" || TOPOLOGY == "TORUS"  || TOPOLOGY ==  "RING" || TOPOLOGY ==  "LINE") begin :mesh_torus
70 56 alirezamon
    /* verilator lint_on WIDTH */
71
 
72 48 alirezamon
    localparam
73
        NX = T1,
74
        NY = T2,
75 56 alirezamon
        RXw = log2(NX),
76
        RYw = (TOPOLOGY=="RING" || TOPOLOGY == "LINE") ? 1 :log2(NY),
77 48 alirezamon
        EXw = RXw,
78 56 alirezamon
        EYw = (TOPOLOGY=="RING" || TOPOLOGY == "LINE") ? 1 : RYw;
79
 
80 48 alirezamon
        wire   [RXw-1   :   0]  current_rx;
81 56 alirezamon
        wire   [RYw-1   :   0]  current_ry;
82 48 alirezamon
        wire   [EXw-1   :   0]  dest_ex;
83
        wire   [EYw-1   :   0]  dest_ey;
84 56 alirezamon
 
85
 
86 48 alirezamon
        mesh_tori_router_addr_decode #(
87
                .TOPOLOGY(TOPOLOGY),
88
            .T1(T1),
89
            .T2(T2),
90
            .T3(T3),
91
                .RAw(RAw)
92
        )
93
        router_addr_decode
94
        (
95
                .r_addr(current_r_addr),
96
                .rx(current_rx),
97
                .ry(current_ry),
98
                .valid( )
99
        );
100 56 alirezamon
 
101
       /* verilator lint_off WIDTH */
102 48 alirezamon
        if(TOPOLOGY == "FMESH") begin :fmesh
103 56 alirezamon
         /* verilator lint_on WIDTH */
104 48 alirezamon
            fmesh_endp_addr_decode #(
105
                .T1(T1),
106
                .T2(T2),
107
                .T3(T3),
108
                .EAw(EAw)
109
            )
110
            end_addr_decode
111
            (
112
                .e_addr(dest_e_addr),
113
                .ex(dest_ex),
114
                .ey(dest_ey),
115
                .ep( ),
116
                .valid()
117 56 alirezamon
            );
118
 
119
 
120
 
121 48 alirezamon
        end else begin : mesh
122
            mesh_tori_endp_addr_decode #(
123
                .TOPOLOGY(TOPOLOGY),
124
                .T1(T1),
125
                .T2(T2),
126
                .T3(T3),
127
                .EAw(EAw)
128
            )
129
            end_addr_decode
130
            (
131
                .e_addr(dest_e_addr),
132
                .ex(dest_ex),
133
                .ey(dest_ey),
134
                .el( ),
135
                .valid()
136 56 alirezamon
            );
137 48 alirezamon
        end//mesh
138 56 alirezamon
 
139 48 alirezamon
            mesh_torus_conventional_routing #(
140
                .TOPOLOGY(TOPOLOGY),
141
                .ROUTE_NAME(ROUTE_NAME),
142
                .ROUTE_TYPE(ROUTE_TYPE),
143
                .NX(T1),
144
                .NY(T2),
145
                .LOCATED_IN_NI(LOCATED_IN_NI)
146
            )
147
            the_conventional_routing
148
            (
149
                .current_x(current_rx),
150
                .current_y(current_ry),
151
                .dest_x(dest_ex),
152
                .dest_y(dest_ey),
153
                .destport(destport)
154
            );
155 56 alirezamon
 
156
    /* verilator lint_off WIDTH */
157 48 alirezamon
    end else if(TOPOLOGY == "FATTREE" || TOPOLOGY == "TREE" ) begin :tree_based
158 56 alirezamon
    /* verilator lint_on WIDTH */
159
 
160 48 alirezamon
        localparam
161
            K=T1,
162
            L=T2,
163
            Kw = log2(K),
164
            LKw= L*Kw,
165
            Lw = log2(L);
166 56 alirezamon
 
167 48 alirezamon
        wire [LKw-1 :0]    current_rx;
168 56 alirezamon
        wire [Lw-1  :0]    current_rl;
169
 
170 48 alirezamon
        fattree_router_addr_decode #(
171
            .K(T1),
172
            .L(T2)
173
        )
174
        router_addr_decode
175
        (
176
            .r_addr(current_r_addr),
177
            .rx(current_rx),
178
            .rl(current_rl)
179 56 alirezamon
        );
180
 
181
        /* verilator lint_off WIDTH */
182
        if(TOPOLOGY == "FATTREE" )begin : fattree
183
        /* verilator lint_on WIDTH */
184
 
185 48 alirezamon
            fattree_conventional_routing #(
186
                .ROUTE_NAME(ROUTE_NAME),
187
                .K(T1),
188
                .L(T2)
189
            )
190
            the_conventional_routing
191
            (
192
                .reset(reset),
193
                .clk(clk),
194
                .current_addr_encoded(current_rx),
195
                .current_level(current_rl),
196
                .dest_addr_encoded(dest_e_addr),
197
                .destport_encoded(destport)
198 56 alirezamon
            );
199
        /* verilator lint_off WIDTH */
200
        end else  if(TOPOLOGY == "TREE" )begin : tree
201
        /* verilator lint_on WIDTH */
202 48 alirezamon
            tree_conventional_routing #(
203
                .ROUTE_NAME(ROUTE_NAME),
204
                .K(T1),
205
                .L(T2)
206
            )
207
            the_conventional_routing
208
            (
209 56 alirezamon
 
210 48 alirezamon
                .current_addr_encoded(current_rx),
211
                .current_level(current_rl),
212
                .dest_addr_encoded(dest_e_addr),
213
                .destport_encoded(destport)
214 56 alirezamon
            );
215
        end // tree
216
 
217
    /* verilator lint_off WIDTH */
218
    end else if (TOPOLOGY == "STAR") begin : star
219
    /* verilator lint_on WIDTH */
220 48 alirezamon
        star_conventional_routing #(
221 56 alirezamon
            .NE(T1)
222 48 alirezamon
        )
223
        the_conventional_routing
224 56 alirezamon
        (
225 48 alirezamon
            .dest_e_addr(dest_e_addr),
226
            .destport(destport)
227 56 alirezamon
        );
228
 
229
 
230
 
231
 
232 48 alirezamon
    end else begin :custom
233 56 alirezamon
 
234 48 alirezamon
        custom_ni_routing  #(
235
            .TOPOLOGY(TOPOLOGY),
236
            .ROUTE_NAME(ROUTE_NAME),
237
            .ROUTE_TYPE(ROUTE_TYPE),
238 56 alirezamon
            .RAw(RAw),
239
            .EAw(EAw),
240
            .DSTPw(DSTPw)
241 48 alirezamon
        )
242
        the_conventional_routing
243
        (
244
            .dest_e_addr(dest_e_addr),
245
            .src_e_addr(src_e_addr),
246 56 alirezamon
            .destport(destport)
247
        );
248
 
249 48 alirezamon
    end //custom
250
    endgenerate
251
 
252
endmodule
253
 
254
 
255
 
256
 
257
 
258
 
259
 
260
 
261
 
262
 
263
/************************************
264
 
265
     look_ahead_routing
266
 
267
*************************************/
268
 
269
module look_ahead_routing #(
270 56 alirezamon
    parameter NOC_ID=0,
271 54 alirezamon
    parameter P = 5,
272 48 alirezamon
    parameter T1= 8,
273
    parameter T2= 8,
274
    parameter T3= 8,
275
    parameter T4= 8,
276 56 alirezamon
    parameter RAw = 3,
277
    parameter EAw = 3,
278 54 alirezamon
    parameter DAw = 3,
279 48 alirezamon
    parameter DSTPw=P-1,
280
    parameter SW_LOC    =0,
281
    parameter TOPOLOGY  ="MESH",//"MESH","TORUS"
282 56 alirezamon
    parameter ROUTE_NAME="XY",//
283 48 alirezamon
    parameter ROUTE_TYPE="DETERMINISTIC"// "DETERMINISTIC", "FULL_ADAPTIVE", "PAR_ADAPTIVE"
284
)
285
(
286
    current_r_addr,  //current router  address
287
    neighbors_r_addr,
288 56 alirezamon
    dest_e_addr,  // destination endpoint address
289
    src_e_addr, //   source endpoint address. Only needed for custom topology
290
    destport_encoded,   // current router destination port number
291 48 alirezamon
    lkdestport_encoded, // look ahead destination port number
292
    reset,
293
    clk
294
);
295 56 alirezamon
 
296 48 alirezamon
    function integer log2;
297 56 alirezamon
    input integer number; begin
298
       log2=(number <=1) ? 1: 0;
299
       while(2**log2<number) begin
300
          log2=log2+1;
301
       end
302
    end
303
    endfunction // log2
304
 
305
    localparam
306 48 alirezamon
        PRAw= P * RAw;
307
    localparam
308
        //K= T1,
309
        //L=T2,
310
            Kw = log2(T1),
311
            Lw = log2(T2),
312
            LKw= T2 * Kw,
313
            PLw = P * Lw,
314
            PLKw = P * LKw;
315 56 alirezamon
 
316 48 alirezamon
    input   [PRAw-1:  0]  neighbors_r_addr;
317
    input   [RAw-1   :   0]  current_r_addr;
318 54 alirezamon
    input   [DAw-1   :   0]  dest_e_addr;
319 48 alirezamon
    input   [EAw-1   :   0]  src_e_addr;
320
    input   [DSTPw-1  :   0]  destport_encoded;
321
    output  [DSTPw-1  :   0]  lkdestport_encoded;
322
    input                   reset,clk;
323 56 alirezamon
 
324 48 alirezamon
    genvar i;
325 56 alirezamon
    generate
326
    /* verilator lint_off WIDTH */
327 48 alirezamon
    if(TOPOLOGY == "MESH" || TOPOLOGY == "FMESH" || TOPOLOGY == "TORUS"  || TOPOLOGY ==  "RING" || TOPOLOGY ==  "LINE")begin :mesh_torus
328 56 alirezamon
    /* verilator lint_on WIDTH */
329
 
330 48 alirezamon
       localparam
331
        NX = T1,
332
        NY = T2,
333 56 alirezamon
        RXw = log2(NX),
334
        RYw = (TOPOLOGY=="RING" || TOPOLOGY == "LINE")? 1 : log2(NY),
335 48 alirezamon
        EXw = RXw,
336
        EYw = RYw;
337 56 alirezamon
 
338 48 alirezamon
        wire   [RXw-1   :   0]  current_rx;
339 56 alirezamon
        wire   [RYw-1   :   0]  current_ry;
340 48 alirezamon
        wire   [EXw-1   :   0]  dest_ex;
341
        wire   [EYw-1   :   0]  dest_ey;
342 56 alirezamon
 
343
        localparam SL_SW_LOC = ( SW_LOC > P-T3) ? 0 : SW_LOC; //single_local
344
 
345 48 alirezamon
        mesh_tori_router_addr_decode #(
346
            .TOPOLOGY(TOPOLOGY),
347
            .T1(T1),
348
            .T2(T2),
349
            .T3(T3),
350
            .RAw(RAw)
351
        )
352
        router_addr_decode
353
        (
354
            .r_addr(current_r_addr),
355
            .rx(current_rx),
356
            .ry(current_ry),
357
            .valid( )
358
        );
359 56 alirezamon
         /* verilator lint_off WIDTH */
360 48 alirezamon
        if(TOPOLOGY == "FMESH") begin :fmesh
361 56 alirezamon
         /* verilator lint_on WIDTH */
362
             fmesh_endp_addr_decode #(
363 48 alirezamon
                .T1(T1),
364
                .T2(T2),
365
                .T3(T3),
366
                .EAw(EAw)
367
            )
368
            end_addr_decode
369
            (
370
                .e_addr(dest_e_addr),
371
                .ex(dest_ex),
372
                .ey(dest_ey),
373
                .ep( ),
374
                .valid()
375
            );
376 56 alirezamon
        end else begin :mesh
377 48 alirezamon
            mesh_tori_endp_addr_decode #(
378
                .TOPOLOGY(TOPOLOGY),
379
                .T1(T1),
380
                .T2(T2),
381
                .T3(T3),
382
                .EAw(EAw)
383
            )
384
            end_addr_decode
385
            (
386
                .e_addr(dest_e_addr),
387
                .ex(dest_ex),
388
                .ey(dest_ey),
389
                .el( ),
390
                .valid()
391
            );
392 56 alirezamon
 
393
 
394 48 alirezamon
        end
395 56 alirezamon
 
396 48 alirezamon
        mesh_torus_look_ahead_routing #(
397
                .NX(T1),
398
                .NY(T2),
399
                .SW_LOC(SL_SW_LOC),
400
                .TOPOLOGY(TOPOLOGY),
401
                .ROUTE_NAME(ROUTE_NAME),
402
                .ROUTE_TYPE(ROUTE_TYPE)
403
        )
404
        look_ahead_route
405
        (
406
                .current_x(current_rx),
407
                .current_y(current_ry),
408
                .dest_x(dest_ex),
409
                .dest_y(dest_ey),
410
                .destport_encoded(destport_encoded),
411
                .lkdestport_encoded(lkdestport_encoded),
412
                .reset(reset),
413
                .clk(clk)
414
        );
415 56 alirezamon
    /* verilator lint_off WIDTH */
416 48 alirezamon
    end else if (TOPOLOGY == "FATTREE") begin: fat
417 56 alirezamon
    /* verilator lint_on WIDTH */
418
 
419 48 alirezamon
        wire  [PLKw-1 : 0]  neighbors_rx;
420
        wire  [PLw-1 : 0]  neighbors_ry;
421 56 alirezamon
 
422 48 alirezamon
        for (i=0; i<P; i=i+1) begin : port
423 56 alirezamon
            assign neighbors_rx[(i+1)*LKw-1: i*LKw] = neighbors_r_addr[(i*RAw)+LKw-1 : i*RAw];
424 48 alirezamon
            assign neighbors_ry[(i+1)*Lw-1 : i*Lw]  = neighbors_r_addr[(i+1)*RAw-1: (i*RAw)+LKw];
425 56 alirezamon
        end//port
426
 
427 48 alirezamon
        fattree_look_ahead_routing #(
428
                .ROUTE_NAME(ROUTE_NAME),
429
                .P(P),
430
                .K(T1),
431
                .L(T2)
432
        )
433
        look_ahead_route
434
        (
435
                .destport_encoded(destport_encoded),
436
                .dest_addr_encoded(dest_e_addr),
437
                .neighbors_rx(neighbors_rx),
438
                .neighbors_ry(neighbors_ry),
439
                .lkdestport_encoded(lkdestport_encoded),
440
                .reset(reset),
441
                .clk(clk)
442
        );
443 56 alirezamon
 
444
    /* verilator lint_off WIDTH */
445 48 alirezamon
    end else if (TOPOLOGY == "TREE") begin: tree
446 56 alirezamon
    /* verilator lint_on WIDTH */
447
 
448 48 alirezamon
        wire  [PLKw-1 : 0]  neighbors_rx_tree;
449
        wire  [PLw-1 : 0]  neighbors_ry_tree;
450 56 alirezamon
 
451 48 alirezamon
        for (i=0; i<P; i=i+1) begin : port
452 56 alirezamon
            assign neighbors_rx_tree[(i+1)*LKw-1: i*LKw] = neighbors_r_addr[(i*RAw)+LKw-1 : i*RAw];
453 48 alirezamon
            assign neighbors_ry_tree[(i+1)*Lw-1 : i*Lw]  = neighbors_r_addr[(i+1)*RAw-1: (i*RAw)+LKw];
454 56 alirezamon
        end//port
455
 
456
 
457 48 alirezamon
        tree_look_ahead_routing #(
458
                .ROUTE_NAME(ROUTE_NAME),
459
                .P(P),
460
                .L(T2),
461
                .K(T1)
462
        )
463
        look_ahead_routing
464
        (
465
                .destport_encoded(destport_encoded),
466
                .dest_addr_encoded(dest_e_addr),
467
                .neighbors_rx(neighbors_rx_tree),
468
                .neighbors_ry(neighbors_ry_tree),
469
                .lkdestport_encoded(lkdestport_encoded),
470
                .reset(reset),
471
                .clk(clk)
472
        );
473 56 alirezamon
 
474
      /* verilator lint_off WIDTH */
475
    end else if (TOPOLOGY == "STAR") begin : star
476
    /* verilator lint_on WIDTH */
477 48 alirezamon
     //look-ahead routing is not needed in star topology as there is only one router
478
        assign  lkdestport_encoded={DSTPw{1'b0}};
479 56 alirezamon
 
480 48 alirezamon
     end else begin : custom
481 56 alirezamon
 
482 48 alirezamon
        custom_lkh_routing  #(
483
            .TOPOLOGY(TOPOLOGY),
484
            .ROUTE_NAME(ROUTE_NAME),
485
            .ROUTE_TYPE(ROUTE_TYPE),
486 56 alirezamon
            .RAw(RAw),
487
            .EAw(EAw),
488
            .DSTPw(DSTPw)
489 48 alirezamon
        )
490
        look_ahead_routing
491
        (
492
            .current_r_addr(current_r_addr),
493
            .dest_e_addr(dest_e_addr),
494
            .src_e_addr(src_e_addr),
495
            .destport(lkdestport_encoded),
496
            .reset(reset),
497
            .clk(clk)
498
        );
499 56 alirezamon
 
500 48 alirezamon
    end
501
    endgenerate
502
endmodule
503 56 alirezamon
 
504 48 alirezamon
/********************************************************
505
 
506
                    next_router_addr_selector
507
 
508 56 alirezamon
Determine the next router address based on the packet destination port
509
 
510 48 alirezamon
********************************************************/
511
 
512
 
513
module next_router_addr_selector_onehot #(
514
    parameter P = 5,
515
    parameter RXw = 3,  // The router's x dimension adress width in bits
516
    parameter RYw = 3  // The router's y dimension adress width in bits
517
    )
518
    (
519
    destport_onehot,
520
    neighbors_rx,
521
    neighbors_ry,
522
    next_rx,
523 56 alirezamon
    next_ry
524 48 alirezamon
    );
525 56 alirezamon
 
526 48 alirezamon
    localparam
527
        PRXw = P * RXw,
528 56 alirezamon
        PRYw = P * RYw;
529
 
530 48 alirezamon
    input [P-1   :  0]  destport_onehot;
531
    input [PRXw-1:  0]  neighbors_rx;
532
    input [PRYw-1:  0]  neighbors_ry;
533
    output[RXw-1  :    0]  next_rx;
534 56 alirezamon
    output[RYw-1  :    0]  next_ry;
535
 
536 48 alirezamon
    onehot_mux_1D #(
537
        .W(RXw),
538 56 alirezamon
        .N(P)
539 48 alirezamon
    )
540
    next_x_mux
541
    (
542
        .in(neighbors_rx),
543
        .out(next_rx),
544
        .sel(destport_onehot)
545
    );
546 56 alirezamon
 
547 48 alirezamon
    onehot_mux_1D #(
548
        .W(RYw),
549 56 alirezamon
        .N(P)
550 48 alirezamon
    )
551
    next_y_mux
552
    (
553
        .in(neighbors_ry),
554
        .out(next_ry),
555
        .sel(destport_onehot)
556
    );
557
 
558 56 alirezamon
endmodule
559 48 alirezamon
 
560
 
561
 
562
 
563 56 alirezamon
 
564 48 alirezamon
module next_router_addr_selector_bin #(
565
    parameter P = 5,
566
    parameter RXw = 3,  // The router's x dimension adress width in bits
567
    parameter RYw = 3  // The router's y dimension adress width in bits
568
    )
569
    (
570
    destport_bin,
571
    neighbors_rx,
572
    neighbors_ry,
573
    next_rx,
574 56 alirezamon
    next_ry
575
 
576 48 alirezamon
    );
577 56 alirezamon
 
578 48 alirezamon
    function integer log2;
579 56 alirezamon
      input integer number; begin
580
         log2=(number <=1) ? 1: 0;
581
         while(2**log2<number) begin
582
            log2=log2+1;
583
         end
584
      end
585
    endfunction // log2
586
 
587 48 alirezamon
    localparam
588
        Pw = log2(P),
589
        PRXw = P * RXw,
590 56 alirezamon
        PRYw = P * RYw;
591
 
592 48 alirezamon
    input [Pw-1   :  0]  destport_bin;
593
    input [PRXw-1:  0]  neighbors_rx;
594
    input [PRYw-1:  0]  neighbors_ry;
595
    output[RXw-1  :    0]  next_rx;
596 56 alirezamon
    output[RYw-1  :    0]  next_ry;
597
 
598 48 alirezamon
    binary_mux #(
599
        .IN_WIDTH(PRXw),
600
        .OUT_WIDTH(RXw)
601
    )
602
    next_x_mux
603
    (
604
        .mux_in(neighbors_rx),
605
        .mux_out(next_rx),
606
        .sel(destport_bin)
607
    );
608 56 alirezamon
 
609 48 alirezamon
    binary_mux  #(
610
        .IN_WIDTH(PRYw),
611
        .OUT_WIDTH(RYw)
612
    )
613
    next_y_mux
614
    (
615
        .mux_in(neighbors_ry),
616
        .mux_out(next_ry),
617
        .sel(destport_bin)
618
    );
619
 
620 56 alirezamon
endmodule
621 48 alirezamon
 
622
 
623 56 alirezamon
 
624
 

powered by: WebSVN 2.1.0

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