@@ -174,6 +174,32 @@ void im2col_2d_cl(
174
174
}
175
175
}
176
176
177
+ template <class data_T , typename CONFIG_T>
178
+ void im2col_2d_pointwise_cl (
179
+ data_T data[CONFIG_T::in_height * CONFIG_T::in_width * CONFIG_T::n_chan],
180
+ data_T data_col[CONFIG_T::n_chan],
181
+ const int row,
182
+ const int col)
183
+ {
184
+ int index = 0 ;
185
+ int input_row = -CONFIG_T::pad_top + row * CONFIG_T::stride_height;
186
+
187
+ ChannelLoop:
188
+ for (int channel = 0 ; channel < CONFIG_T::n_chan; channel++) {
189
+ #pragma HLS UNROLL
190
+ if (input_row < 0 || input_row >= CONFIG_T::in_height) {
191
+ data_col[index++] = 0 ;
192
+ } else {
193
+ int input_col = -CONFIG_T::pad_left + col * CONFIG_T::stride_width;
194
+ if (input_col >= 0 && input_col < CONFIG_T::in_width) {
195
+ data_col[index++] = data[input_row * CONFIG_T::in_width * CONFIG_T::n_chan + input_col * CONFIG_T::n_chan + channel];
196
+ } else {
197
+ data_col[index++] = 0 ;
198
+ }
199
+ }
200
+ }
201
+ }
202
+
177
203
template <class data_T , class res_T , typename CONFIG_T>
178
204
void conv_2d_resource_cl (
179
205
data_T data[CONFIG_T::in_height * CONFIG_T::in_width * CONFIG_T::n_chan],
@@ -212,5 +238,47 @@ void conv_2d_resource_cl(
212
238
}
213
239
}
214
240
241
+
242
+ template <class data_T , class res_T , typename CONFIG_T>
243
+ void pointwise_conv_2d_resource_cl (
244
+ data_T data[CONFIG_T::in_height * CONFIG_T::in_width * CONFIG_T::n_chan],
245
+ res_T res[CONFIG_T::out_height * CONFIG_T::out_width * CONFIG_T::n_filt],
246
+ typename CONFIG_T::weight_t weights[CONFIG_T::n_chan * CONFIG_T::n_filt],
247
+ typename CONFIG_T::bias_t biases[CONFIG_T::n_filt]
248
+ )
249
+ {
250
+ assert (CONFIG_T::filt_height == 1 && CONFIG_T::filt_width == 1 );
251
+
252
+ const int nin = CONFIG_T::n_chan;
253
+ const int nout = CONFIG_T::n_filt;
254
+ const int rufactor = CONFIG_T::reuse_factor;
255
+ const int block_factor = DIV_ROUNDUP (nin*nout, rufactor);
256
+
257
+ // #pragma HLS function_instantiate variable=weights,biases
258
+ // #pragma HLS RESOURCE variable=weights core=RAM_2P_BRAM Commenting out the deisgnation HLS seems to choose correctly
259
+ // #pragma HLS ARRAY_RESHAPE variable=weights block factor=block_factor
260
+ // #pragma HLS ARRAY_PARTITION variable=biases complete
261
+
262
+ data_T data_col[CONFIG_T::n_chan];
263
+ res_T res_col[CONFIG_T::n_filt];
264
+
265
+ #pragma HLS ARRAY_PARTITION variable=data_col complete
266
+ #pragma HLS ARRAY_PARTITION variable=res_col complete
267
+
268
+ HeightLoop:
269
+ for (int i = 0 ; i < CONFIG_T::out_height; i++) {
270
+ WidthLoop:
271
+ for (int j = 0 ; j < CONFIG_T::out_width; j++) {
272
+ #pragma HLS PIPELINE
273
+ im2col_2d_pointwise_cl<data_T, CONFIG_T>(data, data_col, i, j);
274
+ dense<data_T, res_T, typename CONFIG_T::mult_config>(data_col, res_col, weights, biases);
275
+ FiltLoop:
276
+ for (int k = 0 ; k < CONFIG_T::n_filt; k++) {
277
+ res[i * CONFIG_T::out_width * CONFIG_T::n_filt + j * CONFIG_T::n_filt + k] = res_col[k];
278
+ }
279
+ }
280
+ }
281
+ }
282
+
215
283
}
216
284
#endif
0 commit comments