[llvm-branch-commits] [llvm] [libsycl] add single_task (PR #188797)
Tom Honermann via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Apr 3 09:09:54 PDT 2026
================
@@ -138,12 +161,87 @@ class _LIBSYCL_EXPORT queue {
template <typename Param>
typename Param::return_type get_backend_info() const;
+ /// Defines and invokes a SYCL kernel function as a lambda expression or a
+ /// named function object type.
+ ///
+ /// \param kernelFunc is the kernel functor or lambda.
+ /// \return an event that represents the status of the submitted kernel.
+ template <typename KernelName, typename KernelType>
+ event single_task(const KernelType &kernelFunc) {
+ return single_task<KernelName, KernelType>({}, kernelFunc);
+ }
+
+ /// Defines and invokes a SYCL kernel function as a lambda expression or a
+ /// named function object type.
+ ///
+ /// \param depEvent is an event that specifies the kernel dependency.
+ /// \param kernelFunc is the kernel functor or lambda.
+ /// \return an event that represents the status of the submitted kernel.
+ template <typename KernelName, typename KernelType>
+ event single_task(event depEvent, const KernelType &kernelFunc) {
+ return single_task<KernelName, KernelType>({depEvent}, kernelFunc);
+ }
+
+ /// Defines and invokes a SYCL kernel function as a lambda expression or a
+ /// named function object type.
+ ///
+ /// \param depEvents is a collection of events that specify the kernel
+ /// dependencies.
+ /// \param kernelFunc is the kernel functor or lambda.
+ /// \return an event that represents the status of the submitted kernel.
+ template <typename KernelName, typename KernelType>
+ event single_task(const std::vector<event> &depEvents,
+ const KernelType &kernelFunc) {
+ static_assert(
+ (detail::CheckFunctionSignature<std::remove_reference_t<KernelType>,
+ void()>::value),
+ "sycl::queue::single_task() requires a kernel instead of a command "
+ "group");
+
+ setKernelParameters(depEvents);
+ submitSingleTask<KernelName, KernelType>(kernelFunc);
+ return getLastEvent();
+ }
+
/// Blocks the calling thread until all commands previously submitted to this
/// queue have completed. Synchronous errors are reported through SYCL
/// exceptions.
void wait();
private:
+ // Name of this function is defined by compiler. It generates call to this
+ // function in the host implementation of KernelFunc in submitSingleTask.
+ template <typename, typename... Args>
+ void sycl_kernel_launch(const char *KernelName, Args &&...args) {
+ static_assert(
+ (sizeof...(args) == 1) &&
+ "sycl_kernel_launch expects only 2 arguments now: name of kernel and "
+ "callable object passed to kernel invocation by the user.");
+ detail::ArgCollection TypelessArgs;
+ (TypelessArgs.addArg(args), ...);
+
+ submitKernelImpl(KernelName, TypelessArgs);
+ }
----------------
tahonermann wrote:
@pbalcer, I've looked at those APIs, but I can't find a description of the required argument format. Documentation for liboffload seems to be non-existent and the definition of `olLaunchKernel()` [here](https://github.com/llvm/llvm-project/blob/d8ba56ce3f98871ae4e5782c4af2df4c98bebde7/offload/liboffload/API/Kernel.td#L23-L42) is not very helpful and seems to contradict the description of `cuLaunchKernel()` [here](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__EXEC.html#group__CUDA__EXEC_1gb8f3dc3031b40da29d5f9a7139e52e15).
In this PR, the buffer passed to `olLaunchKernel()` includes only a pointer to a single argument (not a pointer to an array of pointers) and the argument size is the size of that argument (see lines 129-130 in `QueueImpl::submitKernelImpl()`). Is that code incorrect? If not, how would additional arguments be passed and what would distinguish their type, size, and alignment so that an invocation of the kernel entry point could be constructed correctly for the target-dependent calling convention?
https://github.com/llvm/llvm-project/pull/188797
More information about the llvm-branch-commits
mailing list