-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][Reduction] Avoid implicit atomic64 requirements #9070
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 3 commits into
intel:sycl
from
steffenlarsen:steffen/fix_implicit_redu_atomic64
Apr 17, 2023
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,67 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
// | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
|
||
// Tests that a previously known case for reduction doesn't cause a requirement | ||
// for atomic64. | ||
// TODO: When aspect requirements are added to testing, this test could be set | ||
// to require that atomic64 is NOT supported, to limit how frequently the | ||
// test is run. However, it should work on devices that support atomic64 | ||
// as well. | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
#include <iostream> | ||
|
||
using namespace sycl; | ||
|
||
int main() { | ||
queue Q; | ||
|
||
if (Q.get_device().has(aspect::atomic64)) { | ||
std::cout << "Device supports aspect::atomic64 so we do not need to run " | ||
"the test." | ||
<< std::endl; | ||
return 0; | ||
} | ||
|
||
long long *Out = malloc_shared<long long>(1, Q); | ||
|
||
// Case 1: nd_range reduction with 64-bit integer and either sycl::plus, | ||
// sycl::minimum or sycl::maximum. group_reduce_and_atomic_cross_wg strategy | ||
// would normally be picked, but if the device does not support atomic64 that | ||
// strategy is invalid. | ||
Q.submit([&](handler &CGH) { | ||
auto Redu = reduction(Out, 0ll, sycl::plus<long long>{}); | ||
CGH.parallel_for(nd_range<1>{range<1>{32}, range<1>{32}}, Redu, | ||
[=](nd_item<1> It, auto &Sum) { | ||
Sum.combine(It.get_global_linear_id()); | ||
}); | ||
}).wait(); | ||
|
||
// Case 2: nd_range reduction with 64-bit integer and either sycl::bit_or, | ||
// sycl::bit_xor, sycl::bit_and. local_mem_tree_and_atomic_cross_wg strategy | ||
// would normally be picked, but if the device does not support atomic64 that | ||
// strategy is invalid. | ||
Q.submit([&](handler &CGH) { | ||
auto Redu = reduction(Out, 0ll, sycl::bit_and<long long>{}); | ||
CGH.parallel_for(nd_range<1>{range<1>{32}, range<1>{32}}, Redu, | ||
[=](nd_item<1> It, auto &Sum) { | ||
Sum.combine(It.get_global_linear_id()); | ||
}); | ||
}).wait(); | ||
|
||
// Case 3: range reduction with 64-bit integer and either sycl::bit_or, | ||
// sycl::bit_xor, sycl::bit_and. local_atomic_and_atomic_cross_wg strategy | ||
// would normally be picked, but if the device does not support atomic64 that | ||
// strategy is invalid. | ||
Q.submit([&](handler &CGH) { | ||
auto Redu = reduction(Out, 0ll, sycl::bit_and<long long>{}); | ||
CGH.parallel_for(range<1>{32}, Redu, | ||
[=](item<1> It, auto &Sum) { Sum.combine(It); }); | ||
}).wait(); | ||
sycl::free(Out, Q); | ||
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.
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'd suggest adding runtime aspect check for that here in this PR with the expectation that we'll uplift it to
// REQUIRES
once the support is added to thellvm.lit.cfg.py
.I also think that a slightly better option would be to "unit-test" the dynamic strategy selector once it's implemented (i.e., don't even run the actual reduction kernel).
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 could do a runtime check if you prefer. The test is still valid, so this TODO is more of a suggestion than a requirement really.
I agree that would be better, but sadly the unittests don't compile the kernels, so we would have no way of knowing if the corresponding kernels had any requirements. We could set the requirements ourselves, but that really defeats the purpose of the tests.