Skip to content

[SYCL] Fix vec class alignment on windows platform #4953

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

Conversation

dongkyunahn-intel
Copy link
Contributor

  • For Windows alignment request for vector type larger than 64 is applied, but limited to 64

  • Before this change, alignment request was ignored due to 64 byte from MSVC limit and default alignment was applied

  • This default alignment could cause segmentation fault for 16-byte aligned memory access such as memory access for XMM

- For Windows alignment request for vector type larger than 64 is
applied, but limited to 64

- Before this change, alignment request was ignored due to 64 byte
from MSVC limit and default alignment was applied

- This default alignment could cause segmentation fault for 16-byte
aligned memory access such as memory access for XMM
#define __SYCL_ALIGNAS(x)
Requested alignment applied, limited at 64.")
#define __SYCL_ALIGNED_VAR(type, x, var) \
type __declspec(align((x < 64) ? x : 64)) var
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we continue using alignas specifier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alignas failed as follows during kernel compilation for 'test_handler' from CTS.

In file included from C:\work\dongkyun\github\opensource\llvm_build\include\sycl\CL/sycl.hpp:11:
In file included from C:\work\dongkyun\github\opensource\llvm_build\include\sycl\CL/sycl/accessor.hpp:13:
In file included from C:\work\dongkyun\github\opensource\llvm_build\include\sycl\CL/sycl/buffer.hpp:11:
In file included from C:\work\dongkyun\github\opensource\llvm_build\include\sycl\CL/sycl/detail/buffer_impl.hpp:20:
C:\work\dongkyun\github\opensource\llvm_build\include\sycl\CL/sycl/types.hpp(1370,3): error: requested alignment is less than minimum alignment of 128 for type 'sycl::vec<double, 16>::DataType' (aka 'double __attribute__((ext_vector_type(16)))')
  __SYCL_ALIGNAS((detail::vector_alignment<DataT, NumElements>::value))
  ^
C:\work\dongkyun\github\opensource\llvm_build\include\sycl\CL/sycl/types.hpp(548,27): note: expanded from macro '__SYCL_ALIGNAS'
#define __SYCL_ALIGNAS(x) alignas((x<64)?x:64)
                          ^

specification requirements, a limitation of the MSVC compiler(Error C2719).\
Applied default alignment.")
#define __SYCL_ALIGNAS(x)
Requested alignment applied, limited at 64.")
Copy link
Contributor

Choose a reason for hiding this comment

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

@alexbatashev
If I remember correctly you found that such a change is an ABI breaking one, could you please confirm?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please remind why?

Copy link
Contributor

Choose a reason for hiding this comment

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

Type alignment is part of ABI: assembled code has no notion of structure layout, it operates raw bytes.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this particular change I do not see how setting alignment can break anything:

  1. The vector type is not passed directly to functions, but as part of the struct, so it's either passed by pointer or thru a register.
  2. The structure has only one field which is already considered to be aligned by the clang as it's a vector type(generates vector instructions)
  3. We set the alignment of vector type being equal to the size of the field itself, so we should not change the size. of the structure to trigger it to be passed differently.

@romanovvlad
Copy link
Contributor

/summary:run

- Updating expected warning message from types.hpp
@bader bader changed the title Vector alignment fix windows [SYCL] Fix vec class alignment on windows platform Nov 18, 2021
Copy link
Contributor

@romanovvlad romanovvlad left a comment

Choose a reason for hiding this comment

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

The patch doesn't fix the problem completely, compiling with -march=skylake triggers the issue even with the patch, but workaround the problem when compiling by "default".

@romanovvlad romanovvlad merged commit 826c569 into intel:sycl Nov 23, 2021
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.

3 participants