tests: lib: cmsis_dsp: matrix: Add Unary Q7 tests for 1.9.0
This commit adds the matrix Unary Q7 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
7b86a9194f
commit
c3647b18e0
7 changed files with 2243 additions and 2 deletions
|
@ -4,10 +4,13 @@ cmake_minimum_required(VERSION 3.20.0)
|
||||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
project(cmsis_dsp_matrix)
|
project(cmsis_dsp_matrix)
|
||||||
|
|
||||||
FILE(GLOB app_sources src/*.c)
|
|
||||||
|
|
||||||
target_sources(app PRIVATE src/main.c)
|
target_sources(app PRIVATE src/main.c)
|
||||||
|
|
||||||
|
target_sources_ifdef(
|
||||||
|
CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q7
|
||||||
|
app PRIVATE src/unary_q7.c
|
||||||
|
)
|
||||||
|
|
||||||
target_sources_ifdef(
|
target_sources_ifdef(
|
||||||
CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q15
|
CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q15
|
||||||
app PRIVATE src/unary_q15.c
|
app PRIVATE src/unary_q15.c
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
# Copyright (c) 2021 Stephanos Ioannidis <root@stephanos.io>
|
# Copyright (c) 2021 Stephanos Ioannidis <root@stephanos.io>
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
config CMSIS_DSP_TEST_MATRIX_UNARY_Q7
|
||||||
|
bool "Test: Matrix Unary Q7"
|
||||||
|
|
||||||
config CMSIS_DSP_TEST_MATRIX_UNARY_Q15
|
config CMSIS_DSP_TEST_MATRIX_UNARY_Q15
|
||||||
bool "Test: Matrix Unary Q15"
|
bool "Test: Matrix Unary Q15"
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ CONFIG_CMSIS_DSP=y
|
||||||
CONFIG_CMSIS_DSP_MATRIX=y
|
CONFIG_CMSIS_DSP_MATRIX=y
|
||||||
|
|
||||||
# Test Options
|
# Test Options
|
||||||
|
CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q7=y
|
||||||
CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q15=y
|
CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q15=y
|
||||||
CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q31=y
|
CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q31=y
|
||||||
CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_F32=y
|
CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_F32=y
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <ztest.h>
|
#include <ztest.h>
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
|
|
||||||
|
extern void test_matrix_unary_q7(void);
|
||||||
extern void test_matrix_unary_q15(void);
|
extern void test_matrix_unary_q15(void);
|
||||||
extern void test_matrix_unary_q31(void);
|
extern void test_matrix_unary_q31(void);
|
||||||
extern void test_matrix_unary_f32(void);
|
extern void test_matrix_unary_f32(void);
|
||||||
|
@ -21,6 +22,9 @@ extern void test_matrix_binary_f64(void);
|
||||||
|
|
||||||
void test_main(void)
|
void test_main(void)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q7
|
||||||
|
test_matrix_unary_q7();
|
||||||
|
#endif
|
||||||
#ifdef CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q15
|
#ifdef CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q15
|
||||||
test_matrix_unary_q15();
|
test_matrix_unary_q15();
|
||||||
#endif
|
#endif
|
||||||
|
|
172
tests/lib/cmsis_dsp/matrix/src/unary_q7.c
Normal file
172
tests/lib/cmsis_dsp/matrix/src/unary_q7.c
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
/*
|
||||||
|
* 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.h>
|
||||||
|
#include "../../common/test_common.h"
|
||||||
|
|
||||||
|
#include "unary_q7.pat"
|
||||||
|
|
||||||
|
#define SNR_ERROR_THRESH ((float32_t)20)
|
||||||
|
#define SNR_ERROR_THRESH_LOW ((float32_t)11)
|
||||||
|
#define ABS_ERROR_THRESH_Q7 ((q7_t)2)
|
||||||
|
|
||||||
|
#define NUM_MATRICES (ARRAY_SIZE(in_dims) / 2)
|
||||||
|
#define MAX_MATRIX_DIM (47)
|
||||||
|
|
||||||
|
#define OP1_TRANS (1)
|
||||||
|
#define OP2V_VEC_MULT (0)
|
||||||
|
|
||||||
|
static void test_op1(int op, const q7_t *ref, size_t length, bool transpose)
|
||||||
|
{
|
||||||
|
size_t index;
|
||||||
|
uint16_t *dims = (uint16_t *)in_dims;
|
||||||
|
q7_t *tmp1, *output;
|
||||||
|
uint16_t rows, columns;
|
||||||
|
arm_status status;
|
||||||
|
|
||||||
|
arm_matrix_instance_q7 mat_in1;
|
||||||
|
arm_matrix_instance_q7 mat_out;
|
||||||
|
|
||||||
|
/* Allocate buffers */
|
||||||
|
tmp1 = malloc(MAX_MATRIX_DIM * MAX_MATRIX_DIM * sizeof(q7_t));
|
||||||
|
zassert_not_null(tmp1, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
output = malloc(length * sizeof(q7_t));
|
||||||
|
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
/* Initialise contexts */
|
||||||
|
mat_in1.pData = tmp1;
|
||||||
|
mat_out.pData = output;
|
||||||
|
|
||||||
|
/* Iterate matrices */
|
||||||
|
for (index = 0; index < NUM_MATRICES; index++) {
|
||||||
|
rows = *dims++;
|
||||||
|
columns = *dims++;
|
||||||
|
|
||||||
|
/* Initialise matrix dimensions */
|
||||||
|
mat_in1.numRows = rows;
|
||||||
|
mat_in1.numCols = columns;
|
||||||
|
mat_out.numRows = transpose ? columns : rows;
|
||||||
|
mat_out.numCols = transpose ? rows : columns;
|
||||||
|
|
||||||
|
/* Load matrix data */
|
||||||
|
memcpy(mat_in1.pData, in_com1, rows * columns * sizeof(q7_t));
|
||||||
|
|
||||||
|
/* Run test function */
|
||||||
|
switch (op) {
|
||||||
|
case OP1_TRANS:
|
||||||
|
status = arm_mat_trans_q7(&mat_in1, &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_q7(length, output, ref, SNR_ERROR_THRESH),
|
||||||
|
ASSERT_MSG_SNR_LIMIT_EXCEED);
|
||||||
|
|
||||||
|
zassert_true(
|
||||||
|
test_near_equal_q7(length, output, ref, ABS_ERROR_THRESH_Q7),
|
||||||
|
ASSERT_MSG_ABS_ERROR_LIMIT_EXCEED);
|
||||||
|
|
||||||
|
/* Free buffers */
|
||||||
|
free(tmp1);
|
||||||
|
free(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_TEST_VARIANT4(op1, arm_mat_trans_q7, OP1_TRANS,
|
||||||
|
ref_trans, ARRAY_SIZE(ref_trans), true);
|
||||||
|
|
||||||
|
static void test_op2v(int op, const q7_t *ref, size_t length)
|
||||||
|
{
|
||||||
|
size_t index;
|
||||||
|
const uint16_t *dims = in_dims;
|
||||||
|
q7_t *tmp1, *vec, *output_buf, *output;
|
||||||
|
uint16_t rows, internal;
|
||||||
|
|
||||||
|
arm_matrix_instance_q7 mat_in1;
|
||||||
|
|
||||||
|
/* Allocate buffers */
|
||||||
|
tmp1 = malloc(2 * MAX_MATRIX_DIM * MAX_MATRIX_DIM * sizeof(q7_t));
|
||||||
|
zassert_not_null(tmp1, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
vec = malloc(2 * MAX_MATRIX_DIM * sizeof(q7_t));
|
||||||
|
zassert_not_null(vec, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
output_buf = malloc(length * sizeof(q7_t));
|
||||||
|
zassert_not_null(output_buf, ASSERT_MSG_BUFFER_ALLOC_FAILED);
|
||||||
|
|
||||||
|
/* Initialise contexts */
|
||||||
|
mat_in1.pData = tmp1;
|
||||||
|
output = output_buf;
|
||||||
|
|
||||||
|
/* Iterate matrices */
|
||||||
|
for (index = 0; index < NUM_MATRICES; index++) {
|
||||||
|
rows = *dims++;
|
||||||
|
internal = *dims++;
|
||||||
|
|
||||||
|
/* Initialise matrix dimensions */
|
||||||
|
mat_in1.numRows = rows;
|
||||||
|
mat_in1.numCols = internal;
|
||||||
|
|
||||||
|
/* Load matrix data */
|
||||||
|
memcpy(mat_in1.pData, in_com1,
|
||||||
|
2 * rows * internal * sizeof(q7_t));
|
||||||
|
memcpy(vec, in_vec1, 2 * internal * sizeof(q7_t));
|
||||||
|
|
||||||
|
/* Run test function */
|
||||||
|
switch (op) {
|
||||||
|
case OP2V_VEC_MULT:
|
||||||
|
arm_mat_vec_mult_q7(&mat_in1, vec, output);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
zassert_unreachable("invalid operation");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment output pointer */
|
||||||
|
output += rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Validate output */
|
||||||
|
zassert_true(
|
||||||
|
test_snr_error_q7(length, output_buf, ref, SNR_ERROR_THRESH_LOW),
|
||||||
|
ASSERT_MSG_SNR_LIMIT_EXCEED);
|
||||||
|
|
||||||
|
zassert_true(
|
||||||
|
test_near_equal_q7(length, output_buf, ref, ABS_ERROR_THRESH_Q7),
|
||||||
|
ASSERT_MSG_ABS_ERROR_LIMIT_EXCEED);
|
||||||
|
|
||||||
|
/* Free buffers */
|
||||||
|
free(tmp1);
|
||||||
|
free(vec);
|
||||||
|
free(output_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_TEST_VARIANT3(op2v, arm_mat_vec_mult_q7, OP2V_VEC_MULT,
|
||||||
|
ref_vec_mult, ARRAY_SIZE(ref_vec_mult));
|
||||||
|
|
||||||
|
void test_matrix_unary_q7(void)
|
||||||
|
{
|
||||||
|
ztest_test_suite(matrix_unary_q7,
|
||||||
|
ztest_unit_test(test_op1_arm_mat_trans_q7),
|
||||||
|
ztest_unit_test(test_op2v_arm_mat_vec_mult_q7)
|
||||||
|
);
|
||||||
|
|
||||||
|
ztest_run_test_suite(matrix_unary_q7);
|
||||||
|
}
|
2034
tests/lib/cmsis_dsp/matrix/src/unary_q7.pat
generated
Normal file
2034
tests/lib/cmsis_dsp/matrix/src/unary_q7.pat
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -3,6 +3,30 @@ tests:
|
||||||
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
|
||||||
tags: cmsis_dsp
|
tags: cmsis_dsp
|
||||||
skip: true
|
skip: true
|
||||||
|
libraries.cmsis_dsp.matrix.unary_q7:
|
||||||
|
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
|
||||||
|
min_flash: 128
|
||||||
|
min_ram: 64
|
||||||
|
extra_args: CONF_FILE=prj_base.conf
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q7=y
|
||||||
|
libraries.cmsis_dsp.matrix.unary_q7.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
|
||||||
|
min_flash: 128
|
||||||
|
min_ram: 64
|
||||||
|
extra_args: CONF_FILE=prj_base.conf
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_CMSIS_DSP_TEST_MATRIX_UNARY_Q7=y
|
||||||
|
- CONFIG_FPU=y
|
||||||
libraries.cmsis_dsp.matrix.unary_q15:
|
libraries.cmsis_dsp.matrix.unary_q15:
|
||||||
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