llvm-project
23e4fe04 - [SYCL] SYCL host kernel launch support for the sycl_kernel_entry_point attribute. (#152403)

Commit
5 days ago
[SYCL] SYCL host kernel launch support for the sycl_kernel_entry_point attribute. (#152403) The `sycl_kernel_entry_point` attribute facilitates the generation of an offload kernel entry point function based on the parameters and body of the attributed function. This change extends the behavior of that attribute to support integration with a SYCL runtime library through an interface that communicates symbol names and kernel arguments for the generated offload kernel entry point functions. Consider the following function declared with the `sycl_kernel_entry_point` attribute with a call to this function occurring in the implementation of a SYCL kernel invocation function such as `sycl::handler::single_task()`. ```c++ template<typename KernelName, typename KernelType> [[clang::sycl_kernel_entry_point(KernelName)]] void kernel_entry_point(KernelType kernel) { kernel(); } ``` The body of the above function specifies the parameters and body of the generated offload kernel entry point. Clearly, a call to the above function by a SYCL kernel invocation function is not intended to execute the body as written. Previously, code generation emitted an empty function body so that calls to the function had no effect other than to trigger the generation of the offload kernel entry point. The function body is therefore available to hook for SYCL library support and is now substituted with a call to a (SYCL library provided) function template or variable template named `sycl_kernel_launch()` with the kernel name type passed as the first template argument, the symbol name of the offload kernel entry point passed as a string literal for the first function argument, and the function parameters passed as the remaining explicit function arguments. Given a call like this: ```c++ kernel_entry_point<struct KN>([]{}) ``` the body of the instantiated `kernel_entry_point()` specialization would be substituted as follows with "kernel-symbol-name" substituted for the generated symbol name and `kernel` forwarded. ```c++ sycl_kernel_launch<KN>("kernel-symbol-name", kernel) ``` Name lookup and overload resolution for the `sycl_kernel_launch()` function is performed at the point of definition of the `sycl_kernel_entry_point` attributed function (or the point of instantiation for an instantiated function template specialization). If overload resolution fails, the program is ill-formed. Implementation of the `sycl_kernel_launch()` function might require additional information provided by the SYCL library. This is facilitated by removing the previous prohibition against use of the `sycl_kernel_entry_point` attribute with a non-static member function. If the `sycl_kernel_entry_point` attributed function is a non-static member function, then overload resolution for the `sycl_kernel_launch()` function template may select a non-static member function in which case, `this` will be implicitly passed as the implicit object argument. If a `sycl_kernel_entry_point` attributed function is a non-static member function, use of `this` in a potentially evaluated expression is prohibited in the definition since `this` is not a kernel argument and will not be available within the generated offload kernel entry point function. The attribute cannot be applied to a function with an explicit object parameter. --------- Co-authored-by: Mariya Podchishchaeva <mariya.podchishchaeva@intel.com>
Author
Parents
Loading