OpenCores
URL https://opencores.org/ocsvn/theia_gpu/theia_gpu/trunk

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [gpu_8_cores/] [rtl/] [GPU/] [TOP/] [Theia.v] - Blame information for rev 129

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

Line No. Rev Author Line
1 76 diegovalve
`timescale 1ns / 1ps
2
`include "aDefinitions.v"
3 129 diegovalve
/**********************************************************************************
4
Theia, Ray Cast Programable graphic Processing Unit.
5
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
6
 
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
21
***********************************************************************************/
22 76 diegovalve
 
23
//---------------------------------------------------------------------------
24
module THEIA
25
(
26 109 diegovalve
 
27
input wire                    CLK_I,    //Input clock
28
input wire                    RST_I,    //Input reset
29
//Theia Interfaces
30
input wire                    MST_I,    //Master signal, THEIA enters configuration mode
31
                                       //when this gets asserted (see documentation)
32
//Wish Bone Interface
33
input wire [`WB_WIDTH-1:0]    DAT_I,     //Input data bus  (Wishbone)
34
input wire                    ACK_I,    //Input ack
35
output wire                   ACK_O,    //Output ack
36
input wire [`WB_WIDTH-1:0]    ADR_I,     //Input address
37
input wire                    WE_I,    //Input write enable
38
input wire                    STB_I,    //Strobe signal, see wishbone documentation
39
input wire                    CYC_I,   //Bus cycle signal, see wishbone documentation
40
input wire [1:0]              TGA_I,   //Input address tag, see THEAI documentation
41 76 diegovalve
input wire [`MAX_CORES-1:0]      SEL_I,  //The WishBone Master uses this signal to configure a specific core (TBD, not sure is needed)
42 109 diegovalve
input wire [`MAX_CORES-1:0]   RENDREN_I,
43
 
44
input wire [`MAX_CORE_BITS-1:0]      OMBSEL_I,  //Output memory bank select
45
input wire [`WB_WIDTH-1:0]           OMADR_I,  //Output adress (relative to current bank)
46
output wire [`WB_WIDTH-1:0]          OMEM_O,      //Output data bus (Wishbone)
47
 
48
input wire [`WB_WIDTH-1:0]           TMDAT_I,
49
input wire [`WB_WIDTH-1:0]           TMADR_I,
50
input wire                           TMWE_I,
51
input wire [`MAX_TMEM_BANKS-1:0]     TMSEL_I,
52
//Control Register
53 76 diegovalve
input wire [15:0]                         CREG_I,
54 109 diegovalve
output wire                   GRDY_O,
55
input wire                    STDONE_I,
56
input wire                    HDA_I,
57
input wire                    GACK_I,
58
output wire                   RCOMMIT_O,
59
output wire                   DONE_O
60 16 diegovalve
 
61 76 diegovalve
);
62 16 diegovalve
 
63
 
64
 
65 76 diegovalve
 
66 109 diegovalve
wire [`MAX_TMEM_BANKS-1:0] wTMemWriteEnable;
67
SELECT_1_TO_N # ( `MAX_TMEM_BANKS, `MAX_TMEM_BANKS ) TMWE_SEL
68
                        (
69
                        .Sel(TMSEL_I),
70
                        .En(TMWE_I),
71
                        .O(wTMemWriteEnable)
72
                        );
73
 
74
 
75 76 diegovalve
wire [`MAX_CORES-1:0] wDone;
76
wire [`MAX_CORES-1:0] wBusGranted,wBusRequest;
77 109 diegovalve
//wire [`WB_WIDTH-1:0]  wDAT_O[`MAX_CORES-1:0];
78
//wire [`WB_WIDTH-1:0]  wADR_O[`MAX_CORES-1:0];
79
//wire [1:0] wTGA_O[`MAX_CORES-1:0];
80
wire [`MAX_CORE_BITS-1:0] wBusSelect;
81 76 diegovalve
 
82
 
83 109 diegovalve
//wire [`MAX_CORES-1:0] wSTB_O;
84
//wire [`MAX_CORES-1:0] wWE_O;
85
wire [`MAX_CORES-1:0]wACK_O;
86 76 diegovalve
 
87
 
88 109 diegovalve
wire wOMem_WE[`MAX_CORES-1:0];
89
wire [`WB_WIDTH-1:0] wOMEM_Address[`MAX_CORES-1:0];
90
wire [`WB_WIDTH-1:0] wOMEM_Dat[`MAX_CORES-1:0];
91
 
