1 |
213 |
diegovalve |
`timescale 1ns / 1ps
|
2 |
|
|
`include "aDefinitions.v"
|
3 |
|
|
/**********************************************************************************
|
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 |
230 |
diegovalve |
//--------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
module THEIA
|
25 |
|
|
(
|
26 |
|
|
input wire Clock,
|
27 |
|
|
input wire Reset,
|
28 |
|
|
input wire iEnable,
|
29 |
|
|
input wire [31:0] iMemReadData, //Data read from Main memory
|
30 |
|
|
input wire iMemDataAvailable,
|
31 |
|
|
output wire [31:0] oMemReadAddress,
|
32 |
|
|
output wire oMEM_ReadRequest,
|
33 |
|
|
|
34 |
|
|
input wire [`WB_WIDTH-1:0] TMDAT_I,
|
35 |
|
|
input wire [`WB_WIDTH-1:0] TMADR_I,
|
36 |
|
|
input wire TMWE_I,
|
37 |
|
|
input wire [`MAX_TMEM_BANKS-1:0] TMSEL_I
|
38 |
|
|
|
39 |
|
|
);
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
wire [`WB_WIDTH-1:0] wMCU_2_VP_InstructionWriteAddress;
|
43 |
|
|
wire [`WB_WIDTH-1:0] wMCU_2_VP_InstructionWriteData;
|
44 |
|
|
wire [`MAX_CORES-1:0] wMCU_2_VP_InstructionWriteEnable;
|
45 |
|
|
wire [`MCU_TAG_SIZE-1:0] wMCU_2_VP_Tag;
|
46 |
|
|
wire wMCU_2_VP_STB;
|
47 |
|
|
wire wMCU_2_VP_Cyc;
|
48 |
|
|
wire wMCU_2_VP_Mst;
|
49 |
|
|
wire [`MAX_CORES-1:0] wVP_2_MCU_ACK;
|
50 |
|
|
wire wVP_Slave_ACK;
|
51 |
|
|
wire [`MCU_REQUEST_SIZE-1:0] wCP_2MCU_BlockCopyCommand;
|
52 |
|
|
wire[`CBC_BUS_WIDTH-1:0] wCP_VP__ControlCommandBus;
|
53 |
|
|
wire wMCU_2_CP__FIFOEmpty;
|
54 |
213 |
diegovalve |
wire wOMem_WE[`MAX_CORES-1:0];
|
55 |
|
|
wire [`WB_WIDTH-1:0] wOMEM_Address[`MAX_CORES-1:0];
|
56 |
230 |
diegovalve |
wire [`WB_WIDTH-1:0] wOMEM_Dat[`MAX_CORES-1:0];
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
//CROSS-BAR wires
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
wire [`MAX_TMEM_BANKS-1:0] wTMemWriteEnable;
|
65 |
|
|
wire [(`MAX_TMEM_BANKS*`WB_WIDTH)-1:0] wCrossBarDataRow; //Horizontal grid Buses comming from each bank
|
66 |
|
|
wire [(`MAX_CORES*`WB_WIDTH)-1:0] wCrossBarDataCollumn; //Vertical grid buses comming from each core.
|
67 |
|
|
wire [(`MAX_CORES*`WB_WIDTH)-1:0] wCrossBarAdressCollumn; //Vertical grid buses comming from each core. (physical addr).
|
68 |
|
|
wire [`WB_WIDTH-1:0] wTMemReadAdr[`MAX_CORES-1:0]; //Horizontal grid Buses comming from each core (virtual addr).
|
69 |
|
|
wire [`WB_WIDTH-1:0] wCrossBarAddressRow[`MAX_TMEM_BANKS-1:0]; //Horizontal grid Buses comming from each bank.
|
70 |
|
|
wire wCORE_2_TMEM__Req[`MAX_CORES-1:0];
|
71 |
|
|
wire [`MAX_TMEM_BANKS -1:0] wBankReadRequest[`MAX_CORES-1:0];
|
72 |
|
|
wire [`MAX_CORES-1:0] wBankReadGranted[`MAX_TMEM_BANKS-1:0];
|
73 |
|
|
wire wTMEM_2_Core__Grant[`MAX_CORES-1:0];
|
74 |
|
|
wire[`MAX_CORE_BITS-1:0] wCurrentCoreSelected[`MAX_TMEM_BANKS-1:0];
|
75 |
|
|
wire[`WIDTH-1:0] wCoreBankSelect[`MAX_CORES-1:0];
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
//////////////////////////////////////////////
|
83 |
|
|
//
|
84 |
|
|
// The control processor
|
85 |
|
|
//
|
86 |
|
|
//////////////////////////////////////////////
|
87 |
|
|
ControlProcessor CP
|
88 |
|
|
(
|
89 |
|
|
.Clock( Clock ),
|
90 |
|
|
.Reset( Reset ),
|
91 |
|
|
.oControlBus( wCP_VP__ControlCommandBus ),
|
92 |
|
|
.iMCUFifoEmpty( wMCU_2_CP__FIFOEmpty ),
|
93 |
|
|
.oCopyBlockCommand( wCP_2MCU_BlockCopyCommand )
|
94 |
|
|
);
|
95 |
|
|
|
96 |
|
|
//////////////////////////////////////////////
|
97 |
|
|
//
|
98 |
|
|
// The control processor
|
99 |
|
|
//
|
100 |
|
|
//////////////////////////////////////////////
|
101 |
|
|
assign wVP_Slave_ACK = wVP_2_MCU_ACK[0] | wVP_2_MCU_ACK[1] | wVP_2_MCU_ACK[2] | wVP_2_MCU_ACK[3];
|
102 |
|
|
|
103 |
|
|
MemoryController #(`MAX_CORES) MCU
|
104 |
|
|
(
|
105 |
|
|
.Clock( Clock ),
|
106 |
|
|
.Reset( Reset ),
|
107 |
|
|
.iRequest( wCP_2MCU_BlockCopyCommand ),
|
108 |
|
|
.oMEM_ReadAddress( oMemReadAddress ),
|
109 |
|
|
.oMEM_ReadRequest( oMEM_ReadRequest ),
|
110 |
|
|
.oFifoEmpty( wMCU_2_CP__FIFOEmpty ),
|
111 |
|
|
.iMEM_ReadData( iMemReadData ),
|
112 |
|
|
.iMEM_DataAvailable( iMemDataAvailable ),
|
113 |
|
|
.DAT_O( wMCU_2_VP_InstructionWriteData ),
|
114 |
|
|
.ADR_O( wMCU_2_VP_InstructionWriteAddress ),
|
115 |
|
|
.STB_O( wMCU_2_VP_STB ),
|
116 |
|
|
.WE_O( wMCU_2_VP_InstructionWriteEnable ),
|
117 |
|
|
.TAG_O( wMCU_2_VP_Tag ),
|
118 |
|
|
.CYC_O( wMCU_2_VP_Cyc ),
|
119 |
|
|
.MST_O( wMCU_2_VP_Mst ),
|
120 |
|
|
.ACK_I( wVP_Slave_ACK )
|
121 |
|
|
);
|
122 |
|
|
|
123 |
|
|
//////////////////////////////////////////////
|
124 |
|
|
//
|
125 |
|
|
// The vector processors
|
126 |
|
|
//
|
127 |
|
|
//////////////////////////////////////////////
|
128 |
213 |
diegovalve |
genvar i;
|
129 |
|
|
generate
|
130 |
|
|
for (i = 0; i < `MAX_CORES; i = i +1)
|
131 |
230 |
diegovalve |
begin : VPX
|
132 |
|
|
|
133 |
|
|
VectorProcessor VP
|
134 |
|
|
(
|
135 |
|
|
.Clock( Clock ),
|
136 |
|
|
.Reset( Reset ),
|
137 |
|
|
.iEnable( iEnable ),
|
138 |
|
|
.iVPID( i+1 ),
|
139 |
|
|
.iCpCommand( wCP_VP__ControlCommandBus ),
|
140 |
|
|
.MCU_STB_I( wMCU_2_VP_STB ),
|
141 |
|
|
.MCU_WE_I( wMCU_2_VP_InstructionWriteEnable[i] ),
|
142 |
|
|
.MCU_DAT_I( wMCU_2_VP_InstructionWriteData ),
|
143 |
|
|
.MCU_ADR_I( wMCU_2_VP_InstructionWriteAddress ),
|
144 |
|
|
.MCU_TAG_I( wMCU_2_VP_Tag ),
|
145 |
|
|
.MCU_ACK_O( wVP_2_MCU_ACK[i] ),
|
146 |
|
|
.MCU_MST_I( wMCU_2_VP_Mst ),
|
147 |
|
|
.MCU_CYC_I( wMCU_2_VP_Cyc ),
|
148 |
|
|
.OMEM_WE( wOMem_WE[i] ),
|
149 |
|
|
.OMEM_ADDR( wOMEM_Address[i] ),
|
150 |
|
|
.OMEM_DATA( wOMEM_Dat[i] ),
|
151 |
|
|
.TMEM_DAT_I( wCrossBarDataCollumn[ (i*`WB_WIDTH)+:`WB_WIDTH ] ),
|
152 |
|
|
.TMEM_ADR_O( wTMemReadAdr[i] ),
|
153 |
|
|
.TMEM_CYC_O( wCORE_2_TMEM__Req[i] ),
|
154 |
|
|
.TMEM_GNT_I( wTMEM_2_Core__Grant[i] )
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
);
|
158 |
|
|
//////////////////////////////////////////////
|
159 |
|
|
//
|
160 |
|
|
// The OMEM
|
161 |
|
|
//
|
162 |
|
|
//////////////////////////////////////////////
|
163 |
|
|
|
164 |
213 |
diegovalve |
RAM_SINGLE_READ_PORT # ( `WB_WIDTH, `WB_WIDTH, `OMEM_SIZE ) OMEM
|
165 |
|
|
(
|
166 |
|
|
.Clock( Clock ),
|
167 |
|
|
.iWriteEnable( wOMem_WE[i] ),
|
168 |
|
|
.iWriteAddress( wOMEM_Address[i] ),
|
169 |
|
|
.iDataIn( wOMEM_Dat[i] ),
|
170 |
|
|
.iReadAddress0( wOMEM_Address[i] )
|
171 |
|
|
|
172 |
230 |
diegovalve |
|
173 |
|
|
);
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
MUXFULLPARALELL_GENERIC # (`WB_WIDTH,`MAX_TMEM_BANKS,`MAX_TMEM_BITS) MUXG1
|
177 |
|
|
(
|
178 |
|
|
.in_bus( wCrossBarDataRow ),
|
179 |
|
|
.sel( wCoreBankSelect[ i ][0+:`MAX_TMEM_BITS] ),
|
180 |
|
|
.out( wCrossBarDataCollumn[ (i*`WB_WIDTH)+:`WB_WIDTH ] )
|
181 |
|
|
);
|
182 |
|
|
|
183 |
|
|
//If there are "n" banks, memory location "X" would reside in bank number X mod n.
|
184 |
|
|
//X mod 2^n == X & (2^n - 1)
|
185 |
|
|
assign wCoreBankSelect[i] = (wTMemReadAdr[i] & (`MAX_TMEM_BANKS-1));
|
186 |
|
|
|
187 |
|
|
//Each core has 1 bank request slot
|
188 |
|
|
//Each slot has MAX_TMEM_BANKS bits. Only 1 bit can
|
189 |
|
|
//be 1 at any given point in time. All bits zero means,
|
190 |
|
|
//we are not requesting to read from any memory bank.
|
191 |
|
|
SELECT_1_TO_N # ( `WIDTH, `MAX_TMEM_BANKS ) READDRQ
|
192 |
|
|
(
|
193 |
|
|
.Sel(wCoreBankSelect[ i]),
|
194 |
|
|
.En(wCORE_2_TMEM__Req[i]),
|
195 |
|
|
.O(wBankReadRequest[i])
|
196 |
|
|
);
|
197 |
|
|
|
198 |
|
|
//The address coming from the core is virtual adress, meaning it assumes linear
|
199 |
|
|
//address space, however, since memory is interleaved in a n-way memory we transform
|
200 |
|
|
//virtual adress into physical adress (relative to the bank) like this
|
201 |
|
|
//fadr = vadr / n = vadr >> log2(n)
|
202 |
|
|
|
203 |
|
|
assign wCrossBarAdressCollumn[(i*`WB_WIDTH)+:`WB_WIDTH] = (wTMemReadAdr[i] >> `MAX_CORE_BITS);
|
204 |
|
|
|
205 |
|
|
//Connect the granted signal to Arbiter of the Bank we want to read from
|
206 |
|
|
assign wTMEM_2_Core__Grant[i] = wBankReadGranted[wCoreBankSelect[i]][i];
|
207 |
|
|
|
208 |
213 |
diegovalve |
end // for
|
209 |
230 |
diegovalve |
endgenerate
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
////////////// CROSS-BAR INTERCONECTION//////////////////////////
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
SELECT_1_TO_N # ( `MAX_TMEM_BANKS, `MAX_TMEM_BANKS ) TMWE_SEL
|
222 |
|
|
(
|
223 |
|
|
.Sel(TMSEL_I),
|
224 |
|
|
.En(TMWE_I),
|
225 |
|
|
.O(wTMemWriteEnable)
|
226 |
|
|
);
|
227 |
|
|
|
228 |
|
|
genvar Core,Bank;
|
229 |
|
|
generate
|
230 |
|
|
for (Bank = 0; Bank < `MAX_TMEM_BANKS; Bank = Bank + 1)
|
231 |
|
|
begin : BANK
|
232 |
|
|
|
233 |
|
|
//The memory bank itself
|
234 |
|
|
|
235 |
|
|
RAM_SINGLE_READ_PORT # ( `WB_WIDTH, `WB_WIDTH, 50000 ) TMEM
|
236 |
|
|
(
|
237 |
|
|
.Clock( Clock ),
|
238 |
|
|
.iWriteEnable( wTMemWriteEnable[Bank] ),
|
239 |
|
|
.iWriteAddress( TMADR_I ),
|
240 |
|
|
.iDataIn( TMDAT_I ),
|
241 |
|
|
.iReadAddress0( wCrossBarAddressRow[Bank] ), //Connect to the Row of the grid
|
242 |
|
|
.oDataOut0( wCrossBarDataRow[(`WB_WIDTH*Bank)+:`WB_WIDTH] ) //Connect to the Row of the grid
|
243 |
|
|
|
244 |
|
|
);
|
245 |
|
|
|
246 |
|
|
//Arbiter will Round-Robin Cores attempting to read from the same Bank
|
247 |
|
|
//at a given point in time
|
248 |
|
|
wire [`MAX_CORES-1:0] wBankReadGrantedDelay[`MAX_TMEM_BANKS-1:0];
|
249 |
|
|
Module_BusArbitrer ARB_TMEM
|
250 |
|
|
(
|
251 |
|
|
.Clock( Clock ),
|
252 |
|
|
.Reset( Reset ),
|
253 |
|
|
.iRequest( {wBankReadRequest[3][Bank],wBankReadRequest[2][Bank],wBankReadRequest[1][Bank],wBankReadRequest[0][Bank]}),
|
254 |
|
|
.oGrant( wBankReadGrantedDelay[Bank] ), //The bit of the core granted to read from this Bank
|
255 |
|
|
.oBusSelect( wCurrentCoreSelected[Bank] ) //The index of the core granted to read from this Bank
|
256 |
|
|
|
257 |
|
|
);
|
258 |
|
|
|
259 |
|
|
FFD_POSEDGE_SYNCRONOUS_RESET # ( `MAX_CORES ) FFD_GNT
|
260 |
|
|
(
|
261 |
|
|
.Clock(Clock),
|
262 |
|
|
.Reset(Reset),
|
263 |
|
|
.Enable( 1'b1 ),
|
264 |
|
|
.D(wBankReadGrantedDelay[Bank]),
|
265 |
|
|
.Q(wBankReadGranted[Bank])
|
266 |
|
|
);
|
267 |
|
|
|
268 |
|
|
MUXFULLPARALELL_GENERIC # (`WB_WIDTH,`MAX_CORES,`MAX_CORE_BITS) MUXG2
|
269 |
|
|
(
|
270 |
|
|
.in_bus( wCrossBarAdressCollumn ),
|
271 |
|
|
.sel( wCurrentCoreSelected[ Bank ] ),
|
272 |
|
|
.out( wCrossBarAddressRow[ Bank ] )
|
273 |
|
|
);
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
end
|
278 |
|
|
endgenerate
|
279 |
|
|
|
280 |
|
|
////////////// CROSS-BAR INTERCONECTION//////////////////////////
|
281 |
|
|
|
282 |
|
|
endmodule
|