Skip to content

Commit d8926e0

Browse files
committed
ggml-cpu: add fp32->fp16
Signed-off-by: Aaron Teo <[email protected]>
1 parent a84e445 commit d8926e0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ggml/src/ggml-cpu/simd-mappings.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ static inline void __lsx_f16x4_store(ggml_fp16_t * x, __m128 y) {
922922
#define GGML_F32_STEP 32
923923
#define GGML_F32_EPR 4
924924

925-
#define GGML_F32x4 __vector float
925+
#define GGML_F32x4 float32x4_t
926926
#define GGML_F32x4_ZERO vec_splats(0.0f)
927927
#define GGML_F32x4_SET1 vec_splats
928928
#define GGML_F32x4_LOAD(p) vec_xl(0, p)
@@ -980,7 +980,15 @@ static inline float32x4_t __lzs_f16cx4_load(const ggml_fp16_t * x) {
980980
#endif
981981
}
982982

983-
static inline void __lzs_f16cx4_store(ggml_fp16_t * x, __vector float y) {
983+
static inline void __lzs_f16cx4_store(ggml_fp16_t * x, float32x4_t y) {
984+
#ifdef __NNPA__
985+
float32x4_t zero = vec_splats(0.0f);
986+
uint16x8_t nnpa = vec_round_from_fp32(y, zero, 0);
987+
x[0] = nnpa[0];
988+
x[1] = nnpa[1];
989+
x[2] = nnpa[2];
990+
x[3] = nnpa[3];
991+
#else
984992
float arr[4];
985993

986994
// note: keep type-cast here to prevent compiler bugs
@@ -990,6 +998,7 @@ static inline void __lzs_f16cx4_store(ggml_fp16_t * x, __vector float y) {
990998
for (int i = 0; i < 4; i++) {
991999
x[i] = GGML_FP32_TO_FP16(arr[i]);
9921000
}
1001+
#endif
9931002
}
9941003

9951004
#define GGML_F16_VEC GGML_F32x4

0 commit comments

Comments
 (0)