-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,7 +144,16 @@ template <typename DataT, int NumElements> class vec_base { | |
static constexpr size_t AdjustedNum = (NumElements == 3) ? 4 : NumElements; | ||
// This represent type of underlying value. There should be only one field | ||
// in the class, so vec<float, 16> should be equal to float16 in memory. | ||
#if defined(__INTEL_PREVIEW_BREAKING_CHANGES) && \ | ||
defined(__SYCL_USE_NEW_VEC_IMPL) | ||
using DataType = DataT[AdjustedNum]; | ||
#else | ||
using DataType = std::array<DataT, AdjustedNum>; | ||
// Assuming that std::array has the same size as the underlying array. | ||
// C++ standard does not guarantee that, but it is true for most popular | ||
// implementations. | ||
static_assert(sizeof(DataType) == sizeof(DataT[AdjustedNum])); | ||
#endif | ||
|
||
protected: | ||
// fields | ||
|
@@ -287,7 +296,8 @@ 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) { | ||
this->m_Data = sycl::bit_cast<decltype(this->m_Data)>(openclVector); | ||
sycl::detail::memcpy_no_adl(&this->m_Data, &openclVector, | ||
sizeof(openclVector)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above. |
||
} | ||
|
||
/* @SYCL2020 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?Uh oh!
There was an error while loading. Please reload this page.
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.
We couldn't have done
sycl::detail::memcpy_no_adl(&Result.m_Data, &val, sizeof(Result));
forstd::array
as base address ofstd::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-dataThere 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: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. 😄