-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Use C-arrays as storage in sycl::vec
#17025
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
Conversation
4f1c4d6
to
74316f2
Compare
@aelovikov-intel @steffenlarsen ping. Please approve if changes looks good. |
@@ -930,7 +933,11 @@ vec<convertT, NumElements> vec<DataT, NumElements>::convert() const { | |||
auto val = | |||
detail::convertImpl<T, R, roundingMode, NumElements, OpenCLVecT, | |||
OpenCLVecR>(bit_cast<OpenCLVecT>(*this)); | |||
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES | |||
sycl::detail::memcpy_no_adl(&Result.m_Data, &val, sizeof(Result)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be a problem in just switching to memcpy_no_adl
for all paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, but I don't see any improvement with that. If we were to do that, we would have something like the following which doesn't simplify the code.
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
sycl::detail::memcpy_no_adl(&Result.m_Data, &val, sizeof(Result)); // For C-array
#else
sycl::detail::memcpy_no_adl(Result.m_Data.data(), &val, sizeof(Result)); // For std::array
#endif
We couldn't have done sycl::detail::memcpy_no_adl(&Result.m_Data, &val, sizeof(Result));
for std::array
as base address of std::array
is not guaranteed by the standard to be same as that of underlying C-array: https://stackoverflow.com/questions/69500721/is-the-address-of-a-stdarray-guaranteed-the-same-as-its-data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second though, as SO answer mentioned, most popular implementations does guarantee std::array
and underlying C-array to have same address. So, I can do something like:
static_assert(sizeof(Result.m_Data) == sizeof(DataT[AdjustedNum]))
sycl::detail::memcpy_no_adl(&Result.m_Data, &val, sizeof(Result)); // for both C-array and std::array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having the static_assert
should be fine. We only risk this hitting weird implementations until preview changes are promoted, so I think the risk is low while the reduced complexity is nice. 😄
@@ -287,7 +291,12 @@ class __SYCL_EBO vec | |||
typename vector_t_ = vector_t, | |||
typename = typename std::enable_if_t<std::is_same_v<vector_t_, vector_t>>> | |||
constexpr vec(vector_t_ openclVector) { | |||
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES | |||
sycl::detail::memcpy_no_adl(&this->m_Data, &openclVector, | |||
sizeof(openclVector)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above.
c13708f
to
71ae31d
Compare
@steffenlarsen , please approve this. You were the one pushing to do this under preview, so you should be approving it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I hadn't noticed the recent changes. Looks good!
The problem with using `std::array` in `sycl::vec` is that we cannot compile it in some environments (namely, Windows) because the former may use something that is illegal in SYCL device code. intel#17025 fixed that, but only did so under preview breaking changes mode, which does not satisfy some of our customers immediately. This PR introduces two main changes: - it allows to opt-in for new behavior through passing `-D__SYCL_USE_NEW_VEC_IMPL=1` macro without using `-fpreview-breaking-changes` flag. That allows for a more gradual opt-in from customers who are interested in this fix - it switches the imlpementation to use the new approach with C-style arrays if their size and alignment is the same as for the corresponding `std::array` - in that case their memory layout is expected to be absolutely the same and therefore it should be safe to use the new approach without fear of some ABI incompatibilities. This allows for customers to benefit from the fix without specifying any extra macro (which should be the case for the most common platforms out there)
The problem with using `std::array` in `sycl::vec` is that we cannot compile it in some environments (namely, Windows) because the former may use something that is illegal in SYCL device code. #17025 fixed that, but only did so under preview breaking changes mode, which does not satisfy some of our customers immediately. This PR introduces two main changes: - it allows to opt-in for new behavior through passing `-D__SYCL_USE_NEW_VEC_IMPL=1` macro without using `-fpreview-breaking-changes` flag. That allows for a more gradual opt-in from customers who are interested in this fix - it switches the imlpementation to use the new approach with C-style arrays if their size and alignment is the same as for the corresponding `std::array` - in that case their memory layout is expected to be absolutely the same and therefore it should be safe to use the new approach without fear of some ABI incompatibilities. This allows for customers to benefit from the fix without specifying any extra macro (which should be the case for the most common platforms out there)
The problem with using `std::array` in `sycl::vec` is that we cannot compile it in some environments (namely, Windows) because the former may use something that is illegal in SYCL device code. intel#17025 fixed that, but only did so under preview breaking changes mode, which does not satisfy some of our customers immediately. This PR introduces two main changes: - it allows to opt-in for new behavior through passing `-D__SYCL_USE_NEW_VEC_IMPL=1` macro without using `-fpreview-breaking-changes` flag. That allows for a more gradual opt-in from customers who are interested in this fix - it switches the imlpementation to use the new approach with C-style arrays if their size and alignment is the same as for the corresponding `std::array` - in that case their memory layout is expected to be absolutely the same and therefore it should be safe to use the new approach without fear of some ABI incompatibilities. This allows for customers to benefit from the fix without specifying any extra macro (which should be the case for the most common platforms out there) This is a cherry-pick of intel#17656
…ses" to sycl-rel-6_0_0 (#17697) This is a cherry-pick of #17656 + changes required to resolve merge conflicts. -------------------------------------- The problem with using std::array in sycl::vec is that we cannot compile it in some environments (namely, Windows) because the former may use something that is illegal in SYCL device code. #17025 fixed that, but only did so under preview breaking changes mode, which does not satisfy some of our customers immediately. This PR introduces two main changes: it allows to opt-in for new behavior through passing -D__SYCL_USE_NEW_VEC_IMPL=1 macro without using -fpreview-breaking-changes flag. That allows for a more gradual opt-in from customers who are interested in this fix it switches the imlpementation to use the new approach with C-style arrays if their size and alignment is the same as for the corresponding std::array - in that case their memory layout is expected to be absolutely the same and therefore it should be safe to use the new approach without fear of some ABI incompatibilities. This allows for customers to benefit from the fix without specifying any extra macro (which should be the case for the most common platforms out there) --------- Co-authored-by: Alexey Sachkov <alexey.sachkov@intel.com>
The problem with using `std::array` in `sycl::vec` is that we cannot compile it in some environments (namely, Windows) because the former may use something that is illegal in SYCL device code. #17025 fixed that, but only did so under preview breaking changes mode, which does not satisfy some of our customers immediately. This PR introduces two main changes: - it allows to opt-in for new behavior through passing `-D__SYCL_USE_NEW_VEC_IMPL=1` macro without using `-fpreview-breaking-changes` flag. That allows for a more gradual opt-in from customers who are interested in this fix - it switches the imlpementation to use the new approach with C-style arrays if their size and alignment is the same as for the corresponding `std::array` - in that case their memory layout is expected to be absolutely the same and therefore it should be safe to use the new approach without fear of some ABI incompatibilities. This allows for customers to benefit from the fix without specifying any extra macro (which should be the case for the most common platforms out there)
### Cherry-pick of: #17656 and some changes to resolve merge conflicts & make it work. The problem with using `std::array` in `sycl::vec` is that we cannot compile it in some environments (namely, Windows) because the former may use something that is illegal in SYCL device code. #17025 fixed that, but only did so under preview breaking changes mode, which does not satisfy some of our customers immediately. This PR introduces two main changes: - it allows to opt-in for new behavior through passing `-D__SYCL_USE_NEW_VEC_IMPL=1` macro without using `-fpreview-breaking-changes` flag. That allows for a more gradual opt-in from customers who are interested in this fix - it switches the imlpementation to use the new approach with C-style arrays if their size and alignment is the same as for the corresponding `std::array` - in that case their memory layout is expected to be absolutely the same and therefore it should be safe to use the new approach without fear of some ABI incompatibilities. This allows for customers to benefit from the fix without specifying any extra macro (which should be the case for the most common platforms out there) Co-authored-by: Alexey Sachkov <alexey.sachkov@intel.com>
The problem with using `std::array` in `sycl::vec` is that we cannot compile it in some environments (namely, Windows) because the former may use something that is illegal in SYCL device code. #17025 fixed that, but only did so under preview breaking changes mode, which does not satisfy some of our customers immediately. This PR introduces two main changes: - it allows to opt-in for new behavior through passing `-D__SYCL_USE_NEW_VEC_IMPL=1` macro without using `-fpreview-breaking-changes` flag. That allows for a more gradual opt-in from customers who are interested in this fix - it switches the imlpementation to use the new approach with C-style arrays if their size and alignment is the same as for the corresponding `std::array` - in that case their memory layout is expected to be absolutely the same and therefore it should be safe to use the new approach without fear of some ABI incompatibilities. This allows for customers to benefit from the fix without specifying any extra macro (which should be the case for the most common platforms out there)
#14130 caused
sycl::vec
to usestd::array
as its underlying storage. However, operations onstd::array
may emit debug-mode-only functions, on which the device compiler may fail.This PR replaces
std::array
with C-style arrays as storage insycl::vec
.