92 76 diegovalve
wire [`MAX_CORES-1:0]   wSTB_I;
93
wire [`MAX_CORES-1:0]   wMST_I;
94
wire [`MAX_CORES-1:0]   wACK_I;
95
wire [`MAX_CORES-1:0]   wCYC_I;
96
wire [1:0]              wTGA_I[`MAX_CORES-1:0];
97
 
98
 
99 129 diegovalve
 
100 109 diegovalve
wire [`WB_WIDTH-1:0]  wTMEM_Data;
101
wire [`WB_WIDTH-1:0]  wTMEM_Address[`MAX_CORES-1:0];
102
wire [`WB_WIDTH-1:0]  wTMEM_ReadAddr;
103
wire [`MAX_CORES-1:0] wTMEM_Resquest;
104
wire [`MAX_CORES-1:0] wTMEM_Granted;
105
 
106
 
107
 
108
//CROSS-BAR cables
109
 
110
 
111
 
112
wire [`WB_WIDTH-1:0]     wCrossBarDataRow[`MAX_TMEM_BANKS-1:0];                   //Horizontal grid Buses comming from each bank 
113
wire [`WB_WIDTH-1:0]     wCrossBarDataCollumn[`MAX_CORES-1:0];          //Vertical grid buses comming from each core.
114
wire [`WB_WIDTH-1:0]     wTMemReadAdr[`MAX_CORES-1:0];                                       //Horizontal grid Buses comming from each core (virtual addr).
115
wire [`WB_WIDTH-1:0]     wCrossBarAdressCollumn[`MAX_CORES-1:0];                  //Vertical grid buses comming from each core. (physical addr).
116
wire [`WB_WIDTH-1:0]     wCrossBarAddressRow[`MAX_TMEM_BANKS-1:0];                //Horizontal grid Buses comming from each bank.
117
 
118
wire                                                wCORE_2_TMEM__Req[`MAX_CORES-1:0];
119
wire [`MAX_TMEM_BANKS -1:0]    wBankReadRequest[`MAX_CORES-1:0];
120
 
121
 
122
wire [`MAX_CORES-1:0]         wBankReadGranted[`MAX_TMEM_BANKS-1:0];
123
wire                           wTMEM_2_Core__Grant[`MAX_CORES-1:0];
124
 
125
wire[`MAX_CORE_BITS-1:0] wCurrentCoreSelected[`MAX_TMEM_BANKS-1:0];
126
wire[7:0]                wCoreBankSelect[`MAX_CORES-1:0];
127
wire [`MAX_CORES-1:0] wGRDY_O;
128
 
129
 
130
wire [`MAX_CORES-1:0] wGReady;
131
wire [`MAX_CORES-1:0] wRCOMMIT_O;
132
wire [`MAX_CORES-1:0] wRCommited;
133
 
134
 
135 129 diegovalve
assign RCOMMIT_O = wRCommited[0] & wRCommited[1] & wRCommited[2] & wRCommited[3] & wRCommited[4] & wRCommited[5] & wRCommited[6] & wRCommited[7];
136
assign GRDY_O = wGReady[0] & wGReady[1] & wGReady[2] & wGReady[3] & wGReady[4] & wGReady[5] & wGReady[6] & wGReady[7];
137 76 diegovalve
//----------------------------------------------------------------      
138 109 diegovalve
//The next secuencial logic just AND all the wDone signals
139
//I know that it would be much more elgant to just do parallel:
140
//assign DONE_O = wDone[0] & wDone[1] & ... & wDone[MAX_CORES-1];
141
//However, I don't know how to achieve this with 'generate' statements
142
//So coding a simple loop instead
143
 
144
/*
145
always @ (posedge CLK_I)
146
begin : AND_DONE_SIGNALS
147
  integer k;
148
  DONE_O = wDone[0];
149
  for (k=0;k<=`MAX_CORES;k=k+1)
150
    DONE_O=DONE_O & wDone[k+1];
151
end
152
*/
153 129 diegovalve
assign DONE_O = wDone[0] & wDone[1] & wDone[2] & wDone[3] & wDone[4] & wDone[5] & wDone[6] & wDone[7];   //Replace this by a counter??
154 109 diegovalve
//----------------------------------------------------------------      
155
 
156 76 diegovalve
        Module_BusArbitrer ARB1
157
        (
158
        .Clock( CLK_I ),
159
        .Reset( RST_I ),
160
        .iRequest( wBusRequest ),
161
        .oGrant(   wBusGranted ),
162
        .oBusSelect( wBusSelect )
163
 
164
        );
165
//----------------------------------------------------------------
166
 
167 129 diegovalve
 
168 109 diegovalve
  assign ACK_O = wACK_O[ wBusSelect];
169 76 diegovalve
 
170 109 diegovalve
 wire [`WB_WIDTH-1:0] wDataOut[`MAX_CORES-1:0];
171
 assign OMEM_O = wDataOut[ OMBSEL_I ];
172 76 diegovalve
 
173 109 diegovalve
  genvar i;
174
  generate
