@@ -107,22 +107,20 @@ void pooling1d_cl(data_T data[CONFIG_T::n_in * CONFIG_T::n_filt], res_T res[CONF
107
107
// TODO partition the arrays according to the reuse factor
108
108
const int limit = pool_op_limit_1d<CONFIG_T>();
109
109
#pragma HLS ALLOCATION function instances=CONFIG_T::pool_op limit=limit
110
- // Add any necessary padding
111
- unsigned padded_width = CONFIG_T::n_in + CONFIG_T::pad_left + CONFIG_T::pad_right;
112
- if (CONFIG_T::pad_left == 0 && CONFIG_T::pad_right == 0 ) {
113
- padded_width -= padded_width - (padded_width / CONFIG_T::stride_width * CONFIG_T::stride_width);
114
- }
110
+ // Add padding and reduce input width to area covered by pooling function
111
+ static constexpr int full_padded_width = CONFIG_T::n_in + CONFIG_T::pad_left + CONFIG_T::pad_right;
112
+ static constexpr int restricted_padded_width = full_padded_width / CONFIG_T::stride_width * CONFIG_T::stride_width;
115
113
116
114
for (int ff = 0 ; ff < CONFIG_T::n_filt; ff++) {
117
115
// Loop over input image x in steps of stride
118
- for (int ii = 0 ; ii < padded_width ; ii += CONFIG_T::stride_width) {
116
+ for (int ii = 0 ; ii < restricted_padded_width ; ii += CONFIG_T::stride_width) {
119
117
data_T pool[CONFIG_T::pool_width];
120
118
#pragma HLS ARRAY_PARTITION variable=pool complete dim=0
121
119
// Keep track of number of pixels in image vs padding region
122
120
unsigned img_overlap = 0 ;
123
121
// Loop over pool window x
124
122
for (int jj = 0 ; jj < CONFIG_T::stride_width; jj++) {
125
- if (ii + jj < CONFIG_T::pad_left || ii + jj >= (padded_width - CONFIG_T::pad_right)) {
123
+ if (ii + jj < CONFIG_T::pad_left || ii + jj >= (full_padded_width - CONFIG_T::pad_right)) {
126
124
// Add padding
127
125
pool[jj] = pad_val<data_T, CONFIG_T::pool_op>();
128
126
if (CONFIG_T::count_pad) {
@@ -211,19 +209,17 @@ void pooling2d_cl(data_T data[CONFIG_T::in_height * CONFIG_T::in_width * CONFIG_
211
209
// TODO partition the arrays according to the reuse factor
212
210
const int limit = pool_op_limit<CONFIG_T>();
213
211
#pragma HLS ALLOCATION function instances=CONFIG_T::pool_op limit=limit
214
- // Add any necessary padding
215
- unsigned padded_height = CONFIG_T::in_height + CONFIG_T::pad_top + CONFIG_T::pad_bottom;
216
- unsigned padded_width = CONFIG_T::in_width + CONFIG_T::pad_left + CONFIG_T::pad_right;
217
- if (CONFIG_T::pad_top == 0 && CONFIG_T::pad_bottom == 0 && CONFIG_T::pad_left == 0 && CONFIG_T::pad_right == 0 ) {
218
- padded_height -= padded_height - (padded_height / CONFIG_T::stride_height * CONFIG_T::stride_height);
219
- padded_width -= padded_width - (padded_width / CONFIG_T::stride_width * CONFIG_T::stride_width);
220
- }
212
+ // Add padding and reduce input width to area covered by pooling function
213
+ static constexpr int full_padded_width = CONFIG_T::in_width + CONFIG_T::pad_left + CONFIG_T::pad_right;
214
+ static constexpr int full_padded_height = CONFIG_T::in_height + CONFIG_T::pad_top + CONFIG_T::pad_bottom;
215
+ static constexpr int restricted_padded_width = full_padded_width / CONFIG_T::stride_width * CONFIG_T::stride_width;
216
+ static constexpr int restricted_padded_height = full_padded_height / CONFIG_T::stride_height * CONFIG_T::stride_height;
221
217
222
218
for (int ff = 0 ; ff < CONFIG_T::n_filt; ff++) {
223
219
// Loop over input image y in steps of stride
224
- for (int ii = 0 ; ii < padded_height ; ii += CONFIG_T::stride_height) {
220
+ for (int ii = 0 ; ii < restricted_padded_height ; ii += CONFIG_T::stride_height) {
225
221
// Loop over input image x in steps of stride
226
- for (int jj = 0 ; jj < padded_width ; jj += CONFIG_T::stride_width) {
222
+ for (int jj = 0 ; jj < restricted_padded_width ; jj += CONFIG_T::stride_width) {
227
223
data_T pool[CONFIG_T::pool_height * CONFIG_T::pool_width];
228
224
#pragma HLS ARRAY_PARTITION variable=pool complete dim=0
229
225
// Keep track of number of pixels in image vs padding region
@@ -232,8 +228,8 @@ void pooling2d_cl(data_T data[CONFIG_T::in_height * CONFIG_T::in_width * CONFIG_
232
228
for (int kk = 0 ; kk < CONFIG_T::stride_height; kk++) {
233
229
// Loop over pool window x
234
230
for (int ll = 0 ; ll < CONFIG_T::stride_width; ll++) {
235
- if (ii + kk < CONFIG_T::pad_top || ii + kk >= (padded_height - CONFIG_T::pad_bottom) ||
236
- jj + ll < CONFIG_T::pad_left || jj + ll >= (padded_width - CONFIG_T::pad_right)) {
231
+ if (ii + kk < CONFIG_T::pad_top || ii + kk >= (full_padded_height - CONFIG_T::pad_bottom) ||
232
+ jj + ll < CONFIG_T::pad_left || jj + ll >= (full_padded_width - CONFIG_T::pad_right)) {
237
233
// Add padding
238
234
pool[kk * CONFIG_T::stride_width + ll] = pad_val<data_T, CONFIG_T::pool_op>();
239
235
if (CONFIG_T::count_pad) {
@@ -275,19 +271,17 @@ void pooling2d_cf(data_T data[CONFIG_T::in_height * CONFIG_T::in_width * CONFIG_
275
271
// TODO partition the arrays according to the reuse factor
276
272
const int limit = pool_op_limit<CONFIG_T>();
277
273
#pragma HLS ALLOCATION function instances=CONFIG_T::pool_op limit=limit
278
- // Add any necessary padding
279
- unsigned padded_height = CONFIG_T::in_height + CONFIG_T::pad_top + CONFIG_T::pad_bottom;
280
- unsigned padded_width = CONFIG_T::in_width + CONFIG_T::pad_left + CONFIG_T::pad_right;
281
- if (CONFIG_T::pad_top == 0 && CONFIG_T::pad_bottom == 0 && CONFIG_T::pad_left == 0 && CONFIG_T::pad_right == 0 ) {
282
- padded_height -= padded_height - (padded_height / CONFIG_T::stride_height * CONFIG_T::stride_height);
283
- padded_width -= padded_width - (padded_width / CONFIG_T::stride_width * CONFIG_T::stride_width);
284
- }
274
+ // Add padding and reduce input width to area covered by pooling function
275
+ static constexpr int full_padded_width = CONFIG_T::in_width + CONFIG_T::pad_left + CONFIG_T::pad_right;
276
+ static constexpr int full_padded_height = CONFIG_T::in_height + CONFIG_T::pad_top + CONFIG_T::pad_bottom;
277
+ static constexpr int restricted_padded_width = full_padded_width / CONFIG_T::stride_width * CONFIG_T::stride_width;
278
+ static constexpr int restricted_padded_height = full_padded_height / CONFIG_T::stride_height * CONFIG_T::stride_height;
285
279
286
280
for (int ff = 0 ; ff < CONFIG_T::n_filt; ff++) {
287
281
// Loop over input image y in steps of stride
288
- for (int ii = 0 ; ii < padded_height ; ii += CONFIG_T::stride_height) {
282
+ for (int ii = 0 ; ii < restricted_padded_height ; ii += CONFIG_T::stride_height) {
289
283
// Loop over input image x in steps of stride
290
- for (int jj = 0 ; jj < padded_width ; jj += CONFIG_T::stride_width) {
284
+ for (int jj = 0 ; jj < restricted_padded_width ; jj += CONFIG_T::stride_width) {
291
285
data_T pool[CONFIG_T::pool_height * CONFIG_T::pool_width];
292
286
#pragma HLS ARRAY_PARTITION variable=pool complete dim=0
293
287
// Keep track of number of pixels in image vs padding region
@@ -296,8 +290,8 @@ void pooling2d_cf(data_T data[CONFIG_T::in_height * CONFIG_T::in_width * CONFIG_
296
290
for (int kk = 0 ; kk < CONFIG_T::stride_height; kk++) {
297
291
// Loop over pool window x
298
292
for (int ll = 0 ; ll < CONFIG_T::stride_width; ll++) {
299
- if (ii + kk < CONFIG_T::pad_top || ii + kk >= (padded_height - CONFIG_T::pad_bottom) ||
300
- jj + ll < CONFIG_T::pad_left || jj + ll >= (padded_width - CONFIG_T::pad_right)) {
293
+ if (ii + kk < CONFIG_T::pad_top || ii + kk >= (full_padded_height - CONFIG_T::pad_bottom) ||
294
+ jj + ll < CONFIG_T::pad_left || jj + ll >= (full_padded_width - CONFIG_T::pad_right)) {
301
295
// Add padding
302
296
pool[kk * CONFIG_T::stride_width + ll] = pad_val<data_T, CONFIG_T::pool_op>();
303
297
if (CONFIG_T::count_pad) {
0 commit comments