Skip to content

Commit 4621a23

Browse files
committed
ggml-cpu: add 4 element loops for fp32->fp16
Signed-off-by: Aaron Teo <[email protected]>
1 parent 373fa28 commit 4621a23

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ggml/src/ggml-cpu/ggml-cpu.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,8 +3146,15 @@ void ggml_cpu_fp32_to_fp16(const float * x, ggml_fp16_t * y, int64_t n) {
31463146
float32x4_t v_xh = vec_xl(0, (const float *)(x + i + 0));
31473147
float32x4_t v_xl = vec_xl(0, (const float *)(x + i + 4));
31483148
uint16x8_t v_xd = vec_round_from_fp32(v_xh, v_xl, 0);
3149-
uint16x8_t v_xfp16 = vec_convert_to_fp16(v_xd, 0);
3150-
vec_xst(v_xfp16, 0, (ggml_fp16_t *)(y + i));
3149+
uint16x8_t v_y = vec_convert_to_fp16(v_xd, 0);
3150+
vec_xst(v_y, 0, (ggml_fp16_t *)(y + i));
3151+
}
3152+
for (; i + 3 < n; i += 4) {
3153+
float32x4_t v_x = vec_xl(0, (const float *)(x + i));
3154+
float32x4_t v_zero = vec_splats(0.0f);
3155+
uint16x8_t v_xd = vec_round_from_fp32(v_x, v_zero, 0);
3156+
uint16x8_t v_y = vec_convert_to_fp16(v_xd, 0);
3157+
vec_xst(v_y, 0, (ggml_fp16_t *)(y + i));
31513158
}
31523159
#endif
31533160
for (; i < n; ++i) {

0 commit comments

Comments
 (0)