Procházet zdrojové kódy

CMSIS-NN: Add Null bias check for DW conv (#1360)

Missing null bias check is added to DW conv along
with unit tests

Change-Id: Ib2f817fd96c4edbde4667fa4cb3419604d118a03
felix-johnny před 4 roky
rodič
revize
e0d78fb9b2
30 změnil soubory, kde provedl 475 přidání a 30 odebrání
  1. 16 11
      CMSIS/NN/Source/ConvolutionFunctions/arm_depthwise_conv_s8.c
  2. 2 0
      CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias/bias.txt
  3. 31 0
      CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias/input.txt
  4. 25 0
      CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias/kernel.txt
  5. 12 0
      CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias/params.txt
  6. 21 0
      CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_0/input.txt
  7. 9 0
      CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_0/kernel.txt
  8. 12 0
      CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_0/params.txt
  9. 21 0
      CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_1/input.txt
  10. 9 0
      CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_1/kernel.txt
  11. 12 0
      CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_1/params.txt
  12. 5 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/biases_data.h
  13. 22 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/config_data.h
  14. 7 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/input_data.h
  15. 5 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/output_mult_data.h
  16. 7 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/output_ref_data.h
  17. 5 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/output_shift_data.h
  18. 8 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/test_data.h
  19. 5 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/weights_data.h
  20. 5 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/biases_data.h
  21. 22 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/config_data.h
  22. 7 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/input_data.h
  23. 6 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/output_mult_data.h
  24. 13 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/output_ref_data.h
  25. 5 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/output_shift_data.h
  26. 8 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/test_data.h
  27. 7 0
      CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/weights_data.h
  28. 5 1
      CMSIS/NN/Tests/UnitTest/TestCases/test_arm_depthwise_conv_s8/Unity/unity_test_arm_depthwise_conv_s8.c
  29. 155 17
      CMSIS/NN/Tests/UnitTest/TestCases/test_arm_depthwise_conv_s8/test_arm_depthwise_conv_s8.c
  30. 8 1
      CMSIS/NN/Tests/UnitTest/generate_test_data.py

+ 16 - 11
CMSIS/NN/Source/ConvolutionFunctions/arm_depthwise_conv_s8.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2021 Arm Limited or its affiliates. All rights reserved.
+ * Copyright (C) 2010-2021 Arm Limited or its affiliates.
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -21,8 +21,8 @@
  * Title:        arm_depthwise_conv_s8.c
  * Description:  s8 version of depthwise convolution.
  *
- * $Date:        11. May 2021
- * $Revision:    V.2.5.0
+ * $Date:        05. Nov 2021
+ * $Revision:    V.2.6.0
  *
  * Target Processor:  Cortex-M CPUs
  *
@@ -73,12 +73,14 @@ static void depthwise_conv_s8_mult_4(const int8_t *input,
             {
                 for (int mult_tile = 0; mult_tile < ch_mult; mult_tile += 4)
                 {
-                    int32_t out_buff[4];
-
-                    out_buff[0] = bias[out_ch + 0 + mult_tile];
-                    out_buff[1] = bias[out_ch + 1 + mult_tile];
-                    out_buff[2] = bias[out_ch + 2 + mult_tile];
-                    out_buff[3] = bias[out_ch + 3 + mult_tile];
+                    int32_t out_buff[4] = {0, 0, 0, 0};
+                    if (bias)
+                    {
+                        out_buff[0] = bias[out_ch + 0 + mult_tile];
+                        out_buff[1] = bias[out_ch + 1 + mult_tile];
+                        out_buff[2] = bias[out_ch + 2 + mult_tile];
+                        out_buff[3] = bias[out_ch + 3 + mult_tile];
+                    }
 
                     for (int32_t ker_h = ker_h_start; ker_h < MIN(kernel_y, input_y - in_h); ++ker_h)
                     {
@@ -183,14 +185,17 @@ static void depthwise_conv_s8_generic(const q7_t *input,
                     for (int i_ch_mult = 0; i_ch_mult < ch_mult; i_ch_mult++)
                     {
                         const int idx_out_ch = i_ch_mult + i_input_ch * ch_mult;
-                        int32_t acc_0;
+                        int32_t acc_0 = 0;
                         /* Condition for kernel start dimension: (base_idx_<x,y> + ker_<x,y>_start) >= 0 */
                         const int ker_y_start = MAX(0, -base_idx_y);
                         const int ker_x_start = MAX(0, -base_idx_x);
                         /* Condition for kernel end dimension: (base_idx_<x,y> + ker_<x,y>_end) < input_<x,y> */
                         const int ker_y_end = MIN(kernel_y, input_y - base_idx_y);
                         const int ker_x_end = MIN(kernel_x, input_x - base_idx_x);
-                        acc_0 = bias[idx_out_ch];
+                        if (bias)
+                        {
+                            acc_0 = bias[idx_out_ch];
+                        }
 
                         for (int i_ker_y = ker_y_start; i_ker_y < ker_y_end; i_ker_y++)
                         {

+ 2 - 0
CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias/bias.txt

@@ -0,0 +1,2 @@
+# 3
+-6.600000000000000000e+01,-8.300000000000000000e+01,-2.100000000000000000e+01

+ 31 - 0
CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias/input.txt

@@ -0,0 +1,31 @@
+# 2,5,3,3
+-4.100000000000000000e+01,-4.600000000000000000e+01,9.000000000000000000e+00
+7.400000000000000000e+01,1.100000000000000000e+02,-8.900000000000000000e+01
+-1.180000000000000000e+02,8.300000000000000000e+01,1.600000000000000000e+01
+-6.500000000000000000e+01,2.200000000000000000e+01,-1.270000000000000000e+02
+8.200000000000000000e+01,-5.200000000000000000e+01,-1.130000000000000000e+02
+1.300000000000000000e+01,3.000000000000000000e+00,6.300000000000000000e+01
+-6.000000000000000000e+00,5.400000000000000000e+01,-6.300000000000000000e+01
+0.000000000000000000e+00,-5.600000000000000000e+01,2.400000000000000000e+01
+-1.070000000000000000e+02,-6.100000000000000000e+01,1.030000000000000000e+02
+6.300000000000000000e+01,-1.070000000000000000e+02,-1.200000000000000000e+01
+6.200000000000000000e+01,-9.000000000000000000e+00,-3.900000000000000000e+01
+-6.200000000000000000e+01,5.000000000000000000e+01,8.300000000000000000e+01
+-4.000000000000000000e+01,-1.000000000000000000e+01,1.400000000000000000e+01
+3.600000000000000000e+01,-9.900000000000000000e+01,-6.000000000000000000e+00
+9.500000000000000000e+01,-5.000000000000000000e+00,-4.900000000000000000e+01
+-4.000000000000000000e+00,4.200000000000000000e+01,8.000000000000000000e+01
+1.060000000000000000e+02,-1.220000000000000000e+02,1.800000000000000000e+01
+5.400000000000000000e+01,7.100000000000000000e+01,-1.200000000000000000e+01
+-1.170000000000000000e+02,1.260000000000000000e+02,-2.900000000000000000e+01
+1.160000000000000000e+02,-7.000000000000000000e+01,-8.000000000000000000e+01
+1.050000000000000000e+02,1.030000000000000000e+02,6.000000000000000000e+00
+-8.000000000000000000e+01,-1.500000000000000000e+01,-1.080000000000000000e+02
+1.210000000000000000e+02,6.700000000000000000e+01,-8.100000000000000000e+01
+3.500000000000000000e+01,-1.200000000000000000e+01,-1.180000000000000000e+02
+-7.400000000000000000e+01,8.200000000000000000e+01,-8.100000000000000000e+01
+8.300000000000000000e+01,3.200000000000000000e+01,4.100000000000000000e+01
+7.300000000000000000e+01,-6.000000000000000000e+01,6.500000000000000000e+01
+-8.000000000000000000e+01,1.190000000000000000e+02,6.100000000000000000e+01
+-9.300000000000000000e+01,-9.500000000000000000e+01,-1.030000000000000000e+02
+2.900000000000000000e+01,-8.500000000000000000e+01,9.500000000000000000e+01

+ 25 - 0
CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias/kernel.txt

@@ -0,0 +1,25 @@
+# 4,2,3,1
+-1.000000000000000000e+00
+1.050000000000000000e+02
+-1.000000000000000000e+01
+-6.700000000000000000e+01
+-4.200000000000000000e+01
+-1.250000000000000000e+02
+-1.180000000000000000e+02
+-2.400000000000000000e+01
+-8.700000000000000000e+01
+7.300000000000000000e+01
+-8.900000000000000000e+01
+3.100000000000000000e+01
+2.900000000000000000e+01
+-7.600000000000000000e+01
+-6.000000000000000000e+01
+-3.000000000000000000e+00
+-2.800000000000000000e+01
+2.400000000000000000e+01
+9.900000000000000000e+01
+-2.100000000000000000e+01
+-9.400000000000000000e+01
+-1.050000000000000000e+02
+1.700000000000000000e+01
+-6.800000000000000000e+01

+ 12 - 0
CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias/params.txt

@@ -0,0 +1,12 @@
+3
+3
+3
+5
+2
+4
+2
+2
+0
+1
+2
+1

+ 21 - 0
CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_0/input.txt

@@ -0,0 +1,21 @@
+# 1,5,4,2
+-9.700000000000000000e+01,-1.130000000000000000e+02
+1.180000000000000000e+02,6.900000000000000000e+01
+3.900000000000000000e+01,-3.200000000000000000e+01
+-1.000000000000000000e+00,-7.900000000000000000e+01
+-3.000000000000000000e+01,-8.000000000000000000e+00
+4.600000000000000000e+01,-1.300000000000000000e+01
+8.200000000000000000e+01,-1.900000000000000000e+01
+1.500000000000000000e+01,1.050000000000000000e+02
+9.400000000000000000e+01,-5.600000000000000000e+01
+3.500000000000000000e+01,5.500000000000000000e+01
+-1.220000000000000000e+02,-1.050000000000000000e+02
+7.000000000000000000e+01,3.300000000000000000e+01
+-1.280000000000000000e+02,-8.700000000000000000e+01
+-1.090000000000000000e+02,5.000000000000000000e+01
+2.000000000000000000e+00,7.800000000000000000e+01
+-1.130000000000000000e+02,1.130000000000000000e+02
+-5.000000000000000000e+01,-3.300000000000000000e+01
+1.900000000000000000e+01,-6.000000000000000000e+00
+-3.800000000000000000e+01,1.220000000000000000e+02
+1.800000000000000000e+01,-1.210000000000000000e+02

+ 9 - 0
CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_0/kernel.txt

@@ -0,0 +1,9 @@
+# 2,2,2,1
+5.300000000000000000e+01
+0.000000000000000000e+00
+2.700000000000000000e+01
+-8.900000000000000000e+01
+1.010000000000000000e+02
+8.800000000000000000e+01
+-7.900000000000000000e+01
+-1.220000000000000000e+02

+ 12 - 0
CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_0/params.txt

@@ -0,0 +1,12 @@
+2
+2
+4
+5
+2
+2
+1
+1
+0
+0
+1
+1

+ 21 - 0
CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_1/input.txt

@@ -0,0 +1,21 @@
+# 1,5,4,2
+-6.500000000000000000e+01,-4.100000000000000000e+01
+3.500000000000000000e+01,-9.900000000000000000e+01
+-8.500000000000000000e+01,-4.600000000000000000e+01
+-8.500000000000000000e+01,-3.900000000000000000e+01
+6.400000000000000000e+01,2.900000000000000000e+01
+-7.100000000000000000e+01,-3.100000000000000000e+01
+-3.400000000000000000e+01,4.800000000000000000e+01
+-3.500000000000000000e+01,-8.600000000000000000e+01
+-2.000000000000000000e+01,-5.800000000000000000e+01
+1.040000000000000000e+02,7.900000000000000000e+01
+-3.300000000000000000e+01,1.120000000000000000e+02
+1.800000000000000000e+01,-1.140000000000000000e+02
+4.000000000000000000e+01,-6.500000000000000000e+01
+-4.000000000000000000e+00,-7.500000000000000000e+01
+1.020000000000000000e+02,1.190000000000000000e+02
+-1.240000000000000000e+02,1.090000000000000000e+02
+9.500000000000000000e+01,-4.000000000000000000e+00
+-1.100000000000000000e+01,-7.000000000000000000e+00
+1.300000000000000000e+01,-9.800000000000000000e+01
+-1.000000000000000000e+00,7.400000000000000000e+01

+ 9 - 0
CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_1/kernel.txt

@@ -0,0 +1,9 @@
+# 2,2,2,4
+-1.080000000000000000e+02,8.400000000000000000e+01,6.700000000000000000e+01,-1.170000000000000000e+02
+-4.300000000000000000e+01,-5.800000000000000000e+01,7.300000000000000000e+01,8.500000000000000000e+01
+5.300000000000000000e+01,3.700000000000000000e+01,7.100000000000000000e+01,-4.900000000000000000e+01
+8.500000000000000000e+01,-2.300000000000000000e+01,-4.500000000000000000e+01,-6.900000000000000000e+01
+-2.700000000000000000e+01,6.300000000000000000e+01,-3.600000000000000000e+01,9.100000000000000000e+01
+1.000000000000000000e+02,3.200000000000000000e+01,-1.260000000000000000e+02,-4.500000000000000000e+01
+-6.100000000000000000e+01,-4.700000000000000000e+01,3.900000000000000000e+01,1.060000000000000000e+02
+-1.110000000000000000e+02,-6.200000000000000000e+01,-5.800000000000000000e+01,2.900000000000000000e+01

+ 12 - 0
CMSIS/NN/Tests/UnitTest/PregeneratedData/depthwise_null_bias_1/params.txt

@@ -0,0 +1,12 @@
+2
+8
+4
+5
+2
+2
+1
+1
+0
+0
+1
+1

+ 5 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/biases_data.h

@@ -0,0 +1,5 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const int32_t depthwise_null_bias_0_biases[2] = {0, 0};

+ 22 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/config_data.h

@@ -0,0 +1,22 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#define DEPTHWISE_NULL_BIAS_0_OUT_CH 2
+#define DEPTHWISE_NULL_BIAS_0_IN_CH 2
+#define DEPTHWISE_NULL_BIAS_0_INPUT_W 4
+#define DEPTHWISE_NULL_BIAS_0_INPUT_H 5
+#define DEPTHWISE_NULL_BIAS_0_DST_SIZE 40
+#define DEPTHWISE_NULL_BIAS_0_INPUT_SIZE 40
+#define DEPTHWISE_NULL_BIAS_0_OUT_ACTIVATION_MIN -128
+#define DEPTHWISE_NULL_BIAS_0_OUT_ACTIVATION_MAX 127
+#define DEPTHWISE_NULL_BIAS_0_INPUT_BATCHES 1
+#define DEPTHWISE_NULL_BIAS_0_FILTER_X 2
+#define DEPTHWISE_NULL_BIAS_0_FILTER_Y 2
+#define DEPTHWISE_NULL_BIAS_0_STRIDE_X 1
+#define DEPTHWISE_NULL_BIAS_0_STRIDE_Y 1
+#define DEPTHWISE_NULL_BIAS_0_PAD_X 0
+#define DEPTHWISE_NULL_BIAS_0_PAD_Y 0
+#define DEPTHWISE_NULL_BIAS_0_OUTPUT_W 4
+#define DEPTHWISE_NULL_BIAS_0_OUTPUT_H 5
+#define DEPTHWISE_NULL_BIAS_0_CH_MULT 1
+#define DEPTHWISE_NULL_BIAS_0_INPUT_OFFSET 128
+#define DEPTHWISE_NULL_BIAS_0_OUTPUT_OFFSET -15

+ 7 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/input_data.h

@@ -0,0 +1,7 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const q7_t depthwise_null_bias_0_input[40] = {
+    -97,  -113, 118, 69, 39,   -32, -1,   -79, -30, -8, 46,   -13, 82,  -19, 15, 105, 94,  -56, 35, 55,
+    -122, -105, 70,  33, -128, -87, -109, 50,  2,   78, -113, 113, -50, -33, 19, -6,  -38, 122, 18, -121};

+ 5 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/output_mult_data.h

@@ -0,0 +1,5 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const int32_t depthwise_null_bias_0_output_mult[2] = {1578366049, 1906541257};

+ 7 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/output_ref_data.h

@@ -0,0 +1,7 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const q7_t depthwise_null_bias_0_output_ref[40] = {1,  -91, 52, -57,  65,  -99, 62, 59,   55, -110, 97,  -2,  -15, -128,
+                                                   85, 36,  38, -128, -13, -56, 49, -107, 29, 62,   -26, -96, 29,  -128,
+                                                   3,  -16, 41, -13,  14,  -54, 22, -96,  17, -17,  13,  -15};

+ 5 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/output_shift_data.h

@@ -0,0 +1,5 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const int32_t depthwise_null_bias_0_output_shift[2] = {-8, -8};

+ 8 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/test_data.h

@@ -0,0 +1,8 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#include "biases_data.h"
+#include "config_data.h"
+#include "input_data.h"
+#include "output_mult_data.h"
+#include "output_ref_data.h"
+#include "output_shift_data.h"
+#include "weights_data.h"

+ 5 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_0/weights_data.h

@@ -0,0 +1,5 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const q7_t depthwise_null_bias_0_weights[8] = {67, 0, 34, -93, 127, 92, -99, -127};

+ 5 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/biases_data.h

@@ -0,0 +1,5 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const int32_t depthwise_null_bias_1_biases[8] = {0, 0, 0, 0, 0, 0, 0, 0};

+ 22 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/config_data.h

@@ -0,0 +1,22 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#define DEPTHWISE_NULL_BIAS_1_OUT_CH 8
+#define DEPTHWISE_NULL_BIAS_1_IN_CH 2
+#define DEPTHWISE_NULL_BIAS_1_INPUT_W 4
+#define DEPTHWISE_NULL_BIAS_1_INPUT_H 5
+#define DEPTHWISE_NULL_BIAS_1_DST_SIZE 160
+#define DEPTHWISE_NULL_BIAS_1_INPUT_SIZE 40
+#define DEPTHWISE_NULL_BIAS_1_OUT_ACTIVATION_MIN -128
+#define DEPTHWISE_NULL_BIAS_1_OUT_ACTIVATION_MAX 127
+#define DEPTHWISE_NULL_BIAS_1_INPUT_BATCHES 1
+#define DEPTHWISE_NULL_BIAS_1_FILTER_X 2
+#define DEPTHWISE_NULL_BIAS_1_FILTER_Y 2
+#define DEPTHWISE_NULL_BIAS_1_STRIDE_X 1
+#define DEPTHWISE_NULL_BIAS_1_STRIDE_Y 1
+#define DEPTHWISE_NULL_BIAS_1_PAD_X 0
+#define DEPTHWISE_NULL_BIAS_1_PAD_Y 0
+#define DEPTHWISE_NULL_BIAS_1_OUTPUT_W 4
+#define DEPTHWISE_NULL_BIAS_1_OUTPUT_H 5
+#define DEPTHWISE_NULL_BIAS_1_CH_MULT 4
+#define DEPTHWISE_NULL_BIAS_1_INPUT_OFFSET 128
+#define DEPTHWISE_NULL_BIAS_1_OUTPUT_OFFSET 7

+ 7 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/input_data.h

@@ -0,0 +1,7 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const q7_t depthwise_null_bias_1_input[40] = {-65, -41, 35,   -99, -85, -46, -85, -39, 64, 29,   -71, -31, -34, 48,
+                                              -35, -86, -20,  -58, 104, 79,  -33, 112, 18, -114, 40,  -65, -4,  -75,
+                                              102, 119, -124, 109, 95,  -4,  -11, -7,  13, -98,  -1,  74};

+ 6 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/output_mult_data.h

@@ -0,0 +1,6 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const int32_t depthwise_null_bias_1_output_mult[8] =
+    {1493638723, 1161718960, 1963858195, 1618108556, 1535128667, 1714918530, 1742578493, 1175548942};

+ 13 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/output_ref_data.h

@@ -0,0 +1,13 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const q7_t depthwise_null_bias_1_output_ref[160] = {
+    -15, 73,  43,  33,  19,  -14, -58,  11,  -65, 53,  57,  -12, -6,   -29, -69, -1,  -27, 29,  27,  43,
+    61,  -5,  -65, -12, -16, 37,  6,    18,  8,   -5,  11,  25,  -104, 52,  78,  36,  -39, -63, -36, 37,
+    -36, 66,  26,  71,  22,  -50, -123, -13, -47, 40,  56,  34,  66,   -7,  -57, 12,  -38, 61,  10,  15,
+    6,   1,   11,  16,  -30, 79,  79,   21,  55,  -25, -41, -24, -113, 71,  93,  19,  -27, -92, -45, 25,
+    -22, 95,  35,  17,  -27, -60, -82,  55,  -44, 47,  38,  -46, 81,   29,  -85, -23, -72, 94,  60,  29,
+    9,   -20, -58, 6,   -35, 70,  90,   7,   95,  -14, -70, -48, -109, 78,  57,  4,   -25, -93, -18, 36,
+    -5,  34,  -7,  43,  39,  -16, -19,  42,  -50, 81,  81,  -95, 23,   -25, 19,  14,  -10, 55,  64,  -59,
+    -1,  -18, 31,  33,  -20, 60,  66,   -66, 58,  -13, -15, -29, -37,  41,  34,  -40, -21, -30, 54,  62};

+ 5 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/output_shift_data.h

@@ -0,0 +1,5 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const int32_t depthwise_null_bias_1_output_shift[8] = {-8, -8, -9, -8, -8, -9, -8, -8};

+ 8 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/test_data.h

@@ -0,0 +1,8 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#include "biases_data.h"
+#include "config_data.h"
+#include "input_data.h"
+#include "output_mult_data.h"
+#include "output_ref_data.h"
+#include "output_shift_data.h"
+#include "weights_data.h"

+ 7 - 0
CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_null_bias_1/weights_data.h

@@ -0,0 +1,7 @@
+// Generated by generate_test_data.py using TFL version 2.6.0 as reference.
+#pragma once
+#include <stdint.h>
+
+const q7_t depthwise_null_bias_1_weights[32] = {-127, 127, 120, -127, -49,  -119, 74,   127,  62,  56,  127,
+                                                -53,  97,  -47, -45,  -103, -32,  95,   -64,  99,  114, 66,
+                                                -127, -67, -72, -71,  70,   115,  -127, -127, -58, 43};

+ 5 - 1
CMSIS/NN/Tests/UnitTest/TestCases/test_arm_depthwise_conv_s8/Unity/unity_test_arm_depthwise_conv_s8.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2020 Arm Limited or its affiliates. All rights reserved.
+ * Copyright (C) 2010-2021 Arm Limited or its affiliates.
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -53,3 +53,7 @@ void test_depthwise_2_arm_depthwise_conv_s8(void) { depthwise_2_arm_depthwise_co
 void test_depthwise_out_activation_arm_depthwise_conv_s8(void) { depthwise_out_activation_arm_depthwise_conv_s8(); }
 
 void test_depthwise_mult_batches_arm_depthwise_conv_s8(void) { depthwise_mult_batches_arm_depthwise_conv_s8(); }
+
+void test_depthwise_null_bias_0_arm_depthwise_conv_s8(void) { depthwise_null_bias_0_arm_depthwise_conv_s8(); }
+
+void test_depthwise_null_bias_1_arm_depthwise_conv_s8(void) { depthwise_null_bias_1_arm_depthwise_conv_s8(); }

+ 155 - 17
CMSIS/NN/Tests/UnitTest/TestCases/test_arm_depthwise_conv_s8/test_arm_depthwise_conv_s8.c

@@ -22,10 +22,26 @@
 #include "../TestData/basic/test_data.h"
 #include "../TestData/depthwise_2/test_data.h"
 #include "../TestData/depthwise_mult_batches/test_data.h"
+#include "../TestData/depthwise_null_bias_0/test_data.h"
+#include "../TestData/depthwise_null_bias_1/test_data.h"
 #include "../TestData/depthwise_out_activation/test_data.h"
 #include "../TestData/stride2pad1/test_data.h"
 #include "../Utils/validate.h"
 
+const int32_t *get_bias_address(const int32_t *bias, int32_t size)
+{
+    const int32_t *return_bias = NULL;
+    for (int i = 0; i < size; i++)
+    {
+        if (bias[i] != 0)
+        {
+            return_bias = bias;
+            break;
+        }
+    }
+    return return_bias;
+}
+
 void basic_arm_depthwise_conv_s8(void)
 {
     const arm_status expected = ARM_MATH_SUCCESS;
@@ -39,7 +55,7 @@ void basic_arm_depthwise_conv_s8(void)
     cmsis_nn_dims bias_dims;
     cmsis_nn_dims output_dims;
 
-    const q31_t *bias_data = basic_biases;
+    const q31_t *bias_data = get_bias_address(basic_biases, BASIC_OUT_CH);
     const q7_t *input_data = basic_input;
 
     input_dims.n = BASIC_INPUT_BATCHES;
@@ -118,7 +134,7 @@ void stride2pad1_arm_depthwise_conv_s8(void)
     cmsis_nn_dims bias_dims;
     cmsis_nn_dims output_dims;
 
-    const q31_t *bias_data = stride2pad1_biases;
+    const q31_t *bias_data = get_bias_address(stride2pad1_biases, STRIDE2PAD1_OUT_CH);
     const q7_t *kernel_data = stride2pad1_weights;
     const q7_t *input_data = stride2pad1_input;
 
@@ -198,7 +214,7 @@ void depthwise_2_arm_depthwise_conv_s8(void)
     cmsis_nn_dims bias_dims;
     cmsis_nn_dims output_dims;
 
-    const q31_t *bias_data = depthwise_2_biases;
+    const q31_t *bias_data = get_bias_address(depthwise_2_biases, DEPTHWISE_2_OUT_CH);
     const q7_t *kernel_data = depthwise_2_weights;
     const q7_t *input_data = depthwise_2_input;
 
@@ -244,20 +260,22 @@ void depthwise_2_arm_depthwise_conv_s8(void)
     TEST_ASSERT_EQUAL(expected, result);
     TEST_ASSERT_TRUE(validate(output, depthwise_2_output_ref, DEPTHWISE_2_DST_SIZE));
 
-    ctx.buf = NULL;
+    const int32_t buf_size =
+        arm_depthwise_conv_wrapper_s8_get_buffer_size(&dw_conv_params, &input_dims, &filter_dims, &output_dims);
+    ctx.buf = malloc(buf_size);
     ctx.size = 0;
 
-    result = arm_depthwise_conv_s8(&ctx,
-                                   &dw_conv_params,
-                                   &quant_params,
-                                   &input_dims,
-                                   input_data,
-                                   &filter_dims,
-                                   kernel_data,
-                                   &bias_dims,
-                                   bias_data,
-                                   &output_dims,
-                                   output);
+    result = arm_depthwise_conv_wrapper_s8(&ctx,
+                                           &dw_conv_params,
+                                           &quant_params,
+                                           &input_dims,
+                                           input_data,
+                                           &filter_dims,
+                                           kernel_data,
+                                           &bias_dims,
+                                           bias_data,
+                                           &output_dims,
+                                           output);
 
     free(ctx.buf);
     TEST_ASSERT_EQUAL(expected, result);
@@ -277,7 +295,7 @@ void depthwise_out_activation_arm_depthwise_conv_s8(void)
     cmsis_nn_dims bias_dims;
     cmsis_nn_dims output_dims;
 
-    const q31_t *bias_data = depthwise_out_activation_biases;
+    const q31_t *bias_data = get_bias_address(depthwise_out_activation_biases, DEPTHWISE_OUT_ACTIVATION_OUT_CH);
     const q7_t *kernel_data = depthwise_out_activation_weights;
     const q7_t *input_data = depthwise_out_activation_input;
 
@@ -356,7 +374,7 @@ void depthwise_mult_batches_arm_depthwise_conv_s8(void)
     cmsis_nn_dims bias_dims;
     cmsis_nn_dims output_dims;
 
-    const q31_t *bias_data = depthwise_mult_batches_biases;
+    const q31_t *bias_data = get_bias_address(depthwise_mult_batches_biases, DEPTHWISE_MULT_BATCHES_OUT_CH);
     const q7_t *kernel_data = depthwise_mult_batches_weights;
     const q7_t *input_data = depthwise_mult_batches_input;
 
@@ -421,3 +439,123 @@ void depthwise_mult_batches_arm_depthwise_conv_s8(void)
     TEST_ASSERT_EQUAL(expected, result);
     TEST_ASSERT_TRUE(validate(output, depthwise_mult_batches_output_ref, DEPTHWISE_MULT_BATCHES_DST_SIZE));
 }
+
+void depthwise_null_bias_0_arm_depthwise_conv_s8(void)
+{
+    const arm_status expected = ARM_MATH_SUCCESS;
+    q7_t output[DEPTHWISE_NULL_BIAS_0_DST_SIZE] = {0};
+
+    cmsis_nn_context ctx;
+    cmsis_nn_dw_conv_params dw_conv_params;
+    cmsis_nn_per_channel_quant_params quant_params;
+    cmsis_nn_dims input_dims;
+    cmsis_nn_dims filter_dims;
+    cmsis_nn_dims bias_dims;
+    cmsis_nn_dims output_dims;
+
+    const q31_t *bias_data = get_bias_address(depthwise_null_bias_0_biases, DEPTHWISE_NULL_BIAS_0_OUT_CH);
+    const q7_t *kernel_data = depthwise_null_bias_0_weights;
+    const q7_t *input_data = depthwise_null_bias_0_input;
+
+    input_dims.n = DEPTHWISE_NULL_BIAS_0_INPUT_BATCHES;
+    input_dims.w = DEPTHWISE_NULL_BIAS_0_INPUT_W;
+    input_dims.h = DEPTHWISE_NULL_BIAS_0_INPUT_H;
+    input_dims.c = DEPTHWISE_NULL_BIAS_0_IN_CH;
+    filter_dims.w = DEPTHWISE_NULL_BIAS_0_FILTER_X;
+    filter_dims.h = DEPTHWISE_NULL_BIAS_0_FILTER_Y;
+    output_dims.w = DEPTHWISE_NULL_BIAS_0_OUTPUT_W;
+    output_dims.h = DEPTHWISE_NULL_BIAS_0_OUTPUT_H;
+    output_dims.c = DEPTHWISE_NULL_BIAS_0_OUT_CH;
+
+    dw_conv_params.padding.w = DEPTHWISE_NULL_BIAS_0_PAD_X;
+    dw_conv_params.padding.h = DEPTHWISE_NULL_BIAS_0_PAD_Y;
+    dw_conv_params.stride.w = DEPTHWISE_NULL_BIAS_0_STRIDE_X;
+    dw_conv_params.stride.h = DEPTHWISE_NULL_BIAS_0_STRIDE_Y;
+    dw_conv_params.ch_mult = DEPTHWISE_NULL_BIAS_0_CH_MULT;
+
+    dw_conv_params.input_offset = DEPTHWISE_NULL_BIAS_0_INPUT_OFFSET;
+    dw_conv_params.output_offset = DEPTHWISE_NULL_BIAS_0_OUTPUT_OFFSET;
+    dw_conv_params.activation.min = DEPTHWISE_NULL_BIAS_0_OUT_ACTIVATION_MIN;
+    dw_conv_params.activation.max = DEPTHWISE_NULL_BIAS_0_OUT_ACTIVATION_MAX;
+    quant_params.multiplier = (int32_t *)depthwise_null_bias_0_output_mult;
+    quant_params.shift = (int32_t *)depthwise_null_bias_0_output_shift;
+
+    ctx.buf = NULL;
+    ctx.size = 0;
+
+    arm_status result = arm_depthwise_conv_s8(&ctx,
+                                              &dw_conv_params,
+                                              &quant_params,
+                                              &input_dims,
+                                              input_data,
+                                              &filter_dims,
+                                              kernel_data,
+                                              &bias_dims,
+                                              bias_data,
+                                              &output_dims,
+                                              output);
+
+    free(ctx.buf);
+    TEST_ASSERT_EQUAL(expected, result);
+    TEST_ASSERT_TRUE(validate(output, depthwise_null_bias_0_output_ref, DEPTHWISE_NULL_BIAS_0_DST_SIZE));
+}
+
+void depthwise_null_bias_1_arm_depthwise_conv_s8(void)
+{
+    const arm_status expected = ARM_MATH_SUCCESS;
+    q7_t output[DEPTHWISE_NULL_BIAS_1_DST_SIZE] = {0};
+
+    cmsis_nn_context ctx;
+    cmsis_nn_dw_conv_params dw_conv_params;
+    cmsis_nn_per_channel_quant_params quant_params;
+    cmsis_nn_dims input_dims;
+    cmsis_nn_dims filter_dims;
+    cmsis_nn_dims bias_dims;
+    cmsis_nn_dims output_dims;
+
+    const q31_t *bias_data = get_bias_address(depthwise_null_bias_1_biases, DEPTHWISE_NULL_BIAS_1_OUT_CH);
+    const q7_t *kernel_data = depthwise_null_bias_1_weights;
+    const q7_t *input_data = depthwise_null_bias_1_input;
+
+    input_dims.n = DEPTHWISE_NULL_BIAS_1_INPUT_BATCHES;
+    input_dims.w = DEPTHWISE_NULL_BIAS_1_INPUT_W;
+    input_dims.h = DEPTHWISE_NULL_BIAS_1_INPUT_H;
+    input_dims.c = DEPTHWISE_NULL_BIAS_1_IN_CH;
+    filter_dims.w = DEPTHWISE_NULL_BIAS_1_FILTER_X;
+    filter_dims.h = DEPTHWISE_NULL_BIAS_1_FILTER_Y;
+    output_dims.w = DEPTHWISE_NULL_BIAS_1_OUTPUT_W;
+    output_dims.h = DEPTHWISE_NULL_BIAS_1_OUTPUT_H;
+    output_dims.c = DEPTHWISE_NULL_BIAS_1_OUT_CH;
+
+    dw_conv_params.padding.w = DEPTHWISE_NULL_BIAS_1_PAD_X;
+    dw_conv_params.padding.h = DEPTHWISE_NULL_BIAS_1_PAD_Y;
+    dw_conv_params.stride.w = DEPTHWISE_NULL_BIAS_1_STRIDE_X;
+    dw_conv_params.stride.h = DEPTHWISE_NULL_BIAS_1_STRIDE_Y;
+    dw_conv_params.ch_mult = DEPTHWISE_NULL_BIAS_1_CH_MULT;
+
+    dw_conv_params.input_offset = DEPTHWISE_NULL_BIAS_1_INPUT_OFFSET;
+    dw_conv_params.output_offset = DEPTHWISE_NULL_BIAS_1_OUTPUT_OFFSET;
+    dw_conv_params.activation.min = DEPTHWISE_NULL_BIAS_1_OUT_ACTIVATION_MIN;
+    dw_conv_params.activation.max = DEPTHWISE_NULL_BIAS_1_OUT_ACTIVATION_MAX;
+    quant_params.multiplier = (int32_t *)depthwise_null_bias_1_output_mult;
+    quant_params.shift = (int32_t *)depthwise_null_bias_1_output_shift;
+
+    ctx.buf = NULL;
+    ctx.size = 0;
+
+    arm_status result = arm_depthwise_conv_s8(&ctx,
+                                              &dw_conv_params,
+                                              &quant_params,
+                                              &input_dims,
+                                              input_data,
+                                              &filter_dims,
+                                              kernel_data,
+                                              &bias_dims,
+                                              bias_data,
+                                              &output_dims,
+                                              output);
+
+    free(ctx.buf);
+    TEST_ASSERT_EQUAL(expected, result);
+    TEST_ASSERT_TRUE(validate(output, depthwise_null_bias_1_output_ref, DEPTHWISE_NULL_BIAS_1_DST_SIZE));
+}

+ 8 - 1
CMSIS/NN/Tests/UnitTest/generate_test_data.py

@@ -1055,7 +1055,14 @@ def load_all_testdatasets():
     ALL_TESTDATA_SETS[dataset] = ConvSettings(dataset, type_of_test, args, in_ch=3, out_ch=3, x_in=3, y_in=5, w_x=2,
                                               w_y=4, stride_x=2, stride_y=2, pad=True,
                                               batches=2)
-
+    dataset = 'depthwise_null_bias_0'
+    ALL_TESTDATA_SETS[dataset] = ConvSettings(dataset, type_of_test, args, in_ch=2, out_ch=2, x_in=4, y_in=5, w_x=2,
+                                              w_y=2, stride_x=1, stride_y=1, pad=True, generate_bias=False,
+                                              batches=1)
+    dataset = 'depthwise_null_bias_1'
+    ALL_TESTDATA_SETS[dataset] = ConvSettings(dataset, type_of_test, args, in_ch=2, out_ch=8, x_in=4, y_in=5, w_x=2,
+                                              w_y=2, stride_x=1, stride_y=1, pad=True, generate_bias=False,
+                                              batches=1)                                                                                         
     type_of_test = 'fully_connected'
     dataset = 'fully_connected'
     ALL_TESTDATA_SETS[dataset] = FullyConnectedSettings(dataset, type_of_test, args, in_ch=10, out_ch=6, x_in=2, y_in=1,