|
| 1 | +// RUN: %{build} -o %t.out |
| 2 | +// RUN: %{run} %t.out |
| 3 | + |
| 4 | +// This test checks that get_kernel_ids returns all the kernels defined |
| 5 | +// in the source regardless of whether they are expressed as lambdas, |
| 6 | +// function objects or free functions. |
| 7 | + |
| 8 | +#include <sycl/detail/core.hpp> |
| 9 | +#include <sycl/ext/oneapi/experimental/free_function_traits.hpp> |
| 10 | +#include <sycl/kernel_bundle.hpp> |
| 11 | + |
| 12 | +class FunctionObjectKernel { |
| 13 | +public: |
| 14 | + void operator()() const {} |
| 15 | +}; |
| 16 | + |
| 17 | +class LambdaKernel; |
| 18 | + |
| 19 | +SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( |
| 20 | + (sycl::ext::oneapi::experimental::nd_range_kernel<1>)) |
| 21 | +void FreeFunctionKernel() {} |
| 22 | + |
| 23 | +int main() { |
| 24 | + sycl::queue Queue; |
| 25 | + sycl::device Dev = Queue.get_device(); |
| 26 | + sycl::context Context = Queue.get_context(); |
| 27 | + |
| 28 | + sycl::kernel_id FunctionObjectKernelId = |
| 29 | + sycl::get_kernel_id<FunctionObjectKernel>(); |
| 30 | + sycl::kernel_id LambdaKernelId = sycl::get_kernel_id<LambdaKernel>(); |
| 31 | + sycl::kernel_id FreeFunctionKernelId = |
| 32 | + sycl::ext::oneapi::experimental::get_kernel_id<FreeFunctionKernel>(); |
| 33 | + |
| 34 | + sycl::kernel_bundle KernelBundle = |
| 35 | + sycl::get_kernel_bundle<sycl::bundle_state::executable>(Context, {Dev}); |
| 36 | + sycl::kernel FreeFunction = KernelBundle.get_kernel(FreeFunctionKernelId); |
| 37 | + Queue.submit( |
| 38 | + [&](sycl::handler &CGH) { CGH.single_task<LambdaKernel>([=]() {}); }); |
| 39 | + Queue.submit([&](sycl::handler &CGH) { |
| 40 | + FunctionObjectKernel kernel; |
| 41 | + CGH.single_task(kernel); |
| 42 | + }); |
| 43 | + Queue.submit([&](sycl::handler &CGH) { |
| 44 | + CGH.parallel_for(sycl::nd_range{{1}, {1}}, FreeFunction); |
| 45 | + }); |
| 46 | + |
| 47 | + std::vector<sycl::kernel_id> KernelIds = KernelBundle.get_kernel_ids(); |
| 48 | + assert(KernelIds.size() == 3); |
| 49 | + for (const sycl::kernel_id &KernelId : |
| 50 | + {FunctionObjectKernelId, LambdaKernelId, FreeFunctionKernelId}) { |
| 51 | + auto FoundId = std::find(KernelIds.begin(), KernelIds.end(), KernelId); |
| 52 | + assert(FoundId != KernelIds.end()); |
| 53 | + } |
| 54 | + return 0; |
| 55 | +} |
0 commit comments