175
        for (i = 0; i < `MAX_CORES; i = i +1)
176
        begin : CORE
177
                assign wMST_I[i] = (SEL_I[i]) ? MST_I : 0;
178
                assign wSTB_I[i] = (SEL_I[i]) ? STB_I : 0;
179
                assign wCYC_I[i] = (SEL_I[i]) ? CYC_I : 0;
180
                assign wTGA_I[i] = (SEL_I[i]) ? TGA_I : 0;
181 76 diegovalve
 
182 109 diegovalve
 
183
                THEIACORE CTHEIA
184
                (
185
                .CLK_I( CLK_I ),
186 76 diegovalve
                .RST_I( RST_I ),
187 109 diegovalve
                .RENDREN_I( RENDREN_I[i] ),
188 76 diegovalve
 
189
                //Slave signals
190 109 diegovalve
                .ADR_I( ADR_I ),
191 76 diegovalve
                .WE_I(  WE_I  ),
192 109 diegovalve
                .STB_I(  wSTB_I[i] ),
193 82 diegovalve
                .ACK_I( ACK_I ),
194 109 diegovalve
                .CYC_I( wCYC_I[i] ),
195
                .MST_I( wMST_I[i] ),
196
                .TGA_I( wTGA_I[i] ),
197 76 diegovalve
                .CREG_I( CREG_I ),
198
 
199 109 diegovalve
                //Master Signals
200
                .ACK_O(         wACK_O[i] ),
201
                .CYC_O(  wBusRequest[i] ),
202
                .GNT_I(         wBusGranted[i] ),
203 76 diegovalve
                `ifdef DEBUG
204 109 diegovalve
                .iDebug_CoreID( i ),
205 76 diegovalve
                `endif
206
 
207 109 diegovalve
                .OMEM_WE_O( wOMem_WE[i] ),
208
                .OMEM_ADR_O( wOMEM_Address[i] ),
209
                .OMEM_DAT_O( wOMEM_Dat[i] ),
210 76 diegovalve
 
211 109 diegovalve
                .TMEM_DAT_I( wCrossBarDataCollumn[i]    ),
212
                .TMEM_ADR_O( wTMemReadAdr[i]  ),
213
                .TMEM_CYC_O( wCORE_2_TMEM__Req[i]       ),
214
                .TMEM_GNT_I( wTMEM_2_Core__Grant[i]     ),
215 82 diegovalve
 
216 109 diegovalve
                .GRDY_O( wGRDY_O[i] ),
217
                .STDONE_I( STDONE_I ),
218
                .RCOMMIT_O( wRCOMMIT_O[i] ),
219
                .HDA_I(     HDA_I ),
220 82 diegovalve
 
221
                //Other
222
                .DAT_I( DAT_I ),
223 109 diegovalve
                .DONE_O( wDone[i] )
224
 
225 82 diegovalve
        );
226 109 diegovalve
 
227
        UPCOUNTER_POSEDGE # (1) UP_RCOMMIT
228
        (
229
        .Clock(  CLK_I ),
230
        .Reset( RST_I | GACK_I ),
231
        .Initial( 1'b0 ),
232
        .Enable( wRCOMMIT_O[i] ),
233
        .Q(wRCommited[i])
234
        );
235
 
236
        UPCOUNTER_POSEDGE # (1) UP_GREADY
237
        (
238
        .Clock(  CLK_I ),
239
        .Reset( RST_I | GACK_I ),
240
        .Initial( 1'b0 ),
241
        .Enable( wGRDY_O[i] ),
242
        .Q(wGReady[i])
243
        );
244
 
245 129 diegovalve
        RAM_SINGLE_READ_PORT # ( `WB_WIDTH, `WB_WIDTH, 250000 ) OMEM //500000 ) OMEM 
246 109 diegovalve
(
247
        .Clock(         CLK_I                ),
248
        .iWriteEnable(  wOMem_WE[i]          ),
249
        .iWriteAddress( wOMEM_Address[i]     ),
250
        .iDataIn(       wOMEM_Dat[i]         ),
251
        .iReadAddress0( OMADR_I              ),
252
        .oDataOut0(     wDataOut[i]          )
253
 
254
);
255
 
256
 
257
//If there are "n" banks, memory location "X" would reside in bank number X mod n.
258
//X mod 2^n == X & (2^n - 1)
259
assign wCoreBankSelect[i] = (wTMemReadAdr[i] & (`MAX_TMEM_BANKS-1));
260
 
261
//Each core has 1 bank request slot
262
//Each slot has MAX_TMEM_BANKS bits. Only 1 bit can
263
//be 1 at any given point in time. All bits zero means,
264
//we are not requesting to read from any memory bank.
265 129 diegovalve
SELECT_1_TO_N # ( `MAX_TMEM_BANKS, `MAX_CORES ) READDRQ
266 109 diegovalve
                        (
267
                        .Sel(wCoreBankSelect[ i]),
268
                        .En(wCORE_2_TMEM__Req[i]),
269
                        .O(wBankReadRequest[i])
270
                        );
