summaryrefslogtreecommitdiff
path: root/fw/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/Common/src/filtering_tests/conv_tests.c
blob: c2fdf0fc8182d9c6e738989582e808b38c7a40dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
#include "jtest.h"
#include "filtering_test_data.h"
#include "arr_desc.h"
#include "arm_math.h"           /* FUTs */
#include "ref.h"                /* Reference Functions */
#include "test_templates.h"
#include "filtering_templates.h"
#include "type_abbrev.h"

/*--------------------------------------------------------------------------------*/
/* Header Stuff */
/*--------------------------------------------------------------------------------*/

#define CONV_MAX_INPUT_ELTS  32
#define CONV_MAX_OUTPUT_ELTS (CONV_MAX_INPUT_ELTS * 2)

#define CONV_TEST_VALID_PARTIAL_PARAMS(input_a_len, input_b_len,           \
                                       first_index, num_points)            \
    (((((input_a_len) + (input_b_len) - 1)) >= num_points + first_index )  \
    && (num_points > 0))

/*--------------------------------------------------------------------------------*/
/* Input Interfaces */
/*--------------------------------------------------------------------------------*/
/*
 *  General:
 *  Input interfaces provide inputs to functions inside test templates.  They
 *  ONLY provide the inputs.  The output variables should be hard coded.
 *
 *  The input interfaces must have the following format:
 *
 *  ARM_xxx_INPUT_INTERFACE() or
 *  REF_xxx_INPUT_INTERFACE()
 *
 *  The xxx must be lowercase, and is intended to be the indentifying substring
 *  in the function's name.  Acceptable values are 'sub' or 'add' from the
 *  functions arm_add_q31.
 */

#define CONV_arm_conv_INPUT_INTERFACE(input_a, input_a_len, input_b, input_b_len) \
    PAREN(input_a, input_a_len, input_b, input_b_len, (void*)filtering_output_fut)

#define CONV_ref_conv_INPUT_INTERFACE(input_a, input_a_len, input_b, input_b_len) \
    PAREN(input_a, input_a_len, input_b, input_b_len, (void*)filtering_output_ref)

#define CONV_arm_conv_opt_INPUT_INTERFACE(              \
    input_a, input_a_len,                               \
    input_b, input_b_len)                               \
    PAREN(input_a, input_a_len, input_b, input_b_len,   \
          (void*) filtering_output_fut,                 \
          (void*) filtering_scratch,                    \
          (void*) filtering_scratch2)

#define CONV_ref_conv_opt_INPUT_INTERFACE(              \
    input_a, input_a_len,                               \
    input_b, input_b_len)                               \
    PAREN(input_a, input_a_len, input_b, input_b_len,   \
          (void*) filtering_output_ref,                 \
          (void*) filtering_scratch,                    \
          (void*) filtering_scratch2)

#define CONV_arm_conv_fast_INPUT_INTERFACE(input_a, input_a_len,        \
                                           input_b, input_b_len)        \
    PAREN(input_a, input_a_len, input_b, input_b_len, (void*)filtering_output_fut)

#define CONV_ref_conv_fast_INPUT_INTERFACE(input_a, input_a_len,        \
                                           input_b, input_b_len)        \
    PAREN(input_a, input_a_len, input_b, input_b_len, (void*)filtering_output_ref)

#define CONV_arm_conv_fast_opt_INPUT_INTERFACE(         \
    input_a, input_a_len,                               \
    input_b, input_b_len)                               \
    PAREN(input_a, input_a_len, input_b, input_b_len,   \
          (void*) filtering_output_fut,                 \
          (void*) filtering_scratch,                    \
          (void*) filtering_scratch2)

#define CONV_ref_conv_fast_opt_INPUT_INTERFACE(         \
    input_a, input_a_len,                               \
    input_b, input_b_len)                               \
    PAREN(input_a, input_a_len, input_b, input_b_len,   \
          (void*) filtering_output_ref,                 \
          (void*) filtering_scratch,                    \
          (void*) filtering_scratch2)

#define CONV_arm_conv_partial_INPUT_INTERFACE(input_a, input_a_len,     \
                                              input_b, input_b_len,     \
                                              first_index, num_points)  \
    PAREN(input_a, input_a_len, input_b, input_b_len,                   \
          (void*)filtering_output_fut, first_index, num_points)

