Skip to content

Commit 1dfebbb

Browse files
committed
hint at split local accessors in the argument count error
A sycl::local_accessor of a kernel compiled from SYCL to SPIR-V can take several arguments; the error says so when a LocalAccessor is given, and the LocalAccessor docstring explains it.
1 parent b7f435b commit 1dfebbb

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎dpctl/_sycl_queue.pyx‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ cdef class LocalAccessor:
175175
Python class for specifying the dimensionality and type of a
176176
``sycl::local_accessor``, to be used as a kernel argument type.
177177
178+
A ``LocalAccessor`` is passed as a single kernel argument. A
179+
``sycl::local_accessor`` parameter of a kernel compiled from SYCL to
180+
SPIR-V can take several arguments, so such a kernel can not be given a
181+
``LocalAccessor``; create it with
182+
:func:`dpctl.compiler.create_kernel_bundle_from_sycl_source` instead.
183+
178184
Args:
179185
dtype (str):
180186
the data type of the local memory.
@@ -1574,10 +1580,19 @@ cdef class SyclQueue(_SyclQueue):
15741580
if kernel._origin == _INTEROP_ORIGIN:
15751581
nKA = kernel.num_args
15761582
if <size_t>len(args) != nKA:
1577-
raise ValueError(
1583+
msg = (
15781584
f"Kernel '{kernel.get_function_name()}' takes {nKA} "
15791585
f"argument(s), got {len(args)}."
15801586
)
1587+
if <size_t>len(args) < nKA and any(
1588+
[isinstance(arg, LocalAccessor) for arg in args]
1589+
):
1590+
msg += (
1591+
" A sycl::local_accessor parameter of a kernel "
1592+
"compiled from SYCL to SPIR-V can take several "
1593+
"arguments, see the dpctl.LocalAccessor documentation."
1594+
)
1595+
raise ValueError(msg)
15811596

15821597
# Allocate the arrays to be sent to DPCTLQueue_Submit
15831598
kargs = <void**>malloc(len(args) * sizeof(void*))
2.01 KB
Binary file not shown.

‎dpctl/tests/test_sycl_kernel_submit.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,49 @@ def test_submit_wrong_number_of_args():
447447
)
448448

449449

450+
# The kernel in local-accessor-free-function-kernel.spv was generated with
451+
# `icpx -fsycl -save-offload-code=<dir>` (DPC++ 2026.2) from:
452+
#
453+
# #include <sycl/sycl.hpp>
454+
#
455+
# namespace syclexp = sycl::ext::oneapi::experimental;
456+
# namespace syclext = sycl::ext::oneapi;
457+
#
458+
# extern "C" SYCL_EXTERNAL
459+
# SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>))
460+
# void local_accessor_kernel(sycl::local_accessor<int, 1> lmem, int *x) {
461+
# auto item = syclext::this_work_item::get_nd_item<1>();
462+
# size_t lid = item.get_local_linear_id();
463+
# lmem[lid] = x[item.get_global_linear_id()];
464+
# sycl::group_barrier(item.get_group());
465+
# x[item.get_global_linear_id()] =
466+
# lmem[item.get_local_range(0) - 1 - lid];
467+
# }
468+
#
469+
# int main() { return 0; }
470+
def test_submit_local_accessor_arg_spirv_from_sycl():
471+
try:
472+
q = dpctl.SyclQueue()
473+
except dpctl.SyclQueueCreationError:
474+
pytest.skip("Could not create default queue")
475+
fn = get_spirv_abspath("local-accessor-free-function-kernel.spv")
476+
with open(fn, "br") as f:
477+
spirv_bytes = f.read()
478+
kb = dpc.create_kernel_bundle_from_spirv(q, spirv_bytes)
479+
krn = kb.get_sycl_kernel("__sycl_kernel_local_accessor_kernel")
480+
# the local accessor takes several arguments in this SPIR-V
481+
assert krn.num_args > 2
482+
483+
x_usm = dpm.MemoryUSMDevice(64, queue=q)
484+
with pytest.raises(ValueError, match="dpctl.LocalAccessor documentation"):
485+
q.submit_async(
486+
krn, [dpctl.LocalAccessor("i4", (16,)), x_usm], [16], [16]
487+
)
488+
with pytest.raises(ValueError) as e:
489+
q.submit_async(krn, [x_usm], [16], [16])
490+
assert "LocalAccessor" not in str(e.value)
491+
492+
450493
def test_submit_wrong_number_of_args_opencl_source():
451494
try:
452495
q = dpctl.SyclQueue("opencl")

0 commit comments

Comments
 (0)