tests: lib: cmsis_dsp: matrix: Add Binary F16 tests for 1.9.0
This commit adds the matrix Binary F16 test patterns and implementations for the CMSIS-DSP 1.9.0. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
This commit is contained in:
parent
9a71d359c1
commit
d612a544c9
7 changed files with 10298 additions and 0 deletions
|
@ -43,6 +43,11 @@ target_sources_ifdef(
|
||||||
app PRIVATE src/binary_q31.c
|
app PRIVATE src/binary_q31.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_sources_ifdef(
|
||||||
|
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F16
|
||||||
|
app PRIVATE src/binary_f16.c
|
||||||
|
)
|
||||||
|
|
||||||
target_sources_ifdef(
|
target_sources_ifdef(
|
||||||
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F32
|
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F32
|
||||||
app PRIVATE src/binary_f32.c
|
app PRIVATE src/binary_f32.c
|
||||||
|
|
|
@ -22,6 +22,10 @@ config CMSIS_DSP_TEST_MATRIX_BINARY_Q15
|
||||||
config CMSIS_DSP_TEST_MATRIX_BINARY_Q31
|
config CMSIS_DSP_TEST_MATRIX_BINARY_Q31
|
||||||
bool "Test: Matrix Binary Q31"
|
bool "Test: Matrix Binary Q31"
|
||||||
|
|
||||||
|
config CMSIS_DSP_TEST_MATRIX_BINARY_F16
|
||||||
|
bool "Test: Matrix Binary F16"
|
||||||
|
depends on CMSIS_DSP_FLOAT16
|
||||||
|
|
||||||
config CMSIS_DSP_TEST_MATRIX_BINARY_F32
|
config CMSIS_DSP_TEST_MATRIX_BINARY_F32
|
||||||
bool "Test: Matrix Binary F32"
|
bool "Test: Matrix Binary F32"
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,5 @@ CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_F64=y
|
||||||
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_Q7=y
|
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_Q7=y
|
||||||
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_Q15=y
|
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_Q15=y
|
||||||
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_Q31=y
|
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_Q31=y
|
||||||
|
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F16=y
|
||||||
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F32=y
|
CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F32=y
|
||||||
|
|
216
tests/lib/cmsis_dsp/matrix/src/binary_f16.c
Normal file
216
tests/lib/cmsis_dsp/matrix/src/binary_f16.c
Normal file
|
@ -0,0 +1,216 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Stephanos Ioannidis <root@stephanos.io>
|
||||||
|
* Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ztest.h>
|
||||||
|
#include <zephyr.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <arm_math_f16.h>
|
||||||
|
#include "../../common/test_common.h"
|
||||||
|
|
||||||
|
#include "binary_f16.pat"
|
||||||
|
|
||||||
|
#define SNR_ERROR_THRESH ((float32_t)60)
|
||||||
|
#define REL_ERROR_THRESH (2.0e-3)
|
||||||
|
#define ABS_ERROR_THRESH (2.0e-3)
|
||||||
|
|
||||||
|
#define NUM_MATRICES (ARRAY_SIZE(in_dims) / 3)
|
||||||
|
#define MAX_MATRIX_DIM (40)
|
||||||
|
|
||||||
|
#define OP2_MULT (0)
|
||||||
|
#define OP2C_CMPLX_MULT (0)
|
||||||
|
|
||||||
|
static void test_op2(int op, const uint16_t *input1, const uint16_t *input2,
|
||||||
|
const uint16_t *ref, size_t length)
|
||||||
|
{
|
||||||
|
size_t index;
|
||||||
|
uint16_t *dims = (uint16_t *)in_dims;
|
||||||
|
float16_t *tmp1, *tmp2, *output;
|
||||||
|
uint16_t rows, internal, columns;
|
||||||
|
arm_status status;
|
||||||
|
|
||||||
|
arm_matrix_instance_f16 mat_in1;
|
||||||
|
arm_matrix_instance_f16 mat_in2;
|
||||||
|
arm_matrix_instance_f16 mat_out;
|
||||||
|
|
||||||
|
/* Allocate buffers */
|
||||||
|
tmp1 = malloc(MAX_MATRIX_DIM * MAX_MATRIX_DIM * sizeof(float16_t));
|
||||||
|
zassert_not_null(tmp1, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
tmp2 = malloc(MAX_MATRIX_DIM * MAX_MATRIX_DIM * sizeof(float16_t));
|
||||||
|
zassert_not_null(tmp2, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
output = malloc(length * sizeof(float16_t));
|
||||||
|
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
/* Initialise contexts */
|
||||||
|
mat_in1.pData = tmp1;
|
||||||
|
mat_in2.pData = tmp2;
|
||||||
|
mat_out.pData = output;
|
||||||
|
|
||||||
|
/* Iterate matrices */
|
||||||
|
for (index = 0; index < NUM_MATRICES; index++) {
|
||||||
|
rows = *dims++;
|
||||||
|
internal = *dims++;
|
||||||
|
columns = *dims++;
|
||||||
|
|
||||||
|
/* Initialise matrix dimensions */
|
||||||
|
mat_in1.numRows = rows;
|
||||||
|
mat_in1.numCols = internal;
|
||||||
|
|
||||||
|
mat_in2.numRows = internal;
|
||||||
|
mat_in2.numCols = columns;
|
||||||
|
|
||||||
|
mat_out.numRows = rows;
|
||||||
|
mat_out.numCols = columns;
|
||||||
|
|
||||||
|
/* Load matrix data */
|
||||||
|
memcpy(mat_in1.pData, input1,
|
||||||
|
rows * internal * sizeof(float16_t));
|
||||||
|
|
||||||
|
memcpy(mat_in2.pData, input2,
|
||||||
|
internal * columns * sizeof(float16_t));
|
||||||
|
|
||||||
|
/* Run test function */
|
||||||
|
switch (op) {
|
||||||
|
case OP2_MULT:
|
||||||
|
status = arm_mat_mult_f16(&mat_in1, &mat_in2,
|
||||||
|
&mat_out);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
zassert_unreachable("invalid operation");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Validate status */
|
||||||
|
zassert_equal(status, ARM_MATH_SUCCESS,
|
||||||
|
ASSERT_MSG_INCORRECT_COMP_RESULT);
|
||||||
|
|
||||||
|
/* Increment output pointer */
|
||||||
|
mat_out.pData += (rows * columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Validate output */
|
||||||
|
zassert_true(
|
||||||
|
test_snr_error_f16(length, output, (float16_t *)ref,
|
||||||
|
SNR_ERROR_THRESH),
|
||||||
|
ASSERT_MSG_SNR_LIMIT_EXCEED);
|
||||||
|
|
||||||
|
zassert_true(
|
||||||
|
test_close_error_f16(length, output, (float16_t *)ref,
|
||||||
|
ABS_ERROR_THRESH, REL_ERROR_THRESH),
|
||||||
|
ASSERT_MSG_ERROR_LIMIT_EXCEED);
|
||||||
|
|
||||||
|
/* Free buffers */
|
||||||
|
free(tmp1);
|
||||||
|
free(tmp2);
|
||||||
|
free(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_TEST_VARIANT5(
|
||||||
|
op2, arm_mat_mult_f16, OP2_MULT,
|
||||||
|
in_mult1, in_mult2, ref_mult,
|
||||||
|
ARRAY_SIZE(ref_mult));
|
||||||
|
|
||||||
|
static void test_op2c(int op, const uint16_t *input1, const uint16_t *input2,
|
||||||
|
const uint16_t *ref, size_t length)
|
||||||
|
{
|
||||||
|
size_t index;
|
||||||
|
uint16_t *dims = (uint16_t *)in_dims;
|
||||||
|
float16_t *tmp1, *tmp2, *output;
|
||||||
|
uint16_t rows, internal, columns;
|
||||||
|
arm_status status;
|
||||||
|
|
||||||
|
arm_matrix_instance_f16 mat_in1;
|
||||||
|
arm_matrix_instance_f16 mat_in2;
|
||||||
|
arm_matrix_instance_f16 mat_out;
|
||||||
|
|
||||||
|
/* Allocate buffers */
|
||||||
|
tmp1 = malloc(2 * MAX_MATRIX_DIM * MAX_MATRIX_DIM * sizeof(float16_t));
|
||||||
|
zassert_not_null(tmp1, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
tmp2 = malloc(2 * MAX_MATRIX_DIM * MAX_MATRIX_DIM * sizeof(float16_t));
|
||||||
|
zassert_not_null(tmp2, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
output = malloc(2 * length * sizeof(float16_t));
|
||||||
|
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
/* Initialise contexts */
|
||||||
|
mat_in1.pData = tmp1;
|
||||||
|
mat_in2.pData = tmp2;
|
||||||
|
mat_out.pData = output;
|
||||||
|
|
||||||
|
/* Iterate matrices */
|
||||||
|
for (index = 0; index < NUM_MATRICES; index++) {
|
||||||
|
rows = *dims++;
|
||||||
|
internal = *dims++;
|
||||||
|
columns = *dims++;
|
||||||
|
|
||||||
|
/* Initialise matrix dimensions */
|
||||||
|
mat_in1.numRows = rows;
|
||||||
|
mat_in1.numCols = internal;
|
||||||
|
|
||||||
|
mat_in2.numRows = internal;
|
||||||
|
mat_in2.numCols = columns;
|
||||||
|
|
||||||
|
mat_out.numRows = rows;
|
||||||
|
mat_out.numCols = columns;
|
||||||
|
|
||||||
|
/* Load matrix data */
|
||||||
|
memcpy(mat_in1.pData, input1,
|
||||||
|
2 * rows * internal * sizeof(float16_t));
|
||||||
|
|
||||||
|
memcpy(mat_in2.pData, input2,
|
||||||
|
2 * internal * columns * sizeof(float16_t));
|
||||||
|
|
||||||
|
/* Run test function */
|
||||||
|
switch (op) {
|
||||||
|
case OP2C_CMPLX_MULT:
|
||||||
|
status = arm_mat_cmplx_mult_f16(&mat_in1, &mat_in2,
|
||||||
|
&mat_out);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
zassert_unreachable("invalid operation");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Validate status */
|
||||||
|
zassert_equal(status, ARM_MATH_SUCCESS,
|
||||||
|
ASSERT_MSG_INCORRECT_COMP_RESULT);
|
||||||
|
|
||||||
|
/* Increment output pointer */
|
||||||
|
mat_out.pData += (2 * rows * columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Validate output */
|
||||||
|
zassert_true(
|
||||||
|
test_snr_error_f16(2 * length, output, (float16_t *)ref,
|
||||||
|
SNR_ERROR_THRESH),
|
||||||
|
ASSERT_MSG_SNR_LIMIT_EXCEED);
|
||||||
|
|
||||||
|
zassert_true(
|
||||||
|
test_close_error_f16(length, output, (float16_t *)ref,
|
||||||
|
ABS_ERROR_THRESH, REL_ERROR_THRESH),
|
||||||
|
ASSERT_MSG_ERROR_LIMIT_EXCEED);
|
||||||
|
|
||||||
|
/* Free buffers */
|
||||||
|
free(tmp1);
|
||||||
|
free(tmp2);
|
||||||
|
free(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_TEST_VARIANT5(
|
||||||
|
op2c, arm_mat_cmplx_mult_f16, OP2C_CMPLX_MULT,
|
||||||
|
in_cmplx_mult1, in_cmplx_mult2, ref_cmplx_mult,
|
||||||
|
ARRAY_SIZE(ref_cmplx_mult) / 2);
|
||||||
|
|
||||||
|
void test_matrix_binary_f16(void)
|
||||||
|
{
|
||||||
|
ztest_test_suite(matrix_binary_f16,
|
||||||
|
ztest_unit_test(test_op2_arm_mat_mult_f16),
|
||||||
|
ztest_unit_test(test_op2c_arm_mat_cmplx_mult_f16)
|
||||||
|
);
|
||||||
|
|
||||||
|
ztest_run_test_suite(matrix_binary_f16);
|
||||||
|
}
|
10042
tests/lib/cmsis_dsp/matrix/src/binary_f16.pat
generated
Normal file
10042
tests/lib/cmsis_dsp/matrix/src/binary_f16.pat
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -15,6 +15,7 @@ extern void test_matrix_unary_f64(void);
|
||||||
extern void test_matrix_binary_q7(void);
|
extern void test_matrix_binary_q7(void);
|
||||||
extern void test_matrix_binary_q15(void);
|
extern void test_matrix_binary_q15(void);
|
||||||
extern void test_matrix_binary_q31(void);
|
extern void test_matrix_binary_q31(void);
|
||||||
|
extern void test_matrix_binary_f16(void);
|
||||||
extern void test_matrix_binary_f32(void);
|
extern void test_matrix_binary_f32(void);
|
||||||
|
|
||||||
void test_main(void)
|
void test_main(void)
|
||||||
|
@ -41,6 +42,9 @@ void test_main(void)
|
||||||
#ifdef CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_Q31
|
#ifdef CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_Q31
|
||||||
test_matrix_binary_q31();
|
test_matrix_binary_q31();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F16
|
||||||
|
test_matrix_binary_f16();
|
||||||
|
#endif
|
||||||
#ifdef CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F32
|
#ifdef CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F32
|
||||||
test_matrix_binary_f32();
|
test_matrix_binary_f32();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -177,6 +177,32 @@ tests:
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_Q31=y
|
- CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_Q31=y
|
||||||
- CONFIG_FPU=y
|
- CONFIG_FPU=y
|
||||||
|
libraries.cmsis_dsp.matrix.binary_f16:
|
||||||
|
filter: ((CONFIG_CPU_CORTEX_R or CONFIG_CPU_CORTEX_M) and TOOLCHAIN_HAS_NEWLIB == 1) or CONFIG_ARCH_POSIX
|
||||||
|
integration_platforms:
|
||||||
|
- frdm_k64f
|
||||||
|
- sam_e70_xplained
|
||||||
|
- mps2_an521
|
||||||
|
- native_posix
|
||||||
|
tags: cmsis_dsp
|
||||||
|
platform_exclude: frdm_kw41z
|
||||||
|
min_flash: 128
|
||||||
|
min_ram: 128
|
||||||
|
extra_args: CONF_FILE=prj_base.conf
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F16=y
|
||||||
|
libraries.cmsis_dsp.matrix.binary_f16.fpu:
|
||||||
|
filter: ((CONFIG_CPU_CORTEX_R or CONFIG_CPU_CORTEX_M) and CONFIG_CPU_HAS_FPU and TOOLCHAIN_HAS_NEWLIB == 1) or CONFIG_ARCH_POSIX
|
||||||
|
integration_platforms:
|
||||||
|
- mps2_an521_remote
|
||||||
|
tags: cmsis_dsp fpu
|
||||||
|
platform_exclude: frdm_kw41z
|
||||||
|
min_flash: 128
|
||||||
|
min_ram: 128
|
||||||
|
extra_args: CONF_FILE=prj_base.conf
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_CMSIS_DSP_TEST_MATRIX_BINARY_F16=y
|
||||||
|
- CONFIG_FPU=y
|
||||||
libraries.cmsis_dsp.matrix.binary_f32:
|
libraries.cmsis_dsp.matrix.binary_f32:
|
||||||
filter: ((CONFIG_CPU_CORTEX_R or CONFIG_CPU_CORTEX_M) and TOOLCHAIN_HAS_NEWLIB == 1) or CONFIG_ARCH_POSIX
|
filter: ((CONFIG_CPU_CORTEX_R or CONFIG_CPU_CORTEX_M) and TOOLCHAIN_HAS_NEWLIB == 1) or CONFIG_ARCH_POSIX
|
||||||
integration_platforms:
|
integration_platforms:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue