-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][Fusion] Test and document group algorithms/function support #12644
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// RUN: %{build} -fsycl-embed-ir -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
// Test fusion works with permute and remapping. | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
#include "../helpers.hpp" | ||
#include "sycl/group_algorithm.hpp" | ||
|
||
using namespace sycl; | ||
|
||
class FillKernel; | ||
class Kernel0; | ||
class Kernel1; | ||
|
||
int main() { | ||
constexpr size_t dataSize = 512; | ||
constexpr size_t localSize = 16; | ||
std::array<int, dataSize / localSize> in; | ||
std::array<int, dataSize> out0; | ||
std::array<int, dataSize / 2> out1; | ||
// Needed to check results | ||
size_t sg_size = 0; | ||
|
||
queue q{ext::codeplay::experimental::property::queue::enable_fusion{}}; | ||
{ | ||
buffer<int> buff_in{in}; | ||
buffer<int> buff_out0{out0}; | ||
buffer<int> buff_out1{out1}; | ||
buffer<size_t> buff_sg_size{&sg_size, 1}; | ||
|
||
ext::codeplay::experimental::fusion_wrapper fw{q}; | ||
|
||
q.submit([&](handler &cgh) { | ||
accessor in(buff_in, cgh, write_only, no_init); | ||
cgh.parallel_for<FillKernel>(nd_range<1>{{dataSize}, {localSize}}, | ||
[=](nd_item<1> i) { | ||
if (i.get_local_id() == 0) { | ||
auto j = i.get_group(0); | ||
in[j] = static_cast<int>(j); | ||
} | ||
}); | ||
}); | ||
|
||
fw.start_fusion(); | ||
|
||
q.submit([&](handler &cgh) { | ||
accessor sg_size(buff_sg_size, cgh, write_only, no_init); | ||
accessor in(buff_in, cgh, read_only); | ||
accessor out(buff_out0, cgh, write_only, no_init); | ||
cgh.parallel_for<Kernel0>( | ||
nd_range<1>{{dataSize}, {localSize}}, [=](nd_item<1> i) { | ||
sub_group group = i.get_sub_group(); | ||
int gid = i.get_global_id(); | ||
int sgid = group.get_group_id(); | ||
sg_size[0] = group.get_max_local_range()[0]; | ||
out[gid] = permute_group_by_xor( | ||
group, gid, sgid % group.get_max_local_range()[0]); | ||
}); | ||
}); | ||
|
||
q.submit([&](handler &cgh) { | ||
accessor in(buff_in, cgh, read_only); | ||
accessor out(buff_out1, cgh, write_only, no_init); | ||
cgh.parallel_for<Kernel1>( | ||
nd_range<1>{{dataSize / 2}, {localSize}}, [=](nd_item<1> i) { | ||
sub_group group = i.get_sub_group(); | ||
int gid = i.get_global_id(); | ||
int sgid = group.get_group_id(); | ||
out[gid] = permute_group_by_xor( | ||
group, gid, sgid % group.get_max_local_range()[0]); | ||
}); | ||
}); | ||
|
||
complete_fusion_with_check(fw); | ||
} | ||
|
||
// Check the results | ||
int SGid = 0; | ||
int SGLid = 0; | ||
int SGBeginGid = 0; | ||
int j = 0; | ||
const auto check = [sg_size, &SGid, &SGLid, &SGBeginGid, &out0, | ||
&out1](int j, bool checkSmall) { | ||
if (j % localSize % sg_size == 0) { | ||
SGid++; | ||
SGLid = 0; | ||
SGBeginGid = j; | ||
} | ||
if (j % localSize == 0) { | ||
SGid = 0; | ||
SGLid = 0; | ||
SGBeginGid = j; | ||
} | ||
assert(out0[j] == SGBeginGid + (SGLid ^ (SGid % sg_size))); | ||
assert(!checkSmall || (out1[j] == SGBeginGid + (SGLid ^ (SGid % sg_size)))); | ||
SGLid++; | ||
}; | ||
for (int end = dataSize / 2; j < end; j++) { | ||
check(j, true); | ||
} | ||
for (int end = dataSize; j < end; j++) { | ||
check(j, false); | ||
} | ||
|
||
return 0; | ||
} |
85 changes: 85 additions & 0 deletions
85
sycl/test-e2e/KernelFusion/GroupFunctions/group_broadcast_remapping.cpp
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// RUN: %{build} -fsycl-embed-ir -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
// Test fusion works with group_broadcast and remapping. | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
#include "../helpers.hpp" | ||
|
||
using namespace sycl; | ||
|
||
class FillKernel; | ||
class Kernel0; | ||
class Kernel1; | ||
|
||
int main() { | ||
constexpr size_t dataSize = 512; | ||
constexpr size_t localSize = 16; | ||
std::array<int, dataSize / localSize> in; | ||
std::array<int, dataSize> out0; | ||
std::array<int, dataSize / 2> out1; | ||
|
||
queue q{ext::codeplay::experimental::property::queue::enable_fusion{}}; | ||
{ | ||
buffer<int> buff_in{in}; | ||
buffer<int> buff_out0{out0}; | ||
buffer<int> buff_out1{out1}; | ||
|
||
ext::codeplay::experimental::fusion_wrapper fw{q}; | ||
|
||
q.submit([&](handler &cgh) { | ||
accessor in(buff_in, cgh, write_only, no_init); | ||
cgh.parallel_for<FillKernel>(nd_range<1>{{dataSize}, {localSize}}, | ||
[=](nd_item<1> i) { | ||
if (i.get_local_id() == 0) { | ||
auto j = i.get_group(0); | ||
in[j] = static_cast<int>(j); | ||
} | ||
}); | ||
}); | ||
|
||
fw.start_fusion(); | ||
|
||
q.submit([&](handler &cgh) { | ||
accessor in(buff_in, cgh, read_only); | ||
accessor out(buff_out0, cgh, write_only, no_init); | ||
cgh.parallel_for<Kernel0>( | ||
nd_range<1>{{dataSize}, {localSize}}, [=](nd_item<1> i) { | ||
auto group = i.get_group(); | ||
out[i.get_global_id()] = group_broadcast( | ||
group, i.get_local_id() == 1 ? in[group.get_group_id(0)] : -1, | ||
1); | ||
}); | ||
}); | ||
|
||
q.submit([&](handler &cgh) { | ||
accessor in(buff_in, cgh, read_only); | ||
accessor out(buff_out1, cgh, write_only, no_init); | ||
cgh.parallel_for<Kernel1>( | ||
nd_range<1>{{dataSize / 2}, {localSize}}, [=](nd_item<1> i) { | ||
auto group = i.get_group(); | ||
out[i.get_global_id()] = group_broadcast( | ||
group, i.get_local_id() == 1 ? in[group.get_group_id(0)] : -1, | ||
1); | ||
}); | ||
}); | ||
|
||
complete_fusion_with_check(fw); | ||
} | ||
|
||
// Check the results | ||
int i = 0; | ||
for (int end = dataSize / 2; i < end; ++i) { | ||
int group_id = i / static_cast<int>(localSize); | ||
assert(out0[i] == group_id && "Computation error"); | ||
assert(out1[i] == group_id && "Computation error"); | ||
} | ||
|
||
for (int end = dataSize; i < end; ++i) { | ||
int group_id = i / static_cast<int>(localSize); | ||
assert(out0[i] == group_id && "Computation error"); | ||
} | ||
|
||
return 0; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.