add some code
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
// 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 <math.h>
|
||||
#include "unity.h"
|
||||
#include "dsp_platform.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "esp_attr.h"
|
||||
#include "esp_dsp.h"
|
||||
#include <malloc.h>
|
||||
#include "dsp_tests.h"
|
||||
|
||||
static const char *TAG = "dspi_conv";
|
||||
|
||||
TEST_CASE("dspi_conv_f32_ansi functionality", "[dspi]")
|
||||
{
|
||||
int max_N = 8192;
|
||||
|
||||
float *data1 = (float *)memalign(16, max_N * sizeof(float));
|
||||
float *data2 = (float *)memalign(16, max_N * sizeof(float));
|
||||
float *data3 = (float *)memalign(16, max_N * sizeof(float));
|
||||
|
||||
image2d_t image1 = {data1, 1, 1, 8, 8, 8, 8}; // Image 8x8
|
||||
image2d_t image2 = {data2, 1, 1, 4, 4, 4, 4}; // Image 4x4
|
||||
image2d_t image3 = {data3, 1, 1, 10, 10, 0, 0}; // Image 8x8
|
||||
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
data1[i] = 0;
|
||||
data2[i] = 0;
|
||||
data3[i] = 0;
|
||||
}
|
||||
|
||||
for (int y = 0 ; y < image1.stride_y / image1.step_y ; y++) {
|
||||
for (int x = 0 ; x < image1.stride_x / image1.step_x ; x++) {
|
||||
data1[y * image1.stride_x * image1.step_y + x * image1.step_x] = 1;
|
||||
}
|
||||
}
|
||||
for (int y = 0 ; y < image2.stride_y / image2.step_y ; y++) {
|
||||
for (int x = 0 ; x < image2.stride_x / image2.step_x ; x++) {
|
||||
data2[y * image2.stride_x * image2.step_y + x * image2.step_x] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
dspi_conv_f32_ansi(&image1, &image2, &image3);
|
||||
// x , y
|
||||
TEST_ASSERT_EQUAL(data3[0 * image3.stride_x * image3.step_y + 0 * image3.step_x], 9);
|
||||
TEST_ASSERT_EQUAL(data3[0 * image3.stride_x * image3.step_y + 6 * image3.step_x], 9);
|
||||
TEST_ASSERT_EQUAL(data3[6 * image3.stride_x * image3.step_y + 6 * image3.step_x], 9);
|
||||
TEST_ASSERT_EQUAL(data3[0 * image3.stride_x * image3.step_y + 6 * image3.step_x], 9);
|
||||
|
||||
TEST_ASSERT_EQUAL(data3[7 * image3.stride_x * image3.step_y + 0 * image3.step_x], 6);
|
||||
TEST_ASSERT_EQUAL(data3[7 * image3.stride_x * image3.step_y + 6 * image3.step_x], 6);
|
||||
TEST_ASSERT_EQUAL(data3[0 * image3.stride_x * image3.step_y + 7 * image3.step_x], 6);
|
||||
TEST_ASSERT_EQUAL(data3[7 * image3.stride_x * image3.step_y + 7 * image3.step_x], 4);
|
||||
|
||||
TEST_ASSERT_EQUAL(data3[1 * image3.stride_x * image3.step_y + 1 * image3.step_x], 16);
|
||||
TEST_ASSERT_EQUAL(data3[5 * image3.stride_x * image3.step_y + 1 * image3.step_x], 16);
|
||||
TEST_ASSERT_EQUAL(data3[1 * image3.stride_x * image3.step_y + 5 * image3.step_x], 16);
|
||||
TEST_ASSERT_EQUAL(data3[5 * image3.stride_x * image3.step_y + 5 * image3.step_x], 16);
|
||||
TEST_ASSERT_EQUAL(data3[3 * image3.stride_x * image3.step_y + 3 * image3.step_x], 16);
|
||||
|
||||
free(data1);
|
||||
free(data2);
|
||||
free(data3);
|
||||
}
|
||||
|
||||
TEST_CASE("dspi_conv_f32_ansi benchmark", "[dspi]")
|
||||
{
|
||||
int max_N = 8192;
|
||||
|
||||
float *data1 = (float *)memalign(16, max_N * sizeof(float));
|
||||
float *data2 = (float *)memalign(16, max_N * sizeof(float));
|
||||
float *data3 = (float *)memalign(16, max_N * sizeof(float));
|
||||
|
||||
image2d_t image1 = {data1, 1, 1, 8, 8, 8, 8}; // Image 8x8
|
||||
image2d_t image2 = {data2, 1, 1, 4, 4, 4, 4}; // Image 4x4
|
||||
image2d_t image3 = {data3, 1, 1, 10, 10, 0, 0}; // Image 8x8
|
||||
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
data1[i] = 0;
|
||||
data2[i] = 0;
|
||||
data3[i] = 0;
|
||||
}
|
||||
|
||||
for (int y = 0 ; y < image1.stride_y / image1.step_y ; y++) {
|
||||
for (int x = 0 ; x < image1.stride_x / image1.step_x ; x++) {
|
||||
data1[y * image1.stride_x * image1.step_y + x * image1.step_x] = 1;
|
||||
}
|
||||
}
|
||||
for (int y = 0 ; y < image2.stride_y / image2.step_y ; y++) {
|
||||
for (int x = 0 ; x < image2.stride_x / image2.step_x ; x++) {
|
||||
data2[y * image2.stride_x * image2.step_y + x * image2.step_x] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int start_b = dsp_get_cpu_cycle_count();
|
||||
dspi_conv_f32_ansi(&image1, &image2, &image3);
|
||||
unsigned int end_b = dsp_get_cpu_cycle_count();
|
||||
float cycles = end_b - start_b;
|
||||
ESP_LOGI(TAG, "dspi_conv_f32_ansi - %f cycles", cycles);
|
||||
|
||||
free(data1);
|
||||
free(data2);
|
||||
free(data3);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// 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 "esp_log.h"
|
||||
|
||||
#include "dsp_tests.h"
|
||||
#include "dsps_ccorr.h"
|
||||
#include "esp_attr.h"
|
||||
|
||||
static const char *TAG = "dsps_ccorr";
|
||||
|
||||
#define lenA 8
|
||||
#define lenB 4
|
||||
|
||||
static float inputA[lenA];
|
||||
static float inputB[lenB];
|
||||
static float output[lenA + lenB - 1 + 2];
|
||||
static float output_ref[lenA + lenB - 1 + 2];
|
||||
|
||||
TEST_CASE("dsps_ccorr_f32 functionality", "[dsps]")
|
||||
{
|
||||
for (int i = 0 ; i < lenA ; i++) {
|
||||
inputA[i] = i + 3;
|
||||
}
|
||||
for (int i = 0 ; i < lenB ; i++) {
|
||||
inputB[i] = i + 10;
|
||||
}
|
||||
for (int i = 0 ; i < (lenA + lenB + 2 - 1); i++) {
|
||||
output[i] = -1;
|
||||
output_ref[i] = -1;
|
||||
}
|
||||
dsps_ccorr_f32(inputA, lenA, inputB, lenB, &output[0]);
|
||||
dsps_ccorr_f32_ansi(inputA, lenA, inputB, lenB, &output_ref[0]);
|
||||
for (int i = 0; i < (lenA + lenB - 1) + 2; i++) {
|
||||
ESP_LOGI(TAG, "Data[%i] = %2.2f, expected = %2.2f", i, output[i], output_ref[i]);
|
||||
}
|
||||
for (size_t i = 0; i < (lenA + lenB - 1) + 2; i++) {
|
||||
TEST_ASSERT_EQUAL(output_ref[i], output[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("dsps_ccorr_f32 benchmark", "[dsps]")
|
||||
{
|
||||
int max_N = 1024;
|
||||
int ccorr_size = 64;
|
||||
float *x = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(x);
|
||||
float *y = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(y);
|
||||
float *z = (float *)malloc((max_N + ccorr_size - 1) * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(z);
|
||||
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
x[i] = 0;
|
||||
y[i] = 1000;
|
||||
}
|
||||
|
||||
unsigned int start_b = dsp_get_cpu_cycle_count();
|
||||
dsps_ccorr_f32(x, max_N, y, ccorr_size, &z[0]);
|
||||
unsigned int end_b = dsp_get_cpu_cycle_count();
|
||||
|
||||
float cycles = end_b - start_b;
|
||||
ESP_LOGI(TAG, "dsps_ccorr_f32 - %f cycles for signal %i and pattern %i", cycles, max_N, ccorr_size);
|
||||
free(x);
|
||||
free(y);
|
||||
free(z);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
// Copyright 2018-2023 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 <math.h>
|
||||
#include "unity.h"
|
||||
#include "dsp_platform.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "dsps_ccorr.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_dsp.h"
|
||||
|
||||
static const char *TAG = "dsps_ccorr";
|
||||
|
||||
#define lenA 20
|
||||
#define lenB 20
|
||||
|
||||
static float inputA[lenA];
|
||||
static float inputB[lenB];
|
||||
static float output_fwd[lenA + lenB - 1 + 2];
|
||||
static float output_back[lenA + lenB - 1 + 2];
|
||||
|
||||
TEST_CASE("dsps_ccorr_f32_ansi functionality", "[dsps]")
|
||||
{
|
||||
for (size_t la = 1; la < lenA; la++) {
|
||||
for (size_t lb = 1; lb < lenB; lb++) {
|
||||
for (int i = 0 ; i < lenA ; i++) {
|
||||
inputA[i] = (float)rand() / (float)INT32_MAX;
|
||||
}
|
||||
for (int i = 0 ; i < lenB ; i++) {
|
||||
inputB[i] = (float)rand() / (float)INT32_MAX;
|
||||
}
|
||||
for (int i = 0 ; i < (lenA + lenB - 1 + 2); i++) {
|
||||
output_fwd[i] = -1;
|
||||
output_back[i] = -1;
|
||||
}
|
||||
dsps_ccorr_f32_ansi(inputA, la, inputB, lb, &output_fwd[1]);
|
||||
dsps_ccorr_f32_ansi(inputB, lb, inputA, la, &output_back[1]);
|
||||
TEST_ASSERT_EQUAL(output_fwd[0], -1);
|
||||
TEST_ASSERT_EQUAL(output_fwd[la + lb], -1);
|
||||
TEST_ASSERT_EQUAL(output_back[0], -1);
|
||||
TEST_ASSERT_EQUAL(output_back[la + lb], -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("dsps_ccorr_f32_ansi draw", "[dsps]")
|
||||
{
|
||||
int max_N = 1024;
|
||||
float *x = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(x);
|
||||
float *y = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(y);
|
||||
float *z = (float *)malloc((max_N * 2 + 1) * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(z);
|
||||
int l1 = 8;
|
||||
int l2 = 4;
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
x[i] = 0;
|
||||
y[i] = 0;
|
||||
z[i] = 0;
|
||||
}
|
||||
x[0] = 20;
|
||||
x[7] = 30;
|
||||
y[0] = 10;
|
||||
y[3] = 8;
|
||||
dsps_ccorr_f32_ansi(x, l1, y, l2, &z[0]);
|
||||
|
||||
dsps_view(z, l1 + l2, l1 + l2, 10, -1, 400, '+');
|
||||
for (int i = 0 ; i < (l1 + l2 - 1) ; i++) {
|
||||
ESP_LOGI(TAG, "Z[%i] = %2.2f", i, z[i]);
|
||||
}
|
||||
|
||||
free(x);
|
||||
free(y);
|
||||
free(z);
|
||||
}
|
||||
|
||||
TEST_CASE("dsps_ccorr_f32_ansi benchmark", "[dsps]")
|
||||
{
|
||||
int max_N = 1024;
|
||||
int conv_size = 64;
|
||||
float *x = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(x);
|
||||
float *y = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(y);
|
||||
float *z = (float *)malloc((max_N * 2 + 1) * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(z);
|
||||
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
x[i] = 0;
|
||||
y[i] = 1000;
|
||||
}
|
||||
|
||||
unsigned int start_b = dsp_get_cpu_cycle_count();
|
||||
dsps_ccorr_f32_ansi(x, max_N, y, conv_size, &z[0]);
|
||||
unsigned int end_b = dsp_get_cpu_cycle_count();
|
||||
|
||||
float cycles = end_b - start_b;
|
||||
ESP_LOGI(TAG, "dsps_conv_f32_ansi - %f cycles for signal %i and pattern %i", cycles, max_N, conv_size);
|
||||
free(x);
|
||||
free(y);
|
||||
free(z);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
// Copyright 2018-2023 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 <math.h>
|
||||
#include <malloc.h>
|
||||
#include "unity.h"
|
||||
#include "dsp_platform.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "dsp_tests.h"
|
||||
#include "dsps_conv.h"
|
||||
#include "esp_attr.h"
|
||||
|
||||
static const char *TAG = "dsps_conv";
|
||||
|
||||
#define lenA 30
|
||||
#define lenB 30
|
||||
|
||||
TEST_CASE("dsps_conv_f32 test output", "[dsps]")
|
||||
{
|
||||
float *inputA = (float *)memalign(16, lenA * sizeof(float));
|
||||
float *inputB = (float *)memalign(16, lenB * sizeof(float));
|
||||
|
||||
float *output_ref = (float *)memalign(16, (lenA + lenB - 1 + 2) * sizeof(float));
|
||||
float *output_fwd = (float *)memalign(16, (lenA + lenB - 1 + 2) * sizeof(float));
|
||||
float *output_back = (float *)memalign(16, (lenA + lenB - 1 + 2) * sizeof(float));
|
||||
|
||||
int la = 3;
|
||||
int lb = 2;
|
||||
|
||||
for (int i = 0; i < lenA; i++) {
|
||||
inputA[i] = 10 + i;
|
||||
}
|
||||
for (int i = 0; i < lenB; i++) {
|
||||
inputB[i] = 20 + i;
|
||||
}
|
||||
for (int i = 0; i < (lenA + lenB - 1 + 2); i++) {
|
||||
output_ref[i] = -1;
|
||||
output_fwd[i] = -1;
|
||||
output_back[i] = -1;
|
||||
}
|
||||
dsps_conv_f32_ansi(inputA, la, inputB, lb, &output_ref[1]);
|
||||
dsps_conv_f32(inputA, la, inputB, lb, &output_fwd[1]);
|
||||
|
||||
for (int i = 0; i < (la + lb + 1); i++) {
|
||||
ESP_LOGD(TAG, "la=%i, lb=%i, i=%i, ref=%2.3f, fwd=%2.3f", la, lb, i, output_ref[i], output_fwd[i]);
|
||||
}
|
||||
float max_eps = 0.000001;
|
||||
for (int i = 0; i < (la + lb + 1); i++) {
|
||||
if (fabs(output_ref[i] - output_fwd[i]) > max_eps) {
|
||||
ESP_LOGI(TAG, "la=%i, lb=%i, i=%i, ref=%2.3f, fwd=%2.3f", la, lb, i, output_ref[i], output_fwd[i]);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(output_ref[i], output_fwd[i]);
|
||||
}
|
||||
free(inputA);
|
||||
free(inputB);
|
||||
free(output_ref);
|
||||
free(output_fwd);
|
||||
free(output_back);
|
||||
}
|
||||
|
||||
TEST_CASE("dsps_conv_f32 functionality", "[dsps]")
|
||||
{
|
||||
float *inputA = (float *)memalign(16, lenA * sizeof(float));
|
||||
float *inputB = (float *)memalign(16, lenB * sizeof(float));
|
||||
|
||||
float *output_ref = (float *)memalign(16, (lenA + lenB - 1 + 2) * sizeof(float));
|
||||
float *output_fwd = (float *)memalign(16, (lenA + lenB - 1 + 2) * sizeof(float));
|
||||
float *output_back = (float *)memalign(16, (lenA + lenB - 1 + 2) * sizeof(float));
|
||||
|
||||
for (int la = 2; la < lenA; la++) {
|
||||
for (int lb = 2; lb < lenB; lb++) {
|
||||
for (int i = 0 ; i < lenA ; i++) {
|
||||
inputA[i] = (float)rand() / (float)INT32_MAX;
|
||||
}
|
||||
for (int i = 0 ; i < lenB ; i++) {
|
||||
inputB[i] = (float)rand() / (float)INT32_MAX;
|
||||
}
|
||||
for (int i = 0 ; i < (lenA + lenB - 1 + 2); i++) {
|
||||
output_ref[i] = -1;
|
||||
output_fwd[i] = -1;
|
||||
output_back[i] = -1;
|
||||
}
|
||||
dsps_conv_f32_ansi(inputA, la, inputB, lb, &output_ref[1]);
|
||||
dsps_conv_f32(inputA, la, inputB, lb, &output_fwd[1]);
|
||||
dsps_conv_f32(inputB, lb, inputA, la, &output_back[1]);
|
||||
float max_eps = 0.000001;
|
||||
for (int i = 0; i < (la + lb + 1); i++) {
|
||||
if ((fabs(output_ref[i] - output_fwd[i]) > max_eps) || (fabs(output_ref[i] - output_back[i]) > max_eps) || (fabs(output_back[i] - output_fwd[i]) > max_eps)) {
|
||||
ESP_LOGI(TAG, "la=%i, lb=%i, i=%i, ref=%2.3f, fwd=%2.3f, back=%2.3f", la, lb, i, output_ref[i], output_fwd[i], output_back[i]);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(output_ref[i], output_fwd[i]);
|
||||
TEST_ASSERT_EQUAL(output_ref[i], output_back[i]);
|
||||
TEST_ASSERT_EQUAL(output_back[i], output_fwd[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
free(inputA);
|
||||
free(inputB);
|
||||
free(output_ref);
|
||||
free(output_fwd);
|
||||
free(output_back);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("dsps_conv_f32 benchmark", "[dsps]")
|
||||
{
|
||||
int max_N = 1024;
|
||||
int conv_size = 64;
|
||||
float *x = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(x);
|
||||
float *y = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(y);
|
||||
float *z = (float *)malloc((max_N * 2 + 1) * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(z);
|
||||
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
x[i] = 0;
|
||||
y[i] = 1000;
|
||||
}
|
||||
|
||||
unsigned int start_b = dsp_get_cpu_cycle_count();
|
||||
dsps_conv_f32(x, max_N, y, conv_size, &z[0]);
|
||||
unsigned int end_b = dsp_get_cpu_cycle_count();
|
||||
|
||||
float cycles = end_b - start_b;
|
||||
ESP_LOGI(TAG, "dsps_conv_f32 - %f cycles for signal %i and pattern %i", cycles, max_N, conv_size);
|
||||
free(x);
|
||||
free(y);
|
||||
free(z);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
// Copyright 2018-2023 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 <math.h>
|
||||
#include <malloc.h>
|
||||
#include "unity.h"
|
||||
#include "dsp_platform.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "dsp_tests.h"
|
||||
#include "dsps_conv.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_dsp.h"
|
||||
|
||||
static const char *TAG = "dsps_conv";
|
||||
|
||||
#define lenA 20
|
||||
#define lenB 20
|
||||
|
||||
esp_err_t dsps_conv_f32_ref(const float *Signal, const int siglen, const float *Kernel, const int kernlen, float *convout)
|
||||
{
|
||||
if (NULL == Signal) {
|
||||
return ESP_ERR_DSP_PARAM_OUTOFRANGE;
|
||||
}
|
||||
if (NULL == Kernel) {
|
||||
return ESP_ERR_DSP_PARAM_OUTOFRANGE;
|
||||
}
|
||||
if (NULL == convout) {
|
||||
return ESP_ERR_DSP_PARAM_OUTOFRANGE;
|
||||
}
|
||||
|
||||
for (int n = 0; n < siglen + kernlen - 1; n++) {
|
||||
size_t kmin, kmax, k;
|
||||
|
||||
convout[n] = 0;
|
||||
|
||||
kmin = (n >= kernlen - 1) ? n - (kernlen - 1) : 0;
|
||||
kmax = (n < siglen - 1) ? n : siglen - 1;
|
||||
|
||||
for (k = kmin; k <= kmax; k++) {
|
||||
convout[n] += Signal[k] * Kernel[n - k];
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
TEST_CASE("dsps_conv_f32_ansi functionality", "[dsps]")
|
||||
{
|
||||
float *inputA = (float *)memalign(16, lenA * sizeof(float));
|
||||
float *inputB = (float *)memalign(16, lenB * sizeof(float));
|
||||
|
||||
float *output_ref = (float *)memalign(16, (lenA + lenB - 1 + 2) * sizeof(float));
|
||||
float *output_fwd = (float *)memalign(16, (lenA + lenB - 1 + 2) * sizeof(float));
|
||||
float *output_back = (float *)memalign(16, (lenA + lenB - 1 + 2) * sizeof(float));
|
||||
|
||||
for (int la = 1; la < lenA; la++) {
|
||||
for (int lb = 1; lb < lenB; lb++) {
|
||||
for (int i = 0 ; i < lenA ; i++) {
|
||||
inputA[i] = (float)rand() / (float)INT32_MAX;
|
||||
}
|
||||
for (int i = 0 ; i < lenB ; i++) {
|
||||
inputB[i] = (float)rand() / (float)INT32_MAX;
|
||||
}
|
||||
for (int i = 0 ; i < (lenA + lenB - 1 + 2); i++) {
|
||||
output_ref[i] = -1;
|
||||
output_fwd[i] = -1;
|
||||
output_back[i] = -1;
|
||||
}
|
||||
dsps_conv_f32_ref(inputA, la, inputB, lb, &output_ref[1]);
|
||||
dsps_conv_f32_ansi(inputA, la, inputB, lb, &output_fwd[1]);
|
||||
dsps_conv_f32_ansi(inputB, lb, inputA, la, &output_back[1]);
|
||||
float max_eps = 0.000001;
|
||||
for (int i = 0; i < (la + lb + 1); i++) {
|
||||
if ((fabs(output_ref[i] - output_fwd[i]) > max_eps) || (fabs(output_ref[i] - output_back[i]) > max_eps) || (fabs(output_back[i] - output_fwd[i]) > max_eps)) {
|
||||
ESP_LOGI(TAG, "la=%i, lb=%i, i=%i, ref=%2.3f, fwd=%2.3f, back=%2.3f", la, lb, i, output_ref[i], output_fwd[i], output_back[i]);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(output_ref[i], output_fwd[i]);
|
||||
TEST_ASSERT_EQUAL(output_ref[i], output_back[i]);
|
||||
TEST_ASSERT_EQUAL(output_back[i], output_fwd[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
free(inputA);
|
||||
free(inputB);
|
||||
free(output_ref);
|
||||
free(output_fwd);
|
||||
free(output_back);
|
||||
}
|
||||
|
||||
TEST_CASE("dsps_conv_f32_ansi draw", "[dsps]")
|
||||
{
|
||||
int max_N = 1024;
|
||||
float *x = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(x);
|
||||
float *y = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(y);
|
||||
float *z = (float *)malloc((max_N * 2 + 1) * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(z);
|
||||
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
x[i] = 10;
|
||||
y[i] = 20;
|
||||
z[i] = 0;
|
||||
}
|
||||
|
||||
dsps_conv_f32_ansi(x, 32, y, 16, &z[0]);
|
||||
|
||||
dsps_view(z, 32 + 16, 32 + 16, 10, -1, 4000, '+');
|
||||
|
||||
free(x);
|
||||
free(y);
|
||||
free(z);
|
||||
}
|
||||
|
||||
TEST_CASE("dsps_conv_f32_ansi benchmark", "[dsps]")
|
||||
{
|
||||
int max_N = 1024;
|
||||
int conv_size = 64;
|
||||
float *x = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(x);
|
||||
float *y = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(y);
|
||||
float *z = (float *)malloc((max_N * 2 + 1) * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(z);
|
||||
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
x[i] = 0;
|
||||
y[i] = 1000;
|
||||
}
|
||||
|
||||
unsigned int start_b = dsp_get_cpu_cycle_count();
|
||||
dsps_conv_f32_ansi(x, max_N, y, conv_size, &z[0]);
|
||||
unsigned int end_b = dsp_get_cpu_cycle_count();
|
||||
|
||||
float cycles = end_b - start_b;
|
||||
ESP_LOGI(TAG, "dsps_conv_f32_ansi - %f cycles for signal %i and pattern %i", cycles, max_N, conv_size);
|
||||
free(x);
|
||||
free(y);
|
||||
free(z);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// 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 "esp_log.h"
|
||||
|
||||
#include "dsp_tests.h"
|
||||
#include "dsps_corr.h"
|
||||
#include "esp_attr.h"
|
||||
|
||||
static const char *TAG = "dsps_corr";
|
||||
|
||||
#define lenA 15
|
||||
#define lenB 10
|
||||
|
||||
static float inputA[lenA];
|
||||
static float inputB[lenB];
|
||||
static float output[lenA + lenB - 1 + 2];
|
||||
static float output_ref[lenA + lenB - 1 + 2];
|
||||
|
||||
TEST_CASE("dsps_corr_f32_aexx functionality", "[dsps]")
|
||||
{
|
||||
for (int i = 0 ; i < lenA ; i++) {
|
||||
inputA[i] = i;
|
||||
}
|
||||
for (int i = 0 ; i < lenB ; i++) {
|
||||
inputB[i] = 10 + i;
|
||||
}
|
||||
for (int i = 0 ; i < (lenA - lenB + 2); i++) {
|
||||
output[i] = -1;
|
||||
output_ref[i] = -1;
|
||||
}
|
||||
inputB[0] = 1;
|
||||
dsps_corr_f32(inputA, lenA, inputB, lenB, &output[1]);
|
||||
dsps_corr_f32_ansi(inputA, lenA, inputB, lenB, &output_ref[1]);
|
||||
for (int i = 0; i < (lenA - lenB) + 2; i++) {
|
||||
ESP_LOGD(TAG, "Data[%i] = %2.2f, expected = %2.2f", i, output[i], output_ref[i]);
|
||||
}
|
||||
for (size_t i = 0; i < (lenA - lenB) + 2; i++) {
|
||||
TEST_ASSERT_EQUAL(output_ref[i], output[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("dsps_corr_f32_aexx benchmark", "[dsps]")
|
||||
{
|
||||
int max_N = 1024;
|
||||
int corr_size = 64;
|
||||
float *x = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(x);
|
||||
float *y = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(y);
|
||||
float *z = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(z);
|
||||
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
x[i] = 0;
|
||||
y[i] = 1000;
|
||||
}
|
||||
|
||||
unsigned int start_b = dsp_get_cpu_cycle_count();
|
||||
dsps_corr_f32(x, max_N, y, corr_size, &z[0]);
|
||||
unsigned int end_b = dsp_get_cpu_cycle_count();
|
||||
|
||||
float cycles = end_b - start_b;
|
||||
ESP_LOGI(TAG, "dsps_corr_f32_ae32 - %f cycles for signal %i and pattern %i", cycles, max_N, corr_size);
|
||||
free(x);
|
||||
free(y);
|
||||
free(z);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// 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 "esp_log.h"
|
||||
|
||||
#include "dsp_tests.h"
|
||||
#include "dsps_corr.h"
|
||||
#include "esp_attr.h"
|
||||
|
||||
static const char *TAG = "dsps_corr";
|
||||
|
||||
#define lenA 15
|
||||
#define lenB 10
|
||||
|
||||
static float inputA[lenA];
|
||||
static float inputB[lenB];
|
||||
static float output[lenA + lenB + 2];
|
||||
|
||||
TEST_CASE("dsps_corr_f32_ansi functionality", "[dsps]")
|
||||
{
|
||||
for (int i = 0 ; i < lenA ; i++) {
|
||||
inputA[i] = i;
|
||||
}
|
||||
for (int i = 0 ; i < lenB ; i++) {
|
||||
inputB[i] = 0;
|
||||
}
|
||||
for (int i = 0 ; i <= (lenA - lenB + 2); i++) {
|
||||
output[i] = -1;
|
||||
}
|
||||
inputB[0] = 1;
|
||||
dsps_corr_f32_ansi(inputA, lenA, inputB, lenB, &output[1]);
|
||||
for (int i = 0; i < lenA + lenB; i++) {
|
||||
ESP_LOGD(TAG, "output[%i] = %2.2f", i, output[i]);
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(output[0], -1);
|
||||
TEST_ASSERT_EQUAL(output[lenA - lenB + 2], -1);
|
||||
for (size_t i = 0; i <= (lenA - lenB); i++) {
|
||||
TEST_ASSERT_EQUAL(output[i + 1], i);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("dsps_corr_f32_ansi benchmark", "[dsps]")
|
||||
{
|
||||
int max_N = 1024;
|
||||
int corr_size = 64;
|
||||
float *x = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(x);
|
||||
float *y = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(y);
|
||||
float *z = (float *)malloc(max_N * sizeof(float));
|
||||
TEST_ASSERT_NOT_NULL(z);
|
||||
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
x[i] = 0;
|
||||
y[i] = 1000;
|
||||
}
|
||||
|
||||
unsigned int start_b = dsp_get_cpu_cycle_count();
|
||||
dsps_corr_f32_ansi(x, max_N, y, corr_size, &z[0]);
|
||||
unsigned int end_b = dsp_get_cpu_cycle_count();
|
||||
|
||||
float cycles = end_b - start_b;
|
||||
ESP_LOGI(TAG, "dsps_corr_f32_ansi - %f cycles for signal %i and pattern %i", cycles, max_N, corr_size);
|
||||
free(x);
|
||||
free(y);
|
||||
free(z);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user