Newer
Older
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
#define AP_INT_MAX_W 1152
#include <ap_int.h>
#include <hls_stream.h>
#include "wino_macro.h"
#include "wino_IO.hpp"
#include "wino_cell.hpp"
#include "../testbench/debug.hpp"
#define DEBUG_FILE_PRINT 1
#define CEIL_DIV(x,y) ( ( (x) + (y) - 1) / (y) )
#define ALIGN(x,y) ( ( (x) + (y) - 1) / (y) * (y) )
void wino_systolic_top(
ap_uint<128> *input_DDR0,
ap_uint<128> *input_DDR1,
ap_uint<128> *input_DDR2,
ap_uint<128> *input_DDR3,
ap_uint<128> *weight_DDR0,
ap_uint<128> *weight_DDR1,
ap_uint<128> *weight_DDR2,
ap_uint<128> *weight_DDR3,
ap_uint<128> *output_DDR0,
ap_uint<128> *output_DDR1,
ap_uint<128> *output_DDR2,
ap_uint<128> *output_DDR3,
int inHeight,
int inWidth,
int inpDepth,
int outHeight,
int outWidth,
int outDepth,
int kernelWindowSize,
int padSize)
{
/******** this version assumes it shall only compute 5x5 and 3x3 for temporarily design **********/
// following part process parameters that may be moved outside the IP, but will keep it here first
//declaration part
ap_uint<16> input_height;
ap_uint<16> input_width;
ap_uint<16> input_depth;
ap_uint<16> output_height;
ap_uint<16> output_width;
ap_uint<16> output_depth;
ap_uint<8> pad_size;
ap_uint<8> kernel_window_size;
ap_uint<8> wino_output_tile_size;
ap_uint<16> input_width_align_8;
ap_uint<16> input_width_align_16;
ap_uint<16> weight_indepth_load_number;
ap_uint<16> weight_outdepth_load_number;
ap_uint<16> weight_outdepth_feed_size;
ap_uint<16> input_depth_align8;
ap_uint<16> input_width_ceildiv_16;
ap_uint<16> weight_total_load_number;
ap_uint<16> weight_total_feed_size;
ap_uint<16> ddr_load_length;
ap_uint<16> ddr_load_length_per_feed;
ap_uint<16> row_repeat_times;
// computation part
input_height=inHeight;
input_width=inWidth;
input_depth=inpDepth;
output_height=outHeight;
output_width=outWidth;
output_depth=outDepth;
pad_size=padSize;
if(kernelWindowSize==3 || kernelWindowSize==5 )
kernel_window_size=1;
else
kernel_window_size=kernelWindowSize;
if(kernelWindowSize==3)
wino_output_tile_size = 4;
else
wino_output_tile_size = 2;
if(inWidth%8)
input_width_align_8 = (input_width/8+1)*8;
else
input_width_align_8 = inWidth;
if(inWidth%16)
input_width_align_16 = (input_width/16+1)*16;
else
input_width_align_16 = inWidth;
input_depth_align8 = ALIGN(input_depth,8);
int output_depth_align_systolic_height = ALIGN(output_depth, WEIGHT_FEED_NUMBER_PER_PORT);
int output_depth_ceildiv_systolic_height = CEIL_DIV(output_depth, WEIGHT_FEED_NUMBER_PER_PORT*4);
int max_weight_outdepth_feed_size = WEIGHT_BUFFER_DEPTH/8;
weight_outdepth_feed_size = max_weight_outdepth_feed_size < output_depth_ceildiv_systolic_height ? max_weight_outdepth_feed_size :output_depth_ceildiv_systolic_height;
int load_size_per_feeding_port = 8 * weight_outdepth_feed_size;
weight_indepth_load_number = input_depth_align8 /8;
weight_outdepth_load_number = CEIL_DIV( output_depth_align_systolic_height, max_weight_outdepth_feed_size);
int ddr_bytes_per_feeding_port = load_size_per_feeding_port/2*80;
int ddr_bytes_per_DDR_port = weight_indepth_load_number*weight_outdepth_load_number*ddr_bytes_per_feeding_port*WEIGHT_FEED_NUMBER_PER_PORT;
int ddr_bytes_total = ddr_bytes_per_DDR_port*4;
input_width_ceildiv_16 = CEIL_DIV(input_width,16);
row_repeat_times = CEIL_DIV(output_width, wino_output_tile_size*2);
weight_total_load_number = weight_indepth_load_number * weight_outdepth_load_number;
weight_total_feed_size = weight_outdepth_feed_size * 8;
ddr_load_length_per_feed = weight_total_feed_size/2*5;
ddr_load_length = ddr_load_length_per_feed* WEIGHT_FEED_NUMBER_PER_PORT;
//input buffer declaration
ap_uint<16> input_buffer[8][16][INPUT_BUFFER_DEPTH];
ap_uint<64> output_buffer0[4][WEIGHT_FEED_NUMBER_PER_PORT][INPUT_FEED_NUMBER][16][OUTPUT_BUFFER_DEPTH];
ap_uint<64> output_buffer1[4][WEIGHT_FEED_NUMBER_PER_PORT][INPUT_FEED_NUMBER][16][OUTPUT_BUFFER_DEPTH];
#if DEBUG_FILE_PRINT
clear_buffer_content<INPUT_BUFFER_DEPTH>(input_buffer);
#endif
load_input_rowtile_from_ddr<0>(
input_DDR0,
input_DDR1,
input_DDR2,
input_DDR3,
input_buffer,
input_height,
input_width,
input_width_align_8,
input_width_align_16,
input_depth,
output_height,
0,
pad_size,
1);
#if DEBUG_FILE_PRINT
attach_input_buffer_content<INPUT_BUFFER_DEPTH>(input_buffer,0,"input_buffer_content.txt");
#endif
for(ap_uint<16> start_output_row =0 ; start_output_row < output_height; start_output_row+=wino_output_tile_size)
{
load_input_rowtile_from_ddr<0>(
input_DDR0,
input_DDR1,
input_DDR2,
input_DDR3,
input_buffer,
input_height,
input_width,
input_width_align_8,
input_width_align_16,
input_depth,
output_height,
start_output_row + wino_output_tile_size,
pad_size,
0);
#if DEBUG_FILE_PRINT
attach_input_buffer_content<INPUT_BUFFER_DEPTH>(input_buffer,start_output_row,"input_buffer_content.txt");
#endif
wino_systolic<0>(
input_buffer,
output_buffer0,
weight_DDR0,
weight_DDR1,
weight_DDR2,
weight_DDR3,
input_height,
input_width,
input_depth,
input_width_ceildiv_16,
input_depth_align8,
output_height,
output_width,
output_depth,
kernel_window_size,
pad_size,
weight_indepth_load_number,
weight_outdepth_load_number,
weight_outdepth_feed_size,
start_output_row,
weight_total_load_number,
weight_total_feed_size,
ddr_load_length,
ddr_load_length_per_feed,
row_repeat_times,
(start_output_row==0) ,
(start_output_row+wino_output_tile_size >= output_height));
}
}
#include "wino_macro.h"