File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -417,6 +417,28 @@ GGML_API void ggml_aligned_free(void * ptr, size_t size);
417417 #define GGML_FP16_TO_FP32 (x ) GGML_COMPUTE_FP16_TO_FP32(x)
418418 #define GGML_FP32_TO_FP16 (x ) GGML_COMPUTE_FP32_TO_FP16(x)
419419
420+ #elif defined(__NNPA__)
421+
422+ #define GGML_COMPUTE_FP16_TO_FP32 (x ) ggml_compute_fp16_to_fp32(x)
423+ #define GGML_COMPUTE_FP32_TO_FP16 (x ) ggml_compute_fp32_to_fp16(x)
424+
425+ #define GGML_FP16_TO_FP32 (x ) GGML_COMPUTE_FP16_TO_FP32(x)
426+ #define GGML_FP32_TO_FP16 (x ) GGML_COMPUTE_FP32_TO_FP16(x)
427+
428+ static inline float ggml_compute_fp16_to_fp32 (ggml_fp16_t h) {
429+ uint16x8_t v_h = vec_splats (h);
430+ uint16x8_t v_hd = vec_convert_from_fp16 (v_h, 0 );
431+ return vec_extend_to_fp32_hi (v_hd, 0 )[0 ];
432+ }
433+
434+ static inline ggml_fp16_t ggml_compute_fp32_to_fp16 (float f) {
435+ float32x4_t v_f = vec_splats (f);
436+ float32x4_t v_zero = vec_splats (0 .0f );
437+ uint16x8_t v_hd = vec_round_from_fp32 (v_f, v_zero, 0 );
438+ uint16x8_t v_h = vec_convert_to_fp16 (v_hd, 0 );
439+ return vec_extract (v_h, 0 );
440+ }
441+
420442#else
421443
422444 // FP16 <-> FP32
You can’t perform that action at this time.
0 commit comments