271
 
272
//The address coming from the core is  virtual adress, meaning it assumes linear
273
//address space, however, since memory is interleaved in a n-way memory we transform
274
//virtual adress into physical adress (relative to the bank) like this
275
//fadr = vadr / n = vadr >> log2(n)
276
 
277 129 diegovalve
assign wCrossBarAdressCollumn[i] = (wTMemReadAdr[i] >> `MAX_CORE_BITS);
278 109 diegovalve
 
279
//Connect the granted signal to Arbiter of the Bank we want to read from        
280
assign wTMEM_2_Core__Grant[i] = wBankReadGranted[wCoreBankSelect[i]][i];
281
 
282
//Connect the request signal to Arbiter of the Bank we want to read from        
283
//assign wBankReadRequest[wCoreBankSelect[i]][i] = wCORE_2_TMEM__Req[i];
284
 
285
        end
286
  endgenerate
287
 
288
 
289
////////////// CROSS-BAR INTERCONECTION//////////////////////////
290
 
291
genvar Core,Bank;
292
generate
293
for (Bank = 0; Bank < `MAX_TMEM_BANKS; Bank = Bank + 1)
294
begin : BANK
295
 
296
        //The memory bank itself
297
RAM_SINGLE_READ_PORT     # ( `WB_WIDTH, `WB_WIDTH, 50000 ) TMEM
298
        (
299
        .Clock(         CLK_I                                   ),
300
        .iWriteEnable(  wTMemWriteEnable[Bank]       ),
301
        .iWriteAddress( TMADR_I                      ),
302
        .iDataIn(       TMDAT_I                      ),
303
        .iReadAddress0( wCrossBarAddressRow[Bank]    ), //Connect to the Row of the grid
304
        .oDataOut0(     wCrossBarDataRow[Bank]                  )  //Connect to the Row of the grid
305
 
306
        );
307
 
308
        //Arbiter will Round-Robin Cores attempting to read from the same Bank
309
        //at a given point in time
310
wire [`MAX_CORES-1:0]         wBankReadGrantedDelay[`MAX_TMEM_BANKS-1:0];
311
        Module_BusArbitrer ARB_TMEM
312
        (
313
        .Clock( CLK_I ),
314
        .Reset( RST_I ),
315 129 diegovalve
        .iRequest( {wBankReadRequest[7][Bank],wBankReadRequest[6][Bank],wBankReadRequest[5][Bank],wBankReadRequest[4][Bank],wBankReadRequest[3][Bank],wBankReadRequest[2][Bank],wBankReadRequest[1][Bank],wBankReadRequest[0][Bank]}),//wBankReadRequest[Bank] ),   //The cores requesting to read from this Bank
316 109 diegovalve
        .oGrant(   wBankReadGrantedDelay[Bank]  ),  //The bit of the core granted to read from this Bank
317
        .oBusSelect( wCurrentCoreSelected[Bank] )                       //The index of the core granted to read from this Bank
318
 
319
        );
320
 
321
        FFD_POSEDGE_SYNCRONOUS_RESET # ( `MAX_CORES ) FFD_GNT
322
(
323
        .Clock(CLK_I),
324
        .Reset(RST_I),
325
        .Enable( 1'b1 ),
326
        .D(wBankReadGrantedDelay[Bank]),
327
        .Q(wBankReadGranted[Bank])
328
);
329
 
330
 
331
        //Create the Cross-Bar interconnection grid now, rows are coonected to the memory banks,
332
        //while collumns are connected to the cores, 2 or more cores can not read from the same
333
        //bank at any given point in time
334
        for (Core = 0; Core < `MAX_CORES; Core = Core + 1)
335
        begin: CORE_CONNECT
336
                //Connect the Data Collum of this core to the Data Row of current bank, only if the Core is looking for data stored in this bank
337
                assign wCrossBarDataCollumn[ Core ] = ( wCoreBankSelect[ Core ] == Bank ) ? wCrossBarDataRow[ Bank ] : `WB_WIDTH'bz;
338
                //Connect the Address Row of this Bank to the Address Column of the core, only if the Arbiter selected this core for reading
339
                assign wCrossBarAddressRow[ Bank ] = ( wCurrentCoreSelected[ Bank ] == Core ) ? wCrossBarAdressCollumn[Core]: `WB_WIDTH'bz;
340
 
341
        end
342
 
343
end
344
endgenerate
345
 
346
////////////// CROSS-BAR INTERCONECTION//////////////////////////
347 82 diegovalve
//----------------------------------------------------------------
348 109 diegovalve
 
349 76 diegovalve
endmodule
350
//---------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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