LLM inference in C/C++
C++ ggml
sycl: fix UE4M3 parsing (#25608)
Chris Leefc3f10b3895e
diff --git a/ggml/src/ggml-sycl/common.hpp b/ggml/src/ggml-sycl/common.hppindex 619933e0fd..4fa34a526f 100644--- a/ggml/src/ggml-sycl/common.hpp+++ b/ggml/src/ggml-sycl/common.hpp@@ -1022,9 +1022,20 @@ static T block_reduce(T val, T * shared_vals, int block_size_template) {}static __dpct_inline__ float ggml_sycl_ue4m3_to_fp32(uint8_t x) {- const uint32_t bits = x * (x != 0x7F && x != 0xFF);- const __nv_fp8_e4m3 xf = *reinterpret_cast<const __nv_fp8_e4m3 *>(&bits);- return static_cast<float>(xf) / 2;+ // UE4M3 is unsigned: 4 exp bits (bias 7), 3 mantissa bits, no sign, no NaN.+ // exp == 0xF is a valid exponent (256-448 range), not NaN.+ if (x == 0 || x == 0x7F) {+ return 0.0f;+ }+ const int exp = (x >> 3) & 0xF;+ const int man = x & 0x7;+ float raw;+ if (exp == 0) {+ raw = man * (1.0f / 8.0f) * sycl::pow(2.0f, -6.0f);+ } else {+ raw = (1.0f + man / 8.0f) * sycl::pow(2.0f, (float) exp - 7.0f);+ }+ return raw * 0.5f;}#endif // GGML_SYCL_COMMON_HPP