|
| 1 | += sycl_ext_oneapi_syclbin |
| 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 | +:endnote: —{nbsp}end{nbsp}note |
| 14 | + |
| 15 | +// Set the default source code type in this document to C++, |
| 16 | +// for syntax highlighting purposes. This is needed because |
| 17 | +// docbook uses c++ and html5 uses cpp. |
| 18 | +:language: {basebackend@docbook:c++:cpp} |
| 19 | + |
| 20 | + |
| 21 | +== Notice |
| 22 | + |
| 23 | +[%hardbreaks] |
| 24 | +Copyright (C) 2025 Intel Corporation. All rights reserved. |
| 25 | + |
| 26 | +Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM) are trademarks |
| 27 | +of The Khronos Group Inc. OpenCL(TM) is a trademark of Apple Inc. used by |
| 28 | +permission by Khronos. |
| 29 | + |
| 30 | + |
| 31 | +== Contact |
| 32 | + |
| 33 | +To report problems with this extension, please open a new issue at: |
| 34 | + |
| 35 | +https://github.com/intel/llvm/issues |
| 36 | + |
| 37 | + |
| 38 | +== Dependencies |
| 39 | + |
| 40 | +This extension is written against the SYCL 2020 revision 9 specification. All |
| 41 | +references below to the "core SYCL specification" or to section numbers in the |
| 42 | +SYCL specification refer to that revision. |
| 43 | + |
| 44 | +This extension also depends on the following other SYCL extension: |
| 45 | + |
| 46 | +* link:../experimental/sycl_ext_oneapi_properties.asciidoc[ |
| 47 | + sycl_ext_oneapi_properties] |
| 48 | + |
| 49 | + |
| 50 | +== Status |
| 51 | + |
| 52 | +This is a proposed extension specification, intended to gather community |
| 53 | +feedback. Interfaces defined in this specification may not be implemented yet |
| 54 | +or may be in a preliminary state. The specification itself may also change in |
| 55 | +incompatible ways before it is finalized. *Shipping software products should |
| 56 | +not rely on APIs defined in this specification.* |
| 57 | + |
| 58 | + |
| 59 | +== Overview |
| 60 | + |
| 61 | +This extensions adds APIs, built upon the existing SYCL 2020 `kernel_bundle` |
| 62 | +APIs, for loading precompiled "SYCLBIN" files. Using these, SYCL code can |
| 63 | +dynamically load kernel binaries produced by the associated compiler, the format |
| 64 | +and options for which are defined by the SYCL implementation. |
| 65 | + |
| 66 | +Conversely, a SYCL implementation supporting this extension allows users to |
| 67 | +create the binary contents in the SYCLBIN format from a `kernel_bundle` object, |
| 68 | +even if that object was not created from a SYCLBIN file originally. As such, |
| 69 | +despite the SYCL implementation defining the format of SYCLBIN files, the format |
| 70 | +is guaranteed to contain the corresponding kernel bundle state of the SYCLBIN |
| 71 | +contents, which must in turn match the state of any `kernel_bundle` object |
| 72 | +created from it. |
| 73 | + |
| 74 | + |
| 75 | +== Specification |
| 76 | + |
| 77 | +=== Feature test macro |
| 78 | + |
| 79 | +This extension provides a feature-test macro as described in the core SYCL |
| 80 | +specification. An implementation supporting this extension must predefine the |
| 81 | +macro `SYCL_EXT_ONEAPI_SYCLBIN` to one of the values defined in the table |
| 82 | +below. Applications can test for the existence of this macro to determine if |
| 83 | +the implementation supports this feature, or applications can test the macro's |
| 84 | +value to determine which of the extension's features the implementation |
| 85 | +supports. |
| 86 | + |
| 87 | + |
| 88 | +=== New kernel_bundle interfaces |
| 89 | + |
| 90 | +|==== |
| 91 | +a| |
| 92 | +[frame=all,grid=none] |
| 93 | +!==== |
| 94 | +a! |
| 95 | +[source] |
| 96 | +---- |
| 97 | +namespace sycl::ext::oneapi::experimental { |
| 98 | +
|
| 99 | +template<bundle_state State, typename PropertyListT = empty_properties_t> |
| 100 | +kernel_bundle<State> get_kernel_bundle(const context& ctxt, |
| 101 | + const std::vector<device>& devs, |
| 102 | + const sycl::span<char>& bytes, |
| 103 | + PropertyListT props = {}); |
| 104 | +
|
| 105 | +// Requires C++20 |
| 106 | +template<bundle_state State, typename PropertyListT = empty_properties_t> |
| 107 | +kernel_bundle<State> get_kernel_bundle(const context& ctxt, |
| 108 | + const std::vector<device>& devs, |
| 109 | + const std::span<char>& bytes, |
| 110 | + PropertyListT props = {}); |
| 111 | +
|
| 112 | +} |
| 113 | +---- |
| 114 | +!==== |
| 115 | + |
| 116 | +_Constraints:_ Available only when `State` is not `ext_oneapi_source`. |
| 117 | + |
| 118 | +_Effects:_ Creates a new kernel bundle containing the kernels from the SYCLBIN |
| 119 | +data contained in `bytes` that are compatible with at least one of the devices |
| 120 | +in `devs`. Any remaining kernels (those that are not compatible with any of the |
| 121 | +devices in `devs`) are not represented in the new kernel bundle. |
| 122 | + |
| 123 | +The bundle is associated with the context `ctxt`, and kernels from this bundle |
| 124 | +may only be submitted to a queue that shares the same context and whose device |
| 125 | +is in `devs`. |
| 126 | + |
| 127 | +_Returns:_ The newly created kernel bundle, which has `State` state. |
| 128 | + |
| 129 | +_Throws:_ |
| 130 | + |
| 131 | +* An `exception` with the `errc::invalid` error code if the contents of `bytes` |
| 132 | + is not in the SYCLBIN format, as defined by the SYCL implementation. |
| 133 | +* An `exception` with the `errc::invalid` error code if the SYCLBIN read from |
| 134 | + `bytes` is not in the `State` state. |
| 135 | +* An `exception` with the `errc::invalid` error code if the `devs` vector is |
| 136 | + empty. |
| 137 | +* An `exception` with the `errc::invalid` error code if `State` is |
| 138 | + `bundle_state::input` and any device in `ctxt.get_devices()` does not have |
| 139 | + `aspect::online_compiler`. |
| 140 | +* An `exception` with the `errc::invalid` error code if `State` is |
| 141 | + `bundle_state::object` and any device in `ctxt.get_devices()` does not have |
| 142 | + `aspect::online_linker`. |
| 143 | +* An `exception` with the `errc::build` error code if `State` is |
| 144 | + `bundle_state::object` or `bundle_state::executable`, if the implementation |
| 145 | + needs to perform an online compile or link, and if the online compile or link |
| 146 | + fails. |
| 147 | + |
| 148 | +a| |
| 149 | +[frame=all,grid=none] |
| 150 | +!==== |
| 151 | +a! |
| 152 | +[source] |
| 153 | +---- |
| 154 | +namespace sycl::ext::oneapi::experimental { |
| 155 | +
|
| 156 | +template<bundle_state State, typename PropertyListT = empty_properties_t> (1) |
| 157 | +kernel_bundle<State> get_kernel_bundle(const context& ctxt, |
| 158 | + const std::vector<device>& devs, |
| 159 | + const std::filesystem::path& filename, |
| 160 | + PropertyListT props = {}); |
| 161 | +
|
| 162 | +template<bundle_state State, typename PropertyListT = empty_properties_t> (2) |
| 163 | +kernel_bundle<State> get_kernel_bundle(const context& ctxt, |
| 164 | + const std::filesystem::path& filename, |
| 165 | + PropertyListT props = {}); |
| 166 | +
|
| 167 | +} |
| 168 | +---- |
| 169 | +!==== |
| 170 | + |
| 171 | +_Constraints:_ Available only when `State` is not `ext_oneapi_source`. |
| 172 | + |
| 173 | +_Effects (1):_ Creates a new kernel bundle containing the kernels inside the |
| 174 | +SYCLBIN file located at `filename`. This is equivalent to |
| 175 | +`get_kernel_bundle(ctxt, devs, data, props)` where `data` is the bytes read from |
| 176 | +the SYCLBIN file at `filename`. |
| 177 | + |
| 178 | +_Effects (2)_: Equivalent to `get_kernel_bundle(ctxt, ctxt.get_devices(), filename, props)`. |
| 179 | + |
| 180 | +_Returns:_ The newly created kernel bundle, which has `State` state. |
| 181 | + |
| 182 | +_Throws:_ |
| 183 | + |
| 184 | +* A `std::ios_base::failure` exception if the function failed to access and read |
| 185 | + the file specified by `filename`. |
| 186 | +* An `exception` with the `errc::invalid` error code if the contents of the file |
| 187 | + specified by `filename` is not in the SYCLBIN format, as defined by the SYCL |
| 188 | + implementation. |
| 189 | +* An `exception` with the `errc::invalid` error code if the SYCLBIN read from |
| 190 | + the file specified by `filename` is not in the `State` state. |
| 191 | +* An `exception` with the `errc::invalid` error code if any of the devices in |
| 192 | + `devs` is not one of devices contained by the context `ctxt` or is not a |
| 193 | + descendent device of some device in `ctxt`. |
| 194 | +* An `exception` with the `errc::invalid` error code if the `devs` vector is |
| 195 | + empty. |
| 196 | +* An `exception` with the `errc::invalid` error code if `State` is |
| 197 | + `bundle_state::input` and any device in `ctxt.get_devices()` does not have |
| 198 | + `aspect::online_compiler`. |
| 199 | +* An `exception` with the `errc::invalid` error code if `State` is |
| 200 | + `bundle_state::object` and any device in `ctxt.get_devices()` does not have |
| 201 | + `aspect::online_linker`. |
| 202 | +* An `exception` with the `errc::build` error code if `State` is |
| 203 | + `bundle_state::object` or `bundle_state::executable`, if the implementation |
| 204 | + needs to perform an online compile or link, and if the online compile or link |
| 205 | + fails. |
| 206 | + |
| 207 | +|==== |
| 208 | + |
| 209 | +``` |
| 210 | +namespace sycl { |
| 211 | +template <bundle_state State> class kernel_bundle { |
| 212 | +public: |
| 213 | + ... |
| 214 | + |
| 215 | + std::vector<char> ext_oneapi_get_content(); |
| 216 | + |
| 217 | +}; |
| 218 | +} |
| 219 | +``` |
| 220 | + |
| 221 | +|==== |
| 222 | +a| |
| 223 | +[frame=all,grid=none] |
| 224 | +!==== |
| 225 | +a! |
| 226 | +[source] |
| 227 | +---- |
| 228 | +std::vector<char> ext_oneapi_get_content() |
| 229 | +---- |
| 230 | +!==== |
| 231 | + |
| 232 | +_Constraints:_ Available only when `State` is not `ext_oneapi_source`. |
| 233 | + |
| 234 | +_Returns:_ A vector of bytes containing the data of the kernel bundle in the |
| 235 | +SYCLBIN format for this implementation. The corresponding SYCLBIN format will |
| 236 | +be in `State` state. |
| 237 | + |
| 238 | +[_Note:_ If the `kernel_bundle` was created using the `get_kernel_bundle` from |
| 239 | +a SYCLBIN file, the contents returned by this member function are not guaranteed |
| 240 | +to be the same as the original SYCLBIN file. |
| 241 | +_{endnote}_] |
| 242 | + |
| 243 | +|==== |
| 244 | + |
0 commit comments