Skip to content

Commit

Permalink
NMSIS/DSP: benchmark fix SupportFunctions test
Browse files Browse the repository at this point in the history
  • Loading branch information
shuzhuo authored and sureZ-sz committed Sep 23, 2024
1 parent a004c2d commit 1d7eebe
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 16 deletions.
4 changes: 2 additions & 2 deletions NMSIS/DSP/Benchmark/SupportFunctions/funcs_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern void q31ToQ15_riscv_q31_to_q15();
extern void sort_riscv_sort_f32();
extern void mergeSort_riscv_merge_sort_f32();

extern void weightedSum_riscv_weighted_sum_f16();
extern void weightedSum_riscv_weighted_sum_f32();
extern void weightedSum_riscv_weighted_average_f16();
extern void weightedSum_riscv_weighted_average_f32();

#endif
4 changes: 2 additions & 2 deletions NMSIS/DSP/Benchmark/SupportFunctions/riscv_dsp_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ int main()
sort_riscv_sort_f32();
mergeSort_riscv_merge_sort_f32();

weightedSum_riscv_weighted_sum_f16();
weightedSum_riscv_weighted_sum_f32();
weightedSum_riscv_weighted_average_f16();
weightedSum_riscv_weighted_average_f32();

printf("All tests are passed.\n");
printf("test for SupportFunctions benchmark finished.\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include <stdio.h>
#include "validate.h"
#include "nmsis_bench.h"
#include "TestData/SupportFunctions/weighted_sum_f16/test_data.h"
#include "TestData/SupportFunctions/weighted_average_f16/test_data.h"

BENCH_DECLARE_VAR();

void weightedSum_riscv_weighted_sum_f16(void)
void weightedSum_riscv_weighted_average_f16(void)
{
#if defined (RISCV_FLOAT16_SUPPORTED)
float16_t f16_weighted_output;
Expand All @@ -16,9 +16,9 @@ void weightedSum_riscv_weighted_sum_f16(void)
f16_weighted_array[i] = (float16_t)rand() / RAND_MAX;
}

BENCH_START(riscv_weighted_sum_f16);
f16_weighted_output = riscv_weighted_sum_f16(f16_weighted_sum_array, f16_weighted_array, WEIGHT_NUM);
BENCH_END(riscv_weighted_sum_f16);
BENCH_START(riscv_weighted_average_f16);
f16_weighted_output = riscv_weighted_average_f16(f16_weighted_sum_array, f16_weighted_array, WEIGHT_NUM);
BENCH_END(riscv_weighted_average_f16);

#endif /* #if defined (RISCV_FLOAT16_SUPPORTED) */
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include <stdio.h>
#include "validate.h"
#include "nmsis_bench.h"
#include "TestData/SupportFunctions/weighted_sum_f32/test_data.h"
#include "TestData/SupportFunctions/weighted_average_f32/test_data.h"

BENCH_DECLARE_VAR();

void weightedSum_riscv_weighted_sum_f32(void)
void weightedSum_riscv_weighted_average_f32(void)
{
float32_t f32_weighted_output;

Expand All @@ -15,7 +15,7 @@ void weightedSum_riscv_weighted_sum_f32(void)
f32_weighted_array[i] = (float32_t)rand() / RAND_MAX;
}

BENCH_START(riscv_weighted_sum_f32);
f32_weighted_output = riscv_weighted_sum_f32(f32_weighted_sum_array, f32_weighted_array, WEIGHT_NUM);
BENCH_END(riscv_weighted_sum_f32);
BENCH_START(riscv_weighted_average_f32);
f32_weighted_output = riscv_weighted_average_f32(f32_weighted_sum_array, f32_weighted_array, WEIGHT_NUM);
BENCH_END(riscv_weighted_average_f32);
}
21 changes: 20 additions & 1 deletion NMSIS/DSP/Source/SupportFunctions/riscv_weighted_average_f16.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,33 @@ RISCV_DSP_ATTRIBUTE float16_t riscv_weighted_average_f16(const float16_t *in, co
accum1=0.0f16;
accum2=0.0f16;

#if defined(RISCV_MATH_VECTOR)
uint32_t blkCnt_v = blockSize;
size_t l;
vfloat16m8_t v_x, v_y;
vfloat16m1_t v_a, v_b;
l = __riscv_vsetvl_e16m1(1);
v_a = __riscv_vfsub_vv_f16m1(v_a, v_a, l);
v_b = __riscv_vfsub_vv_f16m1(v_b, v_b, l);
for (; (l = __riscv_vsetvl_e16m8(blkCnt_v)) > 0; blkCnt_v -= l) {
v_x = __riscv_vle16_v_f16m8(pIn, l);
pIn += l;
v_y = __riscv_vle16_v_f16m8(pW, l);
pW += l;
v_a = __riscv_vfredusum_vs_f16m8_f16m1(__riscv_vfmul_vv_f16m8(v_x, v_y, l), v_a, l);
v_b = __riscv_vfredusum_vs_f16m8_f16m1(v_y, v_b, l);
}
accum1 += __riscv_vfmv_f_s_f16m1_f16(v_a);
accum2 += __riscv_vfmv_f_s_f16m1_f16(v_b);
#else
blkCnt = blockSize;
while(blkCnt > 0)
{
accum1 += (_Float16)*pIn++ * (_Float16)*pW;
accum2 += (_Float16)*pW++;
blkCnt--;
}

#endif /* #if defined(RISCV_MATH_VECTOR) */
return(accum1 / accum2);
}
/**
Expand Down
21 changes: 20 additions & 1 deletion NMSIS/DSP/Source/SupportFunctions/riscv_weighted_average_f32.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,33 @@ RISCV_DSP_ATTRIBUTE float32_t riscv_weighted_average_f32(const float32_t *in, co
accum1=0.0f;
accum2=0.0f;

#if defined(RISCV_MATH_VECTOR)
uint32_t blkCnt_v = blockSize;
size_t l;
vfloat32m8_t v_x, v_y;
vfloat32m1_t v_a, v_b;
l = __riscv_vsetvl_e32m1(1);
v_a = __riscv_vfsub_vv_f32m1(v_a, v_a, l);
v_b = __riscv_vfsub_vv_f32m1(v_b, v_b, l);
for (; (l = __riscv_vsetvl_e32m8(blkCnt_v)) > 0; blkCnt_v -= l) {
v_x = __riscv_vle32_v_f32m8(pIn, l);
pIn += l;
v_y = __riscv_vle32_v_f32m8(pW, l);
pW += l;
v_a = __riscv_vfredusum_vs_f32m8_f32m1(__riscv_vfmul_vv_f32m8(v_x, v_y, l), v_a, l);
v_b = __riscv_vfredusum_vs_f32m8_f32m1(v_y, v_b, l);
}
accum1 += __riscv_vfmv_f_s_f32m1_f32(v_a);
accum2 += __riscv_vfmv_f_s_f32m1_f32(v_b);
#else
blkCnt = blockSize;
while(blkCnt > 0)
{
accum1 += *pIn++ * *pW;
accum2 += *pW++;
blkCnt--;
}

#endif /* #if defined(RISCV_MATH_VECTOR) */
return(accum1 / accum2);
}

Expand Down

0 comments on commit 1d7eebe

Please sign in to comment.