-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathtest_dsp.c
327 lines (268 loc) · 12 KB
/
test_dsp.c
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
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include "unity.h"
#include "dsp_platform.h"
#include <malloc.h>
#include "esp_dsp.h"
#define USE_FULL_REPORT
#include "report.inc"
#include "sdkconfig.h"
#include "dsp_tests.h"
static const char *TAG = "common";
// This is template test for future extensions
// Test on this level should test complex functionality
// for many modules
TEST_CASE("test template", "[dsp][ignore]")
{
size_t size_before = xPortGetFreeHeapSize();
size_t size_after = xPortGetFreeHeapSize();
ptrdiff_t heap_diff = size_before - size_after;
heap_diff = abs(heap_diff);
if (heap_diff > 8) {
TEST_ASSERT_EQUAL(0, heap_diff);
}
}
#define dspm_mult_3x3x1_f32_ansi(data1, data2, data3) dspm_mult_f32_ansi(data1, data2, data3, 3, 3, 1)
#define dspm_mult_3x3x3_f32_ansi(data1, data2, data3) dspm_mult_f32_ansi(data1, data2, data3, 3, 3, 3)
#define dspm_mult_4x4x1_f32_ansi(data1, data2, data3) dspm_mult_f32_ansi(data1, data2, data3, 4, 4, 1)
#define dspm_mult_4x4x4_f32_ansi(data1, data2, data3) dspm_mult_f32_ansi(data1, data2, data3, 4, 4, 4)
TEST_CASE("DSP Libary benchmark table", "[dsp]")
{
#ifndef CONFIG_COMPILER_OPTIMIZATION_PERF
ESP_LOGW(TAG, "WARNING: not optimizing for performance, don't use these benchmark results");
#endif
// This test generates benchmark rst table for all available functions
const size_t test_size = 1024;
esp_err_t ret = dsps_fft2r_init_fc32(NULL, CONFIG_DSP_MAX_FFT_SIZE);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Not possible to initialize floating point FFT-R2. Error = 0x%x", ret);
abort();
}
ret = dsps_fft2r_init_sc16(NULL, CONFIG_DSP_MAX_FFT_SIZE);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Not possible to initialize fixed point FFT-R2. Error = 0x%x", ret);
abort();
}
ret = dsps_fft4r_init_fc32(NULL, CONFIG_DSP_MAX_FFT_SIZE);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Not possible to initialize fixed point FFT-R4. Error = 0x%x", ret);
abort();
}
float *data1 = (float *) memalign(16, test_size * 2 * sizeof(float));
float *data2 = (float *) memalign(16, test_size * 2 * sizeof(float));
float *data3 = (float *) memalign(16, test_size * 2 * sizeof(float));
if (!data1 || !data2 || !data3) {
ESP_LOGE(TAG, "Failed to allocate buffers");
abort();
}
memset(data1, 0, test_size * 2 * sizeof(float));
memset(data2, 0, test_size * 2 * sizeof(float));
memset(data3, 0, test_size * 2 * sizeof(float));
fir_f32_t fir1;
dsps_fir_init_f32(&fir1, data1, data2, 256);
fir_f32_t fir2;
dsps_fird_init_f32(&fir2, data1, data2, 256, 4);
float coeffs[5];
dsps_biquad_gen_lpf_f32(coeffs, 0.1, 1);
#if CONFIG_IDF_TARGET_ESP32
REPORT_HEADER_ESP32();
#elif CONFIG_IDF_TARGET_ESP32S3
REPORT_HEADER_ESP32S3();
#elif CONFIG_IDF_TARGET_ESP32P4
REPORT_HEADER_ESP32P4();
#endif
REPORT_SECTION("**Dot Product**");
REPORT_BENCHMARK("dsps_dotprod_f32 for N=256 points",
dsps_dotprod_f32,
dsps_dotprod_f32_ansi,
data1, data2, data3, 256);
REPORT_BENCHMARK("dsps_dotprode_f32 for N=256 points, with step 1",
dsps_dotprode_f32,
dsps_dotprode_f32_ansi,
data1, data2, data3, 256, 1, 1);
REPORT_BENCHMARK("dsps_dotprod_s16 for N=256 points",
dsps_dotprod_s16,
dsps_dotprod_s16_ansi,
(int16_t *)data1, (int16_t *)data2, (int16_t *)data3, 256, 0);
REPORT_SECTION("**FIR Filters**");
REPORT_BENCHMARK("dsps_fir_f32 1024 input samples and 256 coefficients",
dsps_fir_f32,
dsps_fir_f32_ansi,
&fir1, data1, data2, 1024);
REPORT_BENCHMARK("dsps_fird_f32 1024 samples, 256 coeffs and decimation 4",
dsps_fird_f32,
dsps_fird_f32_ansi,
&fir2, data1, data2, 1024 / 4);
REPORT_SECTION("**FFTs Radix-2 32 bit Floating Point**");
REPORT_BENCHMARK("dsps_fft2r_fc32 for 64 complex points",
dsps_fft2r_fc32,
dsps_fft2r_fc32_ansi,
data1, 64);
REPORT_BENCHMARK("dsps_fft2r_fc32 for 128 complex points",
dsps_fft2r_fc32,
dsps_fft2r_fc32_ansi,
data1, 128);
REPORT_BENCHMARK("dsps_fft2r_fc32 for 256 complex points",
dsps_fft2r_fc32,
dsps_fft2r_fc32_ansi,
data1, 256);
REPORT_BENCHMARK("dsps_fft2r_fc32 for 512 complex points",
dsps_fft2r_fc32,
dsps_fft2r_fc32_ansi,
data1, 512);
REPORT_BENCHMARK("dsps_fft2r_fc32 for 1024 complex points",
dsps_fft2r_fc32,
dsps_fft2r_fc32_ansi,
data1, 1024);
REPORT_SECTION("**FFTs Radix-4 32 bit Floating Point**");
REPORT_BENCHMARK("dsps_fft4r_fc32 for 64 complex points",
dsps_fft4r_fc32,
dsps_fft4r_fc32_ansi,
data1, 64);
REPORT_BENCHMARK("dsps_fft4r_fc32 for 256 complex points",
dsps_fft4r_fc32,
dsps_fft4r_fc32_ansi,
data1, 256);
REPORT_BENCHMARK("dsps_fft4r_fc32 for 1024 complex points",
dsps_fft4r_fc32,
dsps_fft4r_fc32_ansi,
data1, 1024);
REPORT_SECTION("**FFTs 16 bit Fixed Point**");
REPORT_BENCHMARK("dsps_fft2r_sc16 for 64 complex points",
dsps_fft2r_sc16,
dsps_fft2r_sc16_ansi,
(int16_t *)data1, 64);
REPORT_BENCHMARK("dsps_fft2r_sc16 for 128 complex points",
dsps_fft2r_sc16,
dsps_fft2r_sc16_ansi,
(int16_t *)data1, 128);
REPORT_BENCHMARK("dsps_fft2r_sc16 for 256 complex points",
dsps_fft2r_sc16,
dsps_fft2r_sc16_ansi,
(int16_t *)data1, 256);
REPORT_BENCHMARK("dsps_fft2r_sc16 for 512 complex points",
dsps_fft2r_sc16,
dsps_fft2r_sc16_ansi,
(int16_t *)data1, 512);
REPORT_BENCHMARK("dsps_fft2r_sc16 for 1024 complex points",
dsps_fft2r_sc16,
dsps_fft2r_sc16_ansi,
(int16_t *)data1, 1024);
REPORT_SECTION("**IIR Filters**");
REPORT_BENCHMARK("dsps_biquad_f32 - biquad filter for 1024 input samples",
dsps_biquad_f32,
dsps_biquad_f32_ansi,
data1, data2, 1024, coeffs, data3);
REPORT_SECTION("**Matrix Multiplication**");
REPORT_BENCHMARK("dspm_mult_f32 - C[16,16] = A[16,16]*B[16,16];",
dspm_mult_f32,
dspm_mult_f32_ansi,
data1, data2, data3, 16, 16, 16);
REPORT_BENCHMARK("dspm_mult_s16 - C[16,16] = A[16,16]*B[16,16];",
dspm_mult_s16,
dspm_mult_s16_ansi,
(int16_t *)data1, (int16_t *)data2, (int16_t *)data3, 16, 16, 16, 0);
REPORT_BENCHMARK("dspm_mult_3x3x1_f32 - C[3,1] = A[3,3]*B[3,1];",
dspm_mult_3x3x1_f32,
dspm_mult_3x3x1_f32_ansi,
data1, data2, data3);
REPORT_BENCHMARK("dspm_mult_3x3x3_f32 - C[3,3] = A[3,3]*B[3,3];",
dspm_mult_3x3x3_f32,
dspm_mult_3x3x3_f32_ansi,
data1, data2, data3);
REPORT_BENCHMARK("dspm_mult_4x4x1_f32 - C[4,1] = A[4,4]*B[4,1];",
dspm_mult_4x4x1_f32,
dspm_mult_4x4x1_f32_ansi,
data1, data2, data3);
REPORT_BENCHMARK("dspm_mult_4x4x4_f32 - C[4,4] = A[4,4]*B[4,4];",
dspm_mult_4x4x4_f32,
dspm_mult_4x4x4_f32_ansi,
data1, data2, data3);
#ifdef CONFIG_IDF_TARGET_ESP32S3
REPORT_SECTION("**Image processing prototypes**");
// s8
{
image2d_t image1 = {data1, 1, 1, 64, 64, 64, 64}; // Image 64x64
image2d_t image2 = {data2, 1, 1, 16, 16, 16, 16}; // Umage 16x16
REPORT_BENCHMARK("dspi_dotprod_s8/u8 - dotproduct of two images 16x16",
dspi_dotprod_s8,
dspi_dotprod_s8_ansi,
&image1, &image2, (int8_t *)data2, 16, 16, 1);
}
{
image2d_t image1 = {data1, 1, 1, 64, 64, 64, 64}; // Image 64x64
image2d_t image2 = {data2, 1, 1, 16, 16, 16, 16}; // Umage 16x16
REPORT_BENCHMARK("dspi_dotprod_off_s8/u8 - dotproduct of two images 16x16",
dspi_dotprod_off_s8,
dspi_dotprod_off_s8_ansi,
&image1, &image2, (int8_t *)data2, 16, 16, 1, 10);
}
{
image2d_t image1 = {data1, 1, 1, 64, 64, 64, 64}; // Image 64x64
image2d_t image2 = {data2, 1, 1, 64, 64, 64, 64}; // Umage 64x64
REPORT_BENCHMARK("dspi_dotprod_s8/u8- dotproduct of two images 64x64",
dspi_dotprod_s8,
dspi_dotprod_s8_ansi,
&image1, &image2, (int8_t *)data2, 64, 64, 1);
}
{
image2d_t image1 = {data1, 1, 1, 64, 64, 64, 64}; // Image 64x64
image2d_t image2 = {data2, 1, 1, 64, 64, 64, 64}; // Umage 64x64
REPORT_BENCHMARK("dspi_dotprod_off_s8/u8 - dotproduct of two images 64x64",
dspi_dotprod_off_s8,
dspi_dotprod_off_s8_ansi,
&image1, &image2, (int8_t *)data2, 64, 64, 1, 10);
}
// s16
{
image2d_t image1 = {data1, 1, 1, 32, 32, 32, 32}; // Image 32x32
image2d_t image2 = {data2, 1, 1, 8, 8, 8, 8}; // Umage 8x8
REPORT_BENCHMARK("dspi_dotprod_s16/u16 - dotproduct of two images 8x8",
dspi_dotprod_s16,
dspi_dotprod_s16_ansi,
&image1, &image2, (int16_t *)data2, 8, 8, 1);
}
{
image2d_t image1 = {data1, 1, 1, 32, 32, 32, 32}; // Image 32x32
image2d_t image2 = {data2, 1, 1, 8, 8, 8, 8}; // Umage 8x8
REPORT_BENCHMARK("dspi_dotprod_off_s16/u16 - dotproduct of two images 8x8",
dspi_dotprod_off_s16,
dspi_dotprod_off_s16_ansi,
&image1, &image2, (int16_t *)data2, 8, 8, 1, 10);
}
{
image2d_t image1 = {data1, 1, 1, 32, 32, 32, 32}; // Image 64x64
image2d_t image2 = {data2, 1, 1, 32, 32, 32, 32}; // Umage 64x64
REPORT_BENCHMARK("dspi_dotprod_s16 - dotproduct of two images 32x32",
dspi_dotprod_s16,
dspi_dotprod_s16_ansi,
&image1, &image2, (int16_t *)data2, 32, 32, 1);
}
{
image2d_t image1 = {data1, 1, 1, 32, 32, 32, 32}; // Image 32x32
image2d_t image2 = {data2, 1, 1, 32, 32, 32, 32}; // Umage 32x32
REPORT_BENCHMARK("dspi_dotprod_off_s16/u16 - dotproduct of two images 32x32",
dspi_dotprod_off_s16,
dspi_dotprod_off_s16_ansi,
&image1, &image2, (int16_t *)data2, 32, 32, 1, 10);
}
#endif
dsps_fft2r_deinit_fc32();
dsps_fft4r_deinit_fc32();
dsps_fft2r_deinit_sc16();
free(data1);
free(data2);
free(data3);
}