Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 65f48fa

Browse files
authored
[SYCL] Update sub-group mask test (#462)
1 parent 184bff5 commit 65f48fa

File tree

4 files changed

+197
-87
lines changed

4 files changed

+197
-87
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ SYCL/Functor @AlexeySachkov
3535
# Group algorithms
3636
SYCL/GroupAlgorithm @Pennycook @AlexeySachkov
3737
SYCL/SubGroup @Pennycook @AlexeySachkov
38-
SYCL/GroupMask @Pennycook @vladimilaz
38+
SYCL/SubGroupMask @Pennycook @vladimilaz
3939

4040
# Group local memory
4141
SYCL/GroupLocalMemory @sergey-semenov @Pennycook

SYCL/GroupMask/Basic.cpp

Lines changed: 0 additions & 86 deletions
This file was deleted.

SYCL/SubGroupMask/Basic.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// REQUIRES: gpu
3+
// UNSUPPORTED: cuda, hip
4+
// GroupNonUniformBallot capability is supported on Intel GPU only
5+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
6+
7+
//==---------- Basic.cpp - sub-group mask basic test -----------*- C++ -*---==//
8+
//
9+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10+
// See https://llvm.org/LICENSE.txt for license information.
11+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include <CL/sycl.hpp>
16+
using namespace sycl;
17+
constexpr int global_size = 128;
18+
constexpr int local_size = 32;
19+
int main() {
20+
#ifdef SYCL_EXT_ONEAPI_SUB_GROUP_MASK
21+
queue Queue;
22+
23+
try {
24+
nd_range<1> NdRange(global_size, local_size);
25+
int Res = 0;
26+
{
27+
buffer resbuf(&Res, range<1>(1));
28+
29+
Queue.submit([&](handler &cgh) {
30+
auto resacc = resbuf.get_access<access::mode::read_write>(cgh);
31+
32+
cgh.parallel_for<class sub_group_mask_test>(
33+
NdRange, [=](nd_item<1> NdItem) [[intel::reqd_sub_group_size(32)]] {
34+
size_t GID = NdItem.get_global_linear_id();
35+
auto SG = NdItem.get_sub_group();
36+
// AAAAAAAA
37+
auto gmask_gid2 =
38+
ext::oneapi::group_ballot(NdItem.get_sub_group(), GID % 2);
39+
// B6DB6DB6
40+
auto gmask_gid3 =
41+
ext::oneapi::group_ballot(NdItem.get_sub_group(), GID % 3);
42+
43+
if (!GID) {
44+
int res = 0;
45+
46+
for (size_t i = 0; i < SG.get_max_local_range()[0]; i++) {
47+
res |= !((gmask_gid2 | gmask_gid3)[i] == (i % 2 || i % 3))
48+
<< 1;
49+
res |= !((gmask_gid2 & gmask_gid3)[i] == (i % 2 && i % 3))
50+
<< 2;
51+
res |= !((gmask_gid2 ^ gmask_gid3)[i] ==
52+
((bool)(i % 2) ^ (bool)(i % 3)))
53+
<< 3;
54+
}
55+
gmask_gid2 <<= 8;
56+
uint32_t r = 0;
57+
gmask_gid2.extract_bits(r);
58+
res |= (r != 0xaaaaaa00) << 4;
59+
(gmask_gid2 >> 4).extract_bits(r);
60+
res |= (r != 0x0aaaaaa0) << 5;
61+
gmask_gid3.insert_bits((char)0b01010101, 8);
62+
res |= (!gmask_gid3[8] || gmask_gid3[9] || !gmask_gid3[10] ||
63+
gmask_gid3[11])
64+
<< 6;
65+
marray<unsigned char, 6> mr{1};
66+
gmask_gid3.extract_bits(mr);
67+
res |= (mr[0] != 0xb6 || mr[1] != 0x55 || mr[2] != 0xdb ||
68+
mr[3] != 0xb6 || mr[4] || mr[5])
69+
<< 7;
70+
res |= (gmask_gid2[30] || !gmask_gid2[31]) << 8;
71+
gmask_gid3[0] = gmask_gid3[3] = gmask_gid3[6] = true;
72+
gmask_gid3.extract_bits(r);
73+
res |= (r != 0xb6db55ff) << 9;
74+
gmask_gid3.reset();
75+
res |= !(gmask_gid3.none() && gmask_gid2.any() &&
76+
!gmask_gid2.all())
77+
<< 10;
78+
gmask_gid2.set();
79+
res |=
80+
!(gmask_gid3.none() && gmask_gid2.any() && gmask_gid2.all())
81+
<< 11;
82+
gmask_gid3.flip();
83+
res |= (gmask_gid3 != gmask_gid2) << 12;
84+
resacc[0] = res;
85+
}
86+
});
87+
});
88+
}
89+
if (Res) {
90+
std::cout << "Unexpected result for sub_group_mask operation: " << Res
91+
<< std::endl;
92+
exit(1);
93+
}
94+
} catch (exception e) {
95+
std::cout << "SYCL exception caught: " << e.what();
96+
exit(1);
97+
}
98+
99+
std::cout << "Test passed." << std::endl;
100+
#else
101+
std::cout << "Test skipped due to missing extension." << std::endl;
102+
#endif
103+
return 0;
104+
}

SYCL/SubGroupMask/GroupSize.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// REQUIRES: gpu
3+
// UNSUPPORTED: cuda, hip
4+
// GroupNonUniformBallot capability is supported on Intel GPU only
5+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
6+
7+
//==- GroupSize.cpp - sub-group mask dependency on group size --*- C++ -*---==//
8+
//
9+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10+
// See https://llvm.org/LICENSE.txt for license information.
11+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include <CL/sycl.hpp>
16+
using namespace sycl;
17+
#ifdef SYCL_EXT_ONEAPI_SUB_GROUP_MASK
18+
constexpr int global_size = 128;
19+
constexpr int local_size = 32;
20+
template <size_t> class sycl_subgr;
21+
22+
template <size_t SGSize> void test(queue Queue) {
23+
std::cout << "Testing sub_group_mask for sub-group size=" << SGSize
24+
<< std::endl;
25+
try {
26+
nd_range<1> NdRange(global_size, local_size);
27+
int Res[32 / SGSize] = {0};
28+
{
29+
buffer resbuf(Res, range<1>(32 / SGSize));
30+
31+
Queue.submit([&](handler &cgh) {
32+
auto resacc = resbuf.template get_access<access::mode::read_write>(cgh);
33+
34+
cgh.parallel_for<sycl_subgr<SGSize>>(
35+
NdRange, [=
36+
](nd_item<1> NdItem) [[intel::reqd_sub_group_size(SGSize)]] {
37+
auto SG = NdItem.get_sub_group();
38+
auto LID = SG.get_local_id();
39+
auto SGID = SG.get_group_id();
40+
41+
auto gmask_gid2 =
42+
ext::oneapi::group_ballot(NdItem.get_sub_group(), LID % 2);
43+
auto gmask_gid3 =
44+
ext::oneapi::group_ballot(NdItem.get_sub_group(), LID % 3);
45+
46+
if (!LID) {
47+
int res = 0;
48+
49+
for (size_t i = 0; i < SG.get_max_local_range()[0]; i++) {
50+
res |= !((gmask_gid2 | gmask_gid3)[i] == (i % 2 || i % 3))
51+
<< 1;
52+
res |= !((gmask_gid2 & gmask_gid3)[i] == (i % 2 && i % 3))
53+
<< 2;
54+
res |= !((gmask_gid2 ^ gmask_gid3)[i] ==
55+
((bool)(i % 2) ^ (bool)(i % 3)))
56+
<< 3;
57+
}
58+
res |= (gmask_gid2.size() != SG.get_max_local_range()[0]) << 4;
59+
resacc[SGID] = res;
60+
}
61+
});
62+
});
63+
}
64+
for (size_t i = 0; i < 32 / SGSize; i++) {
65+
if (Res[i]) {
66+
std::cout
67+
<< "Unexpected result for sub_group_mask operation for sub-group "
68+
<< i << ": " << Res[i] << std::endl;
69+
exit(1);
70+
}
71+
}
72+
} catch (exception e) {
73+
std::cout << "SYCL exception caught: " << e.what();
74+
exit(1);
75+
}
76+
}
77+
#endif // SYCL_EXT_ONEAPI_SUB_GROUP_MASK
78+
79+
int main() {
80+
#ifdef SYCL_EXT_ONEAPI_SUB_GROUP_MASK
81+
queue Queue;
82+
83+
test<8>(Queue);
84+
test<16>(Queue);
85+
test<32>(Queue);
86+
87+
std::cout << "Test passed." << std::endl;
88+
#else
89+
std::cout << "Test skipped due to missing extension." << std::endl;
90+
#endif
91+
return 0;
92+
}

0 commit comments

Comments
 (0)