#define CONV_ref_conv_partial_INPUT_INTERFACE(input_a, input_a_len,     \
                                              input_b, input_b_len,     \
                                              first_index, num_points)  \
    PAREN(input_a, input_a_len, input_b, input_b_len,                   \
          (void*)filtering_output_ref, first_index, num_points)

#define CONV_arm_conv_partial_fast_INPUT_INTERFACE(input_a, input_a_len,   \
                                              input_b, input_b_len,        \
                                              first_index, num_points)     \
    PAREN(input_a, input_a_len, input_b, input_b_len,                      \
          (void*)filtering_output_fut, first_index, num_points)

#define CONV_ref_conv_partial_fast_INPUT_INTERFACE(input_a, input_a_len,   \
                                              input_b, input_b_len,        \
                                              first_index, num_points)     \
    PAREN(input_a, input_a_len, input_b, input_b_len,                      \
          (void*)filtering_output_ref, first_index, num_points)

#define CONV_arm_conv_partial_opt_INPUT_INTERFACE(input_a, input_a_len, \
                                              input_b, input_b_len,     \
                                              first_index, num_points)  \
    PAREN(input_a, input_a_len, input_b, input_b_len,                   \
          (void*)filtering_output_fut, first_index, num_points,         \
          (void*) filtering_scratch,                                    \
          (void*) filtering_scratch2)

#define CONV_ref_conv_partial_opt_INPUT_INTERFACE(input_a, input_a_len, \
                                              input_b, input_b_len,     \
                                              first_index, num_points)  \
    PAREN(input_a, input_a_len, input_b, input_b_len,                   \
          (void*)filtering_output_ref, first_index, num_points,         \
          (void*) filtering_scratch,                                    \
          (void*) filtering_scratch2)

#define CONV_arm_conv_partial_fast_opt_INPUT_INTERFACE(input_a, input_a_len,  \
                                              input_b, input_b_len,           \
                                              first_index, num_points)        \
    PAREN(input_a, input_a_len, input_b, input_b_len,                         \
          (void*)filtering_output_fut, first_index, num_points,               \
          (void*) filtering_scratch,                                          \
          (void*) filtering_scratch2)

#define CONV_ref_conv_partial_fast_opt_INPUT_INTERFACE(input_a, input_a_len,  \
                                              input_b, input_b_len,           \
                                              first_index, num_points)        \
    PAREN(input_a, input_a_len, input_b, input_b_len,                         \
          (void*)filtering_output_ref, first_index, num_points,               \
          (void*) filtering_scratch,                                          \
          (void*) filtering_scratch2)

/*--------------------------------------------------------------------------------*/
/* Convolution Inputs */
/*--------------------------------------------------------------------------------*/

/* The following symbols alias the filtering_q31_inputs array:
 *
 * - filtering_q15_inputs
 * - filtering_q7_inputs
 *
 * The aliasing conflicts with the instantiation of #ARR_DESC_t structs.
 *
 * These macro-level aliases allow the #CONV_DEFINE_RAND_INPUT_ARR_DESCS() macro
 * to correctly select the filtering_q31_input or filtering_f32_input array,
 * within a template, by type_suffix.
 *
 */
#define CONV_f32_INPUTS filtering_f32_inputs
#define CONV_q31_INPUTS filtering_q31_inputs
#define CONV_q15_INPUTS filtering_q31_inputs
#define CONV_q7_INPUTS  filtering_q31_inputs

/**
 *  Defines #ARR_DESC_t objects that wrap existing, type-specific, common
 *  inputs.
 */
#define CONV_DEFINE_RAND_INPUT_ARR_DESCS(type_suffix)           \
    ARR_DESC_DEFINE_USING_ARR(                                  \
        TYPE_FROM_ABBREV(type_suffix),                          \
        conv_input_rand1_##type_suffix,                         \
        CONV_##type_suffix##_INPUTS,                            \
        0,                                                      \
        CONV_MAX_INPUT_ELTS);                                   \
                                                                \
    ARR_DESC_DEFINE_USING_ARR(                                  \
        TYPE_FROM_ABBREV(type_suffix),                          \
        conv_input_rand2_##type_suffix,                         \
        CONV_##type_suffix##_INPUTS,                            \
        1,                                                      \
        CONV_MAX_INPUT_ELTS)  /* Note the lacking semicolon */

