-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Add fixed_size_group support to algorithms #9181
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
steffenlarsen
merged 7 commits into
intel:sycl
from
Pennycook:fixed_size_group_algorithms
Apr 25, 2023
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da76eba
[SYCL] Add fixed_size_group support to algorithms
Pennycook 27944f9
Add missing periods to comments
Pennycook 41a0b0c
Use constexpr uint32_t for sub-group size
Pennycook 1e20b2b
Merge branch 'sycl' into fixed_size_group_algorithms
Pennycook 73c9cdf
Convert to std::conditional_t
Pennycook 9e6b0a4
Add per_kernel splitting for sub-group size
Pennycook aaba56c
Remove unused group parameter
Pennycook 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
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
132 changes: 132 additions & 0 deletions
132
sycl/test-e2e/NonUniformGroups/fixed_size_group_algorithms.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,132 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
// | ||
// UNSUPPORTED: cpu || cuda || hip | ||
|
||
#include <sycl/sycl.hpp> | ||
#include <vector> | ||
namespace syclex = sycl::ext::oneapi::experimental; | ||
|
||
template <size_t PartitionSize> class TestKernel; | ||
|
||
template <size_t PartitionSize> void test() { | ||
sycl::queue Q; | ||
|
||
auto SGSizes = Q.get_device().get_info<sycl::info::device::sub_group_sizes>(); | ||
if (std::find(SGSizes.begin(), SGSizes.end(), 32) == SGSizes.end()) { | ||
std::cout << "Test skipped due to missing support for sub-group size 32." | ||
<< std::endl; | ||
} | ||
|
||
aelovikov-intel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sycl::buffer<size_t, 1> TmpBuf{sycl::range{32}}; | ||
sycl::buffer<bool, 1> BarrierBuf{sycl::range{32}}; | ||
sycl::buffer<bool, 1> BroadcastBuf{sycl::range{32}}; | ||
sycl::buffer<bool, 1> AnyBuf{sycl::range{32}}; | ||
sycl::buffer<bool, 1> AllBuf{sycl::range{32}}; | ||
sycl::buffer<bool, 1> NoneBuf{sycl::range{32}}; | ||
sycl::buffer<bool, 1> ReduceBuf{sycl::range{32}}; | ||
sycl::buffer<bool, 1> ExScanBuf{sycl::range{32}}; | ||
sycl::buffer<bool, 1> IncScanBuf{sycl::range{32}}; | ||
aelovikov-intel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const auto NDR = sycl::nd_range<1>{32, 32}; | ||
Q.submit([&](sycl::handler &CGH) { | ||
sycl::accessor TmpAcc{TmpBuf, CGH, sycl::write_only}; | ||
sycl::accessor BarrierAcc{BarrierBuf, CGH, sycl::write_only}; | ||
sycl::accessor BroadcastAcc{BroadcastBuf, CGH, sycl::write_only}; | ||
sycl::accessor AnyAcc{AnyBuf, CGH, sycl::write_only}; | ||
sycl::accessor AllAcc{AllBuf, CGH, sycl::write_only}; | ||
sycl::accessor NoneAcc{NoneBuf, CGH, sycl::write_only}; | ||
sycl::accessor ReduceAcc{ReduceBuf, CGH, sycl::write_only}; | ||
sycl::accessor ExScanAcc{ExScanBuf, CGH, sycl::write_only}; | ||
sycl::accessor IncScanAcc{IncScanBuf, CGH, sycl::write_only}; | ||
const auto KernelFunc = | ||
[=](sycl::nd_item<1> item) [[sycl::reqd_sub_group_size(32)]] { | ||
auto WI = item.get_global_id(); | ||
auto SG = item.get_sub_group(); | ||
|
||
// Split into partitions of fixed size | ||
auto Partition = syclex::get_fixed_size_group<PartitionSize>(SG); | ||
|
||
// Check all other members' writes are visible after a barrier | ||
Pennycook marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TmpAcc[WI] = 1; | ||
sycl::group_barrier(Partition); | ||
size_t Visible = 0; | ||
for (size_t Other = 0; Other < 32; ++Other) { | ||
if ((WI / PartitionSize) == (Other / PartitionSize)) { | ||
Visible += TmpAcc[Other]; | ||
} | ||
} | ||
BarrierAcc[WI] = (Visible == PartitionSize); | ||
|
||
// Simple check of group algorithms | ||
Pennycook marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uint32_t OriginalLID = SG.get_local_linear_id(); | ||
uint32_t LID = Partition.get_local_linear_id(); | ||
|
||
uint32_t PartitionLeader = | ||
(OriginalLID / PartitionSize) * PartitionSize; | ||
uint32_t BroadcastResult = | ||
sycl::group_broadcast(Partition, OriginalLID, 0); | ||
BroadcastAcc[WI] = (BroadcastResult == PartitionLeader); | ||
|
||
bool AnyResult = sycl::any_of_group(Partition, (LID == 0)); | ||
AnyAcc[WI] = (AnyResult == true); | ||
|
||
bool Predicate = ((OriginalLID / PartitionSize) % 2 == 0); | ||
bool AllResult = sycl::all_of_group(Partition, Predicate); | ||
if (Predicate) { | ||
AllAcc[WI] = (AllResult == true); | ||
} else { | ||
AllAcc[WI] = (AllResult == false); | ||
} | ||
|
||
bool NoneResult = sycl::none_of_group(Partition, Predicate); | ||
if (Predicate) { | ||
NoneAcc[WI] = (NoneResult == false); | ||
} else { | ||
NoneAcc[WI] = (NoneResult == true); | ||
} | ||
|
||
uint32_t ReduceResult = | ||
sycl::reduce_over_group(Partition, 1, sycl::plus<>()); | ||
ReduceAcc[WI] = (ReduceResult == PartitionSize); | ||
|
||
uint32_t ExScanResult = | ||
sycl::exclusive_scan_over_group(Partition, 1, sycl::plus<>()); | ||
ExScanAcc[WI] = (ExScanResult == LID); | ||
|
||
uint32_t IncScanResult = | ||
sycl::inclusive_scan_over_group(Partition, 1, sycl::plus<>()); | ||
IncScanAcc[WI] = (IncScanResult == LID + 1); | ||
}; | ||
CGH.parallel_for<TestKernel<PartitionSize>>(NDR, KernelFunc); | ||
}); | ||
|
||
sycl::host_accessor BarrierAcc{BarrierBuf, sycl::read_only}; | ||
sycl::host_accessor BroadcastAcc{BroadcastBuf, sycl::read_only}; | ||
sycl::host_accessor AnyAcc{AnyBuf, sycl::read_only}; | ||
sycl::host_accessor AllAcc{AllBuf, sycl::read_only}; | ||
sycl::host_accessor NoneAcc{NoneBuf, sycl::read_only}; | ||
sycl::host_accessor ReduceAcc{ReduceBuf, sycl::read_only}; | ||
sycl::host_accessor ExScanAcc{ExScanBuf, sycl::read_only}; | ||
sycl::host_accessor IncScanAcc{IncScanBuf, sycl::read_only}; | ||
for (int WI = 0; WI < 32; ++WI) { | ||
assert(BarrierAcc[WI] == true); | ||
assert(BroadcastAcc[WI] == true); | ||
assert(AnyAcc[WI] == true); | ||
assert(AllAcc[WI] == true); | ||
assert(NoneAcc[WI] == true); | ||
assert(ReduceAcc[WI] == true); | ||
assert(ExScanAcc[WI] == true); | ||
assert(IncScanAcc[WI] == true); | ||
} | ||
} | ||
|
||
int main() { | ||
test<1>(); | ||
test<2>(); | ||
test<4>(); | ||
test<8>(); | ||
test<16>(); | ||
test<32>(); | ||
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.