From 7bba2dd63dffb56e414a59c8efbf712fe7e6b88e Mon Sep 17 00:00:00 2001 From: Abitofevrything Date: Mon, 2 Jan 2023 10:49:51 +0100 Subject: [PATCH] Add Imath support for fp16-fp32 conversions --- Makefile | 4 ++++ ggml.c | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/Makefile b/Makefile index ff1ee74..5a5a825 100644 --- a/Makefile +++ b/Makefile @@ -130,6 +130,10 @@ ifdef WHISPER_GPROF CFLAGS += -pg CXXFLAGS += -pg endif +ifdef WHISPER_IMATH + CFLAGS += -DGGML_USE_IMATH + LDFLAGS += -lImath +endif ifneq ($(filter aarch64%,$(UNAME_M)),) endif ifneq ($(filter armv6%,$(UNAME_M)),) diff --git a/ggml.c b/ggml.c index 897d141..1aab0f6 100644 --- a/ggml.c +++ b/ggml.c @@ -158,6 +158,13 @@ ggml_fp16_t ggml_fp32_to_fp16(float f) { #define GGML_FP16_TO_FP32(x) _cvtsh_ss(x) #define GGML_FP32_TO_FP16(x) _cvtss_sh(x, 0) +#elif GGML_USE_IMATH + +#include + +#define GGML_FP16_TO_FP32(x) imath_half_to_float(x) +#define GGML_FP32_TO_FP16(x) imath_float_to_half(x) + #else // FP16 <-> FP32