Skip to content

Commit 5edc8fe

Browse files
authored
[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 1072231 commit 5edc8fe

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
@@ -12,7 +12,6 @@
1212
#include <sycl/group_barrier.hpp>
1313
#include <sycl/usm.hpp>
1414

15-
constexpr size_t Size = 1024;
1615
using DataType = int;
1716

1817
namespace sycl_ext = sycl::ext::oneapi::experimental;
@@ -44,25 +43,29 @@ template <typename T> struct KernelFunctor {
4443

4544
int main() {
4645
sycl::queue queue;
47-
DataType *a = sycl::malloc_device<DataType>(Size, queue);
48-
DataType *b = sycl::malloc_device<DataType>(Size, queue);
49-
std::vector<DataType> a_host(Size, 1.0);
50-
std::vector<DataType> b_host(Size, -5.0);
46+
auto size = std::min(
47+
queue.get_device().get_info<sycl::info::device::max_work_group_size>(),
48+
1024ul);
5149

52-
queue.copy(a_host.data(), a, Size).wait_and_throw();
50+
DataType *a = sycl::malloc_device<DataType>(size, queue);
51+
DataType *b = sycl::malloc_device<DataType>(size, queue);
52+
std::vector<DataType> a_host(size, 1.0);
53+
std::vector<DataType> b_host(size, -5.0);
54+
55+
queue.copy(a_host.data(), a, size).wait_and_throw();
5356

5457
queue
5558
.submit([&](sycl::handler &cgh) {
5659
cgh.parallel_for(
57-
sycl::nd_range<1>({Size}, {Size}),
60+
sycl::nd_range<1>({size}, {size}),
5861
KernelFunctor(
5962
sycl_ext::properties{
60-
sycl_ext::work_group_scratch_size(Size * sizeof(DataType))},
63+
sycl_ext::work_group_scratch_size(size * sizeof(DataType))},
6164
a, b));
6265
})
6366
.wait_and_throw();
6467

65-
queue.copy(b, b_host.data(), Size).wait_and_throw();
68+
queue.copy(b, b_host.data(), size).wait_and_throw();
6669
for (size_t i = 0; i < b_host.size(); i++) {
6770
assert(b_host[i] == a_host[i]);
6871
}

sycl/test-e2e/WorkGroupScratchMemory/dynamic_unused.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
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;
@@ -29,25 +28,29 @@ template <typename T> struct KernelFunctor {
2928

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

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

3942
queue
4043
.submit([&](sycl::handler &cgh) {
4144
cgh.parallel_for(
42-
sycl::nd_range<1>({Size}, {Size}),
45+
sycl::nd_range<1>({size}, {size}),
4346
KernelFunctor(
4447
sycl_ext::properties{
45-
sycl_ext::work_group_scratch_size(Size * sizeof(DataType))},
48+
sycl_ext::work_group_scratch_size(size * sizeof(DataType))},
4649
a, b));
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
}

0 commit comments

Comments
 (0)