aboutsummaryrefslogtreecommitdiff
path: root/src/core/CL/cl_kernels/depthwise_convolution_quantized.cl
diff options
context:
space:
mode:
authorGiorgio Arena <giorgio.arena@arm.com>2018-01-31 10:30:59 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:49:37 +0000
commitdfca60b8e8805966624c7c941f289e090e3d73bb (patch)
treeee2763d823ed3d0dc68caef76edd6c991764c5c0 /src/core/CL/cl_kernels/depthwise_convolution_quantized.cl
parentfe5ef38cdbc1e9a44c3786744dfc0cc915a608a6 (diff)
downloadComputeLibrary-dfca60b8e8805966624c7c941f289e090e3d73bb.tar.gz
COMPMID-811 Add NHWC data format support for CL depthwise convolution QASYMM8
Change-Id: I89de432f3fbcba7abf9e1d4f8396a4334b4fa2c2 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/118324 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
Diffstat (limited to 'src/core/CL/cl_kernels/depthwise_convolution_quantized.cl')
-rw-r--r--src/core/CL/cl_kernels/depthwise_convolution_quantized.cl486
1 files changed, 482 insertions, 4 deletions
diff --git a/src/core/CL/cl_kernels/depthwise_convolution_quantized.cl b/src/core/CL/cl_kernels/depthwise_convolution_quantized.cl
index 21daee8230..635bc9d50b 100644
--- a/src/core/CL/cl_kernels/depthwise_convolution_quantized.cl
+++ b/src/core/CL/cl_kernels/depthwise_convolution_quantized.cl
@@ -24,17 +24,21 @@
#include "helpers_asymm.h"
-#if defined(CONV_STRIDE_X) && defined(CONV_STRIDE_Y) && defined(WEIGHTS_OFFSET) && defined(INPUT_OFFSET) && defined(K_OFFSET) && defined(OUTPUT_OFFSET) && defined(OUTPUT_MULTIPLIER) && defined(OUTPUT_SHIFT)
+#if defined(WEIGHTS_OFFSET) && defined(INPUT_OFFSET) && defined(K_OFFSET) && defined(OUTPUT_OFFSET) && defined(OUTPUT_MULTIPLIER) && defined(OUTPUT_SHIFT)
#if defined(FUSED_ACTIVATION)
#define DATA_TYPE uchar
+#ifndef VEC_SIZE
#define VEC_SIZE 8
+#endif /* VEC_SIZE */
#include "activation_layer_qa8.cl"
#define ACTIVATION_FUNC(x) PERFORM_ACTIVATION_QA8(FUSED_ACTIVATION, x)
#else /* defined(FUSED_ACTIVATION) */
#define ACTIVATION_FUNC(x) (x)
#endif /* defined(FUSED_ACTIVATION) */
+#if defined(CONV_STRIDE_Y) && defined(CONV_STRIDE_X)
+
#if CONV_STRIDE_X > 3
#error "Stride X not supported"
#endif /* CONV_STRIDE_X > 3 */
@@ -71,7 +75,7 @@
})
#endif /* CONV_STRIDE_X */
-/** This function computes the horizontal integral of the image and adds offsets.
+/** This function computes the depthwise convolution quantized.
*
* @param[in] src_ptr Pointer to the source image. Supported data types: QASYMM8
* @param[in] src_stride_x Stride of the source image in X dimension (in bytes)
@@ -103,7 +107,7 @@
* @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector
*/
-__kernel void depthwise_convolution_3x3_quantized(
+__kernel void depthwise_convolution_3x3_quantized_nchw(
TENSOR3D_DECLARATION(src),
TENSOR3D_DECLARATION(dst),
TENSOR3D_DECLARATION(weights)
@@ -244,4 +248,478 @@ __kernel void depthwise_convolution_3x3_quantized(
#endif /* CONV_STRIDE_Y == 1 */
}
-#endif /* defined(CONV_STRIDE_X) && defined(CONV_STRIDE_Y) && defined(WEIGHTS_OFFSET) && defined(INPUT_OFFSET) && defined(K_OFFSET) && defined(OUTPUT_OFFSET) && defined(OUTPUT_MULTIPLIER) && defined(OUTPUT_SHIFT) */
+#endif /* defined(CONV_STRIDE_Y) && defined(CONV_STRIDE_X) */
+
+#if defined(VEC_SIZE) && defined(SRC_DEPTH) && defined(CONV_PAD_TOP) && defined(ROWS_READ)
+
+#define asymm_mult_by_quant_multiplier_less_than_one(x, y, z) ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(x, y, z, VEC_SIZE)
+
+#define VEC_INT VEC_DATA_TYPE(int, VEC_SIZE)
+#define VEC_UCHAR VEC_DATA_TYPE(uchar, VEC_SIZE)
+
+#define BIFROST_MAD_4(acc, x, y) \
+ ({ \
+ acc.s0 += (ushort)x.s0 * (ushort)y.s0; \
+ acc.s1 += (ushort)x.s1 * (ushort)y.s1; \
+ acc.s2 += (ushort)x.s2 * (ushort)y.s2; \
+ acc.s3 += (ushort)x.s3 * (ushort)y.s3; \
+ })
+
+#if WEIGHTS_OFFSET != 0
+#define BIFROST_MAD_ACC_4(acc, sum, x, y) \
+ ({ \
+ sum += CONVERT(x, VEC_INT); \
+ BIFROST_MAD_4(acc, x, y); \
+ })
+#else /* WEIGHTS_OFFSET != 0 */
+#define BIFROST_MAD_ACC_4(acc, sum, x, y) BIFROST_MAD_4(acc, x, y)
+#endif /* WEIGHTS_OFFSET != 0 */
+
+/** This function computes the depthwise convolution quantized.
+ *
+ * @param[in] src_ptr Pointer to the source image. Supported data types: QASYMM8
+ * @param[in] src_stride_x Stride of the source image in X dimension (in bytes)
+ * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes)
+ * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image
+ * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
+ * @param[in] src_step_z src_stride_z * number of elements along Y processed per workitem(in bytes)
+ * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: QASYMM8
+ * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
+ * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
+ * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
+ * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes)
+ * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
+ * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: QASYMM8
+ * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes)
+ * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes)
+ * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[in] weights_stride_z Stride of the weights tensor in Z dimension (in bytes)
+ * @param[in] weights_step_z weights_stride_z * number of elements along Y processed per workitem(in bytes)
+ * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor
+ * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: QASYMM8
+ * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes)
+ * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector
+ */
+
+__kernel void depthwise_convolution_3x3_quantized_nhwc_stride1(
+ TENSOR3D_DECLARATION(src),
+ TENSOR3D_DECLARATION(dst),
+ TENSOR3D_DECLARATION(weights),
+#if defined(HAS_BIAS)
+ VECTOR_DECLARATION(biases)
+#endif /* defined(HAS_BIAS) */
+)
+{
+ Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst);
+ Vector weights = CONVERT_TO_VECTOR_STRUCT(weights);
+#if defined(HAS_BIAS)
+ Vector biases = CONVERT_TO_VECTOR_STRUCT(biases);
+
+ VEC_INT bias_values = VLOAD(VEC_SIZE)(0, (__global int *)biases.ptr);
+#endif /* defined(HAS_BIAS) */
+
+ __global uchar *first_elem = src_ptr + src_offset_first_element_in_bytes;
+
+ const int z = get_global_id(2);
+ const int pad_offs = -ROWS_READ * src_stride_y;
+ const int src_offs0 = get_global_id(0) * src_step_x + get_global_id(1) * src_step_y + z * src_step_z - CONV_PAD_TOP * src_stride_z;
+ const int src_offs1 = src_offs0 + src_stride_z;
+ const int src_offs2 = src_offs1 + src_stride_z;
+
+ const int cond_top = z - CONV_PAD_TOP < 0;
+ const int cond_bottom = z * (src_step_z / src_stride_z) + 2 >= SRC_DEPTH;
+
+ __global uchar *src_addr0 = first_elem + select(src_offs0, pad_offs, cond_top);
+ __global uchar *src_addr1 = first_elem + src_offs1;
+ __global uchar *src_addr2 = first_elem + select(src_offs2, pad_offs, cond_bottom);
+
+ VEC_INT sum_we = 0;
+ VEC_INT acc0 = 0, acc1 = 0, acc2 = 0, acc3 = 0;
+ VEC_INT sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0;
+
+ // z == 0
+ VEC_UCHAR w0, w1, w2;
+ w0 = VLOAD(VEC_SIZE)(0, weights.ptr + 0 * weights_stride_y);
+ w1 = VLOAD(VEC_SIZE)(0, weights.ptr + 1 * weights_stride_y);
+ w2 = VLOAD(VEC_SIZE)(0, weights.ptr + 2 * weights_stride_y);
+
+#if INPUT_OFFSET != 0
+ sum_we += CONVERT(w0, VEC_INT) + CONVERT(w1, VEC_INT) + CONVERT(w2, VEC_INT);
+#endif /* INPUT_OFFSET != 0 */
+
+ VEC_UCHAR values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w0);
+
+ src_addr0 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w1);
+ BIFROST_MAD_ACC_4(acc1, sum1, values, w0);
+
+ src_addr0 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w2);
+ BIFROST_MAD_ACC_4(acc1, sum1, values, w1);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w0);
+
+ src_addr0 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc1, sum1, values, w2);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w1);
+ BIFROST_MAD_ACC_4(acc3, sum3, values, w0);
+
+ src_addr0 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w2);
+ BIFROST_MAD_ACC_4(acc3, sum3, values, w1);
+
+ src_addr0 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc3, sum3, values, w2);
+
+ weights.ptr += weights_stride_z;
+
+ // z == 1
+ w0 = VLOAD(VEC_SIZE)(0, weights.ptr + 0 * weights_stride_y);
+ w1 = VLOAD(VEC_SIZE)(0, weights.ptr + 1 * weights_stride_y);
+ w2 = VLOAD(VEC_SIZE)(0, weights.ptr + 2 * weights_stride_y);
+
+#if INPUT_OFFSET != 0
+ sum_we += CONVERT(w0, VEC_INT) + CONVERT(w1, VEC_INT) + CONVERT(w2, VEC_INT);
+#endif /* INPUT_OFFSET != 0 */
+
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w0);
+
+ src_addr1 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w1);
+ BIFROST_MAD_ACC_4(acc1, sum1, values, w0);
+
+ src_addr1 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w2);
+ BIFROST_MAD_ACC_4(acc1, sum1, values, w1);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w0);
+
+ src_addr1 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc1, sum1, values, w2);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w1);
+ BIFROST_MAD_ACC_4(acc3, sum3, values, w0);
+
+ src_addr1 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w2);
+ BIFROST_MAD_ACC_4(acc3, sum3, values, w1);
+
+ src_addr1 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc3, sum3, values, w2);
+
+ weights.ptr += weights_stride_z;
+
+ // z == 2
+ w0 = VLOAD(VEC_SIZE)(0, weights.ptr + 0 * weights_stride_y);
+ w1 = VLOAD(VEC_SIZE)(0, weights.ptr + 1 * weights_stride_y);
+ w2 = VLOAD(VEC_SIZE)(0, weights.ptr + 2 * weights_stride_y);
+
+#if INPUT_OFFSET != 0
+ sum_we += CONVERT(w0, VEC_INT) + CONVERT(w1, VEC_INT) + CONVERT(w2, VEC_INT);
+#endif /* INPUT_OFFSET != 0 */
+
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w0);
+
+ src_addr2 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w1);
+ BIFROST_MAD_ACC_4(acc1, sum1, values, w0);
+
+ src_addr2 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w2);
+ BIFROST_MAD_ACC_4(acc1, sum1, values, w1);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w0);
+
+ src_addr2 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc1, sum1, values, w2);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w1);
+ BIFROST_MAD_ACC_4(acc3, sum3, values, w0);
+
+ src_addr2 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w2);
+ BIFROST_MAD_ACC_4(acc3, sum3, values, w1);
+
+ src_addr2 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc3, sum3, values, w2);
+
+#if defined(HAS_BIAS)
+ acc0 += bias_values;
+ acc1 += bias_values;
+ acc2 += bias_values;
+ acc3 += bias_values;
+#endif /* defined(HAS_BIAS) */
+
+#if WEIGHTS_OFFSET != 0
+ acc0 += WEIGHTS_OFFSET * sum0;
+ acc1 += WEIGHTS_OFFSET * sum1;
+ acc2 += WEIGHTS_OFFSET * sum2;
+ acc3 += WEIGHTS_OFFSET * sum3;
+#endif /* WEIGHTS_OFFSET != 0 */
+
+#if INPUT_OFFSET != 0
+ VEC_INT offs = INPUT_OFFSET * sum_we;
+
+ acc0 += offs;
+ acc1 += offs;
+ acc2 += offs;
+ acc3 += offs;
+#endif /* INPUT_OFFSET != 0 */
+
+#if K_OFFSET != 0
+ acc0 += (VEC_INT)K_OFFSET;
+ acc1 += (VEC_INT)K_OFFSET;
+ acc2 += (VEC_INT)K_OFFSET;
+ acc3 += (VEC_INT)K_OFFSET;
+#endif /* K_OFFSET != 0 */
+
+ acc0 = asymm_mult_by_quant_multiplier_less_than_one(acc0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
+ acc1 = asymm_mult_by_quant_multiplier_less_than_one(acc1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
+ acc2 = asymm_mult_by_quant_multiplier_less_than_one(acc2, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
+ acc3 = asymm_mult_by_quant_multiplier_less_than_one(acc3, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
+
+ acc0 += (VEC_INT)OUTPUT_OFFSET;
+ acc1 += (VEC_INT)OUTPUT_OFFSET;
+ acc2 += (VEC_INT)OUTPUT_OFFSET;
+ acc3 += (VEC_INT)OUTPUT_OFFSET;
+
+ VEC_UCHAR res0 = CONVERT_SAT(acc0, VEC_UCHAR);
+ VEC_UCHAR res1 = CONVERT_SAT(acc1, VEC_UCHAR);
+ VEC_UCHAR res2 = CONVERT_SAT(acc2, VEC_UCHAR);
+ VEC_UCHAR res3 = CONVERT_SAT(acc3, VEC_UCHAR);
+
+ res0 = CLAMP(res0, (VEC_UCHAR)0, (VEC_UCHAR)255);
+ res1 = CLAMP(res1, (VEC_UCHAR)0, (VEC_UCHAR)255);
+ res2 = CLAMP(res2, (VEC_UCHAR)0, (VEC_UCHAR)255);
+ res3 = CLAMP(res3, (VEC_UCHAR)0, (VEC_UCHAR)255);
+
+ VSTORE(VEC_SIZE)
+ (res0, 0, dst.ptr + 0 * dst_stride_y);
+ VSTORE(VEC_SIZE)
+ (res1, 0, dst.ptr + 1 * dst_stride_y);
+ VSTORE(VEC_SIZE)
+ (res2, 0, dst.ptr + 2 * dst_stride_y);
+ VSTORE(VEC_SIZE)
+ (res3, 0, dst.ptr + 3 * dst_stride_y);
+}
+
+/** This function computes the depthwise convolution quantized.
+ *
+ * @param[in] src_ptr Pointer to the source image. Supported data types: QASYMM8
+ * @param[in] src_stride_x Stride of the source image in X dimension (in bytes)
+ * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes)
+ * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image
+ * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
+ * @param[in] src_step_z src_stride_z * number of elements along Y processed per workitem(in bytes)
+ * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: QASYMM8
+ * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
+ * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
+ * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
+ * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes)
+ * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
+ * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: QASYMM8
+ * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes)
+ * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes)
+ * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[in] weights_stride_z Stride of the weights tensor in Z dimension (in bytes)
+ * @param[in] weights_step_z weights_stride_z * number of elements along Y processed per workitem(in bytes)
+ * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor
+ * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: QASYMM8
+ * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes)
+ * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector
+ */
+
+__kernel void depthwise_convolution_3x3_quantized_nhwc_stride2(
+ TENSOR3D_DECLARATION(src),
+ TENSOR3D_DECLARATION(dst),
+ TENSOR3D_DECLARATION(weights),
+#if defined(HAS_BIAS)
+ VECTOR_DECLARATION(biases)
+#endif /* defined(HAS_BIAS) */
+)
+{
+ Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst);
+ Vector weights = CONVERT_TO_VECTOR_STRUCT(weights);
+#if defined(HAS_BIAS)
+ Vector biases = CONVERT_TO_VECTOR_STRUCT(biases);
+
+ VEC_INT bias_values = VLOAD(VEC_SIZE)(0, (__global int *)biases.ptr);
+#endif /* defined(HAS_BIAS) */
+
+ __global uchar *first_elem = src_ptr + src_offset_first_element_in_bytes;
+
+ const int z = get_global_id(2);
+ const int pad_offs = -ROWS_READ * src_stride_y;
+ const int src_offs0 = get_global_id(0) * src_step_x + get_global_id(1) * src_step_y + z * src_step_z - CONV_PAD_TOP * src_stride_z;
+ const int src_offs1 = src_offs0 + src_stride_z;
+ const int src_offs2 = src_offs1 + src_stride_z;
+
+ const int cond_top = z - CONV_PAD_TOP < 0;
+ const int cond_bottom = z * (src_step_z / src_stride_z) + 2 >= SRC_DEPTH;
+ ;
+
+ __global uchar *src_addr0 = first_elem + select(src_offs0, pad_offs, cond_top);
+ __global uchar *src_addr1 = first_elem + src_offs1;
+ __global uchar *src_addr2 = first_elem + select(src_offs2, pad_offs, cond_bottom);
+
+ VEC_INT sum_we = 0;
+ VEC_INT acc0 = 0, acc2 = 0;
+ VEC_INT sum0 = 0, sum2 = 0;
+
+ // z == 0
+ VEC_UCHAR w0, w1, w2;
+ w0 = VLOAD(VEC_SIZE)(0, weights.ptr + 0 * weights_stride_y);
+ w1 = VLOAD(VEC_SIZE)(0, weights.ptr + 1 * weights_stride_y);
+ w2 = VLOAD(VEC_SIZE)(0, weights.ptr + 2 * weights_stride_y);
+
+#if INPUT_OFFSET != 0
+ sum_we += CONVERT(w0, VEC_INT) + CONVERT(w1, VEC_INT) + CONVERT(w2, VEC_INT);
+#endif /* INPUT_OFFSET != 0 */
+
+ VEC_UCHAR values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w0);
+
+ src_addr0 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w1);
+
+ src_addr0 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w2);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w0);
+
+ src_addr0 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w1);
+
+ src_addr0 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr0);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w2);
+
+ weights.ptr += weights_stride_z;
+
+ // z == 1
+ w0 = VLOAD(VEC_SIZE)(0, weights.ptr + 0 * weights_stride_y);
+ w1 = VLOAD(VEC_SIZE)(0, weights.ptr + 1 * weights_stride_y);
+ w2 = VLOAD(VEC_SIZE)(0, weights.ptr + 2 * weights_stride_y);
+
+#if INPUT_OFFSET != 0
+ sum_we += CONVERT(w0, VEC_INT) + CONVERT(w1, VEC_INT) + CONVERT(w2, VEC_INT);
+#endif /* INPUT_OFFSET != 0 */
+
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w0);
+
+ src_addr1 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w1);
+
+ src_addr1 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w2);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w0);
+
+ src_addr1 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w1);
+
+ src_addr1 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr1);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w2);
+
+ weights.ptr += weights_stride_z;
+
+ // z == 2
+ w0 = VLOAD(VEC_SIZE)(0, weights.ptr + 0 * weights_stride_y);
+ w1 = VLOAD(VEC_SIZE)(0, weights.ptr + 1 * weights_stride_y);
+ w2 = VLOAD(VEC_SIZE)(0, weights.ptr + 2 * weights_stride_y);
+
+#if INPUT_OFFSET != 0
+ sum_we += CONVERT(w0, VEC_INT) + CONVERT(w1, VEC_INT) + CONVERT(w2, VEC_INT);
+#endif /* INPUT_OFFSET != 0 */
+
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w0);
+
+ src_addr2 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w1);
+
+ src_addr2 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc0, sum0, values, w2);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w0);
+
+ src_addr2 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w1);
+
+ src_addr2 += src_stride_y;
+ values = VLOAD(VEC_SIZE)(0, src_addr2);
+ BIFROST_MAD_ACC_4(acc2, sum2, values, w2);
+
+#if defined(HAS_BIAS)
+ acc0 += bias_values;
+ acc2 += bias_values;
+#endif /* defined(HAS_BIAS) */
+
+#if WEIGHTS_OFFSET != 0
+ acc0 += WEIGHTS_OFFSET * sum0;
+ acc2 += WEIGHTS_OFFSET * sum2;
+#endif /* WEIGHTS_OFFSET != 0 */
+
+#if INPUT_OFFSET != 0
+ VEC_INT offs = INPUT_OFFSET * sum_we;
+
+ acc0 += offs;
+ acc2 += offs;
+#endif /* INPUT_OFFSET != 0 */
+
+#if K_OFFSET != 0
+ acc0 += (VEC_INT)K_OFFSET;
+ acc2 += (VEC_INT)K_OFFSET;
+#endif /* K_OFFSET != 0 */
+
+ acc0 = asymm_mult_by_quant_multiplier_less_than_one(acc0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
+ acc2 = asymm_mult_by_quant_multiplier_less_than_one(acc2, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
+ acc0 += (VEC_INT)OUTPUT_OFFSET;
+ acc2 += (VEC_INT)OUTPUT_OFFSET;
+ VEC_UCHAR res0 = CONVERT_SAT(acc0, VEC_UCHAR);
+ VEC_UCHAR res2 = CONVERT_SAT(acc2, VEC_UCHAR);
+ res0 = CLAMP(res0, (VEC_UCHAR)0, (VEC_UCHAR)255);
+ res2 = CLAMP(res2, (VEC_UCHAR)0, (VEC_UCHAR)255);
+
+ VSTORE(VEC_SIZE)
+ (res0, 0, dst.ptr + 0 * dst_stride_y);
+ VSTORE(VEC_SIZE)
+ (res2, 0, dst.ptr + 1 * dst_stride_y);
+}
+
+#endif /* defined(VEC_SIZE) && defined(SRC_DEPTH) && defined(CONV_PAD_TOP) && defined(ROWS_READ) */
+
+#endif /* defined(WEIGHTS_OFFSET) && defined(INPUT_OFFSET) && defined(K_OFFSET) && defined(OUTPUT_OFFSET) && defined(OUTPUT_MULTIPLIER) && defined(OUTPUT_SHIFT) */