Skip to content

Commit 859a94f

Browse files
authored
[SYCL] Fix the test/basic_tests/buffer/subbuffer.cpp (#1277)
Signed-off-by: Rehana Begam <[email protected]>
1 parent 9b7a317 commit 859a94f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

sycl/test/basic_tests/buffer/subbuffer.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
22
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
33
// RUN: %CPU_RUN_PLACEHOLDER %t.out
44
// RUN: %GPU_RUN_PLACEHOLDER %t.out
@@ -19,16 +19,19 @@
1919
// 2) Exceptions if we trying to create sub buffer not according to spec
2020

2121
#include <CL/sycl.hpp>
22+
23+
#include <algorithm>
2224
#include <iostream>
2325
#include <numeric>
2426
#include <vector>
2527

2628
void checkHostAccessor(cl::sycl::queue &q) {
27-
std::size_t size =
28-
q.get_device().get_info<cl::sycl::info::device::mem_base_addr_align>() /
29-
8;
29+
std::size_t subbuf_align =
30+
q.get_device().get_info<cl::sycl::info::device::mem_base_addr_align>() / 8;
31+
std::size_t size = std::max(subbuf_align, 10 * 2 * sizeof(int)); // hold at least 20 elements
3032
size /= sizeof(int);
3133
size *= 2;
34+
3235
std::vector<int> data(size);
3336
std::iota(data.begin(), data.end(), 0);
3437
{
@@ -59,9 +62,9 @@ void checkHostAccessor(cl::sycl::queue &q) {
5962
}
6063

6164
void check1DSubBuffer(cl::sycl::queue &q) {
62-
std::size_t size =
63-
q.get_device().get_info<cl::sycl::info::device::mem_base_addr_align>() /
64-
8;
65+
std::size_t subbuf_align =
66+
q.get_device().get_info<cl::sycl::info::device::mem_base_addr_align>() / 8;
67+
std::size_t size = std::max(subbuf_align, 32 * sizeof(int)); // hold at least 32 elements
6568
size /= sizeof(int);
6669
size *= 2;
6770

@@ -201,7 +204,7 @@ void copyBlock() {
201204
using typename cl::sycl::access::mode;
202205
using buffer = cl::sycl::buffer<int, 1>;
203206

204-
auto CopyF = [](buffer& Buffer, buffer& Block, size_t Idx, size_t BlockSize) {
207+
auto CopyF = [](buffer &Buffer, buffer &Block, size_t Idx, size_t BlockSize) {
205208
auto Subbuf = buffer(Buffer, Idx * BlockSize, BlockSize);
206209
auto *Src = Subbuf.get_access<mode::read>().get_pointer();
207210
auto *Dst = Block.get_access<mode::write>().get_pointer();
@@ -244,8 +247,7 @@ void copyBlock() {
244247
"Invalid data in block buffer");
245248
}
246249
}
247-
}
248-
catch (cl::sycl::exception& ex) {
250+
} catch (cl::sycl::exception &ex) {
249251
assert(false && "Unexpected exception captured!");
250252
}
251253
}

0 commit comments

Comments
 (0)