|
| 1 | +// RUN: %{build} -o %t.out |
| 2 | +// RUN: %{run} %t.out |
| 3 | + |
| 4 | +#include <iostream> |
| 5 | +#include <sycl/detail/core.hpp> |
| 6 | +#include <sycl/ext/oneapi/get_kernel_info.hpp> |
| 7 | +#include <sycl/kernel_bundle.hpp> |
| 8 | + |
| 9 | +namespace syclext = sycl::ext::oneapi; |
| 10 | +namespace syclexp = sycl::ext::oneapi::experimental; |
| 11 | + |
| 12 | +static constexpr size_t NUM = 1024; |
| 13 | +static constexpr size_t WGSIZE = 16; |
| 14 | +static constexpr auto FFTestMark = "Free function Kernel Test:"; |
| 15 | + |
| 16 | +SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<2>)) |
| 17 | +void func_range(float start, float *ptr) {} |
| 18 | + |
| 19 | +SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::single_task_kernel)) |
| 20 | +void func_single(float start, float *ptr) {} |
| 21 | + |
| 22 | +template <auto *Func> int test_free_function_kernel_id(sycl::context &ctxt) { |
| 23 | + sycl::kernel_id id = syclexp::get_kernel_id<Func>(); |
| 24 | + auto exe_bndl = |
| 25 | + syclexp::get_kernel_bundle<Func, sycl::bundle_state::executable>(ctxt); |
| 26 | + const auto kernel_ids = exe_bndl.get_kernel_ids(); |
| 27 | + const bool res = |
| 28 | + std::find(kernel_ids.begin(), kernel_ids.end(), id) == kernel_ids.end(); |
| 29 | + if (res) |
| 30 | + std::cout << FFTestMark << "test_kernel_id failed: kernel id is not found" |
| 31 | + << std::endl; |
| 32 | + return res; |
| 33 | +} |
| 34 | + |
| 35 | +template <auto *Func> |
| 36 | +int test_kernel_bundle_ctxt(sycl::context &ctxt, std::string_view fname) { |
| 37 | + sycl::kernel_id id = syclexp::get_kernel_id<Func>(); |
| 38 | + auto exe_bndl = |
| 39 | + syclexp::get_kernel_bundle<Func, sycl::bundle_state::executable>(ctxt); |
| 40 | + const bool res = |
| 41 | + exe_bndl.has_kernel(id) && |
| 42 | + exe_bndl.get_kernel(id) |
| 43 | + .template get_info<sycl::info::kernel::function_name>() == fname; |
| 44 | + if (!res) |
| 45 | + std::cout |
| 46 | + << FFTestMark |
| 47 | + << "test_kernel_bundle_ctxt failed: bundle does not contain kernel id " |
| 48 | + "or function name " |
| 49 | + << fname << std::endl; |
| 50 | + return res; |
| 51 | +} |
| 52 | + |
| 53 | +template <auto *Func> |
| 54 | +int test_kernel_bundle_ctxt_dev(sycl::context &ctxt, sycl::device &dev, |
| 55 | + std::string_view fname) { |
| 56 | + sycl::kernel_id id = syclexp::get_kernel_id<Func>(); |
| 57 | + auto exe_bndl = |
| 58 | + syclexp::get_kernel_bundle<Func, sycl::bundle_state::executable>(ctxt, |
| 59 | + {dev}); |
| 60 | + const bool res = |
| 61 | + exe_bndl.has_kernel(id) && |
| 62 | + exe_bndl.get_kernel(id) |
| 63 | + .template get_info<sycl::info::kernel::function_name>() == fname; |
| 64 | + if (!res) |
| 65 | + std::cout << FFTestMark |
| 66 | + << "test_kernel_bundle_ctxt_dev failed: bundle does not contain " |
| 67 | + "kernel id " |
| 68 | + "or function name " |
| 69 | + << fname << std::endl; |
| 70 | + return res; |
| 71 | +} |
| 72 | + |
| 73 | +int main() { |
| 74 | + sycl::queue q; |
| 75 | + sycl::context ctxt = q.get_context(); |
| 76 | + sycl::device dev = q.get_device(); |
| 77 | + |
| 78 | + int ret = test_free_function_kernel_id<func_range>(ctxt); |
| 79 | + ret |= test_free_function_kernel_id<func_single>(ctxt); |
| 80 | + ret |= test_kernel_bundle_ctxt<func_range>(ctxt, "func_range"); |
| 81 | + ret |= test_kernel_bundle_ctxt<func_single>(ctxt, "func_single"); |
| 82 | + ret |= test_kernel_bundle_ctxt_dev<func_range>(ctxt, dev, "func_range"); |
| 83 | + ret |= test_kernel_bundle_ctxt_dev<func_single>(ctxt, dev, "func_single"); |
| 84 | + return ret; |
| 85 | +} |
0 commit comments