Skip to content

Count a LocalAccessor as up to 4 arguments in the kernel argument count check - #2425

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

ndgrigorian wants to merge 2 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 for a kernel compiled from SYCL source is the number of arguments of the backend kernel, in which a sycl::local_accessor is 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.

A dpctl.LocalAccessor is now counted as 1 to 4 arguments: the check raises ValueError if more arguments are given than the kernel takes, or if fewer are given with each dpctl.LocalAccessor counted as 4. Without a dpctl.LocalAccessor, the check is exact as before. Every other argument type, including dpctl.WorkGroupMemory and dpctl.RawKernelArg, is 1 argument in every kind of kernel. This was measured with DPC++ 2026.2 on OpenCL CPU, OpenCL GPU and Level Zero GPU, for kernels from OpenCL C source, SPIR-V and SYCL source. The dpctl.LocalAccessor arguments are counted in a C loop over the argument types already collected for submission

A kernel compiled from SYCL to SPIR-V expects a sycl::local_accessor parameter as 4 arguments: the local memory pointer, followed by the access range, memory range and offset, each of which is one argument of N size_t for an N-dimensional accessor. The dpctl.LocalAccessor docstring now shows how to pass them

DPCTLKernel_GetNumArgs also no longer aborts the process when the query throws, returning -1, and SyclKernel.get_num_args raises RuntimeError in that case. The arguments of a kernel whose number of arguments can not be queried are not checked

  • 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?

@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

Comment thread dpctl/compiler/_compiler.pxd Resolved
Comment thread dpctl/_sycl_queue.pyx Resolved
Comment thread dpctl/_sycl_queue.pyx Resolved
DPCTLKernel_GetNumArgs returns -1 when the query throws, and
SyclKernel.get_num_args raises RuntimeError
a sycl::local_accessor is 4 arguments in a kernel compiled from SYCL source,
so the argument count check rejected such kernels; the LocalAccessor
docstring now describes passing a split local accessor to SPIR-V from SYCL
@ndgrigorian
ndgrigorian force-pushed the fix-kernel-arg-count-check branch from 40dcdf2 to 83c01c8 Compare December 3, 2026 07:31
@ndgrigorian ndgrigorian changed the title Check the number of kernel arguments only for interoperability kernels Count a LocalAccessor as up to 4 arguments in the kernel argument count check Dec 3, 2026

@vlad-perevezentsev vlad-perevezentsev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I checked 83c01c8 on Battlemage GPUs (Level Zero and OpenCL), an iGPU without fp64 and the OpenCL CPU: all three points are fixed, and dpnp built without this PR passes its test suite with it, with no warnings on import.

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.

3 participants