}
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