Skip to content

Commit e28fb6e

Browse files
committed
replace assert by MLI_ASSERT
1 parent 8b42f26 commit e28fb6e

File tree

9 files changed

+62
-99
lines changed

9 files changed

+62
-99
lines changed

lib/src/kernels/common/mli_krn_common.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@
3838
#include "mli_math.h"
3939
#include "mli_types.h"
4040

41-
#if 0
42-
#define MY_ASSERT(a) assert(a)
43-
#else
44-
#define MY_ASSERT(a) (void)(a)
45-
#endif
46-
4741
static inline accum40_t __attribute__ ((always_inline)) mli_prv_ashift_accu(accum40_t accu, const int shift_right)
4842
{
4943
return fx_asr_a40(accu, shift_right);

lib/src/kernels/common/mli_krn_fully_connected.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,12 @@
3030
#ifndef _MLI_KRN_FULLY_CONNECTED_H_
3131
#define _MLI_KRN_FULLY_CONNECTED_H_
3232

33-
#include <assert.h>
34-
3533
#include "mli_config.h"
34+
#include "mli_debug.h"
3635
#include "mli_helpers_api.h"
3736
#include "mli_prv_dsp.h"
3837
#include "mli_prv_tensor.h"
3938

40-
#if 0
41-
#define MY_ASSERT(a) assert(a)
42-
#else
43-
#define MY_ASSERT(a) (void)(a)
44-
#endif
45-
4639
/******************************************************************************
4740
*
4841
* Version & platform description
@@ -82,7 +75,7 @@ static void __attribute__((always_inline)) full_connection(
8275
w_ptr += 4;
8376
}
8477
in_ptr -= inp_size;
85-
MY_ASSERT(start_in_ptr == in_ptr);
78+
MLI_EXTRA_ASSERT(start_in_ptr == in_ptr);
8679

8780
mli_prv_clip_and_store_output(o_ptr++, &ip_out, out_shift);
8881
}
@@ -103,7 +96,7 @@ static void __attribute__((always_inline)) full_connection(
10396
w_ptr += 4;
10497
}
10598
in_ptr -= inp_size;
106-
MY_ASSERT(start_in_ptr == in_ptr);
99+
MLI_EXTRA_ASSERT(start_in_ptr == in_ptr);
107100

108101
mli_prv_clip_and_store_output(o_ptr++, &ip_out, out_shift);
109102
}

lib/src/kernels/convolution/mli_krn_conv2d_chw.h

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,12 @@
3030
#ifndef _MLI_KRN_CONV2D_CHW_H_
3131
#define _MLI_KRN_CONV2D_CHW_H_
3232

33-
#include <assert.h>
34-
#include <stdio.h>
35-
3633
#include "mli_config.h"
3734
#include "mli_debug.h"
3835
#include "mli_helpers_api.h"
3936
#include "mli_prv_dsp.h"
4037
#include "mli_krn_dotprod_chw.h"
4138

42-
#if 0 /* when debugging, set this to 1 to get more asserts */
43-
#define MY_ASSERT(a) assert(a)
44-
#else
45-
#define MY_ASSERT(a) (void)(a)
46-
#endif
47-
4839
#ifdef DEBUG_CONV2D
4940
#define CONV2D_DBG_PRINT(out_ch_idx, H_idx, W_idx, out_val) \
5041
MLI_PRINTF("MLI_CONV2D: [%d, %d, %d] out_val = %d\n", out_ch_idx, H_idx, W_idx , (int)out_val)
@@ -591,8 +582,8 @@ static inline void __attribute__ ((always_inline)) conv2d_chw_nopad_k1x1_str1 (
591582
const int clmn_begin = perception_area->clmn_beg;
592583
const int clmn_end = perception_area->clmn_end;
593584

594-
assert (kernel_height == 1);
595-
assert (kernel_width == 1);
585+
MLI_ASSERT(kernel_height == 1);
586+
MLI_ASSERT(kernel_width == 1);
596587

597588
for (int out_ch_idx = 0; out_ch_idx < out_ch; out_ch_idx++) {
598589
for (int H_idx = row_begin; H_idx < row_end; H_idx++) {
@@ -703,8 +694,8 @@ static inline void __attribute__ ((always_inline)) conv2d_chw_nopad_k1x1_str1 (
703694
const int clmn_begin = perception_area->clmn_beg;
704695
const int clmn_end = perception_area->clmn_end;
705696

706-
assert (kernel_height == 1);
707-
assert (kernel_width == 1);
697+
MLI_ASSERT(kernel_height == 1);
698+
MLI_ASSERT(kernel_width == 1);
708699

709700
for (int out_ch_idx = 0; out_ch_idx < out_ch; out_ch_idx++) {
710701
for (int H_idx = row_begin; H_idx < row_end; H_idx++) {
@@ -838,8 +829,8 @@ static inline void __attribute__ ((always_inline)) conv2d_row_str1 (
838829

839830
MLI_PTR (io_T) __restrict o_ptr = out_ftrs + out_ch_idx * out_width * out_height + H_idx * out_width + clmn_begin;
840831

841-
assert (stride_width == 1);
842-
assert (H_idx < out_height);
832+
MLI_ASSERT(stride_width == 1);
833+
MLI_ASSERT(H_idx < out_height);
843834

844835
/* for large kernel sizes use a loop for the first part of the run-in
845836
* for the rest of the run-in and for small kernel sizes, use the
@@ -979,7 +970,7 @@ static inline void __attribute__ ((always_inline)) conv2d_chw_str1 (
979970
int left_comp = -MIN ((clmn_begin * stride_width) - padding_left, 0);
980971
int right_comp = -MIN (in_width - ((clmn_end * stride_width) - padding_left + kernel_width - 1), 0);
981972

982-
assert (stride_width == 1);
973+
MLI_ASSERT(stride_width == 1);
983974

984975
for (int out_ch_idx = 0; out_ch_idx < out_ch; out_ch_idx++) {
985976
int H_idx = 0;
@@ -1155,16 +1146,16 @@ static inline void __attribute__ ((always_inline)) conv2d_row_anystride (
11551146
out_ch_idx * out_width * out_height +
11561147
H_idx * out_width + clmn_begin;
11571148

1158-
assert (H_idx < out_height);
1149+
MLI_ASSERT(H_idx < out_height);
11591150

11601151
/* for large kernel sizes use a loop for the first part of the run-in
11611152
* for the rest of the run-in and for small kernel sizes, use the
11621153
* unrolled part below.
11631154
*/
11641155
if (pad_left > 0) {
11651156
for (; W_input_idx < left_comp; W_input_idx += stride_width) {
1166-
MY_ASSERT ((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1167-
MY_ASSERT (weights_offset == -MIN (W_idx * stride_width - pad_left, 0));
1157+
MLI_EXTRA_ASSERT((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1158+
MLI_EXTRA_ASSERT(weights_offset == -MIN (W_idx * stride_width - pad_left, 0));
11681159

11691160
convolution (in_ptr, w_ptr + weights_offset, o_ptr, biases[out_ch_idx], bias_shift,
11701161
out_shift, val_min_limit, val_max_limit, in_width, in_height, kernel_w, kernel_h,
@@ -1186,8 +1177,8 @@ static inline void __attribute__ ((always_inline)) conv2d_row_anystride (
11861177

11871178
if ((kernel_w & 1) == 0) {
11881179
for (; W_input_idx < clmn_end * stride_width - right_comp; W_input_idx += stride_width) {
1189-
MY_ASSERT ((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1190-
MY_ASSERT (W_input_idx + kernel_w - pad_left <= in_width);
1180+
MLI_EXTRA_ASSERT((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1181+
MLI_EXTRA_ASSERT(W_input_idx + kernel_w - pad_left <= in_width);
11911182

11921183
convolution_even (in_ptr, w_ptr, o_ptr, biases[out_ch_idx], bias_shift,
11931184
out_shift, val_min_limit, val_max_limit, in_width, in_height, kernel_w, kernel_h, kernel_w,
@@ -1200,8 +1191,8 @@ static inline void __attribute__ ((always_inline)) conv2d_row_anystride (
12001191

12011192
} else if ((kernel_w & 3) == 3) {
12021193
for (; W_input_idx < clmn_end * stride_width - right_comp; W_input_idx += stride_width) {
1203-
MY_ASSERT ((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1204-
MY_ASSERT (W_input_idx + kernel_w - pad_left <= in_width);
1194+
MLI_EXTRA_ASSERT((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1195+
MLI_EXTRA_ASSERT(W_input_idx + kernel_w - pad_left <= in_width);
12051196

12061197
convolution_unroll4_plus3 (in_ptr, w_ptr, o_ptr, biases[out_ch_idx], bias_shift,
12071198
out_shift, val_min_limit, val_max_limit, in_width, in_height, kernel_w, kernel_h, kernel_w,
@@ -1214,8 +1205,8 @@ static inline void __attribute__ ((always_inline)) conv2d_row_anystride (
12141205

12151206
} else if ((kernel_w & 3) == 1) {
12161207
for (; W_input_idx < clmn_end * stride_width - right_comp; W_input_idx += stride_width) {
1217-
MY_ASSERT ((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1218-
MY_ASSERT (W_input_idx + kernel_w - pad_left <= in_width);
1208+
MLI_EXTRA_ASSERT((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1209+
MLI_EXTRA_ASSERT(W_input_idx + kernel_w - pad_left <= in_width);
12191210

12201211
convolution_unroll4_plus1 (in_ptr, w_ptr, o_ptr, biases[out_ch_idx], bias_shift,
12211212
out_shift, val_min_limit, val_max_limit, in_width, in_height, kernel_w, kernel_h, kernel_w,
@@ -1228,8 +1219,8 @@ static inline void __attribute__ ((always_inline)) conv2d_row_anystride (
12281219

12291220
} else {
12301221
for (; W_input_idx < clmn_end * stride_width - right_comp; W_input_idx += stride_width) {
1231-
MY_ASSERT ((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1232-
MY_ASSERT (W_input_idx + kernel_w - pad_left <= in_width);
1222+
MLI_EXTRA_ASSERT((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1223+
MLI_EXTRA_ASSERT(W_input_idx + kernel_w - pad_left <= in_width);
12331224

12341225
convolution (in_ptr, w_ptr, o_ptr, biases[out_ch_idx], bias_shift,
12351226
out_shift, val_min_limit, val_max_limit, in_width, in_height, kernel_w, kernel_h, kernel_w,
@@ -1246,7 +1237,7 @@ static inline void __attribute__ ((always_inline)) conv2d_row_anystride (
12461237
if (pad_right > 0) {
12471238
for (; W_input_idx < (clmn_end * stride_width); W_input_idx += stride_width) {
12481239
int clmns = kernel_w - MAX (W_input_idx + kernel_w - pad_left - in_width, 0);
1249-
MY_ASSERT ((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
1240+
MLI_EXTRA_ASSERT((in_ptr - in_ptr_start) == MAX (W_idx * stride_width - pad_left, 0));
12501241

12511242
convolution (in_ptr, w_ptr, o_ptr, biases[out_ch_idx], bias_shift,
12521243
out_shift, val_min_limit, val_max_limit, in_width, in_height, kernel_w, kernel_h, clmns, rows, in_ch);

lib/src/kernels/convolution/mli_krn_conv2d_hwc_fx16.cc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929

30-
#include <stdio.h>
31-
#include <assert.h>
32-
3330
#include "mli_config.h"
3431
#include "mli_debug.h"
3532
#include "mli_helpers_api.h"
@@ -228,12 +225,12 @@ mli_status mli_krn_conv2d_hwc_fx16_1x1_str1_nopad (
228225
uint8_t padding_left = cfg->padding_left;
229226
uint8_t padding_right = cfg->padding_right;
230227

231-
assert (stride_width == 1);
232-
assert (stride_height == 1);
233-
assert (padding_top == 0);
234-
assert (padding_bot == 0);
235-
assert (padding_left == 0);
236-
assert (padding_right == 0);
228+
MLI_ASSERT(stride_width == 1);
229+
MLI_ASSERT(stride_height == 1);
230+
MLI_ASSERT(padding_top == 0);
231+
MLI_ASSERT(padding_bot == 0);
232+
MLI_ASSERT(padding_left == 0);
233+
MLI_ASSERT(padding_right == 0);
237234

238235
stride_width = 1;
239236
stride_height = 1;
@@ -256,8 +253,8 @@ mli_status mli_krn_conv2d_hwc_fx16_1x1_str1_nopad (
256253

257254
int kernel_height = (int) weights->shape[1];
258255
int kernel_width = (int) weights->shape[2];
259-
assert (kernel_width == 1);
260-
assert (kernel_height == 1);
256+
MLI_ASSERT(kernel_width == 1);
257+
MLI_ASSERT(kernel_height == 1);
261258
kernel_width = 1;
262259
kernel_height = 1;
263260

lib/src/kernels/convolution/mli_krn_dotprod_chw.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
#ifndef _MLI_KRN_DOTPROD_CHW_H_
3131
#define _MLI_KRN_DOTPROD_CHW_H_
3232

33-
#include <assert.h>
34-
3533
#include "mli_config.h"
34+
#include "mli_debug.h"
3635
#include "mli_types.h"
3736
#include "mli_prv_dsp.h"
3837

@@ -73,7 +72,7 @@ static inline void __attribute__ ((always_inline)) dotprod2D_unroll2 (
7372
int in_row_step,
7473
int kern_row_step,
7574
acc_T * accu) {
76-
assert (width % 2 == 0);
75+
MLI_ASSERT(width % 2 == 0);
7776

7877
in_row_step -= width;
7978
kern_row_step -= width;
@@ -124,7 +123,7 @@ static inline void __attribute__ ((always_inline)) dotprod2D_unroll4 (
124123
int in_row_step,
125124
int kern_row_step,
126125
acc_T * accu) {
127-
assert (width % 4 == 0);
126+
MLI_ASSERT(width % 4 == 0);
128127

129128
in_row_step -= width;
130129
kern_row_step -= width;
@@ -154,7 +153,7 @@ static inline void __attribute__ ((always_inline)) dotprod2D_unroll4_plus1 (
154153
int in_row_step,
155154
int kern_row_step,
156155
acc_T * accu) {
157-
assert (width % 4 == 1);
156+
MLI_ASSERT(width % 4 == 1);
158157

159158
in_row_step -= width;
160159
kern_row_step -= width;
@@ -187,7 +186,7 @@ static inline void __attribute__ ((always_inline)) dotprod2D_unroll4_plus2 (
187186
int in_row_step,
188187
int kern_row_step,
189188
acc_T * accu) {
190-
assert (width % 4 == 2);
189+
MLI_ASSERT(width % 4 == 2);
191190

192191
in_row_step -= width;
193192
kern_row_step -= width;
@@ -221,7 +220,7 @@ static inline void __attribute__ ((always_inline)) dotprod2D_unroll4_plus3 (
221220
int in_row_step,
222221
int kern_row_step,
223222
acc_T * accu) {
224-
assert (width % 4 == 3);
223+
MLI_ASSERT(width % 4 == 3);
225224

226225
in_row_step -= width;
227226
kern_row_step -= width;
@@ -272,7 +271,7 @@ dotprod1D_v_unroll2 (
272271
const int height,
273272
int in_step,
274273
acc_T * accu) {
275-
assert ((height & 1) == 0);
274+
MLI_ASSERT((height & 1) == 0);
276275
//#pragma clang loop unroll(full)
277276
for (int32_t row = 0; row < height / 2; row++) {
278277
#if defined __Xxy

lib/src/kernels/eltwise/mli_krn_eltwise.h

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
#ifndef _MLI_KRN_ELTWISE_H_
3030
#define _MLI_KRN_ELTWISE_H_
3131

32-
#include <assert.h>
33-
#include <stdio.h>
34-
32+
#include "mli_debug.h"
3533
#include "mli_math.h"
3634
#include "mli_prv_dsp.h"
3735
#include "mli_prv_load_store.h"
@@ -71,7 +69,7 @@ static inline void __attribute__ ((always_inline)) eltwise_op_sub_fx (
7169
} else {
7270
// Elemetnwise between tensors of the same shape
7371
//==============================================
74-
assert(op1_size == op2_size);
72+
MLI_ASSERT(op1_size == op2_size);
7573

7674
for (int idx = 0; idx < op1_size; idx++) {
7775
*out++ = mli_math_sub_fx(*op1++, *op2++);
@@ -100,7 +98,7 @@ static inline void __attribute__ ((always_inline)) eltwise_op_add_fx (
10098
// Elemetnwise between tensors of the same shape
10199
//==============================================
102100
else {
103-
assert(op1_size == op2_size);
101+
MLI_ASSERT(op1_size == op2_size);
104102

105103
for (int idx = 0; idx < op1_size; idx++) {
106104
*out++ = mli_math_add_fx(*op1++, *op2++);
@@ -129,7 +127,7 @@ static inline void __attribute__ ((always_inline)) eltwise_op_max_fx (
129127
// Elemetnwise between tensors of the same shape
130128
//==============================================
131129
else {
132-
assert(op1_size == op2_size);
130+
MLI_ASSERT(op1_size == op2_size);
133131

134132
for (int idx = 0; idx < op1_size; idx++) {
135133
*out++ = mli_math_max_fx(*op1++, *op2++);
@@ -158,7 +156,7 @@ static inline void __attribute__ ((always_inline)) eltwise_op_min_fx (
158156
// Elemetnwise between tensors of the same shape
159157
//==============================================
160158
else {
161-
assert(op1_size == op2_size);
159+
MLI_ASSERT(op1_size == op2_size);
162160

163161
for (int idx = 0; idx < op1_size; idx++) {
164162
*out++ = mli_math_min_fx(*op1++, *op2++);
@@ -194,7 +192,7 @@ static inline void __attribute__ ((always_inline)) eltwise_op_add_fx (
194192
// Elemetnwise between tensors of the same shape
195193
//==============================================
196194
else {
197-
assert(op1_size == op2_size);
195+
MLI_ASSERT(op1_size == op2_size);
198196

199197
for (int idx = 0; idx < op1_size / 2; idx++) {
200198
mli_prv_store_2_samples(out, mli_prv_load_add_vec2(op1, op2));
@@ -242,7 +240,7 @@ static inline void __attribute__ ((always_inline)) eltwise_op_sub_fx (
242240
} else {
243241
// Elemetnwise between tensors of the same shape
244242
//==============================================
245-
assert(op1_size == op2_size);
243+
MLI_ASSERT(op1_size == op2_size);
246244

247245
for (int idx = 0; idx < op1_size / 2; idx++) {
248246
mli_prv_store_2_samples(out, mli_prv_load_sub_vec2(op1, op2));
@@ -282,7 +280,7 @@ static inline void __attribute__ ((always_inline)) eltwise_op_max_fx (
282280
} else {
283281
// Elemetnwise between tensors of the same shape
284282
//==============================================
285-
assert(op1_size == op2_size);
283+
MLI_ASSERT(op1_size == op2_size);
286284

287285
for (int idx = 0; idx < op1_size / 2; idx++) {
288286
mli_prv_store_2_samples(out, mli_prv_load_max_vec2(op1, op2));
@@ -322,7 +320,7 @@ static inline void __attribute__ ((always_inline)) eltwise_op_min_fx (
322320
} else {
323321
// Elemetnwise between tensors of the same shape
324322
//==============================================
325-
assert(op1_size == op2_size);
323+
MLI_ASSERT(op1_size == op2_size);
326324

327325
for (int idx = 0; idx < op1_size / 2; idx++) {
328326
mli_prv_store_2_samples(out, mli_prv_load_min_vec2(op1, op2));
@@ -378,7 +376,7 @@ static inline void __attribute__ ((always_inline)) eltwise_op_mul_fx (
378376
} else {
379377
// Elemetnwise between tensors of the same shape
380378
//==============================================
381-
assert(op1_size == op2_size);
379+
MLI_ASSERT(op1_size == op2_size);
382380

383381
if (op1_size & 0x3) {
384382
for (int j = 0; j < (op1_size & 0x3); j++) {
@@ -452,7 +450,7 @@ static inline void __attribute__ ((always_inline)) eltwise_op_mul_with_restricts
452450
} else {
453451
// Elemetnwise between tensors of the same shape
454452
//==============================================
455-
assert(op1_size == op2_size);
453+
MLI_ASSERT(op1_size == op2_size);
456454

457455
if (op1_size & 0x3) {
458456
for (int j = 0; j < (op1_size & 0x3); j++) {

0 commit comments

Comments
 (0)