Skip to content

Commit e50c2fc

Browse files
committed
don't run (sub) function when height or widht is zero
1 parent b9fdd86 commit e50c2fc

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

lib/src/kernels/convolution/mli_krn_conv2d_hwc.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ static __attribute__ ((always_inline)) void depthwise_convolution2D_hwcn_krnpad(
386386
perception_area_nopad.clmn_beg = CEIL_DIV(padding_left, stride_width);
387387
perception_area_nopad.clmn_end = out_width - CEIL_DIV(padding_right, stride_width);
388388

389+
if ((perception_area_nopad.row_end - perception_area_nopad.row_beg > 0)
390+
&& (perception_area_nopad.clmn_end - perception_area_nopad.clmn_beg > 0)){
389391
depthwise_convolution2D_hwcn_nopad<int8_t, int8_t, int32_t, mli_acc32_t>(
390392
in_ftrs, weights, biases, out_ftrs, &perception_area_nopad, quant_params,
391393
val_min_limit, val_max_limit,
@@ -395,7 +397,7 @@ static __attribute__ ((always_inline)) void depthwise_convolution2D_hwcn_krnpad(
395397
stride_height, stride_width,
396398
padding_top, padding_left,
397399
padding_bot, padding_right);
398-
400+
}
399401
// Phase 2: Process border part with more complex algorithm
400402
// (usually significantly smaller part of computations)
401403
//=======================================================================
@@ -680,8 +682,10 @@ static __attribute__ ((always_inline)) void convolution2D_nhwc_krnpad(
680682
perception_area_nopad.row_end = out_height - CEIL_DIV(padding_bot, stride_height);
681683
perception_area_nopad.clmn_beg = CEIL_DIV(padding_left, stride_width);
682684
perception_area_nopad.clmn_end = out_width - CEIL_DIV(padding_right, stride_width);
683-
684-
convolution2D_nhwc_nopad<int8_t, int8_t, int32_t, mli_acc32_t>(
685+
686+
if ((perception_area_nopad.row_end - perception_area_nopad.row_beg > 0)
687+
&& (perception_area_nopad.clmn_end - perception_area_nopad.clmn_beg > 0)){
688+
convolution2D_nhwc_nopad<int8_t, int8_t, int32_t, mli_acc32_t>(
685689
in_ftrs, weights, biases, out_ftrs, &perception_area_nopad, quant_params,
686690
val_min_limit, val_max_limit,
687691
in_ch, in_width, in_height,
@@ -690,6 +694,7 @@ static __attribute__ ((always_inline)) void convolution2D_nhwc_krnpad(
690694
stride_height, stride_width,
691695
padding_top, padding_left,
692696
padding_bot, padding_right);
697+
}
693698

694699
// Phase 2: Process border part with more complex algorithm
695700
// (usually significantly smaller part of computations)

lib/src/kernels/pooling/mli_krn_avepool_hwc.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,13 @@ static inline void __attribute__((always_inline)) avepool_hwc_krnpad(
194194
const int padding_bot) {
195195
// Phase 1: Process central part (without border effects - padding free)
196196
//=======================================================================
197-
{
198-
const int row_beg = CEIL_DIV(padding_top, stride_height);
199-
const int row_end = out_height - CEIL_DIV(padding_bot, stride_height);
200-
const int clmn_beg = CEIL_DIV(padding_left, stride_width);
201-
const int clmn_end = out_width - CEIL_DIV(padding_right, stride_width);
202197

198+
const int row_beg = CEIL_DIV(padding_top, stride_height);
199+
const int row_end = out_height - CEIL_DIV(padding_bot, stride_height);
200+
const int clmn_beg = CEIL_DIV(padding_left, stride_width);
201+
const int clmn_end = out_width - CEIL_DIV(padding_right, stride_width);
202+
203+
if ((row_end - row_beg > 0) && (clmn_end - clmn_beg > 0)) {
203204
avepool_hwc_nopad(
204205
row_beg, row_end, clmn_beg, clmn_end,
205206
in_ftrs, out_ftrs, channels, in_width,

lib/src/kernels/pooling/mli_krn_maxpool_hwc.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,20 @@ static inline void __attribute__((always_inline)) maxpool_hwc_pad(
191191

192192
// Phase 1: Process central part (without border effects - padding free)
193193
//=======================================================================
194-
maxpool_hwc_nopad<io_T>(
195-
row_beg, row_end, clmn_beg, clmn_end,
196-
stride_width, stride_height, padding_top,
197-
padding_bot, padding_left, padding_right,
198-
in_ftrs, out_ftrs, channels_num, kernel_height,
199-
kernel_width, in_height, in_width, out_width,
200-
out_height);
194+
int row_beg = CEIL_DIV(padding_top, stride_height);
195+
int row_end = out_height - CEIL_DIV(padding_bot, stride_height);
196+
int clmn_beg = CEIL_DIV(padding_left, stride_width);
197+
int clmn_end = out_width - CEIL_DIV(padding_right, stride_width);
198+
199+
if ((row_end - row_beg > 0) && (clmn_end - clmn_beg > 0)) {
200+
maxpool_hwc_nopad<io_T>(
201+
row_beg, row_end, clmn_beg, clmn_end,
202+
stride_width, stride_height, padding_top,
203+
padding_bot, padding_left, padding_right,
204+
in_ftrs, out_ftrs, channels_num, kernel_height,
205+
kernel_width, in_height, in_width, out_width,
206+
out_height);
207+
}
201208
// Phase 2: Process border part with more complex algorithm
202209
// (usually significantly smaller part of computations)
203210
//=======================================================================

0 commit comments

Comments
 (0)