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/] [baseline.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
`timescale     1ns/1ps
2
 /**********************************************************************
3
**      File: baseline.v
4
**
5
**      Copyright (C) 2014-2017  Alireza Monemi
6
**
7
**      This file is part of ProNoC
8
**
9
**      ProNoC ( stands for Prototype Network-on-chip)  is free software:
10
**      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
**
24
**      Description:
25
**      baseline allocators:
26
**      Canonical VC allocator and speculative switch allocator
27
**  It is just developed for comparsion with combined allocators. It is not recommended to be used.
28
**  Does not support single-flit sized packets
29
*************************************/
30
 
31
 
32
module baseline_allocator #(
33
    parameter V = 4,// Virtual chanel num per port
34
    parameter P = 5,//port number
35
    parameter TREE_ARBITER_EN = 0,
36
    parameter DEBUG_EN = 1,
37
    parameter SWA_ARBITER_TYPE = "WRRA",
38
    parameter SELF_LOOP_EN= "NO"
39
)
40
(
41
    dest_port_all,
42
    ovc_is_assigned_all,
43
    ivc_request_all,
44
    assigned_ovc_not_full_all,
45
    ovc_allocated_all,
46
    granted_ovc_num_all,
47
    ivc_num_getting_ovc_grant,
48
    ivc_num_getting_sw_grant,
49
    spec_first_arbiter_granted_ivc_all,
50
    nonspec_first_arbiter_granted_ivc_all,
51
    granted_dest_port_all,
52
    nonspec_granted_dest_port_all,
53
    spec_granted_dest_port_all,
54
    any_ivc_sw_request_granted_all,
55
    spec_ovc_num_all,
56
    masked_ovc_request_all,
57
    vc_weight_is_consumed_all,
58
    iport_weight_is_consumed_all,
59
    clk,reset
60
);
61
 
62
    localparam
63
        PV = V * P,
64
        PVV = PV * V,
65
        P_1 = (SELF_LOOP_EN == "NO") ? P-1 : P,
66
        PP_1 = P_1 * P,
67
        PVP_1 = PV * P_1;
68
 
69
    input  [PVP_1-1:   0]    dest_port_all;
70
    input  [PV-1:   0]    ovc_is_assigned_all;
71
    input  [PV-1:   0]  ivc_request_all;
72
    input  [PV-1:   0]  assigned_ovc_not_full_all;
73
    input  [PV-1 : 0] vc_weight_is_consumed_all;
74
    input  [P-1 : 0] iport_weight_is_consumed_all;
75
 
76
    output [PV-1:   0] ovc_allocated_all;
77
    output [PVV-1:   0] granted_ovc_num_all;
78
    output [PV-1:   0] ivc_num_getting_ovc_grant;
79
    output [PV-1:   0] ivc_num_getting_sw_grant;
80
    output [PV-1:   0] nonspec_first_arbiter_granted_ivc_all;
81
    output [PV-1:   0] spec_first_arbiter_granted_ivc_all;
82
 
83
    output [PP_1-1:   0] granted_dest_port_all;
84
    output [PP_1-1:   0] nonspec_granted_dest_port_all;
85
    output [PP_1-1:   0] spec_granted_dest_port_all;
86
    output [P-1:   0] any_ivc_sw_request_granted_all;
87
    output [PVV-1:   0] spec_ovc_num_all;
88
    input  [PVV-1:  0] masked_ovc_request_all;
89
    input  clk,reset;
90
 
91
 
92
    wire [V-1:   0] spec_first_arbiter_granted_ivc    [P-1:   0];
93
    wire [V-1:   0] ivc_local_num_getting_ovc_grant  [P-1:   0];
94
    wire [P-1:   0] valid_speculation;
95
 
96
 
97
 
98
 
99
    // canonical VC allocator
100
    canonical_vc_alloc #(
101
        .TREE_ARBITER_EN(TREE_ARBITER_EN),
102
        .V(V),
103
        .P(P)
104
    )
105
    the_canonical_VC_allocator
106
    (
107
        .granted_ovc_num_all(granted_ovc_num_all),
108
        .ovc_allocated_all  (ovc_allocated_all),
109
        .ivc_num_getting_ovc_grant (ivc_num_getting_ovc_grant),
110
        .masked_ovc_request_all (masked_ovc_request_all),
111
        .dest_port_all (dest_port_all),
112
        .spec_ovc_num_all (spec_ovc_num_all),
113
        .clk (clk),
114
        .reset (reset)
115
    );
116
 
117
    //speculative switch allocator 
118
    spec_sw_alloc_can #(
119
        .V(V),
120
        .P(P),
121
        .DEBUG_EN (DEBUG_EN),
122
        .SWA_ARBITER_TYPE (SWA_ARBITER_TYPE)
123
    )
124
    speculative_sw_allocator
125
    (
126
        .ivc_granted_all (ivc_num_getting_sw_grant),
127
        .ivc_request_all (ivc_request_all),
128
        .ovc_is_assigned_all (ovc_is_assigned_all),
129
        .assigned_ovc_not_full_all (assigned_ovc_not_full_all),
130
        .dest_port_all (dest_port_all),
131
        .granted_dest_port_all (granted_dest_port_all),
132
        .nonspec_granted_dest_port_all (nonspec_granted_dest_port_all),
133
        .spec_granted_dest_port_all (spec_granted_dest_port_all),
134
        .valid_speculation (valid_speculation),
135
        .spec_first_arbiter_granted_ivc_all (spec_first_arbiter_granted_ivc_all),
136
        .nonspec_first_arbiter_granted_ivc_all (nonspec_first_arbiter_granted_ivc_all),
137
        .any_ivc_sw_request_granted_all (any_ivc_sw_request_granted_all),
138
        .vc_weight_is_consumed_all(vc_weight_is_consumed_all),
139
        .iport_weight_is_consumed_all(iport_weight_is_consumed_all),
140
        .clk (clk),
141
        .reset (reset)
142
    );
143
 
144
    // check valid speculation
145
    genvar i;
146
    generate
147
    for(i=0;i<P; i=i+1) begin :valid_chek_lp
148
 
149
        assign spec_first_arbiter_granted_ivc[i] = spec_first_arbiter_granted_ivc_all[(i+1)*V-1:   i*V];
150
        assign ivc_local_num_getting_ovc_grant[i] = ivc_num_getting_ovc_grant [(i+1)*V-1:   i*V];
151
 
152
        //speculative VC request multiplexer
153
        one_hot_mux #(
154
            .IN_WIDTH (V),
155
            .SEL_WIDTH (V)
156
        )
157
        multiplexer
158
        (
159
            .mux_in (ivc_local_num_getting_ovc_grant [i]),
160
            .mux_out (valid_speculation [i]),
161
            .sel (spec_first_arbiter_granted_ivc [i])
162
        );
163
 
164
    end//for
165
    endgenerate
166
 
167
 
168
endmodule
169
 
170
 
171
 
172
/***********************************
173
*
174
*
175
*    canonical VC allocator
176
*
177
*
178
************************************/
179
 
180
 
181
 
182
module canonical_vc_alloc #(
183
    parameter TREE_ARBITER_EN = 1,
184
    parameter V = 4,
185
    parameter P = 5
186
)
187
(
188
    granted_ovc_num_all,
189
    ivc_num_getting_ovc_grant,
190
    ovc_allocated_all,
191
    dest_port_all,
192
    masked_ovc_request_all,
193
    spec_ovc_num_all,
194
    clk,
195
    reset
196
);
197
 
198
 
199
    localparam
200
        P_1 = P-1,//assumed that no port request for itself!
201
        PV  = V * P,
202
        PVV = PV * V,
203
        PVP_1 = PV * P_1,
204
        VP_1 = V * P_1;
205
 
206
    //input/output
207
    output [PVV-1:  0]  granted_ovc_num_all;
208
    output [PV-1:  0]  ovc_allocated_all;
209
    output [PV-1:  0] ivc_num_getting_ovc_grant;
210
    input  [PVV-1:  0]  masked_ovc_request_all;
211
    input  [PVP_1-1:  0]  dest_port_all;
212
    output [PVV-1:  0]  spec_ovc_num_all;
213
    input  clk,reset;
214
 
215
    wire    [V-1:  0]  ovc_granted_ivc [PV-1:  0]  ;
216
    wire    [P_1-1: 0]  dest_port_ivc  [PV-1:  0]  ;
217
    wire    [V-1:  0]  masked_ovc_request [PV-1:  0]  ;
218
    wire    [V-1:  0] first_arbiter_grant [PV-1:  0]  ;
219
    wire    [VP_1-1 : 0]  ovc_demuxed  [PV-1:  0]  ;
220
    wire    [VP_1-1 : 0]  second_arbiter_request  [PV-1:  0]  ;
221
    wire    [VP_1-1 : 0]  second_arbiter_grant [PV-1:  0]  ;
222
    wire    [VP_1-1 : 0]  granted_ovc_array [PV-1:  0]  ;
223
    genvar i,j;
224
 
225
 
226
    generate
227
 
228
 
229
    // IVC loop
230
    for(i=0;i< PV;i=i+1) begin :total_vc_loop
231
       //seprate input/output
232
       assign granted_ovc_num_all    [(i+1)*V-1:  i*V ] = ovc_granted_ivc[i] ;
233
       assign masked_ovc_request     [i]  = masked_ovc_request_all[(i+1)*V-1:  i*V ];
234
       assign dest_port_ivc   [i]    =   dest_port_all [(i+1)*P_1-1:  i*P_1   ];
235
 
236
       //first level arbiter
237
       arbiter #(
238
        .ARBITER_WIDTH  (V)
239
       )first_arbiter
240
       (
241
        .clk        (clk),
242
        .reset       (reset),
243
        .request       (masked_ovc_request  [i]),
244
        .grant       (first_arbiter_grant[i]),
245
        .any_grant   ()
246
       );
247
 
248
       assign spec_ovc_num_all[(i+1)*V-1 :i*V]   = first_arbiter_grant[i];
249
       //demultiplexer
250
 
251
       one_hot_demux    #(
252
        .IN_WIDTH   (V),
253
        .SEL_WIDTH  (P_1)
254
       )demux
255
       (
256
        .demux_sel  (dest_port_ivc [i]),//selectore
257
        .demux_in   (first_arbiter_grant[i]),//repeated
258
        .demux_out  (ovc_demuxed[i])
259
       );
260
 
261
       //second arbiter input/output generate
262
 
263
 
264
       for(j=0;j<PV;    j=j+1)begin: assign_loop2
265
        if((i/V)<(j/V))begin: jj
266
              assign second_arbiter_request[i][j-V] = ovc_demuxed[j][i] ;
267
              assign granted_ovc_array[j][i]    = second_arbiter_grant  [i][j-V]    ;
268
        end else if((i/V)>(j/V)) begin: hh
269
              assign second_arbiter_request[i][j]   = ovc_demuxed[j][i-V]   ;
270
              assign granted_ovc_array[j][i-V]  = second_arbiter_grant  [i][j]  ;
271
        end
272
        //if(i==j)  s are left disconnected  
273
 
274
       end
275
 
276
 
277
       //second level arbiter 
278
       if(TREE_ARBITER_EN) begin :tree
279
        tree_arbiter #(
280
              .GROUP_NUM (P_1),
281
              .ARBITER_WIDTH (VP_1)
282
        )
283
        second_arbiter
284
        (
285
              .clk (clk),
286
              .reset (reset),
287
              .request (second_arbiter_request[i]),
288
              .grant (second_arbiter_grant  [i]),
289
              .any_grant (ovc_allocated_all[i])
290
        );
291
       end else begin :arb
292
        arbiter #(
293
              .ARBITER_WIDTH    (VP_1)
294
        )
295
        second_arbiter
296
        (
297
              .clk (clk),
298
              .reset (reset),
299
              .request (second_arbiter_request[i]),
300
              .grant (second_arbiter_grant  [i]),
301
              .any_grant (ovc_allocated_all[i])
302
        );
303
       end
304
 
305
       custom_or #(
306
        .IN_NUM (P_1),
307
        .OUT_WIDTH (V)
308
 
309
       )
310
       or_gate
311
       (
312
        .or_in  (granted_ovc_array[i]),
313
        .or_out (ovc_granted_ivc[i])
314
       );
315
 
316
       assign ivc_num_getting_ovc_grant[i]  =   |ovc_granted_ivc[i];
317
 
318
    end//for
319
    endgenerate
320
 
321
endmodule
322
 
323
 
324
 /*************************************
325
 
326
            spec_sw_alloc_can
327
    speculative switch allocator for baseline
328
 
329
 *************************************/
330
 
331
 
332
 
333
module spec_sw_alloc_can #(
334
    parameter V = 4,
335
    parameter P = 5,
336
    parameter DEBUG_EN = 1,
337
    parameter SWA_ARBITER_TYPE = "WRRA"
338
)(
339
    ivc_granted_all,
340
    ivc_request_all,
341
    ovc_is_assigned_all,
342
    assigned_ovc_not_full_all,
343
    dest_port_all,
344
    granted_dest_port_all,
345
    nonspec_granted_dest_port_all,
346
    spec_granted_dest_port_all,
347
    valid_speculation,
348
    spec_first_arbiter_granted_ivc_all,
349
    nonspec_first_arbiter_granted_ivc_all,
350
    any_ivc_sw_request_granted_all,
351
    vc_weight_is_consumed_all,
352
    iport_weight_is_consumed_all,
353
    clk,
354
    reset
355
);
356
 
357
 
358
    localparam
359
        P_1 = P-1,//assumed that no port request for itself!
360
        PV  = V * P,
361
        VP_1 = V * P_1,
362
        PVP_1 = P * VP_1,
363
        PP_1 = P_1* P;
364
 
365
    output [PV-1:  0]  ivc_granted_all;
366
    input  [PV-1:  0] ivc_request_all;
367
    input  [PV-1:  0] ovc_is_assigned_all;
368
    input  [PV-1:  0] assigned_ovc_not_full_all;
369
    input  [PVP_1-1:  0]  dest_port_all;
370
    output [PP_1-1:  0]  granted_dest_port_all;
371
    output [PP_1-1:  0]  nonspec_granted_dest_port_all;
372
    output [PP_1-1:  0]  spec_granted_dest_port_all;
373
    input  [P-1:  0]  valid_speculation;
374
    output [PV-1:  0]  spec_first_arbiter_granted_ivc_all;
375
    output [PV-1:  0]  nonspec_first_arbiter_granted_ivc_all;
376
    output [P-1:  0] any_ivc_sw_request_granted_all;
377
    input  [PV-1 : 0 ] vc_weight_is_consumed_all;
378
    input  [P-1:0] iport_weight_is_consumed_all;
379
    input clk, reset;
380
 
381
 
382
    //internal wire 
383
    wire  [PV-1:  0]  spec_ivc_granted_all,nonspec_ivc_granted_all;
384
    wire  [PV-1:  0] spec_ivc_request_all,nonspec_ivc_request_all;
385
    wire  [PV-1:  0] spec_assigned_ovc_not_full_all,nonspec_assigned_ovc_not_full_all;
386
    wire  [PVP_1-1:  0]  spec_dest_port_all,nonspec_dest_port_all;
387
    wire  [PP_1-1:  0]  spec_granted_dest_port_all_pre;
388
    wire  [PP_1-1:  0] nonspec_granted_dest_port_all_pre;
389
    wire  [PP_1-1:  0] spec_granted_dest_port_all_accepted;
390
    wire  [P-1:  0]  nonspec_inport_granted_all,nonspec_outport_granted_all;
391
 
392
 
393
    wire    [P_1-1:  0]  nonspec_portsel_granted [P-1:  0];
394
    wire    [PP_1-1:  0]  spec_request_acceptable;
395
    wire  [P_1-1:  0]  spec_request_accepted [P-1:  0];
396
    wire  [P-1:  0]  any_spec_request_accepted;
397
    wire    [PV-1:  0]  spec_ivc_granted_all_accepted;
398
    wire    [P-1:  0] nonspec_any_ivc_grant,spec_any_ivc_grant;
399
    wire    [P-1:  0] spec_any_ivc_grant_valid;
400
 
401
 
402
 
403
    sw_alloc_sub#(
404
        .V(V),
405
        .P(P),
406
        .SWA_ARBITER_TYPE(SWA_ARBITER_TYPE)
407
    )
408
    speculative_alloc
409
    (
410
        .ivc_granted_all (spec_ivc_granted_all),
411
        .ivc_request_all (spec_ivc_request_all),
412
        .assigned_ovc_not_full_all (spec_assigned_ovc_not_full_all),
413
        .dest_port_all (spec_dest_port_all),
414
        .granted_dest_port_all (spec_granted_dest_port_all_pre),
415
        .inport_granted_all  ( ),
416
        .outport_granted_all ( ),
417
        .first_arbiter_granted_ivc_all  (spec_first_arbiter_granted_ivc_all),
418
        .first_arbiter_granted_port_all ( ),
419
        .any_ivc_grant (spec_any_ivc_grant),
420
        .vc_weight_is_consumed_all (vc_weight_is_consumed_all),
421
        .iport_weight_is_consumed_all(iport_weight_is_consumed_all),
422
        .pck_is_single_flit_all( ),
423
        .granted_dst_is_from_a_single_flit_pck( ),
424
        .clk (clk),
425
        .reset (reset)
426
    );
427
 
428
 
429
 
430
    sw_alloc_sub#(
431
        .V (V),
432
        .P (P),
433
        .SWA_ARBITER_TYPE(SWA_ARBITER_TYPE)
434
    )
435
    nonspeculative_alloc
436
    (
437
 
438
        .ivc_granted_all(nonspec_ivc_granted_all),
439
        .ivc_request_all(nonspec_ivc_request_all),
440
        .assigned_ovc_not_full_all(nonspec_assigned_ovc_not_full_all),
441
        .dest_port_all(nonspec_dest_port_all),
442
        .granted_dest_port_all(nonspec_granted_dest_port_all_pre),
443
        .inport_granted_all(nonspec_inport_granted_all),
444
        .outport_granted_all(nonspec_outport_granted_all),
445
        .first_arbiter_granted_ivc_all(nonspec_first_arbiter_granted_ivc_all),
446
        .first_arbiter_granted_port_all(),
447
        .any_ivc_grant(nonspec_any_ivc_grant),
448
        .vc_weight_is_consumed_all (vc_weight_is_consumed_all),
449
        .iport_weight_is_consumed_all(iport_weight_is_consumed_all),
450
        .pck_is_single_flit_all( ),
451
        .granted_dst_is_from_a_single_flit_pck( ),
452
        .clk (clk),
453
        .reset(reset)
454
 
455
    );
456
 
457
    assign nonspec_ivc_request_all              = ivc_request_all &  ovc_is_assigned_all;
458
    assign spec_ivc_request_all                 = ivc_request_all &  ~ovc_is_assigned_all;
459
    assign spec_assigned_ovc_not_full_all       = {PV{1'b1}};
460
    assign nonspec_assigned_ovc_not_full_all    = assigned_ovc_not_full_all;
461
    assign spec_dest_port_all                       = dest_port_all;
462
    assign nonspec_dest_port_all                    = dest_port_all;
463
 
464
    genvar i,j;
465
    generate
466
    for(i=0;i<P; i=i+1) begin :port_lp
467
        //remove non-spec inport from the nonspec_outport_granted_all
468
        for(j=0;j<P;    j=j+1)begin: port_loop2
469
            if(i<j)begin: jj
470
                assign nonspec_portsel_granted[i][j-1]  = nonspec_outport_granted_all[j];
471
            end else if(i>j)begin: hh
472
                assign nonspec_portsel_granted[i][j]        = nonspec_outport_granted_all [j];
473
            end
474
            //if(i==j) wires are left disconnected  
475
        end//j
476
        // an speculative grant is acceptable if the non-speculative request is not granted for both inport request and outport grant
477
        assign spec_request_acceptable  [(i+1)*P_1-1:  i*P_1] = (nonspec_inport_granted_all[i])? {P_1{1'b0}} : ~nonspec_portsel_granted[i];
478
        assign spec_request_accepted    [i]= spec_request_acceptable[(i+1)*P_1-1:  i*P_1] & spec_granted_dest_port_all_pre[(i+1)*P_1-1:  i*P_1];
479
        assign any_spec_request_accepted [i] = |spec_request_accepted  [i];
480
        assign spec_ivc_granted_all_accepted[(i+1)*V-1:  i*V] = (any_spec_request_accepted [i] & valid_speculation[i])? spec_ivc_granted_all[(i+1)*V-1:  i*V]: {V{1'b0}};
481
        assign spec_granted_dest_port_all_accepted[(i+1)*P_1-1:  i*P_1]=valid_speculation[i]? (spec_request_acceptable[(i+1)*P_1-1:  i*P_1] & spec_granted_dest_port_all_pre[(i+1)*P_1-1:  i*P_1]): {P_1{1'b0}};
482
 
483
    //synthesis translate_off
484
    //synopsys  translate_off
485
 
486
        if(DEBUG_EN)begin :dbg
487
            always @(posedge clk) begin
488
                if(nonspec_granted_dest_port_all[(i+1)*P_1-1:  i*P_1] >0 && spec_granted_dest_port_all_accepted[(i+1)*P_1-1:  i*P_1]>0 ) $display("%t: Error: Both speculative and nonspeculative is granted for one port",$time);
489
                if(nonspec_ivc_granted_all [(i+1)*V-1:  i*V] >0 && spec_ivc_granted_all_accepted[(i+1)*V-1:  i*V]>0 ) $display("%t: Error: Both speculative and nonspeculative is granted for one port",$time);
490
            end
491
        end
492
    //synopsys  translate_on
493
    //synthesis translate_on
494
 
495
 
496
    end//i
497
    endgenerate
498
 
499
    assign spec_any_ivc_grant_valid  = any_spec_request_accepted & valid_speculation & spec_any_ivc_grant;
500
    assign any_ivc_sw_request_granted_all = nonspec_any_ivc_grant | spec_any_ivc_grant_valid;
501
    assign granted_dest_port_all = nonspec_granted_dest_port_all_pre | spec_granted_dest_port_all_accepted;
502
    assign ivc_granted_all = nonspec_ivc_granted_all  | spec_ivc_granted_all_accepted;
503
    assign nonspec_granted_dest_port_all = nonspec_granted_dest_port_all_pre;
504
    assign spec_granted_dest_port_all = spec_granted_dest_port_all_accepted;
505
 
506
endmodule
507
 
508
 
509
 

powered by: WebSVN 2.1.0

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