CONV_DEFINE_RAND_INPUT_ARR_DESCS(f32);
CONV_DEFINE_RAND_INPUT_ARR_DESCS(q31);
CONV_DEFINE_RAND_INPUT_ARR_DESCS(q15);
CONV_DEFINE_RAND_INPUT_ARR_DESCS(q7);
ARR_DESC_DEFINE(float32_t, conv_input_zeros, CONV_MAX_INPUT_ELTS, CURLY(0));

/**
 *  Define Input #ARR_DESC_t arrays by type suffix.
 *
 *  Taking inputs in parallel from the 'a' and 'b' arrays yields the following
 *  test cases (star is convolution):
 *
 *  - zero_array   * zero_array
 *  - zero_array   * random_array
 *  - random_array * zero_array
 *  - random_array * different_random_arary
 */
#define CONV_DEFINE_ALL_INPUTS(type_suffix)                 \
    ARR_DESC_DEFINE(ARR_DESC_t *,                           \
                    conv_##type_suffix##_a_inputs,          \
                    4,                                      \
                    CURLY(                                  \
                        &conv_input_zeros,                  \
                        &conv_input_zeros,                  \
                        &conv_input_rand1_##type_suffix,    \
                        &conv_input_rand1_##type_suffix     \
                        ));                                 \
    ARR_DESC_DEFINE(ARR_DESC_t *,                           \
                    conv_##type_suffix##_b_inputs,          \
                    4,                                      \
                    CURLY(                                  \
                        &conv_input_zeros,                  \
                        &conv_input_rand1_##type_suffix,    \
                        &conv_input_zeros,                  \
                        &conv_input_rand2_##type_suffix     \
                        )) /* Note the lacking semicolon */

CONV_DEFINE_ALL_INPUTS(f32);
CONV_DEFINE_ALL_INPUTS(q31);
CONV_DEFINE_ALL_INPUTS(q15);
CONV_DEFINE_ALL_INPUTS(q7);

/*--------------------------------------------------------------------------------*/
/* Convolution Lengths */
/*--------------------------------------------------------------------------------*/

/*
 *  The conv_lens_a and conv_lens_b #ARR_DESC_t objects are accessed in parallel
 *  to provide convolution-length pairs. Taken in parallel they provide the
 *  following cases:
 *
 *  - 1 * 1    : Shortest convolution possible.
 *  - 1 * 2    : Short convolution   , one side is degenerate .
 *  - 17 * 1   : Medium convolution  , one side is degenerate .
 *  - 15 * MAX : Longest convolution , one side is degenerate .
 *  MAX * MAX  : Longest convolution.
 */
ARR_DESC_DEFINE(uint32_t,
                conv_lens_a,
                5,
                CURLY(
                    1,
                    1,
                    17,
                    15,
                    CONV_MAX_INPUT_ELTS
                    ));

ARR_DESC_DEFINE(uint32_t,
                conv_lens_b,
                5,
                CURLY(
                    1,
                    2,
                    1,
                    CONV_MAX_INPUT_ELTS,
                    CONV_MAX_INPUT_ELTS
                    ));

/*--------------------------------------------------------------------------------*/
/* Partial Indexing */
/*--------------------------------------------------------------------------------*/

ARR_DESC_DEFINE(uint32_t,
                first_index_arr_desc,
                4,
                CURLY(
                    0,
                    1,
                    CONV_MAX_INPUT_ELTS / 2,
                    CONV_MAX_INPUT_ELTS
                    ));

ARR_DESC_DEFINE(uint32_t,
                num_points_arr_desc,
                3,
                CURLY(
                    1,
                    CONV_MAX_OUTPUT_ELTS / 2,
                    CONV_MAX_OUTPUT_ELTS
                    ));

/*--------------------------------------------------------------------------------*/
/* Convolution Tests */
/*--------------------------------------------------------------------------------*/

