@@ -184,9 +184,9 @@ void pooling2d_cl(data_T data[CONFIG_T::in_height * CONFIG_T::in_width * CONFIG_
184184 for (int ff = 0 ; ff < CONFIG_T::n_filt; ff++) {
185185
186186 // Loop over input image y in steps of stride
187- for (int ii = 0 ; ii < padded_height ; ii += CONFIG_T::stride_height) {
187+ for (int ii = 0 ; ii < restricted_padded_height ; ii += CONFIG_T::stride_height) {
188188 // Loop over input image x in steps of stride
189- for (int jj = 0 ; jj < padded_width ; jj += CONFIG_T::stride_width) {
189+ for (int jj = 0 ; jj < restricted_padded_width ; jj += CONFIG_T::stride_width) {
190190 data_T pool[CONFIG_T::pool_height * CONFIG_T::pool_width];
191191 #pragma HLS ARRAY_PARTITION variable=pool complete dim=0
192192
@@ -229,19 +229,17 @@ void pooling2d_cf(data_T data[CONFIG_T::in_height * CONFIG_T::in_width * CONFIG_
229229 // TODO partition the arrays according to the reuse factor
230230 const int limit = pool_op_limit<CONFIG_T>();
231231 #pragma HLS ALLOCATION function instances=CONFIG_T::pool_op limit=limit
232- // Add any necessary padding
233- unsigned padded_height = CONFIG_T::in_height + CONFIG_T::pad_top + CONFIG_T::pad_bottom;
234- unsigned padded_width = CONFIG_T::in_width + CONFIG_T::pad_left + CONFIG_T::pad_right;
235- if (CONFIG_T::pad_top == 0 && CONFIG_T::pad_bottom == 0 && CONFIG_T::pad_left == 0 && CONFIG_T::pad_right == 0 ) {
236- padded_height -= padded_height - (padded_height / CONFIG_T::stride_height * CONFIG_T::stride_height);
237- padded_width -= padded_width - (padded_width / CONFIG_T::stride_width * CONFIG_T::stride_width);
238- }
232+ // Add padding and reduce input width to area covered by pooling function
233+ static constexpr int full_padded_width = CONFIG_T::in_width + CONFIG_T::pad_left + CONFIG_T::pad_right;
234+ static constexpr int full_padded_height = CONFIG_T::in_height + CONFIG_T::pad_top + CONFIG_T::pad_bottom;
235+ static constexpr int restricted_padded_width = full_padded_width / CONFIG_T::stride_width * CONFIG_T::stride_width;
236+ static constexpr int restricted_padded_height = full_padded_height / CONFIG_T::stride_height * CONFIG_T::stride_height;
239237
240238 for (int ff = 0 ; ff < CONFIG_T::n_filt; ff++) {
241239 // Loop over input image y in steps of stride
242- for (int ii = 0 ; ii < padded_height ; ii += CONFIG_T::stride_height) {
240+ for (int ii = 0 ; ii < restricted_padded_height ; ii += CONFIG_T::stride_height) {
243241 // Loop over input image x in steps of stride
244- for (int jj = 0 ; jj < padded_width ; jj += CONFIG_T::stride_width) {
242+ for (int jj = 0 ; jj < restricted_padded_width ; jj += CONFIG_T::stride_width) {
245243 data_T pool[CONFIG_T::pool_height * CONFIG_T::pool_width];
246244 #pragma HLS ARRAY_PARTITION variable=pool complete dim=0
247245 // Keep track of number of pixels in image vs padding region
@@ -250,8 +248,8 @@ void pooling2d_cf(data_T data[CONFIG_T::in_height * CONFIG_T::in_width * CONFIG_
250248 for (int kk = 0 ; kk < CONFIG_T::stride_height; kk++) {
251249 // Loop over pool window x
252250 for (int ll = 0 ; ll < CONFIG_T::stride_width; ll++) {
253- if (ii + kk < CONFIG_T::pad_top || ii + kk >= (padded_height - CONFIG_T::pad_bottom) ||
254- jj + ll < CONFIG_T::pad_left || jj + ll >= (padded_width - CONFIG_T::pad_right)) {
251+ if (ii + kk < CONFIG_T::pad_top || ii + kk >= (full_padded_height - CONFIG_T::pad_bottom) ||
252+ jj + ll < CONFIG_T::pad_left || jj + ll >= (full_padded_width - CONFIG_T::pad_right)) {
255253 // Add padding
256254 pool[kk * CONFIG_T::stride_width + ll] = pad_val<data_T, CONFIG_T::pool_op>();
257255 if (CONFIG_T::count_pad)
0 commit comments