-
Notifications
You must be signed in to change notification settings - Fork 798
[SYCL] Add tangle/opportunistic algorithms #9220
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 6 commits into
intel:sycl
from
Pennycook:tangle_and_opportunistic_algorithms
May 2, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
41e3705
[SYCL] Add tangle/opportunistic algorithms
Pennycook e9ce19a
Test results for all work-items
Pennycook 2045e6a
Replace macro with lambda
Pennycook 92c0b10
Remove device split flag
Pennycook a296e0b
Disable early optimizations for tangle_group
Pennycook 40ec628
Temporarily disable tangle_group test on Windows
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
131 changes: 131 additions & 0 deletions
131
sycl/test-e2e/NonUniformGroups/opportunistic_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,131 @@ | ||
// 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; | ||
|
||
class TestKernel; | ||
|
||
constexpr uint32_t SGSize = 32; | ||
constexpr uint32_t ArbitraryItem = 5; | ||
|
||
int main() { | ||
sycl::queue Q; | ||
|
||
auto SGSizes = Q.get_device().get_info<sycl::info::device::sub_group_sizes>(); | ||
if (std::find(SGSizes.begin(), SGSizes.end(), SGSize) == SGSizes.end()) { | ||
std::cout << "Test skipped due to missing support for sub-group size 32." | ||
<< std::endl; | ||
return 0; | ||
} | ||
|
||
sycl::buffer<size_t, 1> TmpBuf{sycl::range{SGSize}}; | ||
sycl::buffer<bool, 1> BarrierBuf{sycl::range{SGSize}}; | ||
sycl::buffer<bool, 1> BroadcastBuf{sycl::range{SGSize}}; | ||
sycl::buffer<bool, 1> AnyBuf{sycl::range{SGSize}}; | ||
sycl::buffer<bool, 1> AllBuf{sycl::range{SGSize}}; | ||
sycl::buffer<bool, 1> NoneBuf{sycl::range{SGSize}}; | ||
sycl::buffer<bool, 1> ReduceBuf{sycl::range{SGSize}}; | ||
sycl::buffer<bool, 1> ExScanBuf{sycl::range{SGSize}}; | ||
sycl::buffer<bool, 1> IncScanBuf{sycl::range{SGSize}}; | ||
|
||
const auto NDR = sycl::nd_range<1>{SGSize, SGSize}; | ||
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(SGSize)]] { | ||
auto WI = item.get_global_id(); | ||
auto SG = item.get_sub_group(); | ||
|
||
uint32_t OriginalLID = SG.get_local_linear_id(); | ||
|
||
// Given the dynamic nature of opportunistic groups, the simplest | ||
// case we can reason about is a single work-item. This isn't a very | ||
// robust test, but choosing an arbitrary work-item (i.e. rather | ||
// than the leader) should test an implementation's ability to handle | ||
// arbitrary group membership. | ||
if (OriginalLID == ArbitraryItem) { | ||
auto OpportunisticGroup = | ||
syclex::this_kernel::get_opportunistic_group(); | ||
|
||
// This is trivial, but does test that group_barrier can be called. | ||
TmpAcc[WI] = 1; | ||
sycl::group_barrier(OpportunisticGroup); | ||
size_t Visible = TmpAcc[WI]; | ||
BarrierAcc[WI] = (Visible == 1); | ||
|
||
// Simple check of group algorithms. | ||
uint32_t LID = OpportunisticGroup.get_local_linear_id(); | ||
|
||
uint32_t BroadcastResult = | ||
sycl::group_broadcast(OpportunisticGroup, OriginalLID, 0); | ||
BroadcastAcc[WI] = (BroadcastResult == OriginalLID); | ||
|
||
bool AnyResult = sycl::any_of_group(OpportunisticGroup, (LID == 0)); | ||
AnyAcc[WI] = (AnyResult == true); | ||
|
||
bool AllResult = sycl::all_of_group(OpportunisticGroup, (LID == 0)); | ||
AllAcc[WI] = (AllResult == true); | ||
|
||
bool NoneResult = | ||
sycl::none_of_group(OpportunisticGroup, (LID != 0)); | ||
NoneAcc[WI] = (NoneResult == true); | ||
|
||
uint32_t ReduceResult = | ||
sycl::reduce_over_group(OpportunisticGroup, 1, sycl::plus<>()); | ||
ReduceAcc[WI] = | ||
(ReduceResult == OpportunisticGroup.get_local_linear_range()); | ||
|
||
uint32_t ExScanResult = sycl::exclusive_scan_over_group( | ||
OpportunisticGroup, 1, sycl::plus<>()); | ||
ExScanAcc[WI] = (ExScanResult == LID); | ||
|
||
uint32_t IncScanResult = sycl::inclusive_scan_over_group( | ||
OpportunisticGroup, 1, sycl::plus<>()); | ||
IncScanAcc[WI] = (IncScanResult == LID + 1); | ||
} else { | ||
BarrierAcc[WI] = false; | ||
BroadcastAcc[WI] = false; | ||
AnyAcc[WI] = false; | ||
AllAcc[WI] = false; | ||
NoneAcc[WI] = false; | ||
ReduceAcc[WI] = false; | ||
ExScanAcc[WI] = false; | ||
IncScanAcc[WI] = false; | ||
} | ||
}; | ||
CGH.parallel_for<TestKernel>(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 (uint32_t WI = 0; WI < 32; ++WI) { | ||
bool ExpectedResult = (WI == ArbitraryItem); | ||
assert(BarrierAcc[WI] == ExpectedResult); | ||
assert(BroadcastAcc[WI] == ExpectedResult); | ||
assert(AnyAcc[WI] == ExpectedResult); | ||
assert(AllAcc[WI] == ExpectedResult); | ||
assert(NoneAcc[WI] == ExpectedResult); | ||
assert(ReduceAcc[WI] == ExpectedResult); | ||
assert(ExScanAcc[WI] == ExpectedResult); | ||
assert(IncScanAcc[WI] == ExpectedResult); | ||
} | ||
return 0; | ||
} |
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.
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.
Since you only have a single thread per group is this going to properly test the group implementations for intel case? In cuda backend it wouldn't for the reduce_over_group case. Also in cuda impl the reduce algorithm behaves differently if
OpportunisticGroup.get_local_range()
equals 2^n where n is positive integer not zero, or if it does not equal this, or if it is equal 1 (like in this test currently, the more trivial case), or if it 32 (full warp). Making four different cases in total.But I could add these cases later if needs be.
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.
This isn't going to test every path, but I couldn't think of a good way to do that reliably. The semantics of opportunistic groups are (deliberately) really weird.
Even if we added a case where we picked a power of 2 (say, 8) work-items and had them all take the same branch, the specification doesn't require all 8 of those work-items to end up in the same opportunistic group. The specification only requires that all the work-items who encounter the constructor "together" (furious hand waving) form an opportunistic group. There's no way to query which work-items end up in which group, or how many groups are formed. A single work-item executing the branch was the only case I could think of with predictable, portable behavior.
Ideally, we'd probably want to somehow work out which work-items were split into which opportunistic groups, and then dynamically determine what the algorithm results should be given the partitioning that actually happened at runtime. But I couldn't think of a good way to do that. If we can figure out a good way to write that test, we should definitely add it.
I agree that adding some backend-specific tests would be a good idea, too.