Skip to content

Commit a7cac18

Browse files
RossBruntonAlexeySachkov
authored andcommitted
[SYCL][E2E] Limit work group size in WorkGroupScratchMemory tests (#17046)
Some devices don't support work group sizes of 1024, so use the maximum size if it is smaller in the copy_dynamic_size.cpp and dynamic_unused.cpp tests.
1 parent c86c46d commit a7cac18

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

sycl/test-e2e/WorkGroupScratchMemory/copy_dynamic_size.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <sycl/group_barrier.hpp>
1111
#include <sycl/usm.hpp>
1212

13-
constexpr size_t Size = 1024;
1413
using DataType = int;
1514

1615
namespace sycl_ext = sycl::ext::oneapi::experimental;
@@ -31,23 +30,27 @@ void copy_via_smem(DataType *a, DataType *b, sycl::nd_item<1> it) {
3130

3231
int main() {
3332
sycl::queue queue;
34-
DataType *a = sycl::malloc_device<DataType>(Size, queue);
35-
DataType *b = sycl::malloc_device<DataType>(Size, queue);
36-
std::vector<DataType> a_host(Size, 1.0);
37-
std::vector<DataType> b_host(Size, -5.0);
33+
auto size = std::min(
34+
queue.get_device().get_info<sycl::info::device::max_work_group_size>(),
35+
1024ul);
3836

39-
queue.copy(a_host.data(), a, Size).wait_and_throw();
37+
DataType *a = sycl::malloc_device<DataType>(size, queue);
38+
DataType *b = sycl::malloc_device<DataType>(size, queue);
39+
std::vector<DataType> a_host(size, 1.0);
40+
std::vector<DataType> b_host(size, -5.0);
41+
42+
queue.copy(a_host.data(), a, size).wait_and_throw();
4043

4144
queue
4245
.submit([&](sycl::handler &cgh) {
43-
cgh.parallel_for(sycl::nd_range<1>({Size}, {Size}),
46+
cgh.parallel_for(sycl::nd_range<1>({size}, {size}),
4447
sycl_ext::properties{sycl_ext::work_group_scratch_size(
45-
Size * sizeof(DataType))},
48+
size * sizeof(DataType))},
4649
[=](sycl::nd_item<1> it) { copy_via_smem(a, b, it); });
4750
})
4851
.wait_and_throw();
4952

50-
queue.copy(b, b_host.data(), Size).wait_and_throw();
53+
queue.copy(b, b_host.data(), size).wait_and_throw();
5154
for (size_t i = 0; i < b_host.size(); i++) {
5255
assert(b_host[i] == a_host[i]);
5356
}

sycl/test-e2e/WorkGroupScratchMemory/dynamic_unused.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,36 @@
99
#include <sycl/ext/oneapi/work_group_scratch_memory.hpp>
1010
#include <sycl/usm.hpp>
1111

12-
constexpr size_t Size = 1024;
1312
using DataType = int;
1413

1514
namespace sycl_ext = sycl::ext::oneapi::experimental;
1615

1716
int main() {
1817
sycl::queue queue;
19-
DataType *a = sycl::malloc_device<DataType>(Size, queue);
20-
DataType *b = sycl::malloc_device<DataType>(Size, queue);
21-
std::vector<DataType> a_host(Size, 1.0);
22-
std::vector<DataType> b_host(Size, -5.0);
18+
auto size = std::min(
19+
queue.get_device().get_info<sycl::info::device::max_work_group_size>(),
20+
1024ul);
2321

24-
queue.copy(a_host.data(), a, Size).wait_and_throw();
22+
DataType *a = sycl::malloc_device<DataType>(size, queue);
23+
DataType *b = sycl::malloc_device<DataType>(size, queue);
24+
std::vector<DataType> a_host(size, 1.0);
25+
std::vector<DataType> b_host(size, -5.0);
26+
27+
queue.copy(a_host.data(), a, size).wait_and_throw();
2528

2629
queue
2730
.submit([&](sycl::handler &cgh) {
28-
cgh.parallel_for(sycl::nd_range<1>({Size}, {Size}),
31+
cgh.parallel_for(sycl::nd_range<1>({size}, {size}),
2932
sycl_ext::properties{sycl_ext::work_group_scratch_size(
30-
Size * sizeof(DataType))},
33+
size * sizeof(DataType))},
3134
[=](sycl::nd_item<1> it) {
3235
b[it.get_local_linear_id()] =
3336
a[it.get_local_linear_id()];
3437
});
3538
})
3639
.wait_and_throw();
3740

38-
queue.copy(b, b_host.data(), Size).wait_and_throw();
41+
queue.copy(b, b_host.data(), size).wait_and_throw();
3942
for (size_t i = 0; i < b_host.size(); i++) {
4043
assert(b_host[i] == a_host[i]);
4144
}

0 commit comments

Comments
 (0)