Skip to content

Commit 80ecd7f

Browse files
authored
[SYCL] Fix launching a kernel with a default constructed local accessor (#13382)
According to [4.7.6.11.1. Interface for local accessors](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_interface_for_local_accessors), passing a default constructed local accessor to a kernel function is allowed, as long as no accesses to the data elements are made. When default constructing a `local_accessor`, it will default construct its `local_accessor_base` https://github.com/intel/llvm/blob/3f841ff1d21bac2601beaf087bc3d09170af6d35/sycl/include/sycl/accessor.hpp#L2803-L2805 leading its `LocalAccessorImplHost` to be constructed with `MDims == 0`. When setting the kernel arguments corresponding to the local accessor, this caused `piKernelSetArg` to be called with `arg_size == 0`, which then causes an error. This PR fixes this by checking if `MDims` would be 0 and then setting an appropriate value.
1 parent a0d8f01 commit 80ecd7f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

sycl/source/handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ void handler::processArg(void *Ptr, const detail::kernel_param_kind_t &Kind,
775775
// to a single kernel argument set above.
776776
if (!IsESIMD && !IsKernelCreatedFromSource) {
777777
++IndexShift;
778-
const size_t SizeAccField = Dims * sizeof(Size[0]);
778+
const size_t SizeAccField = (Dims == 0 ? 1 : Dims) * sizeof(Size[0]);
779779
MArgs.emplace_back(kernel_param_kind_t::kind_std_layout, &Size,
780780
SizeAccField, Index + IndexShift);
781781
++IndexShift;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// -O0 is necessary; on higher levels of optimization, an error
2+
// would not occur because of dead argument elimination of the local_accessor.
3+
// RUN: %{build} -o %t.out -O0
4+
// RUN: %{run} %t.out
5+
6+
#include <sycl/detail/core.hpp>
7+
8+
using namespace sycl;
9+
10+
using acc_t = local_accessor<int, 1>;
11+
12+
struct foo {
13+
acc_t acc;
14+
void operator()(nd_item<1>) const {}
15+
};
16+
17+
int main() {
18+
queue q;
19+
q.submit([&](handler &cgh) { cgh.parallel_for(nd_range<1>(1, 1), foo{}); });
20+
}

0 commit comments

Comments
 (0)