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

Subversion Repositories theia_gpu

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 76 diegovalve
`timescale 1ns / 1ps
2
`include "aDefinitions.v"
3 137 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 137 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 137 diegovalve
wire[`WIDTH-1:0]                wCoreBankSelect[`MAX_CORES-1:0];
127 109 diegovalve
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 137 diegovalve
assign RCOMMIT_O = wRCommited[0] & wRCommited[1] & wRCommited[2] & wRCommited[3] & wRCommited[4] & wRCommited[5] & wRCommited[6] & wRCommited[7] & wRCommited[8] & wRCommited[9] & wRCommited[10] & wRCommited[11] & wRCommited[12] & wRCommited[13] & wRCommited[14] & wRCommited[15];
136
assign GRDY_O = wGReady[0] &  wGReady[1] &  wGReady[2] &  wGReady[3] &  wGReady[4] &  wGReady[5] &  wGReady[6] &  wGReady[7] &  wGReady[8] &  wGReady[9] &  wGReady[10] &  wGReady[11] &  wGReady[12] &  wGReady[13] &  wGReady[14] &  wGReady[15];
137
assign DONE_O = wDone[0] & wDone[1] & wDone[2] & wDone[3] & wDone[4] & wDone[5] & wDone[6] & wDone[7] & wDone[8] & wDone[9] & wDone[10] & wDone[11] & wDone[12] & wDone[13] & wDone[14] & wDone[15];
138
 
139
 
140 109 diegovalve
 
141
//----------------------------------------------------------------      
142
 
143 76 diegovalve
        Module_BusArbitrer ARB1
144
        (
145
        .Clock( CLK_I ),
146
        .Reset( RST_I ),
147
        .iRequest( wBusRequest ),
148
        .oGrant(   wBusGranted ),
149
        .oBusSelect( wBusSelect )
150
 
151
        );
152
//----------------------------------------------------------------
153
 
154 137 diegovalve
 
155 109 diegovalve
  assign ACK_O = wACK_O[ wBusSelect];
156 76 diegovalve
 
157 109 diegovalve
 wire [`WB_WIDTH-1:0] wDataOut[`MAX_CORES-1:0];
158
 assign OMEM_O = wDataOut[ OMBSEL_I ];
159 76 diegovalve
 
160 109 diegovalve
  genvar i;
161
  generate
