Update CHW DWCONV to pass in input_height and not output_height.
Some fixes to the implicitly padded DW NCHW kernels.
Update NCHW Convolution tests - padding instead of padding_width
PiperOrigin-RevId: 310887885
diff --git a/src/f32-dwconv-spchw/3x3s2p1-scalar.c b/src/f32-dwconv-spchw/3x3s2p1-scalar.c
index 5da3d70..31398c7 100644
--- a/src/f32-dwconv-spchw/3x3s2p1-scalar.c
+++ b/src/f32-dwconv-spchw/3x3s2p1-scalar.c
@@ -5,13 +5,15 @@
#include <assert.h>
+#include <stdio.h>
+
#include <xnnpack/dwconv.h>
#include <xnnpack/math.h>
void xnn_f32_dwconv_spchw_ukernel_3x3s2p1__scalar(
- size_t m,
- size_t n,
+ size_t input_height,
+ size_t input_width,
const float* input,
const float* weights,
const float* zero,
@@ -23,12 +25,16 @@
size_t output_width_stride,
const union xnn_f32_spchw_params params[restrict XNN_MIN_ELEMENTS(1)])
{
- assert(n != 0);
- assert(padding_top <= 1);
+ assert(input_height!= 0);
+ assert(input_width != 0);
+ assert(padding_top >= 0 && padding_top <= 1);
- const size_t input_width_decrement_single = (n/2) * 2 * input_tuple_stride;;
+ const size_t padded_input_height = input_height + padding_top + 1 /* padding_bottom */;
+ const size_t output_height = (padded_input_height - 3) / 2 + 1;
+
+ const size_t input_width_decrement_single = (input_width/2) * 2 * input_tuple_stride;;
const size_t input_width_increment = 2 * input_width_stride - input_width_decrement_single;
- const size_t output_width_increment = output_width_stride - (n/2) * output_tuple_stride;
+ const size_t output_width_increment = output_width_stride - (input_width/2) * output_tuple_stride;
const float params_min = params->scalar.min;
const float params_max = params->scalar.max;
@@ -41,14 +47,17 @@
i0 = input;
i1 = (const float*) ((uintptr_t) i0 + input_width_stride);
i2 = (const float*) ((uintptr_t) i1 + input_width_stride);
- if (m == 1) {
+ if (input_height <= 2) {
i2 = zero;
}
+ if (input_height == 1) {
+ i1 = zero;
+ }
} else {
i0 = zero;
i1 = input;
i2 = (const float*) ((uintptr_t) i1 + input_width_stride);
- if (m == 1) {
+ if (input_height == 1) {
i2 = zero;
}
}
@@ -66,12 +75,13 @@
const float vw8 = weights[8];
const float vw9 = weights[9];
+ size_t m = output_height;
while (m > 0) {
float vi0x0 = 0.0f;
float vi1x0 = 0.0f;
float vi2x0 = 0.0f;
- size_t k = n;
+ size_t k = input_width;
for (; k >= 2; k -= 2) {
const float vi0x1 = *i0; i0 = (const float*) ((uintptr_t) i0 + input_tuple_stride);
const float vi1x1 = *i1; i1 = (const float*) ((uintptr_t) i1 + input_tuple_stride);
@@ -117,7 +127,14 @@
i2 = (const float*) ((uintptr_t) i2 + input_width_increment);
output0 = (float*) ((uintptr_t) output0 + output_width_increment);
m -= 1;
- if (m == 1) {
+ if (m == 1 && padding_top == input_height % 2) {
+ // to mimic the following code with only one if, we do some small
+ // shenanigans...
+ // if (padding_top == 0 && input_height % 2 == 0) {
+ // i2 = zero;
+ // } else if (padding_top == 1 && input_height % 2 == 1) {
+ // i2 = zero;
+ // }
i2 = zero;
}
}