-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Implement sub_group_mask version 2 #11195
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
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6bc3d1e
[SYCL] Implement sub_group_mask version 2
steffenlarsen c3af751
Test
KornevNikita ddce977
format
KornevNikita 0a34335
Update test
KornevNikita 6434bf5
Update failed tests
KornevNikita 318bfb9
Add missing include
KornevNikita 2923728
Move test to e2e
KornevNikita 101ae16
Add endline
KornevNikita bc6ca62
Increase mask size on host
KornevNikita 9cf3733
Use 64 bits for all devices
KornevNikita 7f21e53
Replace BITS_TYPE by BitsType
KornevNikita a22890d
Apply suggestion
KornevNikita 739885f
Revert "Apply suggestion"
KornevNikita 305defb
Apply suggestion & fix
KornevNikita 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
#include <iostream> | ||
#include <sycl/sycl.hpp> | ||
|
||
#define TEST_ON_DEVICE(TEST_BODY) \ | ||
{ \ | ||
sycl::queue queue; \ | ||
sycl::buffer<bool, 1> buf(&res, 1); \ | ||
queue.submit([&](sycl::handler &h) { \ | ||
auto acc = buf.get_access<sycl::access_mode::write>(h); \ | ||
h.parallel_for(sycl::nd_range<1>(sycl::range<1>(1), sycl::range<1>(1)), \ | ||
[=](sycl::nd_item<1> item) { TEST_BODY }); \ | ||
}); \ | ||
queue.wait(); \ | ||
} \ | ||
assert(res); | ||
|
||
int main() { | ||
#if SYCL_EXT_ONEAPI_SUB_GROUP_MASK >= 2 | ||
using mask_type = sycl::ext::oneapi::sub_group_mask; | ||
|
||
// sub_group_mask() | ||
{ | ||
mask_type mask; | ||
assert(mask.none() && mask_type::max_bits == mask.size()); | ||
|
||
bool res = false; | ||
// clang-format off | ||
TEST_ON_DEVICE( | ||
mask_type mask; | ||
auto sg = item.get_sub_group(); | ||
acc[0] = mask.none() && (sg.get_max_local_range().size() == mask.size()); | ||
) | ||
// clang-format on | ||
} | ||
// sub_group_mask(unsigned long long val) | ||
{ | ||
unsigned long long val = 4815162342; | ||
mask_type mask(val); | ||
std::bitset<sizeof(val) * CHAR_BIT> bs(val); | ||
bool res = true; | ||
for (size_t i = 0; | ||
i < std::min(static_cast<size_t>(mask.size()), bs.size()); ++i) | ||
res &= mask[i] == bs[i]; | ||
assert(res); | ||
|
||
// clang-format off | ||
TEST_ON_DEVICE( | ||
mask_type mask(val); | ||
auto sg = item.get_sub_group(); | ||
acc[0] = sg.get_max_local_range().size() == mask.size(); | ||
for (size_t i = 0; | ||
i < sycl::min(static_cast<size_t>(mask.size()), bs.size()); | ||
++i) | ||
acc[0] &= mask[i] == bs[i]; | ||
) | ||
// clang-format on | ||
} | ||
// template <typename T, std::size_t K> sub_group_mask(const sycl::marray<T, | ||
// K>& &val) | ||
{ | ||
sycl::marray<char, 4> marr{1, 2, 3, 4}; | ||
mask_type mask(marr); | ||
std::bitset<CHAR_BIT> bs[4] = {1, 2, 3, 4}; | ||
bool res = true; | ||
for (size_t i = 0; i < mask.size() && (i / CHAR_BIT) < 4; ++i) | ||
res &= mask[i] == bs[i / CHAR_BIT][i % CHAR_BIT]; | ||
assert(res); | ||
|
||
// clang-format off | ||
TEST_ON_DEVICE( | ||
mask_type mask(marr); | ||
auto sg = item.get_sub_group(); | ||
acc[0] = sg.get_max_local_range().size() == mask.size(); | ||
for (size_t i = 0; i < mask.size() && (i / CHAR_BIT) < 4; ++i) | ||
acc[0] &= mask[i] == bs[i / CHAR_BIT][i % CHAR_BIT]; | ||
) | ||
// clang-format on | ||
} | ||
{ | ||
// sub_group_mask(const sub_group_mask &other) | ||
unsigned long long val = 4815162342; | ||
mask_type mask1(val); | ||
mask_type mask2(mask1); | ||
assert(mask1 == mask2); | ||
|
||
bool res = false; | ||
// clang-format off | ||
TEST_ON_DEVICE( | ||
mask_type mask1(val); | ||
mask_type mask2(mask1); | ||
acc[0] = mask1 == mask2; | ||
) | ||
// clang-format on | ||
} | ||
{ | ||
// sub_group_mask& operator=(const sub_group_mask &other) | ||
unsigned long long val = 4815162342; | ||
mask_type mask1(val); | ||
mask_type mask2 = mask1; | ||
assert(mask1 == mask2); | ||
|
||
bool res = false; | ||
// clang-format off | ||
TEST_ON_DEVICE( | ||
mask_type mask1(val); | ||
mask_type mask2 = mask1; | ||
acc[0] = mask1 == mask2; | ||
) | ||
// clang-format on | ||
} | ||
#else | ||
std::cout << "Test skipped due to unsupported extension." << std::endl; | ||
#endif | ||
|
||
return 0; | ||
} |
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
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.