162
        for (i = 0; i < `MAX_CORES; i = i +1)
163
        begin : CORE
164
                assign wMST_I[i] = (SEL_I[i]) ? MST_I : 0;
165
                assign wSTB_I[i] = (SEL_I[i]) ? STB_I : 0;
166
                assign wCYC_I[i] = (SEL_I[i]) ? CYC_I : 0;
167
                assign wTGA_I[i] = (SEL_I[i]) ? TGA_I : 0;
168 76 diegovalve
 
169 109 diegovalve
 
170
                THEIACORE CTHEIA
171
                (
172
                .CLK_I( CLK_I ),
173 76 diegovalve
                .RST_I( RST_I ),
174 109 diegovalve
                .RENDREN_I( RENDREN_I[i] ),
175 76 diegovalve
 
176
                //Slave signals
177 109 diegovalve
                .ADR_I( ADR_I ),
178 76 diegovalve
                .WE_I(  WE_I  ),
179 109 diegovalve
                .STB_I(  wSTB_I[i] ),
180 82 diegovalve
                .ACK_I( ACK_I ),
181 109 diegovalve
                .CYC_I( wCYC_I[i] ),
182
                .MST_I( wMST_I[i] ),
183
                .TGA_I( wTGA_I[i] ),
184 76 diegovalve
                .CREG_I( CREG_I ),
185
 
186 109 diegovalve
                //Master Signals
187
                .ACK_O(         wACK_O[i] ),
188
                .CYC_O(  wBusRequest[i] ),
189
                .GNT_I(         wBusGranted[i] ),
190 76 diegovalve
                `ifdef DEBUG
191 109 diegovalve
                .iDebug_CoreID( i ),
192 76 diegovalve
                `endif
193
 
194 109 diegovalve
                .OMEM_WE_O( wOMem_WE[i] ),
195
                .OMEM_ADR_O( wOMEM_Address[i] ),
196
                .OMEM_DAT_O( wOMEM_Dat[i] ),
197 76 diegovalve
 
198 109 diegovalve
                .TMEM_DAT_I( wCrossBarDataCollumn[i]    ),
199
                .TMEM_ADR_O( wTMemReadAdr[i]  ),
200
                .TMEM_CYC_O( wCORE_2_TMEM__Req[i]       ),
201
                .TMEM_GNT_I( wTMEM_2_Core__Grant[i]     ),
202 82 diegovalve
 
203 109 diegovalve
                .GRDY_O( wGRDY_O[i] ),
204
                .STDONE_I( STDONE_I ),
205
                .RCOMMIT_O( wRCOMMIT_O[i] ),
206
                .HDA_I(     HDA_I ),
207 82 diegovalve
 
208
                //Other
209
                .DAT_I( DAT_I ),
210 109 diegovalve
                .DONE_O( wDone[i] )
211
 
212 82 diegovalve
        );
213 109 diegovalve
 
214
        UPCOUNTER_POSEDGE # (1) UP_RCOMMIT
215
        (
216
        .Clock(  CLK_I ),
217
        .Reset( RST_I | GACK_I ),
218
        .Initial( 1'b0 ),
219
        .Enable( wRCOMMIT_O[i] ),
220
        .Q(wRCommited[i])
221
        );
222
 
223
        UPCOUNTER_POSEDGE # (1) UP_GREADY
224
        (
225
        .Clock(  CLK_I ),
226
        .Reset( RST_I | GACK_I ),
227
        .Initial( 1'b0 ),
228
        .Enable( wGRDY_O[i] ),
229
        .Q(wGReady[i])
230
        );
231
 
232 137 diegovalve
        RAM_SINGLE_READ_PORT # ( `WB_WIDTH, `WB_WIDTH, 250000 ) OMEM //500000 ) OMEM 
233 109 diegovalve
(
234
        .Clock(         CLK_I                ),
235
        .iWriteEnable(  wOMem_WE[i]          ),
236
        .iWriteAddress( wOMEM_Address[i]     ),
237
        .iDataIn(       wOMEM_Dat[i]         ),
238
        .iReadAddress0( OMADR_I              ),
239
        .oDataOut0(     wDataOut[i]          )
240
 
241
);
242
 
243
 
244
//If there are "n" banks, memory location "X" would reside in bank number X mod n.
245
//X mod 2^n == X & (2^n - 1)
246
assign wCoreBankSelect[i] = (wTMemReadAdr[i] & (`MAX_TMEM_BANKS-1));
247
 
248
//Each core has 1 bank request slot
249
//Each slot has MAX_TMEM_BANKS bits. Only 1 bit can
250
//be 1 at any given point in time. All bits zero means,
251
//we are not requesting to read from any memory bank.
252 137 diegovalve
SELECT_1_TO_N # ( `WIDTH, `MAX_CORES ) READDRQ
253 109 diegovalve
                        (
254
                        .Sel(wCoreBankSelect[ i]),
255
                        .En(wCORE_2_TMEM__Req[i]),
256
                        .O(wBankReadRequest[i])
257
                        );
258
 
259
//The address coming from the core is  virtual adress, meaning it assumes linear
260
//address space, however, since memory is interleaved in a n-way memory we transform
261
//virtual adress into physical adress (relative to the bank) like this
262
//fadr = vadr / n = vadr >> log2(n)
263
 