#define CONV_TEST_TEMPLATE(fut, fut_arg_interface,                            \
                           ref, ref_arg_interface,                            \
                           suffix, output_type)                               \
    JTEST_DEFINE_TEST(fut##_tests, fut)                                       \
    {                                                                         \
        TEMPLATE_DO_ARR_DESC(                                                 \
            input_idx, ARR_DESC_t *, input_ptr, conv_##suffix##_a_inputs      \
            ,                                                                 \
            void * input_a_ptr = input_ptr->data_ptr;                         \
            void * input_b_ptr = ARR_DESC_ELT(                                \
                ARR_DESC_t *, input_idx,                                      \
                &(conv_##suffix##_b_inputs))->data_ptr;                       \
                                                                              \
            TEMPLATE_DO_ARR_DESC(                                             \
                conv_len_idx, uint32_t, conv_len_a, conv_lens_a               \
                ,                                                             \
                uint32_t conv_len_b = ARR_DESC_ELT(                           \
                    uint32_t, conv_len_idx, &(conv_lens_b));                  \
                                                                              \
                JTEST_DUMP_STRF("Input A Length: %d\n"                        \
                                "Input B Length: %d\n",                       \
                                (int)conv_len_a,                              \
                                (int)conv_len_b);                             \
                                                                              \
                TEST_CALL_FUT_AND_REF(                                        \
                    fut, fut_arg_interface(                                   \
                        input_a_ptr, conv_len_a, input_b_ptr, conv_len_b),    \
                    ref, ref_arg_interface(                                   \
                        input_a_ptr, conv_len_a, input_b_ptr, conv_len_b));   \
                                                                              \
                FILTERING_SNR_COMPARE_INTERFACE(                              \
                    conv_len_a + conv_len_b - 1,                              \
                    output_type)));                                           \
                                                                              \
        return JTEST_TEST_PASSED;                                             \
    }                                                                         \
                                                                              \

#define CONV_PARTIAL_TEST_TEMPLATE(fut, fut_arg_interface,                    \
                                   ref, ref_arg_interface,                    \
                                   suffix, output_type)                       \
    JTEST_DEFINE_TEST(fut##_tests, fut)                                       \
    {                                                                         \
        TEMPLATE_DO_ARR_DESC(                                                 \
            input_idx, ARR_DESC_t *, input_ptr, conv_##suffix##_a_inputs      \
            ,                                                                 \
            void * input_a_ptr = input_ptr->data_ptr;                         \
            void * input_b_ptr = ARR_DESC_ELT(                                \
                ARR_DESC_t *, input_idx,                                      \
                &(conv_##suffix##_b_inputs))->data_ptr;                       \
            TEMPLATE_DO_ARR_DESC(                                             \
                conv_len_idx, uint32_t, conv_len_a, conv_lens_a               \
                ,                                                             \
                uint32_t conv_len_b = ARR_DESC_ELT(                           \
                    uint32_t, conv_len_idx, &(conv_lens_b));                  \
                                                                              \
                TEMPLATE_DO_ARR_DESC(                                         \
                    first_index_idx, uint32_t, first_index,                   \
                    first_index_arr_desc                                      \
                    ,                                                         \
                    TEMPLATE_DO_ARR_DESC(                                     \
                        num_points_idx, uint32_t, num_points,                 \
                        num_points_arr_desc                                   \
                        ,                                                     \
                        if (CONV_TEST_VALID_PARTIAL_PARAMS(                   \
                                conv_len_a, conv_len_b,                       \
                                first_index, num_points))                     \
                        {                                                     \
                            /* Display test parameter values */               \
                            JTEST_DUMP_STRF("Input A Length: %d\n"            \
                                            "Input B Length: %d\n"            \
                                            "First Sample Index: %d\n"        \
                                            "Number of Output Points: %d\n",  \
                                            (int)conv_len_a,                  \
                                            (int)conv_len_b,                  \
                                            (int)first_index,                 \
                                            (int)num_points);                 \
                                                                              \
                           memset(filtering_output_ref,0,                     \
                                 (2*CONV_MAX_INPUT_ELTS)*sizeof(output_type)); \
                           memset(filtering_output_fut,0,                     \
                                 (2*CONV_MAX_INPUT_ELTS)*sizeof(output_type)); \
                                                                              \
                            TEST_CALL_FUT_AND_REF(                            \
                                fut, fut_arg_interface(                       \
                                    input_a_ptr, conv_len_a,                  \
                                    input_b_ptr, conv_len_b,                  \
                                    first_index, num_points),                 \
                                ref, ref_arg_interface(                       \
                                    input_a_ptr, conv_len_a,                  \
                                    input_b_ptr, conv_len_b,                  \
                                    first_index, num_points));                \
                                                                              \
                            FILTERING_SNR_COMPARE_INTERFACE_OFFSET(           \
                                first_index,                                  \
                                num_points,                                   \
                                output_type);                                 \
                        } else {                                              \
                            /* FUT should return ARM_MATH_ARGUMENT_ERROR*/    \
                            /* if first_index and num_points don't make */    \
                            /* sense*/                                        \
                                                                              \
                            arm_status conv_test_retval;                      \
                            TEST_CALL_FUT(                                    \
                                conv_test_retval = fut,                       \
                                fut_arg_interface(                            \
                                    input_a_ptr, conv_len_a,                  \
                                    input_b_ptr, conv_len_b,                  \
                                    first_index, num_points));                \
                                                                              \
                            if (conv_test_retval != ARM_MATH_ARGUMENT_ERROR) { \
                                JTEST_DUMP_STR("FUT failed to raise error."); \
                                /* return JTEST_TEST_FAILED; */               \
                            }                                                 \
                        }))));                                                \
                                                                              \
        return JTEST_TEST_PASSED;                                             \
    }

#define CONV_DEFINE_TEST(fn_name, suffix, output_type, test_template)   \
    test_template(                                                      \
        arm_##fn_name##_##suffix,                                       \
        CONV_arm_##fn_name##_INPUT_INTERFACE,                           \
        ref_##fn_name##_##suffix,                                       \
        CONV_ref_##fn_name##_INPUT_INTERFACE,                           \
        suffix,                                                         \
        output_type                                                     \
        ) /* Note the lacking semicolon*/

/* Tests on functions without partial outputs */
CONV_DEFINE_TEST(conv          , f32, float32_t, CONV_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv          , q31, q31_t    , CONV_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv          , q15, q15_t    , CONV_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv          , q7 , q7_t     , CONV_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_opt      , q15, q15_t    , CONV_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_opt      , q7 , q7_t     , CONV_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_fast     , q31, q31_t    , CONV_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_fast     , q15, q15_t    , CONV_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_fast_opt , q15, q15_t    , CONV_TEST_TEMPLATE);

/* Tests on functions with partial outputs  */
CONV_DEFINE_TEST(conv_partial          , f32, float32_t, CONV_PARTIAL_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_partial          , q31, q31_t    , CONV_PARTIAL_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_partial          , q15, q15_t    , CONV_PARTIAL_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_partial          , q7 , q7_t     , CONV_PARTIAL_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_partial_fast     , q31, q31_t    , CONV_PARTIAL_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_partial_fast     , q15, q15_t    , CONV_PARTIAL_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_partial_fast_opt , q15, q15_t    , CONV_PARTIAL_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_partial_opt      , q15, q15_t    , CONV_PARTIAL_TEST_TEMPLATE);
CONV_DEFINE_TEST(conv_partial_opt      , q7 , q7_t     , CONV_PARTIAL_TEST_TEMPLATE);

/*--------------------------------------------------------------------------------*/
/* Collect all tests in a group. */
/*--------------------------------------------------------------------------------*/

JTEST_DEFINE_GROUP(conv_tests)
{
    /*
      To skip a test, comment it out.
    */
    JTEST_TEST_CALL(arm_conv_f32_tests);
    JTEST_TEST_CALL(arm_conv_q31_tests);
    JTEST_TEST_CALL(arm_conv_q15_tests);
    JTEST_TEST_CALL(arm_conv_q7_tests);

    JTEST_TEST_CALL(arm_conv_opt_q15_tests);
    JTEST_TEST_CALL(arm_conv_opt_q7_tests);

    JTEST_TEST_CALL(arm_conv_fast_q31_tests);
    JTEST_TEST_CALL(arm_conv_fast_q15_tests);

    JTEST_TEST_CALL(arm_conv_fast_opt_q15_tests);

    JTEST_TEST_CALL(arm_conv_partial_f32_tests);
    JTEST_TEST_CALL(arm_conv_partial_q31_tests);
    JTEST_TEST_CALL(arm_conv_partial_q15_tests);
    JTEST_TEST_CALL(arm_conv_partial_q7_tests);

    JTEST_TEST_CALL(arm_conv_partial_fast_q31_tests);
    JTEST_TEST_CALL(arm_conv_partial_fast_q15_tests);

    JTEST_TEST_CALL(arm_conv_partial_fast_opt_q15_tests);

    JTEST_TEST_CALL(arm_conv_partial_opt_q15_tests);
    JTEST_TEST_CALL(arm_conv_partial_opt_q7_tests);
}