|
| 1 | += sycl_ext_oneapi_get_kernel_info |
| 2 | + |
| 3 | +:source-highlighter: coderay |
| 4 | +:coderay-linenums-mode: table |
| 5 | + |
| 6 | +// This section needs to be after the document title. |
| 7 | +:doctype: book |
| 8 | +:toc2: |
| 9 | +:toc: left |
| 10 | +:encoding: utf-8 |
| 11 | +:lang: en |
| 12 | +:dpcpp: pass:[DPC++] |
| 13 | + |
| 14 | +// Set the default source code type in this document to C++, |
| 15 | +// for syntax highlighting purposes. This is needed because |
| 16 | +// docbook uses c++ and html5 uses cpp. |
| 17 | +:language: {basebackend@docbook:c++:cpp} |
| 18 | + |
| 19 | + |
| 20 | +== Notice |
| 21 | + |
| 22 | +[%hardbreaks] |
| 23 | +Copyright (C) 2024 Intel Corporation. All rights reserved. |
| 24 | + |
| 25 | +Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM) are trademarks |
| 26 | +of The Khronos Group Inc. OpenCL(TM) is a trademark of Apple Inc. used by |
| 27 | +permission by Khronos. |
| 28 | + |
| 29 | + |
| 30 | +== Contact |
| 31 | + |
| 32 | +To report problems with this extension, please open a new issue at: |
| 33 | + |
| 34 | +https://github.com/intel/llvm/issues |
| 35 | + |
| 36 | + |
| 37 | +== Dependencies |
| 38 | + |
| 39 | +This extension is written against the SYCL 2020 revision 8 specification. All |
| 40 | +references below to the "core SYCL specification" or to section numbers in the |
| 41 | +SYCL specification refer to that revision. |
| 42 | + |
| 43 | + |
| 44 | +== Status |
| 45 | + |
| 46 | +This is a proposed extension specification, intended to gather community |
| 47 | +feedback. Interfaces defined in this specification may not be implemented yet |
| 48 | +or may be in a preliminary state. The specification itself may also change in |
| 49 | +incompatible ways before it is finalized. *Shipping software products should |
| 50 | +not rely on APIs defined in this specification.* |
| 51 | + |
| 52 | + |
| 53 | +== Overview |
| 54 | + |
| 55 | +Applications sometimes need to query a kernel's information descriptor in order |
| 56 | +to decide how to launch the kernel. |
| 57 | +For example, an application may need to query |
| 58 | +`info::kernel_device_specific::work_group_size` in order to determine the |
| 59 | +nd-range to use when launching the kernel. |
| 60 | + |
| 61 | +Currently, the only way to do this is to create a kernel bundle, get the |
| 62 | +`kernel` object from that bundle, and then query the `kernel` object. |
| 63 | +This is very verbose, especially when the application doesn't need any of the |
| 64 | +other facilities provided by the kernel bundle API. |
| 65 | + |
| 66 | +This extension provides a less verbose way to query a kernel's information |
| 67 | +descriptor without creating a kernel bundle. |
| 68 | + |
| 69 | + |
| 70 | +== Specification |
| 71 | + |
| 72 | +=== Feature test macro |
| 73 | + |
| 74 | +This extension provides a feature-test macro as described in the core SYCL |
| 75 | +specification. An implementation supporting this extension must predefine the |
| 76 | +macro `SYCL_EXT_ONEAPI_GET_KERNEL_INFO` to one of the values defined in the |
| 77 | +table below. |
| 78 | +Applications can test for the existence of this macro to determine if the |
| 79 | +implementation supports this feature, or applications can test the macro's value |
| 80 | +to determine which of the extension's features the implementation supports. |
| 81 | + |
| 82 | +[%header,cols="1,5"] |
| 83 | +|=== |
| 84 | +|Value |
| 85 | +|Description |
| 86 | + |
| 87 | +|1 |
| 88 | +|Initial version of this extension. |
| 89 | +|=== |
| 90 | + |
| 91 | +=== New free functions |
| 92 | + |
| 93 | +This extension adds the following new free functions for querying a kernel's |
| 94 | +information descriptors. |
| 95 | + |
| 96 | +''' |
| 97 | + |
| 98 | +[frame=all,grid=none,separator="@"] |
| 99 | +!==== |
| 100 | +a@ |
| 101 | +[source,c++] |
| 102 | +---- |
| 103 | +namespace sycl::ext::oneapi { |
| 104 | +
|
| 105 | +template<typename KernelName, typename Param> |
| 106 | +typename Param::return_type get_kernel_info(const context& ctxt); |
| 107 | +
|
| 108 | +} // namespace sycl::ext::oneapi |
| 109 | +---- |
| 110 | +!==== |
| 111 | + |
| 112 | +_Constraints:_ Available only if `Param` is an information descriptor for the |
| 113 | +`kernel` class, which can be used by the `kernel::get_info()` overload. |
| 114 | + |
| 115 | +_Preconditions:_ The `KernelName` must be the type kernel name of a kernel that |
| 116 | +is defined in the application. |
| 117 | + |
| 118 | +_Returns:_ The same value `ret` that would be computed by: |
| 119 | + |
| 120 | +[source,c++] |
| 121 | +---- |
| 122 | +auto bundle = |
| 123 | + sycl::get_kernel_bundle<KernelName, sycl::bundle_state::executable>(ctxt); |
| 124 | +auto ret = bundle.get_kernel<KernelName>().get_info<Param>(); |
| 125 | +---- |
| 126 | + |
| 127 | +_Remarks:_ Each information descriptor may specify additional preconditions, |
| 128 | +exceptions that are thrown, etc. |
| 129 | + |
| 130 | +''' |
| 131 | + |
| 132 | +[frame=all,grid=none,separator="@"] |
| 133 | +!==== |
| 134 | +a@ |
| 135 | +[source,c++] |
| 136 | +---- |
| 137 | +namespace sycl::ext::oneapi { |
| 138 | +
|
| 139 | +template<typename KernelName, typename Param> |
| 140 | +typename Param::return_type get_kernel_info(const context& ctxt, |
| 141 | + const device& dev); |
| 142 | +
|
| 143 | +} // namespace sycl::ext::oneapi |
| 144 | +---- |
| 145 | +!==== |
| 146 | + |
| 147 | +_Constraints:_ Available only if `Param` is an information descriptor for the |
| 148 | +`kernel` class, which can be used by the `kernel::get_info(const device &)` |
| 149 | +overload. |
| 150 | + |
| 151 | +_Preconditions:_ The `KernelName` must be the type kernel name of a kernel that |
| 152 | +is defined in the application. |
| 153 | +The device `dev` must be one of the devices contained by `ctxt` or must be a |
| 154 | +descendent device of some device in `ctxt`. |
| 155 | +The kernel `KernelName` must be compatible with the device `dev` as defined by |
| 156 | +`is_compatible`. |
| 157 | + |
| 158 | +_Returns:_ The same value `ret` that would be computed by: |
| 159 | + |
| 160 | +[source,c++] |
| 161 | +---- |
| 162 | +auto bundle = |
| 163 | + sycl::get_kernel_bundle<KernelName, sycl::bundle_state::executable>(ctxt); |
| 164 | +auto ret = bundle.get_kernel<KernelName>().get_info<Param>(dev); |
| 165 | +---- |
| 166 | + |
| 167 | +_Remarks:_ Each information descriptor may specify additional preconditions, |
| 168 | +exceptions that are thrown, etc. |
| 169 | + |
| 170 | +''' |
| 171 | + |
| 172 | +[frame=all,grid=none,separator="@"] |
| 173 | +!==== |
| 174 | +a@ |
| 175 | +[source,c++] |
| 176 | +---- |
| 177 | +namespace sycl::ext::oneapi { |
| 178 | +
|
| 179 | +template<typename KernelName, typename Param> |
| 180 | +typename Param::return_type get_kernel_info(const queue& q); |
| 181 | +
|
| 182 | +} // namespace sycl::ext::oneapi |
| 183 | +---- |
| 184 | +!==== |
| 185 | + |
| 186 | +_Constraints:_ Available only if `Param` is an information descriptor for the |
| 187 | +`kernel` class, which can be used by the `kernel::get_info(const device &)` |
| 188 | +overload. |
| 189 | + |
| 190 | +_Preconditions:_ The `KernelName` must be the type kernel name of a kernel that |
| 191 | +is defined in the application. |
| 192 | +The kernel `KernelName` must be compatible with the device associated with `q` |
| 193 | +as defined by `is_compatible`. |
| 194 | + |
| 195 | +_Returns:_ The same value `ret` that would be computed by: |
| 196 | + |
| 197 | +[source,c++] |
| 198 | +---- |
| 199 | +sycl::context ctxt = q.get_context(); |
| 200 | +sycl::device dev = q.get_device(); |
| 201 | +auto bundle = |
| 202 | + sycl::get_kernel_bundle<KernelName, sycl::bundle_state::executable>(ctxt); |
| 203 | +auto ret = bundle.get_kernel<KernelName>().get_info<Param>(dev); |
| 204 | +---- |
| 205 | + |
| 206 | +_Remarks:_ Each information descriptor may specify additional preconditions, |
| 207 | +exceptions that are thrown, etc. |
| 208 | + |
| 209 | + |
| 210 | +== Issues |
| 211 | + |
| 212 | +* I purposely reduced the exceptions that are required to be thrown for certain |
| 213 | + error conditions and instead listed these as preconditions. |
| 214 | + An implementation can still diagnose these error conditions by throwing an |
| 215 | + exception, but it is not required. |
| 216 | + Since these APIs are likely on the critical path for launching a kernel, I |
| 217 | + don't think we want to mandate an error check at runtime. |
| 218 | + In retrospect, I think this is the right behavior for the core SYCL spec also, |
| 219 | + and we should consider changing the specified behavior. |
| 220 | + Thoughts? |
| 221 | + |
| 222 | +* I'm not sure how to formally specify the requirements for `KernelName`. |
| 223 | + I think an implementation should be able to fail with a link-time error if |
| 224 | + `KernelName` is not the type-name of some kernel that is defined in the |
| 225 | + application. |
| 226 | + However, this seems different from a _Constraint_, which is expected to result |
| 227 | + in a compile-time error. |
| 228 | + For now, I just listed it as a _Precondition_, so there is no formal |
| 229 | + requirement for an implementation to diagnose this error. |
0 commit comments