Skip to content

Check the number of kernel arguments only for interoperability kernels - #2425

Open
ndgrigorian wants to merge 3 commits into
masterfrom
fix-kernel-arg-count-check
Open

ndgrigorian wants to merge 3 commits into
masterfrom
fix-kernel-arg-count-check

Conversation

@ndgrigorian

@ndgrigorian ndgrigorian commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

This PR fixes the check on the number of kernel arguments added to SyclQueue.submit and SyclQueue.submit_async in gh-2382. It compares the number of arguments given with info::kernel::num_args, which SYCL defines only for kernels in kernel bundles created through backend interoperability. For a kernel compiled from SYCL source, DPC++ reports the backend's count instead, in which a sycl::local_accessor takes 4 arguments, so such a kernel can not be submitted with a dpctl.LocalAccessor:

ValueError: Kernel 'reverse_in_group' takes 6 argument(s), got 3.

dpctl.compiler.SyclKernel now records the kind of kernel bundle it comes from, and the number of arguments is only checked for kernels from kernel bundles created from OpenCL C source or SPIR-V. The arguments of other kernels, including those passed to dpctl through SyclKernel_Make, are not checked. On OpenCL, the backend rejects a wrong number of arguments on submission, raising SyclKernelSubmitError, while on Level Zero too few arguments are not detected

A kernel compiled from SYCL to SPIR-V may also expect a sycl::local_accessor parameter as several arguments: the local memory pointer, followed by the accessor's access range, memory range and offset. A dpctl.LocalAccessor provides only the pointer, so the others have to be passed explicitly after it. For kernels from a SPIR-V bundle, the error now says so when the arguments include a dpctl.LocalAccessor, and the dpctl.LocalAccessor docstring shows how to pass them:

ValueError: Kernel '__sycl_kernel_local_accessor_kernel' takes 5 argument(s), got 2. A kernel compiled from SYCL to SPIR-V may expect a sycl::local_accessor parameter as several arguments, of which a dpctl.LocalAccessor is only the first; see the dpctl.LocalAccessor documentation.

DPCTLKernel_GetNumArgs also no longer aborts the process when the query throws, returning -1, and SyclKernel.get_num_args raises RuntimeError in that case

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?
  • If this PR is a work in progress, are you opening the PR as a draft?

The number of arguments is only defined for kernels from OpenCL C source or
SPIR-V bundles, so SyclKernel records the kind of bundle it comes from and
submit checks the count only for those. DPCTLKernel_GetNumArgs no longer
aborts when the query throws.
@ndgrigorian
ndgrigorian force-pushed the fix-kernel-arg-count-check branch from c562604 to b7f435b Compare November 8, 2026 20:51
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

@coveralls

coveralls commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 75.112% (-0.03%) from 75.137% — fix-kernel-arg-count-check into master

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.
A LocalAccessor works for a kernel compiled from SYCL to SPIR-V when the
accessor's ranges are passed after it; say so in the docstring and the error,
and test it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants