Skip to content

Commit 1d7eebe

Browse files
shuzhuosureZ-sz
shuzhuo
authored andcommitted
NMSIS/DSP: benchmark fix SupportFunctions test
1 parent a004c2d commit 1d7eebe

File tree

8 files changed

+54
-16
lines changed

8 files changed

+54
-16
lines changed

NMSIS/DSP/Benchmark/SupportFunctions/funcs_def.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern void q31ToQ15_riscv_q31_to_q15();
5353
extern void sort_riscv_sort_f32();
5454
extern void mergeSort_riscv_merge_sort_f32();
5555

56-
extern void weightedSum_riscv_weighted_sum_f16();
57-
extern void weightedSum_riscv_weighted_sum_f32();
56+
extern void weightedSum_riscv_weighted_average_f16();
57+
extern void weightedSum_riscv_weighted_average_f32();
5858

5959
#endif

NMSIS/DSP/Benchmark/SupportFunctions/riscv_dsp_benchmark.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ int main()
5858
sort_riscv_sort_f32();
5959
mergeSort_riscv_merge_sort_f32();
6060

61-
weightedSum_riscv_weighted_sum_f16();
62-
weightedSum_riscv_weighted_sum_f32();
61+
weightedSum_riscv_weighted_average_f16();
62+
weightedSum_riscv_weighted_average_f32();
6363

6464
printf("All tests are passed.\n");
6565
printf("test for SupportFunctions benchmark finished.\n");

NMSIS/DSP/Benchmark/SupportFunctions/test_riscv_weighted_sum_f16.c NMSIS/DSP/Benchmark/SupportFunctions/test_riscv_weighted_average_f16.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#include <stdio.h>
33
#include "validate.h"
44
#include "nmsis_bench.h"
5-
#include "TestData/SupportFunctions/weighted_sum_f16/test_data.h"
5+
#include "TestData/SupportFunctions/weighted_average_f16/test_data.h"
66

77
BENCH_DECLARE_VAR();
88

9-
void weightedSum_riscv_weighted_sum_f16(void)
9+
void weightedSum_riscv_weighted_average_f16(void)
1010
{
1111
#if defined (RISCV_FLOAT16_SUPPORTED)
1212
float16_t f16_weighted_output;
@@ -16,9 +16,9 @@ void weightedSum_riscv_weighted_sum_f16(void)
1616
f16_weighted_array[i] = (float16_t)rand() / RAND_MAX;
1717
}
1818

19-
BENCH_START(riscv_weighted_sum_f16);
20-
f16_weighted_output = riscv_weighted_sum_f16(f16_weighted_sum_array, f16_weighted_array, WEIGHT_NUM);
21-
BENCH_END(riscv_weighted_sum_f16);
19+
BENCH_START(riscv_weighted_average_f16);
20+
f16_weighted_output = riscv_weighted_average_f16(f16_weighted_sum_array, f16_weighted_array, WEIGHT_NUM);
21+
BENCH_END(riscv_weighted_average_f16);
2222

2323
#endif /* #if defined (RISCV_FLOAT16_SUPPORTED) */
2424
}

NMSIS/DSP/Benchmark/SupportFunctions/test_riscv_weighted_sum_f32.c NMSIS/DSP/Benchmark/SupportFunctions/test_riscv_weighted_average_f32.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#include <stdio.h>
33
#include "validate.h"
44
#include "nmsis_bench.h"
5-
#include "TestData/SupportFunctions/weighted_sum_f32/test_data.h"
5+
#include "TestData/SupportFunctions/weighted_average_f32/test_data.h"
66

77
BENCH_DECLARE_VAR();
88

9-
void weightedSum_riscv_weighted_sum_f32(void)
9+
void weightedSum_riscv_weighted_average_f32(void)
1010
{
1111
float32_t f32_weighted_output;
1212

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

18-
BENCH_START(riscv_weighted_sum_f32);
19-
f32_weighted_output = riscv_weighted_sum_f32(f32_weighted_sum_array, f32_weighted_array, WEIGHT_NUM);
20-
BENCH_END(riscv_weighted_sum_f32);
18+
BENCH_START(riscv_weighted_average_f32);
19+
f32_weighted_output = riscv_weighted_average_f32(f32_weighted_sum_array, f32_weighted_array, WEIGHT_NUM);
20+
BENCH_END(riscv_weighted_average_f32);
2121
}

NMSIS/DSP/Source/SupportFunctions/riscv_weighted_average_f16.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,33 @@ RISCV_DSP_ATTRIBUTE float16_t riscv_weighted_average_f16(const float16_t *in, co
7777
accum1=0.0f16;
7878
accum2=0.0f16;
7979

80+
#if defined(RISCV_MATH_VECTOR)
81+
uint32_t blkCnt_v = blockSize;
82+
size_t l;
83+
vfloat16m8_t v_x, v_y;
84+
vfloat16m1_t v_a, v_b;
85+
l = __riscv_vsetvl_e16m1(1);
86+
v_a = __riscv_vfsub_vv_f16m1(v_a, v_a, l);
87+
v_b = __riscv_vfsub_vv_f16m1(v_b, v_b, l);
88+
for (; (l = __riscv_vsetvl_e16m8(blkCnt_v)) > 0; blkCnt_v -= l) {
89+
v_x = __riscv_vle16_v_f16m8(pIn, l);
90+
pIn += l;
91+
v_y = __riscv_vle16_v_f16m8(pW, l);
92+
pW += l;
93+
v_a = __riscv_vfredusum_vs_f16m8_f16m1(__riscv_vfmul_vv_f16m8(v_x, v_y, l), v_a, l);
94+
v_b = __riscv_vfredusum_vs_f16m8_f16m1(v_y, v_b, l);
95+
}
96+
accum1 += __riscv_vfmv_f_s_f16m1_f16(v_a);
97+
accum2 += __riscv_vfmv_f_s_f16m1_f16(v_b);
98+
#else
8099
blkCnt = blockSize;
81100
while(blkCnt > 0)
82101
{
83102
accum1 += (_Float16)*pIn++ * (_Float16)*pW;
84103
accum2 += (_Float16)*pW++;
85104
blkCnt--;
86105
}
87-
106+
#endif /* #if defined(RISCV_MATH_VECTOR) */
88107
return(accum1 / accum2);
89108
}
90109
/**

NMSIS/DSP/Source/SupportFunctions/riscv_weighted_average_f32.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,33 @@ RISCV_DSP_ATTRIBUTE float32_t riscv_weighted_average_f32(const float32_t *in, co
6363
accum1=0.0f;
6464
accum2=0.0f;
6565

66+
#if defined(RISCV_MATH_VECTOR)
67+
uint32_t blkCnt_v = blockSize;
68+
size_t l;
69+
vfloat32m8_t v_x, v_y;
70+
vfloat32m1_t v_a, v_b;
71+
l = __riscv_vsetvl_e32m1(1);
72+
v_a = __riscv_vfsub_vv_f32m1(v_a, v_a, l);
73+
v_b = __riscv_vfsub_vv_f32m1(v_b, v_b, l);
74+
for (; (l = __riscv_vsetvl_e32m8(blkCnt_v)) > 0; blkCnt_v -= l) {
75+
v_x = __riscv_vle32_v_f32m8(pIn, l);
76+
pIn += l;
77+
v_y = __riscv_vle32_v_f32m8(pW, l);
78+
pW += l;
79+
v_a = __riscv_vfredusum_vs_f32m8_f32m1(__riscv_vfmul_vv_f32m8(v_x, v_y, l), v_a, l);
80+
v_b = __riscv_vfredusum_vs_f32m8_f32m1(v_y, v_b, l);
81+
}
82+
accum1 += __riscv_vfmv_f_s_f32m1_f32(v_a);
83+
accum2 += __riscv_vfmv_f_s_f32m1_f32(v_b);
84+
#else
6685
blkCnt = blockSize;
6786
while(blkCnt > 0)
6887
{
6988
accum1 += *pIn++ * *pW;
7089
accum2 += *pW++;
7190
blkCnt--;
7291
}
73-
92+
#endif /* #if defined(RISCV_MATH_VECTOR) */
7493
return(accum1 / accum2);
7594
}
7695

0 commit comments

Comments
 (0)