/
sortnet_Stream_Adapter2.vhdl
385 lines (322 loc) · 12.3 KB
/
sortnet_Stream_Adapter2.vhdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
-- EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*-
-- vim: tabstop=2:shiftwidth=2:noexpandtab
-- kate: tab-width 2; replace-tabs off; indent-width 2;
-- =============================================================================
-- Authors: Patrick Lehmann
--
-- Entity: Sorting Network: Stream to sortnet adapter
--
-- Description:
-- -------------------------------------
-- .. TODO:: No documentation available.
--
-- License:
-- =============================================================================
-- Copyright 2007-2016 Technische Universitaet Dresden - Germany
-- Chair of VLSI-Design, Diagnostics and Architecture
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- =============================================================================
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
library PoC;
use PoC.utils.all;
use PoC.vectors.all;
use PoC.components.all;
use PoC.sortnet.all;
entity sortnet_Stream_Adapter2 is
generic (
STREAM_DATA_BITS : positive := 32;
STREAM_META_BITS : positive := 2;
DATA_COLUMNS : positive := 2;
SORTNET_IMPL : T_SORTNET_IMPL := SORT_SORTNET_IMPL_ODDEVEN_MERGESORT;
SORTNET_SIZE : positive := 32;
SORTNET_KEY_BITS : positive := 32;
SORTNET_DATA_BITS : natural := 32;
SORTNET_REG_AFTER : natural := 2;
MERGENET_STAGES : positive := 2
);
port (
Clock : in std_logic;
Reset : in std_logic;
Inverse : in std_logic := '0';
In_Valid : in std_logic;
In_Data : in std_logic_vector(STREAM_DATA_BITS - 1 downto 0);
In_Meta : in std_logic_vector(STREAM_META_BITS - 1 downto 0);
In_SOF : in std_logic;
In_IsKey : in std_logic;
In_EOF : in std_logic;
In_Ack : out std_logic;
Out_Valid : out std_logic;
Out_Data : out std_logic_vector(STREAM_DATA_BITS - 1 downto 0);
Out_Meta : out std_logic_vector(STREAM_META_BITS - 1 downto 0);
Out_SOF : out std_logic;
Out_IsKey : out std_logic;
Out_EOF : out std_logic;
Out_Ack : in std_logic
);
end entity;
architecture rtl of sortnet_Stream_Adapter2 is
constant C_VERBOSE : boolean := FALSE;
constant GEARBOX_BITS : positive := SORTNET_SIZE * SORTNET_DATA_BITS;
constant TRANSFORM_BITS : positive := DATA_COLUMNS * SORTNET_DATA_BITS;
constant MERGE_BITS : positive := TRANSFORM_BITS;
constant META_ISKEY_BIT : natural := 0;
constant META_BITS : positive := STREAM_META_BITS + 1;
signal Synchronized_r : std_logic := '0';
signal SyncIn : std_logic;
signal MetaIn : std_logic_vector(META_BITS - 1 downto 0);
signal gearup_Sync : std_logic;
signal gearup_Valid : std_logic;
signal gearup_Data : std_logic_vector(GEARBOX_BITS - 1 downto 0);
signal gearup_Meta : std_logic_vector(META_BITS - 1 downto 0);
signal gearup_First : std_logic;
signal gearup_Last : std_logic;
signal sort_Valid : std_logic;
signal sort_IsKey : std_logic;
signal sort_Data : std_logic_vector(GEARBOX_BITS - 1 downto 0);
signal sort_Meta : std_logic_vector(STREAM_META_BITS - 1 downto 0);
signal transform_Valid : std_logic;
signal transform_Data : std_logic_vector(TRANSFORM_BITS - 1 downto 0);
signal transform_Meta : std_logic_vector(STREAM_META_BITS - 1 downto 0);
signal transform_SOF : std_logic;
signal transform_EOF : std_logic;
signal merge_Sync : std_logic;
signal merge_Valid : std_logic;
signal merge_Data : std_logic_vector(MERGE_BITS - 1 downto 0);
signal merge_Meta : std_logic_vector(STREAM_META_BITS - 1 downto 0);
signal merge_SOF : std_logic;
signal merge_EOF : std_logic;
signal merge_Ack : std_logic;
signal geardown_nxt : std_logic;
signal geardown_Meta : std_logic_vector(STREAM_META_BITS - 1 downto 0);
signal geardown_First : std_logic;
signal geardown_Last : std_logic;
begin
In_Ack <= '1';
Synchronized_r <= ffrs(q => Synchronized_r, set => (In_SOF and In_Valid), rst => Reset) when rising_edge(Clock);
SyncIn <= (In_SOF and In_Valid) and not Synchronized_r;
MetaIn(META_ISKEY_BIT) <= In_IsKey;
MetaIn(META_BITS - 1 downto META_BITS - STREAM_META_BITS) <= In_Meta;
gearup : entity PoC.gearbox_up_cc
generic map (
INPUT_BITS => STREAM_DATA_BITS,
OUTPUT_BITS => GEARBOX_BITS,
META_BITS => META_BITS,
ADD_INPUT_REGISTERS => TRUE,
ADD_OUTPUT_REGISTERS => FALSE
)
port map (
Clock => Clock,
In_Sync => SyncIn,
In_Data => In_Data,
In_Meta => MetaIn,
In_Valid => In_Valid,
Out_Sync => gearup_Sync,
Out_Valid => gearup_Valid,
Out_Data => gearup_Data,
Out_Meta => gearup_Meta,
Out_First => gearup_First,
Out_Last => gearup_Last
);
genOES : if SORTNET_IMPL = SORT_SORTNET_IMPL_ODDEVEN_SORT generate
signal DataInputMatrix : T_SLM(SORTNET_SIZE - 1 downto 0, SORTNET_DATA_BITS - 1 downto 0);
signal DataOutputMatrix : T_SLM(SORTNET_SIZE - 1 downto 0, SORTNET_DATA_BITS - 1 downto 0);
begin
DataInputMatrix <= to_slm(gearup_Data, SORTNET_SIZE, SORTNET_DATA_BITS);
-- MetaInputMatric <=
-- mux(gearup_Valid, (SORTNET_SIZE * SORTNET_DATA_BITS downto 1 => 'U'), gearup_Data)
sort : entity PoC.sortnet_OddEvenSort
generic map (
INPUTS => SORTNET_SIZE,
KEY_BITS => SORTNET_KEY_BITS,
DATA_BITS => SORTNET_DATA_BITS,
META_BITS => STREAM_META_BITS,
PIPELINE_STAGE_AFTER => SORTNET_REG_AFTER,
ADD_OUTPUT_REGISTERS => FALSE
)
port map (
Clock => Clock,
Reset => Reset,
Inverse => Inverse,
In_Valid => gearup_Valid,
In_IsKey => gearup_Meta(META_ISKEY_BIT),
In_Data => DataInputMatrix,
In_Meta => gearup_Meta(META_BITS - 1 downto META_BITS - STREAM_META_BITS),
Out_Valid => sort_Valid,
Out_IsKey => sort_IsKey,
Out_Data => DataOutputMatrix,
Out_Meta => sort_Meta
);
sort_Data <= to_slv(DataOutputMatrix);
end generate;
genOEMS : if SORTNET_IMPL = SORT_SORTNET_IMPL_ODDEVEN_MERGESORT generate
signal DataInputMatrix : T_SLM(SORTNET_SIZE - 1 downto 0, SORTNET_DATA_BITS - 1 downto 0);
signal DataOutputMatrix : T_SLM(SORTNET_SIZE - 1 downto 0, SORTNET_DATA_BITS - 1 downto 0);
begin
DataInputMatrix <= to_slm(gearup_Data, SORTNET_SIZE, SORTNET_DATA_BITS);
sort : entity PoC.sortnet_OddEvenMergeSort
generic map (
INPUTS => SORTNET_SIZE,
KEY_BITS => SORTNET_KEY_BITS,
DATA_BITS => SORTNET_DATA_BITS,
META_BITS => STREAM_META_BITS,
PIPELINE_STAGE_AFTER => SORTNET_REG_AFTER,
ADD_OUTPUT_REGISTERS => FALSE
)
port map (
Clock => Clock,
Reset => Reset,
Inverse => Inverse,
In_Valid => gearup_Valid,
In_IsKey => gearup_Meta(META_ISKEY_BIT),
In_Data => DataInputMatrix,
In_Meta => gearup_Meta(META_BITS - 1 downto META_BITS - STREAM_META_BITS),
Out_Valid => sort_Valid,
Out_IsKey => sort_IsKey,
Out_Data => DataOutputMatrix,
Out_Meta => sort_Meta
);
sort_Data <= to_slv(DataOutputMatrix);
end generate;
genBS : if SORTNET_IMPL = SORT_SORTNET_IMPL_BITONIC_SORT generate
signal DataInputMatrix : T_SLM(SORTNET_SIZE - 1 downto 0, SORTNET_DATA_BITS - 1 downto 0);
signal DataOutputMatrix : T_SLM(SORTNET_SIZE - 1 downto 0, SORTNET_DATA_BITS - 1 downto 0);
begin
DataInputMatrix <= to_slm(gearup_Data, SORTNET_SIZE, SORTNET_DATA_BITS);
sort : entity PoC.sortnet_BitonicSort
generic map (
INPUTS => SORTNET_SIZE,
KEY_BITS => SORTNET_KEY_BITS,
DATA_BITS => SORTNET_DATA_BITS,
META_BITS => STREAM_META_BITS,
PIPELINE_STAGE_AFTER => SORTNET_REG_AFTER,
ADD_OUTPUT_REGISTERS => FALSE
)
port map (
Clock => Clock,
Reset => Reset,
Inverse => Inverse,
In_Valid => gearup_Valid,
In_IsKey => gearup_Meta(META_ISKEY_BIT),
In_Data => DataInputMatrix,
In_Meta => gearup_Meta(META_BITS - 1 downto META_BITS - STREAM_META_BITS),
Out_Valid => sort_Valid,
Out_IsKey => sort_IsKey,
Out_Data => DataOutputMatrix,
Out_Meta => sort_Meta
);
sort_Data <= to_slv(DataOutputMatrix);
end generate;
blkTransform : block
signal DataInputMatrix : T_SLM(SORTNET_SIZE - 1 downto 0, SORTNET_DATA_BITS - 1 downto 0);
signal DataOutputMatrix : T_SLM(DATA_COLUMNS - 1 downto 0, SORTNET_DATA_BITS - 1 downto 0);
begin
DataInputMatrix <= to_slm(sort_Data, SORTNET_SIZE, SORTNET_DATA_BITS);
transform : entity PoC.sortnet_Transform
generic map (
ROWS => SORTNET_SIZE,
COLUMNS => DATA_COLUMNS,
DATA_BITS => SORTNET_DATA_BITS
)
port map (
Clock => Clock,
Reset => Reset,
-- In_Sync => '0',
In_Valid => sort_Valid,
In_Data => DataInputMatrix,
In_SOF => sort_IsKey,
In_EOF => '0',
Out_Valid => transform_Valid,
Out_Data => DataOutputMatrix,
Out_SOF => transform_SOF,
Out_EOF => transform_EOF
);
transform_Data <= to_slv(DataOutputMatrix);
end block;
blkMergeSort : block
subtype T_MERGE_DATA is std_logic_vector(TRANSFORM_BITS - 1 downto 0);
type T_MERGE_DATA_VECTOR is array(natural range <>) of T_MERGE_DATA;
signal MergeSortMatrix_Valid : std_logic_vector(MERGENET_STAGES downto 0);
signal MergeSortMatrix_Data : T_MERGE_DATA_VECTOR(MERGENET_STAGES downto 0);
signal MergeSortMatrix_SOF : std_logic_vector(MERGENET_STAGES downto 0);
signal MergeSortMatrix_EOF : std_logic_vector(MERGENET_STAGES downto 0);
signal MergeSortMatrix_Ack : std_logic_vector(MERGENET_STAGES downto 0);
begin
MergeSortMatrix_Valid(0) <= transform_Valid;
MergeSortMatrix_Data(0) <= transform_Data;
MergeSortMatrix_SOF(0) <= transform_SOF;
MergeSortMatrix_EOF(0) <= transform_EOF;
merge_Ack <= MergeSortMatrix_Ack(0);
genMerge : for i in 0 to MERGENET_STAGES - 1 generate
constant FIFO_DEPTH : positive := 2**i * SORTNET_SIZE;
begin
merge : entity PoC.sortnet_MergeSort_Streamed
generic map (
FIFO_DEPTH => FIFO_DEPTH,
KEY_BITS => SORTNET_KEY_BITS,
DATA_BITS => MERGE_BITS
)
port map (
Clock => Clock,
Reset => Reset,
Inverse => Inverse,
In_Valid => MergeSortMatrix_Valid(i),
In_Data => MergeSortMatrix_Data(i),
In_SOF => MergeSortMatrix_SOF(i),
In_IsKey => '1',
In_EOF => MergeSortMatrix_EOF(i),
In_Ack => MergeSortMatrix_Ack(i),
Out_Valid => MergeSortMatrix_Valid(i + 1),
Out_Data => MergeSortMatrix_Data(i + 1),
Out_SOF => MergeSortMatrix_SOF(i + 1),
Out_IsKey => open,
Out_EOF => MergeSortMatrix_EOF(i + 1),
Out_Ack => MergeSortMatrix_Ack(i + 1)
);
end generate;
merge_Valid <= MergeSortMatrix_Valid(MERGENET_STAGES);
merge_Data <= MergeSortMatrix_Data(MERGENET_STAGES);
merge_Meta <= (others => 'U');
merge_SOF <= MergeSortMatrix_SOF(MERGENET_STAGES);
merge_EOF <= MergeSortMatrix_EOF(MERGENET_STAGES);
MergeSortMatrix_Ack(MERGENET_STAGES) <= geardown_nxt;
end block;
merge_Sync <= merge_SOF and merge_Valid;
geardown : entity PoC.gearbox_down_cc
generic map (
INPUT_BITS => MERGE_BITS,
OUTPUT_BITS => STREAM_DATA_BITS,
META_BITS => STREAM_META_BITS,
ADD_INPUT_REGISTERS => TRUE,
ADD_OUTPUT_REGISTERS => FALSE
)
port map (
Clock => Clock,
In_Sync => merge_Sync,
In_Valid => merge_Valid,
In_Next => geardown_nxt,
In_Data => merge_Data,
In_Meta => merge_Meta,
Out_Sync => open,
Out_Valid => Out_Valid,
Out_Data => Out_Data,
Out_Meta => geardown_Meta,
Out_First => geardown_First,
Out_Last => geardown_Last
);
Out_Meta <= geardown_Meta;
Out_SOF <= geardown_First and 'U';
Out_EOF <= geardown_Last and 'U';
end architecture;