Skip to content
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

[SYCL] Improve performance of generic shuffles #3815

Merged
merged 2 commits into from
Jul 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions sycl/include/CL/sycl/detail/spirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ template <typename T, typename Functor>
void GenericCall(const Functor &ApplyToBytes) {
if (sizeof(T) >= sizeof(ShuffleChunkT)) {
#pragma unroll
for (size_t Offset = 0; Offset < sizeof(T);
for (size_t Offset = 0; Offset + sizeof(ShuffleChunkT) <= sizeof(T);
Offset += sizeof(ShuffleChunkT)) {
ApplyToBytes(Offset, sizeof(ShuffleChunkT));
}
Expand Down Expand Up @@ -153,9 +153,9 @@ EnableIfGenericBroadcast<T, IdT> GroupBroadcast(T x, IdT local_id) {
char *ResultBytes = reinterpret_cast<char *>(&Result);
auto BroadcastBytes = [=](size_t Offset, size_t Size) {
uint64_t BroadcastX, BroadcastResult;
detail::memcpy(&BroadcastX, XBytes + Offset, Size);
std::memcpy(&BroadcastX, XBytes + Offset, Size);
Copy link
Contributor

Choose a reason for hiding this comment

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

It look like this breaks the tests due to missing #include <cstring>. See pre-commit failures for #4153.
@Pennycook, could you fix this ASAP, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that. Opened #4157 to (hopefully) fix it.

BroadcastResult = GroupBroadcast<Group>(BroadcastX, local_id);
detail::memcpy(ResultBytes + Offset, &BroadcastResult, Size);
std::memcpy(ResultBytes + Offset, &BroadcastResult, Size);
};
GenericCall<T>(BroadcastBytes);
return Result;
Expand Down Expand Up @@ -206,9 +206,9 @@ EnableIfGenericBroadcast<T> GroupBroadcast(T x, id<Dimensions> local_id) {
char *ResultBytes = reinterpret_cast<char *>(&Result);
auto BroadcastBytes = [=](size_t Offset, size_t Size) {
uint64_t BroadcastX, BroadcastResult;
detail::memcpy(&BroadcastX, XBytes + Offset, Size);
std::memcpy(&BroadcastX, XBytes + Offset, Size);
BroadcastResult = GroupBroadcast<Group>(BroadcastX, local_id);
detail::memcpy(ResultBytes + Offset, &BroadcastResult, Size);
std::memcpy(ResultBytes + Offset, &BroadcastResult, Size);
};
GenericCall<T>(BroadcastBytes);
return Result;
Expand Down Expand Up @@ -682,9 +682,9 @@ EnableIfGenericShuffle<T> SubgroupShuffle(T x, id<1> local_id) {
char *ResultBytes = reinterpret_cast<char *>(&Result);
auto ShuffleBytes = [=](size_t Offset, size_t Size) {
ShuffleChunkT ShuffleX, ShuffleResult;
detail::memcpy(&ShuffleX, XBytes + Offset, Size);
std::memcpy(&ShuffleX, XBytes + Offset, Size);
ShuffleResult = SubgroupShuffle(ShuffleX, local_id);
detail::memcpy(ResultBytes + Offset, &ShuffleResult, Size);
std::memcpy(ResultBytes + Offset, &ShuffleResult, Size);
};
GenericCall<T>(ShuffleBytes);
return Result;
Expand All @@ -697,9 +697,9 @@ EnableIfGenericShuffle<T> SubgroupShuffleXor(T x, id<1> local_id) {
char *ResultBytes = reinterpret_cast<char *>(&Result);
auto ShuffleBytes = [=](size_t Offset, size_t Size) {
ShuffleChunkT ShuffleX, ShuffleResult;
detail::memcpy(&ShuffleX, XBytes + Offset, Size);
std::memcpy(&ShuffleX, XBytes + Offset, Size);
ShuffleResult = SubgroupShuffleXor(ShuffleX, local_id);
detail::memcpy(ResultBytes + Offset, &ShuffleResult, Size);
std::memcpy(ResultBytes + Offset, &ShuffleResult, Size);
};
GenericCall<T>(ShuffleBytes);
return Result;
Expand All @@ -712,9 +712,9 @@ EnableIfGenericShuffle<T> SubgroupShuffleDown(T x, id<1> local_id) {
char *ResultBytes = reinterpret_cast<char *>(&Result);
auto ShuffleBytes = [=](size_t Offset, size_t Size) {
ShuffleChunkT ShuffleX, ShuffleResult;
detail::memcpy(&ShuffleX, XBytes + Offset, Size);
std::memcpy(&ShuffleX, XBytes + Offset, Size);
ShuffleResult = SubgroupShuffleDown(ShuffleX, local_id);
detail::memcpy(ResultBytes + Offset, &ShuffleResult, Size);
std::memcpy(ResultBytes + Offset, &ShuffleResult, Size);
};
GenericCall<T>(ShuffleBytes);
return Result;
Expand All @@ -727,9 +727,9 @@ EnableIfGenericShuffle<T> SubgroupShuffleUp(T x, id<1> local_id) {
char *ResultBytes = reinterpret_cast<char *>(&Result);
auto ShuffleBytes = [=](size_t Offset, size_t Size) {
ShuffleChunkT ShuffleX, ShuffleResult;
detail::memcpy(&ShuffleX, XBytes + Offset, Size);
std::memcpy(&ShuffleX, XBytes + Offset, Size);
ShuffleResult = SubgroupShuffleUp(ShuffleX, local_id);
detail::memcpy(ResultBytes + Offset, &ShuffleResult, Size);
std::memcpy(ResultBytes + Offset, &ShuffleResult, Size);
};
GenericCall<T>(ShuffleBytes);
return Result;
Expand Down