264 137 diegovalve
assign wCrossBarAdressCollumn[i] = (wTMemReadAdr[i] >> `MAX_CORE_BITS);
265 109 diegovalve
 
266
//Connect the granted signal to Arbiter of the Bank we want to read from        
267
assign wTMEM_2_Core__Grant[i] = wBankReadGranted[wCoreBankSelect[i]][i];
268
 
269
//Connect the request signal to Arbiter of the Bank we want to read from        
270
//assign wBankReadRequest[wCoreBankSelect[i]][i] = wCORE_2_TMEM__Req[i];
271
 
272
        end
273
  endgenerate
274
 
275
 
276
////////////// CROSS-BAR INTERCONECTION//////////////////////////
277
 
278
genvar Core,Bank;
279
generate
280
for (Bank = 0; Bank < `MAX_TMEM_BANKS; Bank = Bank + 1)
281
begin : BANK
282
 
283
        //The memory bank itself
284
RAM_SINGLE_READ_PORT     # ( `WB_WIDTH, `WB_WIDTH, 50000 ) TMEM
285
        (
286
        .Clock(         CLK_I                                   ),
287
        .iWriteEnable(  wTMemWriteEnable[Bank]       ),
288
        .iWriteAddress( TMADR_I                      ),
289
        .iDataIn(       TMDAT_I                      ),
290
        .iReadAddress0( wCrossBarAddressRow[Bank]    ), //Connect to the Row of the grid
291
        .oDataOut0(     wCrossBarDataRow[Bank]                  )  //Connect to the Row of the grid
292
 
293
        );
294
 
295
        //Arbiter will Round-Robin Cores attempting to read from the same Bank
296
        //at a given point in time
297
wire [`MAX_CORES-1:0]         wBankReadGrantedDelay[`MAX_TMEM_BANKS-1:0];
298
        Module_BusArbitrer ARB_TMEM
299
        (
300
        .Clock( CLK_I ),
301
        .Reset( RST_I ),
302 137 diegovalve
        .iRequest( {wBankReadRequest[15][Bank],wBankReadRequest[14][Bank],wBankReadRequest[13][Bank],wBankReadRequest[12][Bank],wBankReadRequest[11][Bank],wBankReadRequest[10][Bank],wBankReadRequest[9][Bank],wBankReadRequest[8][Bank],wBankReadRequest[7][Bank],wBankReadRequest[6][Bank],wBankReadRequest[5][Bank],wBankReadRequest[4][Bank],wBankReadRequest[3][Bank],wBankReadRequest[2][Bank],wBankReadRequest[1][Bank],wBankReadRequest[0][Bank]}),
303 109 diegovalve
        .oGrant(   wBankReadGrantedDelay[Bank]  ),  //The bit of the core granted to read from this Bank
304
        .oBusSelect( wCurrentCoreSelected[Bank] )                       //The index of the core granted to read from this Bank
305
 
306
        );
307
 
308
        FFD_POSEDGE_SYNCRONOUS_RESET # ( `MAX_CORES ) FFD_GNT
309
(
310
        .Clock(CLK_I),
311
        .Reset(RST_I),
312
        .Enable( 1'b1 ),
313
        .D(wBankReadGrantedDelay[Bank]),
314
        .Q(wBankReadGranted[Bank])
315
);
316
 
317
 
318
        //Create the Cross-Bar interconnection grid now, rows are coonected to the memory banks,
319
        //while collumns are connected to the cores, 2 or more cores can not read from the same
320
        //bank at any given point in time
321
        for (Core = 0; Core < `MAX_CORES; Core = Core + 1)
322
        begin: CORE_CONNECT
323
                //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
324
                assign wCrossBarDataCollumn[ Core ] = ( wCoreBankSelect[ Core ] == Bank ) ? wCrossBarDataRow[ Bank ] : `WB_WIDTH'bz;
325
                //Connect the Address Row of this Bank to the Address Column of the core, only if the Arbiter selected this core for reading
326
                assign wCrossBarAddressRow[ Bank ] = ( wCurrentCoreSelected[ Bank ] == Core ) ? wCrossBarAdressCollumn[Core]: `WB_WIDTH'bz;
327
 
328
        end
329
 
330
end
331
endgenerate
332
 
333
////////////// CROSS-BAR INTERCONECTION//////////////////////////
334 82 diegovalve
//----------------------------------------------------------------
335 109 diegovalve
 
336 76 diegovalve
endmodule
337
//---------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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