Skip to content

Commit 5f1c8d4

Browse files
againullbader
authored andcommitted
[SYCL] Fix argument size calculation for zero-dimensional accessor
Signed-off-by: Artur Gainullin <[email protected]>
1 parent 634fbdc commit 5f1c8d4

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

sycl/include/CL/sycl/handler.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ class handler {
256256
detail::Requirement *AccImpl = static_cast<detail::Requirement *>(Ptr);
257257
MArgs.emplace_back(Kind, AccImpl, Size, Index + IndexShift);
258258
if (!IsKernelCreatedFromSource) {
259-
const size_t SizeAccField = sizeof(size_t) * AccImpl->MDims;
259+
// Dimensionality of the buffer is 1 when dimensionality of the
260+
// accessor is 0.
261+
const size_t SizeAccField =
262+
sizeof(size_t) * (AccImpl->MDims == 0 ? 1 : AccImpl->MDims);
260263
++IndexShift;
261264
MArgs.emplace_back(kind_std_layout, &AccImpl->MAccessRange[0],
262265
SizeAccField, Index + IndexShift);

sycl/test/basic_tests/accessor/accessor.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,28 @@ int main() {
355355
return 1;
356356
}
357357
}
358+
359+
// Accessor with dimensionality 0.
360+
{
361+
try {
362+
int data = -1;
363+
{
364+
sycl::buffer<int, 1> b(&data, sycl::range<1>(1));
365+
sycl::queue queue;
366+
queue.submit([&](sycl::handler &cgh) {
367+
sycl::accessor<int, 0, sycl::access::mode::read_write,
368+
sycl::access::target::global_buffer>
369+
B(b, cgh);
370+
cgh.single_task<class acc_with_zero_dim>([=]() {
371+
auto B2 = B;
372+
(int &)B2 = 399;
373+
});
374+
});
375+
}
376+
assert(data == 399);
377+
} catch (sycl::exception e) {
378+
std::cout << "SYCL exception caught: " << e.what();
379+
return 1;
380+
}
381+
}
358382
}

0 commit comments

Comments
 (0)