From 7a2db560aa08e12a0e146d26cfc67d269b59f651 Mon Sep 17 00:00:00 2001 From: Hugh Delaney Date: Fri, 29 Jul 2022 15:17:28 +0100 Subject: [PATCH] Add host impl for bf16 conversion --- .../sycl/ext/oneapi/experimental/bfloat16.hpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/sycl/include/sycl/ext/oneapi/experimental/bfloat16.hpp b/sycl/include/sycl/ext/oneapi/experimental/bfloat16.hpp index 533976f36b89..058dd88d8480 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/bfloat16.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/bfloat16.hpp @@ -35,25 +35,20 @@ class bfloat16 { return __spirv_ConvertFToBF16INTEL(a); #endif #else - (void)a; - throw exception{errc::feature_not_supported, - "Bfloat16 conversion is not supported on host device"}; + float tmp = a; + uint32_t *res = reinterpret_cast(&tmp); + *res = *res >> 16; + return (storage_t)*res; #endif } static float to_float(const storage_t &a) { -#if defined(__SYCL_DEVICE_ONLY__) -#if defined(__NVPTX__) +#if defined(__SPIR__) + return __spirv_ConvertBF16ToFINTEL(a); +#else uint32_t y = a; y = y << 16; float *res = reinterpret_cast(&y); return *res; -#else - return __spirv_ConvertBF16ToFINTEL(a); -#endif -#else - (void)a; - throw exception{errc::feature_not_supported, - "Bfloat16 conversion is not supported on host device"}; #endif }