Skip to content

Conversation

@dklochkov-emb
Copy link
Contributor

@dklochkov-emb dklochkov-emb commented Jul 1, 2025

This PR adds clang diagnostic message in case if:

  1. kernel free function argument type is virtually derived on any level of inheritance
  2. kernel free function argument type has virtual methods

Also, tests were added according to test plan

@dklochkov-emb dklochkov-emb requested a review from a team as a code owner July 1, 2025 15:07
Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

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

Does the free function spec not allow such kernel arguments? At least regarding virtual functions AFAIK in SYCL 2020 such an object can be captured to the device code and is fine unless a virtual function is called.
See
https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:language.restrictions.kernels

The odr-use of polymorphic classes and classes with virtual inheritance is allowed. However, no virtual member functions are allowed to be called in a device function.

@dklochkov-emb
Copy link
Contributor Author

Does the free function spec not allow such kernel arguments? At least regarding virtual functions AFAIK in SYCL 2020 such an object can be captured to the device code and is fine unless a virtual function is called. See https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:language.restrictions.kernels

The odr-use of polymorphic classes and classes with virtual inheritance is allowed. However, no virtual member functions are allowed to be called in a device function.

@Fznamznon kernel free function docs tell that:
Each of the function’s arguments must have a type that is an allowed kernel parameter type as specified in section 4.12.4 "Rules for parameter passing to kernels" of the core SYCL specification. The function must not be declared with parameters of type reducer or kernel_handler. These special kernel arguments cannot be passed to a free function kernel
.12.4 "Rules for parameter passing to kernels" contains information about virtual only the next:
Regardless of how the parameter is passed, the following rules define the allowable types for a kernel parameter: ... A class type S with a non-virtual base class of type T is a legal parameter type if T is a legal parameter type and if S would otherwise be a legal parameter type aside from this base class.

i.e. S is allowed only if it has non-virtual inheritance from allowed type which means virtual inheritance is not allowed, does not it?

@Fznamznon
Copy link
Contributor

@dklochkov-emb , yeah, that vaguely reads that virtual bases are not allowed in kernel arguments. I mailed spec folks to double check. Two concerns though:

  1. This seems to have nothing to do with virtual functions. Classes with virtual functions should be allowed in kernel arguments.
  2. The restriction is not limited to free functions, meaning the infrastructure of visitors in SemaSYCL is better to be used instead of manually recursing through bases of all kernel arguments. What I'm saying is that we probably need to extend SyclKernelFieldChecker class to check for virtual bases.

@dklochkov-emb
Copy link
Contributor Author

@intel/llvm-gatekeepers Please, merge it

@steffenlarsen steffenlarsen merged commit e18f533 into intel:sycl Aug 21, 2025
44 of 48 checks passed
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.

5 participants