Skip to content

[SYCL][ESIMD] Fix compilation break occurring when bfloat16 constructor is used in a kernel #8892

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

Merged
merged 12 commits into from
Apr 4, 2023

Conversation

fineg74
Copy link
Contributor

@fineg74 fineg74 commented Mar 30, 2023

No description provided.

@fineg74 fineg74 requested a review from a team as a code owner March 30, 2023 21:34
@fineg74 fineg74 temporarily deployed to aws March 31, 2023 01:07 — with GitHub Actions Inactive
@fineg74 fineg74 temporarily deployed to aws March 31, 2023 20:36 — with GitHub Actions Inactive
@fineg74 fineg74 temporarily deployed to aws March 31, 2023 22:02 — with GitHub Actions Inactive
@fineg74 fineg74 temporarily deployed to aws March 31, 2023 23:05 — with GitHub Actions Inactive
@v-klochkov v-klochkov requested a review from sarnex April 1, 2023 06:03
Copy link
Contributor

@sarnex sarnex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review, I missed this somehow.

Can you bring me up to speed on the root cause and the solution? I looked at the internal bug tracker but didn't totally understand how it's related to this PR.

My understanding is that all __devicelib_ConvertFToBF16INTEL does is call __spirv_ConvertFToBF16INTEL, at least that's what this code seems to be doing.

Do we not link against whatever sycl device library contains the implementation for __devicelib_ConvertFToBF16INTEL so we never see the defn or something?

Thanks

@fineg74
Copy link
Contributor Author

fineg74 commented Apr 4, 2023

My understanding of the problem is:
BF16 uses __devicelib_ConvertFToBF16INTEL and __devicelib_ConvertBF16ToFINTEL rather than spirv extensions for some reason. The issue is that these functions are not implemented on GPU backend while spirv extensions are implemented there. I also found implementation of these functions at llvm/libdevice/bfloat16_wrapper.cpp (wrappers from _devicelib* functions to their appropriate spirv extensions) but they are covered with SPIR define which is not set at the time of backend compilation. I am not sure why it was done this way and why. So the basic idea of the fix is to make sycl-post-link replace calls of _devicelib* functions with spirv extensions. It is slightly more complicated then usual due to 2 reasons:

  1. _devicelib* functions are declared as extern "C" which means it is not mangled which causes sycl-post-link to crash as it tries to demangle the function names (it assumes the function names are always mangled). So there is code that creates a name mangling before processing to make sycl-post-link happy.
  2. _devicelib* functions receive their parameters as references (not sure why as it doesn't make a lot of sense to use a reference to pass a const scalar as a parameter) while spirv extensions get their parameters by value which requires insertion of load instruction for function parameters

@sarnex
Copy link
Contributor

sarnex commented Apr 4, 2023

Thanks for the explanation.

I investigated it a bit more and it seems __devicelib_ConvertBF16ToFINTEL is never translated to __spirv_ConvertFToBF16INTEL even in working non-ESIMD cases, even the GPU VISA does a function call for it, so I guess it's defined somewhere somehow.

It seems like we need to handle this on our side, so this solution makes sense, will review it in depth soon.

Copy link
Contributor

@sarnex sarnex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good, thanks. i dont understand why the bf16 feature was implemented this way but this looks to be a good way to deal with it.

@v-klochkov v-klochkov merged commit bc063ac into intel:sycl Apr 4, 2023
@fineg74 fineg74 deleted the bfloat16ConstructorFix branch April 4, 2023 21:10
@taozha2
Copy link

taozha2 commented Jul 14, 2023

verify failed with oneapi 2023.2.0.20230622, still meet compiler issue like below:
In file included from /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/algorithm:60:
In file included from /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/utility:70:
In file included from /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_pair.h:59:
In file included from /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/move.h:57:
/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/type_traits:2585:44: error: no type named 'type' in 'std::enable_if'; 'enable_if' cannot be used to disable this declaration
using enable_if_t = typename enable_if<_Cond, _Tp>::type;
^~~~~
/opt/intel/oneapi/compiler/2023.2.0/linux/bin-llvm/../include/sycl/ext/intel/esimd/simd.hpp:57:23: note: in instantiation of template type alias 'enable_if_t' requested here
std::enable_if_t<detail::is_valid_simd_elem_type_v>> {
^
/home/zt/workspace/xetla_validation/libraries.gpu.xetla/build/tests/bug_track/compiler/convert_0_to_bf16.cpp:35:45: note: in instantiation of template class 'sycl::_V1::ext::intel::esimd::simd<gpu::xetla::bf16, 32>' requested here
__ESIMD_NS::simd<data_type, 32> data = data_type(0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants