66#include "simd-mappings.h"
77#include "ggml.h"
88
9+ #ifdef GGML_USE_CPU_RISCV64_SPACEMIT
10+ #include "ggml-cpu-riscv64-spacemit.h"
11+ #endif
12+
913#if defined(GGML_USE_ACCELERATE )
1014#include <Accelerate/Accelerate.h>
1115#endif
@@ -54,7 +58,13 @@ inline static void ggml_vec_cpy_i32(const int n, int32_t * y, const int32_t * x)
5458
5559inline static void ggml_vec_set_f16 (const int n , ggml_fp16_t * x , const ggml_fp16_t v ) { for (int i = 0 ; i < n ; ++ i ) x [i ] = v ; }
5660inline static void ggml_vec_set_bf16 (const int n , ggml_bf16_t * x , const ggml_bf16_t v ) { for (int i = 0 ; i < n ; ++ i ) x [i ] = v ; }
61+ #ifdef GGML_USE_CPU_RISCV64_SPACEMIT
62+ inline static void ggml_vec_add_f32 (const int n , float * z , const float * x , const float * y ) {
63+ ggml_vec_add_f32_rvv (x , y , z , n );
64+ }
65+ #else
5766inline static void ggml_vec_add_f32 (const int n , float * z , const float * x , const float * y ) { for (int i = 0 ; i < n ; ++ i ) z [i ] = x [i ] + y [i ]; }
67+ #endif
5868inline static void ggml_vec_add_f16 (const int n , ggml_fp16_t * z , const ggml_fp16_t * x , const ggml_fp16_t * y ) {
5969 for (int i = 0 ; i < n ; ++ i ) {
6070 z [i ] = GGML_FP32_TO_FP16 (GGML_FP16_TO_FP32 (x [i ]) + GGML_FP16_TO_FP32 (y [i ]));
@@ -77,8 +87,13 @@ inline static void ggml_vec_neg_f16 (const int n, ggml_fp16_t * y, const ggml_fp
7787 y [i ] = GGML_FP32_TO_FP16 (- GGML_FP16_TO_FP32 (x [i ]));
7888 }
7989}
80-
90+ #ifdef GGML_USE_CPU_RISCV64_SPACEMIT
91+ inline static void ggml_vec_mul_f32 (const int n , float * z , const float * x , const float * y ) {
92+ ggml_vec_mul_f32_rvv (x , y , z , n );
93+ }
94+ #else
8195inline static void ggml_vec_mul_f32 (const int n , float * z , const float * x , const float * y ) { for (int i = 0 ; i < n ; ++ i ) z [i ] = x [i ]* y [i ]; }
96+ #endif
8297inline static void ggml_vec_mul_f16 (const int n , ggml_fp16_t * z , const ggml_fp16_t * x , const ggml_fp16_t * y ) {
8398 for (int i = 0 ; i < n ; ++ i ) {
8499 z [i ] = GGML_FP32_TO_FP16 (GGML_FP16_TO_FP32 (x [i ]) * GGML_FP16_TO_FP32 (y [i ]));
@@ -200,6 +215,9 @@ inline static void ggml_vec_mad_f16(const int n, ggml_fp16_t * GGML_RESTRICT y,
200215 for (int i = np ; i < n ; ++ i ) {
201216 y [i ] = GGML_FP32_TO_FP16 (GGML_FP16_TO_FP32 (y [i ]) + GGML_FP16_TO_FP32 (x [i ])* v );
202217 }
218+ #elif defined(GGML_USE_CPU_RISCV64_SPACEMIT )
219+ ggml_vec_mad_f16_hp_rvv (x , y , v , n );
220+ return ;
203221#else
204222 // scalar
205223 for (int i = 0 ; i < n ; ++ i ) {
@@ -284,6 +302,8 @@ inline static void ggml_vec_scale_f32(const int n, float * y, const float v) {
284302 for (int i = np ; i < n ; ++ i ) {
285303 y [i ] *= v ;
286304 }
305+ #elif defined(GGML_USE_CPU_RISCV64_SPACEMIT )
306+ ggml_vec_scale_f32_rvv (y , v , y , n );
287307#else
288308 // scalar
289309 for (int i = 0 ; i < n ; ++ i ) {
@@ -777,6 +797,8 @@ inline static void ggml_vec_max_f32(const int n, float * s, const float * x) {
777797 max = MAX (max , x [i ]);
778798 }
779799 * s = max ;
800+ #elif defined(GGML_USE_CPU_RISCV64_SPACEMIT )
801+ ggml_vec_max_f32_rvv (n , s , x );
780802#else
781803 vDSP_maxv (x , 1 , s , n );
782804#endif
0 commit comments