Skip to content

[DO NOT MERGE] [SYCL][ABI break] Make sycl::vec trivially_copyable and align layout #6816

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

Conversation

romanovvlad
Copy link
Contributor

Before the patch the data sycl::vec used underneath was either cl_* types or clang vector types(aka ext_vector_type) depending on the host compiler.

This was causing binary compatibility issues because such types are passed differently according to the SysV calling convention. The way such types are passed also depends on the instruction set a compiler allowed to use(aka -avx).

The vector types were used underneath in order speed up sycl::vec operations on the host when available(when compiling with clang). So, to avoid performance degradation we need to continue doing the operations using vector types.

The patch solves this problem by changing the underlying type to std::array in all the cases for the host compilation. And adds conversions to vector types when the host compiler is clang to avoid loosing performance. The GCC vector_size could be used to cover both compiler, but it has some problems to solve, e.g. it does not support vector of lenght 3.

This also allows us to untie sycl::vec from OpenCL types.

The are things to improve:

  1. Use vectors data type in more sycl::vec methods
  2. Use vectors for half type
  3. Refactor several ifdef SYCL_DEVICE_ONLY to if constexpr constructs.

Before the patch the data sycl::vec used underneath was either
cl_* types or clang vector types(aka ext_vector_type) depending
on the host compiler.

This was causing binary compatibility issues because such types
are passed differently according to the SysV calling convention.
The way such types are passed also depends on the instruction set
a compiler allowed to use(aka -avx).

The vector types were used underneath in order speed up sycl::vec
operations on the host when available(when compiling with clang).
So, to avoid performance degradation we need to continue doing the
operations using vector types.

The patch solves this problem by changing the underlying type to
std::array in all the cases for the host compilation. And adds
conversions to vector types when the host compiler is clang to
avoid loosing performance. The GCC vector_size could be used
to cover both compiler, but it has some problems to solve, e.g.
it does not support vector of lenght 3.

This also allows us to untie sycl::vec from OpenCL types.

The are things to improve:
1. Use vectors data type in more sycl::vec methods
2. Use vectors for half type
3. Refactor several ifdef SYCL_DEVICE_ONLY to if constexpr
   constructs.
@romanovvlad romanovvlad requested a review from a team as a code owner September 19, 2022 17:15
@romanovvlad romanovvlad changed the title [SYCL] Make sycl::vec trivially_copyable and align layout [SYCL][ABI break] Make sycl::vec trivially_copyable and align layout Sep 19, 2022
@romanovvlad
Copy link
Contributor Author

The pre-commit failed with very strange error. Cannot reproduce neither with clang nor with GCC 9.3. Anyway, adding an init to zero.

@@ -63,6 +63,8 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
else()
target_compile_options(${LIB_OBJ_NAME} PUBLIC
-fvisibility=hidden -fvisibility-inlines-hidden)

target_compile_options(${LIB_OBJ_NAME} PUBLIC -Wno-psabi)
Copy link
Contributor Author

@romanovvlad romanovvlad Sep 20, 2022

Choose a reason for hiding this comment

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

Add a comment:

Silencing GCC note about changed ABI in quite old version of GCC which is not supported by the product:
"the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6" 

BTW. For some reason I was not able to silence the note just using pragma in the files, so silencing it globally.

@romanovvlad romanovvlad changed the title [SYCL][ABI break] Make sycl::vec trivially_copyable and align layout [DO NOT MERGE] [SYCL][ABI break] Make sycl::vec trivially_copyable and align layout Sep 20, 2022
Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

Changes LGTM. Is there any way we could add a test for the mentioned incompatibility so we don't have regressions in the future?

@romanovvlad
Copy link
Contributor Author

Is there any way we could add a test for the mentioned incompatibility so we don't have regressions in the future?

Speaking honestly, I don't have a good idea how to write such a test. We need to pass a sycl::vec object between two TUs compiled using clang and gcc to reproduce that.

againull pushed a commit that referenced this pull request Aug 2, 2023
adapted from #6816   

sycl::vec now uses std::array on host in all cases, but device access is
via `ext_vector_type` so as to not lose performance. Alignment is set
the same as the size to a maximum of 64 bytes, which aligns with an
upcoming spec change proposal. In the cases where the size is greater
than 64 we use std::array on the device. We no longer need to emit a
pragma on Windows and we can use `alignas()` on all platforms.
mdtoguchi pushed a commit to mdtoguchi/llvm that referenced this pull request Oct 18, 2023
adapted from intel#6816   

sycl::vec now uses std::array on host in all cases, but device access is
via `ext_vector_type` so as to not lose performance. Alignment is set
the same as the size to a maximum of 64 bytes, which aligns with an
upcoming spec change proposal. In the cases where the size is greater
than 64 we use std::array on the device. We no longer need to emit a
pragma on Windows and we can use `alignas()` on all platforms.
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.

2 participants