Skip to content

[SYCL][ext] Add host impl for bf16 conversion #6492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions sycl/include/sycl/ext/oneapi/experimental/bfloat16.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t *>(&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<float *>(&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
}

Expand Down