Skip to content

Commit f09c138

Browse files
committed
Merge branch 'feature/mat_matrix_subset' into 'master'
New mat class methods pt1 See merge request idf/esp-dsp!104
2 parents 74e23cd + 59a08aa commit f09c138

File tree

69 files changed

+3811
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3811
-98
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ exmaples/**/managed_components
3232
test_app/build
3333
test_app/sdkconfig
3434
test_app/sdkconfig.old
35+
test_app/dependencies.lock
3536

3637
# Doc build artifacts
3738
docs/_build/
@@ -54,3 +55,6 @@ coverage_report/
5455

5556
# VS Code Settings
5657
.vscode/
58+
59+
# incorrect build locations
60+
build/

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Application for Azure IoT board
1313
- FIR f32 decimation filter optimized for esp32s3
1414
- Add Esp32-LyraT board application
15+
- New methods for Mat class to support sub-matrix operations
1516

1617
### Fixed
1718
- Add Bi-Quad for esp32s3 into common CMakeLists.txt

CMakeLists.txt

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,32 @@ set(srcs "modules/common/misc/dsps_pwroftwo.cpp"
3131
"modules/dotprod/fixed/dspi_dotprod_u8_aes3.S"
3232
"modules/dotprod/fixed/dspi_dotprod_off_u8_aes3.S"
3333
"modules/dotprod/fixed/dspi_dotprod_off_s8_aes3.S"
34-
3534

36-
"modules/matrix/float/dspm_mult_3x3x1_f32_ae32.S"
37-
"modules/matrix/float/dspm_mult_3x3x3_f32_ae32.S"
38-
"modules/matrix/float/dspm_mult_4x4x1_f32_ae32.S"
39-
"modules/matrix/float/dspm_mult_4x4x4_f32_ae32.S"
40-
"modules/matrix/float/dspm_mult_f32_ae32.S"
41-
"modules/matrix/float/dspm_mult_f32_aes3.S"
42-
"modules/matrix/float/dspm_mult_f32_ansi.c"
43-
"modules/matrix/fixed/dspm_mult_s16_ae32.S"
44-
"modules/matrix/fixed/dspm_mult_s16_m_ae32_vector.S"
45-
"modules/matrix/fixed/dspm_mult_s16_m_ae32.S"
46-
"modules/matrix/fixed/dspm_mult_s16_ansi.c"
47-
"modules/matrix/fixed/dspm_mult_s16_aes3.S"
35+
"modules/matrix/mul/float/dspm_mult_3x3x1_f32_ae32.S"
36+
"modules/matrix/mul/float/dspm_mult_3x3x3_f32_ae32.S"
37+
"modules/matrix/mul/float/dspm_mult_4x4x1_f32_ae32.S"
38+
"modules/matrix/mul/float/dspm_mult_4x4x4_f32_ae32.S"
39+
"modules/matrix/mul/float/dspm_mult_f32_ae32.S"
40+
"modules/matrix/mul/float/dspm_mult_f32_aes3.S"
41+
"modules/matrix/mul/float/dspm_mult_f32_ansi.c"
42+
"modules/matrix/mul/float/dspm_mult_ex_f32_ansi.c"
43+
"modules/matrix/mul/float/dspm_mult_ex_f32_ae32.S"
44+
"modules/matrix/mul/float/dspm_mult_ex_f32_aes3.S"
45+
"modules/matrix/mul/fixed/dspm_mult_s16_ae32.S"
46+
"modules/matrix/mul/fixed/dspm_mult_s16_m_ae32_vector.S"
47+
"modules/matrix/mul/fixed/dspm_mult_s16_m_ae32.S"
48+
"modules/matrix/mul/fixed/dspm_mult_s16_ansi.c"
49+
"modules/matrix/mul/fixed/dspm_mult_s16_aes3.S"
50+
"modules/matrix/add/float/dspm_add_f32_ansi.c"
51+
"modules/matrix/add/float/dspm_add_f32_ae32.S"
52+
"modules/matrix/addc/float/dspm_addc_f32_ansi.c"
53+
"modules/matrix/addc/float/dspm_addc_f32_ae32.S"
54+
"modules/matrix/mulc/float/dspm_mulc_f32_ansi.c"
55+
"modules/matrix/mulc/float/dspm_mulc_f32_ae32.S"
56+
"modules/matrix/sub/float/dspm_sub_f32_ansi.c"
57+
"modules/matrix/sub/float/dspm_sub_f32_ae32.S"
4858
"modules/matrix/mat/mat.cpp"
59+
4960
"modules/math/mulc/float/dsps_mulc_f32_ansi.c"
5061
"modules/math/addc/float/dsps_addc_f32_ansi.c"
5162
"modules/math/mulc/fixed/dsps_mulc_s16_ansi.c"
@@ -75,7 +86,7 @@ set(srcs "modules/common/misc/dsps_pwroftwo.cpp"
7586
"modules/fft/fixed/dsps_fft2r_sc16_ae32.S"
7687
"modules/fft/fixed/dsps_fft2r_sc16_ansi.c"
7788
"modules/fft/fixed/dsps_fft2r_sc16_aes3.S"
78-
89+
7990
"modules/dct/float/dsps_dct_f32.c"
8091
"modules/support/snr/float/dsps_snr_f32.cpp"
8192
"modules/support/sfdr/float/dsps_sfdr_f32.cpp"
@@ -143,11 +154,17 @@ set(include_dirs "modules/dotprod/include"
143154
"modules/math/addc/include"
144155
"modules/math/mulc/include"
145156
"modules/math/sqrt/include"
157+
"modules/matrix/mul/include"
158+
"modules/matrix/add/include"
159+
"modules/matrix/addc/include"
160+
"modules/matrix/mulc/include"
161+
"modules/matrix/sub/include"
146162
"modules/matrix/include"
147163
"modules/fft/include"
148164
"modules/dct/include"
149165
"modules/conv/include"
150166
"modules/common/include"
167+
"modules/matrix/mul/test/include"
151168
# EKF files
152169
"modules/kalman/ekf/include"
153170
"modules/kalman/ekf_imu13states/include"

component.mk

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ COMPONENT_ADD_INCLUDEDIRS := modules/dotprod/include \
1616
modules/math/addc/include \
1717
modules/math/mulc/include \
1818
modules/math/sqrt/include \
19+
modules/matrix/add/include \
20+
modules/matrix/addc/include \
21+
modules/matrix/mul/include \
22+
modules/matrix/mulc/include \
23+
modules/matrix/sub/include \
1924
modules/matrix/include \
2025
modules/fft/include \
2126
modules/dct/include \
@@ -31,8 +36,17 @@ COMPONENT_SRCDIRS :=. \
3136
modules/dotprod/float \
3237
modules/dotprod/fixed \
3338
modules/matrix \
34-
modules/matrix/float \
35-
modules/matrix/fixed \
39+
modules/matrix/add \
40+
modules/matrix/add/float \
41+
modules/matrix/addc \
42+
modules/matrix/addc/float \
43+
modules/matrix/mul \
44+
modules/matrix/mul/float \
45+
modules/matrix/mul/fixed \
46+
modules/matrix/mulc \
47+
modules/matrix/mulc/float \
48+
modules/matrix/sub \
49+
modules/matrix/sub/float \
3650
modules/matrix/mat \
3751
modules/math \
3852
modules/math/mulc \

docs/Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ INPUT = \
3535
$(PROJECT_PATH)/modules/math/add/include/dsps_add.h \
3636
$(PROJECT_PATH)/modules/math/sub/include/dsps_sub.h \
3737
$(PROJECT_PATH)/modules/math/mul/include/dsps_mul.h \
38-
$(PROJECT_PATH)/modules/matrix/include/dspm_mult.h \
38+
$(PROJECT_PATH)/modules/matrix/mul/include/dspm_mult.h \
3939
$(PROJECT_PATH)/modules/matrix/include/mat.h \
4040
$(PROJECT_PATH)/modules/conv/include/dsps_conv.h \
4141
$(PROJECT_PATH)/modules/conv/include/dsps_corr.h \

idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.4.8"
1+
version: "1.4.9"
22

33
description: ESP-DSP is the official DSP library for Espressif SoCs.
44
url: https://github.com/espressif/esp-dsp

modules/common/include/esp_dsp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
1+
// Copyright 2018-2023 Espressif Systems (Shanghai) PTE LTD
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ extern "C"
4545
#include "dsps_dct.h"
4646

4747
// Matrix operations
48-
#include "dspm_mult.h"
48+
#include "dspm_matrix.h"
4949

5050
// Support functions
5151
#include "dsps_view.h"

modules/fir/fixed/dsps_fird_s16_ansi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
#include "dsps_fir.h"
8-
#include "esp_dsp.h"
98

109
int32_t dsps_fird_s16_ansi(fir_s16_t *fir, const int16_t *input, int16_t *output, int32_t len)
1110
{

modules/kalman/ekf_imu13states/ekf_imu13states.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void ekf_imu13states::Test()
117117

118118
void ekf_imu13states::TestFull(bool enable_att)
119119
{
120-
int total_N = 4096;
120+
int total_N = 2048;
121121
float pi = std::atan(1) * 4;
122122
float gyro_err_data[] = {0.1, 0.2, 0.3}; // static constatnt error
123123
dspm::Mat gyro_err(gyro_err_data, 3, 1);

modules/kalman/ekf_imu13states/test/test_ekf_imu13states.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ TEST_CASE("ekf_imu13states functionality gyro and magn", "[dspm]")
5151
unsigned int end_b = xthal_get_ccount();
5252
ESP_LOGI(TAG, "Total time %i (K cycles)", (end_b - start_b)/1000);
5353

54-
TEST_ASSERT_LESS_THAN(100, (int)(1000*abs(ekf13->X.data[4] - 0.1)));
55-
TEST_ASSERT_LESS_THAN(100, (int)(1000*abs(ekf13->X.data[5] - 0.2)));
56-
TEST_ASSERT_LESS_THAN(100, (int)(1000*abs(ekf13->X.data[6] - 0.3)));
54+
TEST_ASSERT_LESS_THAN(300, (int)(1000*abs(ekf13->X.data[4] - 0.1)));
55+
TEST_ASSERT_LESS_THAN(300, (int)(1000*abs(ekf13->X.data[5] - 0.2)));
56+
TEST_ASSERT_LESS_THAN(300, (int)(1000*abs(ekf13->X.data[6] - 0.3)));
5757
printf("Expected result = %i, calculated result = %i\n", 100, (int)(1000*ekf13->X.data[4] + 0.5));
5858
printf("Expected result = %i, calculated result = %i\n", 200, (int)(1000*ekf13->X.data[5] + 0.5));
5959
printf("Expected result = %i, calculated result = %i\n", 300, (int)(1000*ekf13->X.data[6] + 0.5));

modules/math/mulc/include/dsps_mulc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ esp_err_t dsps_mulc_f32_ae32(const float *input, float *output, int len, float C
4848
esp_err_t dsps_mulc_s16_ae32(const int16_t *input, int16_t *output, int len, int16_t C, int step_in, int step_out);
4949
esp_err_t dsps_mulc_s16_ansi(const int16_t *input, int16_t *output, int len, int16_t C, int step_in, int step_out);
5050

51-
/**@}*/
5251

5352
#ifdef __cplusplus
5453
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "dspm_add_platform.h"
8+
#if (dspm_add_f32_ae32_enabled == 1)
9+
10+
// This is an add function for sub-matrices for ESP32 processor
11+
.text
12+
.align 4
13+
.global dspm_add_f32_ae32
14+
.type dspm_add_f32_ae32,@function
15+
// The function implements the following C code:
16+
// esp_err_t dspm_add_f32_ansi(const float *input1, const float *input2, float *output, int rows, int cols, int padd1, int padd2, int padd_out, int step1, int step2, int step_out);
17+
18+
dspm_add_f32_ae32:
19+
// input1 - a2
20+
// input2 - a3
21+
// output - a4
22+
// rows - a5
23+
// cols - a6
24+
// padd1 - a7
25+
// padd2 - a8
26+
// padd_out - a9
27+
// step1 - a10
28+
// step2 - a11
29+
// step_out - a12
30+
31+
entry a1, 16
32+
33+
l32i.n a8, a1, 16 // padd2
34+
l32i.n a9, a1, 20 // padd_out
35+
l32i.n a10, a1, 24 // step1
36+
l32i.n a11, a1, 24 // step2
37+
l32i.n a12, a1, 24 // step_out
38+
39+
slli a10, a10, 2 // a10 - step1 << 2
40+
slli a11, a11, 2 // a11 - step2 << 2
41+
slli a12, a12, 2 // a12 - step_out << 2
42+
43+
.outer_loop_add_f32_ae32:
44+
45+
loopnez a6, .loop_add_f32_ae32
46+
lsxp f0, a2, a10 // load input1 to f0, increment input1 (input1_ptr+=step1)
47+
lsxp f1, a3, a11 // load input2 to f1, increment input2 (input2_ptr+=step2)
48+
49+
add.s f2, f0, f1 // f2 = f0 + f1
50+
ssxp f2, a4, a12 // save result f2 to output a4, increment output (output_ptr+=step_out)
51+
.loop_add_f32_ae32:
52+
53+
addx4 a3, a8, a3 // input2_ptr += (padd2 << 2);
54+
addx4 a2, a7, a2 // input1_ptr += (padd1 << 2);
55+
addx4 a4, a9, a4 // output_ptr += (padd_out << 2);
56+
addi.n a5, a5, -1 // rows - 1
57+
58+
bnez a5, .outer_loop_add_f32_ae32
59+
60+
movi.n a2, 0 // return status ESP_OK
61+
retw.n
62+
63+
#endif // dspm_add_f32_ae32_enabled
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
8+
#include "dspm_add.h"
9+
10+
esp_err_t dspm_add_f32_ansi(const float *input1, const float *input2, float *output, int rows, int cols, int padd1, int padd2, int padd_out, int step1, int step2, int step_out)
11+
{
12+
if (NULL == input1) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
13+
if (NULL == input2) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
14+
if (NULL == output) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
15+
16+
if (rows <= 0) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
17+
if (cols <= 0) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
18+
19+
if (padd1 < 0) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
20+
if (padd2 < 0) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
21+
if (padd_out < 0) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
22+
23+
if (step1 <= 0) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
24+
if (step2 <= 0) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
25+
if (step_out <= 0) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
26+
27+
const int ptr_input1_step = cols + padd1;
28+
const int ptr_input2_step = cols + padd2;
29+
const int ptr_output_step = cols + padd_out;
30+
float *ptr_input1 = (float *)input1;
31+
float *ptr_input2 = (float *)input2;
32+
33+
for (int row = 0; row < rows; row++) {
34+
for (int col = 0; col < cols; col++) {
35+
output[col * step_out] = ptr_input1[col * step1] + ptr_input2[col * step2];
36+
}
37+
ptr_input1 += ptr_input1_step;
38+
ptr_input2 += ptr_input2_step;
39+
output += ptr_output_step;
40+
}
41+
return ESP_OK;
42+
}

modules/matrix/add/include/dspm_add.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
8+
#ifndef _dspm_add_H_
9+
#define _dspm_add_H_
10+
#include "dsp_err.h"
11+
12+
#include "dspm_add_platform.h"
13+
14+
15+
#ifdef __cplusplus
16+
extern "C"
17+
{
18+
#endif
19+
20+
21+
/**@{*/
22+
/**
23+
* @brief add two arrays with paddings (add two sub-matrices)
24+
*
25+
* The function adds two arrays defined as sub-matrices with paddings
26+
* out[row * ptr_step_out + col * step_out] = in1[row * ptr_step_in1 + col * step1] + in2[row * ptr_step_in2 + col * step2];
27+
* The implementation use ANSI C and could be compiled and run on any platform
28+
*
29+
* @param[in] input1: input array 1
30+
* @param[in] input2: input array 2
31+
* @param[out] output: output array
32+
* @param[in] rows: matrix rows
33+
* @param[in] cols: matrix cols
34+
* @param[in] padd1: input array 1 padding
35+
* @param[in] padd2: input array 2 padding
36+
* @param[in] padd_out: output array padding
37+
* @param[in] step1: step over input array 1 (by default should be 1)
38+
* @param[in] step2: step over input array 2 (by default should be 1)
39+
* @param[in] step_out: step over output array (by default should be 1)
40+
*
41+
* @return
42+
* - ESP_OK on success
43+
* - One of the error codes from DSP library
44+
*/
45+
esp_err_t dspm_add_f32_ansi(const float *input1, const float *input2, float *output, int rows, int cols, int padd1, int padd2, int padd_out, int step1, int step2, int step_out);
46+
esp_err_t dspm_add_f32_ae32(const float *input1, const float *input2, float *output, int rows, int cols, int padd1, int padd2, int padd_out, int step1, int step2, int step_out);
47+
/**@}*/
48+
49+
#ifdef __cplusplus
50+
}
51+
#endif
52+
53+
#if CONFIG_DSP_OPTIMIZED
54+
55+
#if (dspm_add_f32_ae32_enabled == 1)
56+
#define dspm_add_f32 dspm_add_f32_ae32
57+
#else
58+
#define dspm_add_f32 dspm_add_f32_ansi
59+
#endif
60+
61+
#else // CONFIG_DSP_OPTIMIZED
62+
#define dspm_add_f32 dspm_add_f32_ansi
63+
#endif // CONFIG_DSP_OPTIMIZED
64+
65+
#endif // _dspm_add_H_
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef _dspm_add_platform_H_
2+
#define _dspm_add_platform_H_
3+
4+
#include "sdkconfig.h"
5+
6+
#ifdef __XTENSA__
7+
#include <xtensa/config/core-isa.h>
8+
#include <xtensa/config/core-matmap.h>
9+
10+
11+
#if ((XCHAL_HAVE_FP == 1) && (XCHAL_HAVE_LOOPS == 1))
12+
13+
#define dspm_add_f32_ae32_enabled 1
14+
15+
#endif
16+
17+
#endif // __XTENSA__
18+
19+
20+
#endif // _dspm_add_platform_H_

0 commit comments

Comments
 (0)