|
| 1 | += sycl_ext_oneapi_raw_kernel_arg |
| 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) 2023-2023 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 8 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 | + |
| 45 | +== Status |
| 46 | + |
| 47 | +This is a proposed extension specification, intended to gather community |
| 48 | +feedback. Interfaces defined in this specification may not be implemented yet |
| 49 | +or may be in a preliminary state. The specification itself may also change in |
| 50 | +incompatible ways before it is finalized. *Shipping software products should |
| 51 | +not rely on APIs defined in this specification.* |
| 52 | + |
| 53 | + |
| 54 | +== Overview |
| 55 | + |
| 56 | +When launching kernels that are represented as `sycl::kernel` objects, |
| 57 | +developers must pass arguments via the `set_arg` or `set_args` functions. |
| 58 | + |
| 59 | +There are situations where developers would like to pass a raw byte |
| 60 | +representation of the kernel argument to the backend (e.g., when a single |
| 61 | +`parallel_for` in the source code is used to invoke multiple kernels with |
| 62 | +different arguments types, or when passing an argument to a built-in kernel |
| 63 | +for which there is no equivalent type defined on the host). |
| 64 | + |
| 65 | +=== Usage example |
| 66 | + |
| 67 | +[source,c++] |
| 68 | +---- |
| 69 | +int a; |
| 70 | +char* opaque_type; |
| 71 | +int nbytes; |
| 72 | +... |
| 73 | +h.set_arg(0, a); |
| 74 | +h.set_arg(1, sycl::ext::oneapi::raw_kernel_arg(opaque_type, nbytes)); |
| 75 | +h.parallel_for(range, kernel); |
| 76 | +---- |
| 77 | + |
| 78 | + |
| 79 | +== Specification |
| 80 | + |
| 81 | +=== Feature test macro |
| 82 | + |
| 83 | +This extension provides a feature-test macro as described in the core SYCL |
| 84 | +specification. An implementation supporting this extension must predefine the |
| 85 | +macro `SYCL_EXT_ONEAPI_RAW_KERNEL_ARG` to one of the values defined in the |
| 86 | +table below. Applications can test for the existence of this macro to |
| 87 | +determine if the implementation supports this feature, or applications can test |
| 88 | +the macro's value to determine which of the extension's features the |
| 89 | +implementation supports. |
| 90 | + |
| 91 | +[%header,cols="1,5"] |
| 92 | +|=== |
| 93 | +|Value |
| 94 | +|Description |
| 95 | + |
| 96 | +|1 |
| 97 | +|Initial version of this extension. |
| 98 | +|=== |
| 99 | + |
| 100 | +=== The `raw_kernel_arg` class |
| 101 | + |
| 102 | +This extension adds a new `raw_kernel_arg` class that can be used to declare |
| 103 | +kernel arguments via a raw byte representation. |
| 104 | + |
| 105 | +[source,c++] |
| 106 | +---- |
| 107 | +namespace sycl::ext::oneapi { |
| 108 | +
|
| 109 | + class raw_kernel_arg { |
| 110 | + public: |
| 111 | + raw_kernel_arg(void* bytes, size_t count); |
| 112 | + }; |
| 113 | +
|
| 114 | +} // namespace sycl::ext::oneapi |
| 115 | +---- |
| 116 | + |
| 117 | +[source,c++] |
| 118 | +---- |
| 119 | +raw_kernel_arg(void* bytes, size_t count); |
| 120 | +---- |
| 121 | +_Preconditions_: `bytes` must point to an array of at least `count` bytes, |
| 122 | +which is the byte representation of a kernel argument that is trivially |
| 123 | +copyable. |
| 124 | + |
| 125 | +_Effects_: Constructs a `raw_kernel_arg` representing a view of the `count` |
| 126 | +bytes starting at the address specified by `bytes`. |
| 127 | + |
| 128 | +=== Using a raw kernel argument |
| 129 | + |
| 130 | +Instances of `raw_kernel_arg` are passed to kernels via the existing `set_arg` |
| 131 | +and `set_args` functions defined by the SYCL specification. |
| 132 | + |
| 133 | +This extension adds a new overload of `set_arg`, as defined below. |
| 134 | + |
| 135 | +[_Note:_ Since the definition of `set_args` says that it acts "as if each |
| 136 | +argument in `args` was passed to `set_arg` ", adding a new overload of |
| 137 | +`set_arg` is sufficient to change the behavior of `set_args`. _{endnote}_] |
| 138 | + |
| 139 | +[source,c++] |
| 140 | +---- |
| 141 | +void set_arg(int argIndex, sycl::ext::oneapi::raw_kernel_arg&& arg); |
| 142 | +---- |
| 143 | +_Effects_: Sets the kernel argument associated with index `argIndex` using the |
| 144 | +bytes represented by `arg`. |
| 145 | + |
| 146 | + |
| 147 | +== Issues |
| 148 | + |
| 149 | +None. |
0 commit comments