|
| 1 | += SYCL_EXT_ONEAPI_FREE_FUNCTION_QUERIES |
| 2 | +:source-highlighter: coderay |
| 3 | +:coderay-linenums-mode: table |
| 4 | + |
| 5 | +// This section needs to be after the document title. |
| 6 | +:doctype: book |
| 7 | +:toc2: |
| 8 | +:toc: left |
| 9 | +:encoding: utf-8 |
| 10 | +:lang: en |
| 11 | + |
| 12 | +:blank: pass:[ +] |
| 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 | +== Introduction |
| 20 | +IMPORTANT: This specification is a draft. |
| 21 | + |
| 22 | +NOTE: Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM) are trademarks of The Khronos Group Inc. OpenCL(TM) is a trademark of Apple Inc. used by permission by Khronos. |
| 23 | + |
| 24 | +This document describes an extension that adds features for SYCL work items and groups to be available globally. |
| 25 | + |
| 26 | +== Notice |
| 27 | + |
| 28 | +Copyright (c) 2020-2021 Intel Corporation. All rights reserved. |
| 29 | + |
| 30 | +== Status |
| 31 | + |
| 32 | +Working Draft |
| 33 | + |
| 34 | +This is a preview extension specification, intended to provide early access to a feature for review and community feedback. When the feature matures, this specification may be released as a formal extension. |
| 35 | + |
| 36 | +Because the interfaces defined by this specification are not final and are subject to change they are not intended to be used by shipping software products. |
| 37 | + |
| 38 | +== Version |
| 39 | + |
| 40 | +Revision: 1 |
| 41 | + |
| 42 | +== Contact |
| 43 | +Ruslan Arutyunyan, Intel (ruslan 'dot' arutyunyan 'at' intel 'dot' com) |
| 44 | + |
| 45 | +John Pennycook, Intel (john 'dot' pennycook 'at' intel 'dot' com) |
| 46 | + |
| 47 | +== Dependencies |
| 48 | + |
| 49 | +This extension is written against the SYCL 2020 specification, Revision 4. |
| 50 | + |
| 51 | +== Feature Test Macro |
| 52 | + |
| 53 | +This extension provides a feature-test macro as described in the core SYCL |
| 54 | +specification section 6.3.3 "Feature test macros". Therefore, an implementation |
| 55 | +supporting this extension must predefine the macro `SYCL_EXT_ONEAPI_FREE_FUNCTION_QUERIES` |
| 56 | +to one of the values defined in the table below. Applications can test for the |
| 57 | +existence of this macro to determine if the implementation supports this |
| 58 | +feature, or applications can test the macro's value to determine which of the |
| 59 | +extension's APIs the implementation supports. |
| 60 | + |
| 61 | +[%header,cols="1,5"] |
| 62 | +|=== |
| 63 | +|Value |Description |
| 64 | +|1 |Initial extension version. Base features are supported. |
| 65 | +|=== |
| 66 | + |
| 67 | +== Overview |
| 68 | + |
| 69 | +The extension allows to get `sycl::id`, `sycl::item`, `sycl::nd_item`, |
| 70 | +`sycl::group` and `sycl::sub_group` instances globally, without having to |
| 71 | +explicitly pass them as arguments to each function used on the device. |
| 72 | + |
| 73 | +NOTE: Passing such instances as arguments can result in a clearer interface |
| 74 | +that is less error-prone to use. For example, if a function accepts a |
| 75 | +`sycl::group`, the caller must assume that function may call a |
| 76 | +`sycl::group_barrier` and ensure that associated control flow requirements are |
| 77 | +satisfied. It is recommended that this extension is used only when modifying |
| 78 | +existing interfaces is not feasible. |
| 79 | + |
| 80 | +== Accessing Instances of Special SYCL Classes |
| 81 | + |
| 82 | +The `sycl::ext::oneapi::this_kernel` namespace contains functionality related |
| 83 | +to the currently executing kernel. |
| 84 | + |
| 85 | +It is the user's responsibility to ensure that that these functions are called |
| 86 | +in a manner that is compatible with the kernel's launch parameters, as detailed |
| 87 | +in the definition of each function. Calling these functions from an incompatible |
| 88 | +kernel results in undefined behavior. |
| 89 | + |
| 90 | +[source,c++] |
| 91 | +---- |
| 92 | +namespace sycl { |
| 93 | +namespace ext { |
| 94 | +namespace oneapi { |
| 95 | +namespace this_kernel { |
| 96 | +
|
| 97 | +size_t get_linear_id(); |
| 98 | +
|
| 99 | +template <int Dimensions> |
| 100 | +id<Dimensions> get_id(); |
| 101 | +
|
| 102 | +template <int Dimensions> |
| 103 | +item<Dimensions, false> get_item(); |
| 104 | +
|
| 105 | +template <int Dimensions> |
| 106 | +nd_item<Dimensions> get_nd_item(); |
| 107 | +
|
| 108 | +template <int Dimensions> |
| 109 | +group<Dimensions> get_group(); |
| 110 | +
|
| 111 | +sub_group get_sub_group(); |
| 112 | +
|
| 113 | +} |
| 114 | +} |
| 115 | +} |
| 116 | +} |
| 117 | +---- |
| 118 | + |
| 119 | +[source,c++] |
| 120 | +---- |
| 121 | +size_t get_linear_id(); |
| 122 | +---- |
| 123 | +_Preconditions_: The currently executing kernel must have been launched with a |
| 124 | +`sycl::range` or `sycl::nd_range` argument. |
| 125 | + |
| 126 | +_Returns_: A `size_t` representing the current work-item's linear position in |
| 127 | +the global iteration space. Multi-dimensional indices are converted into a |
| 128 | +linear index following the linearization equations defined in Section 3.11.1 of |
| 129 | +the SYCL 2020 specification. |
| 130 | + |
| 131 | +[source,c++] |
| 132 | +---- |
| 133 | +template <int Dimensions> |
| 134 | +id<Dimensions> get_id(); |
| 135 | +---- |
| 136 | +_Preconditions_: `Dimensions` must match the dimensionality of the currently |
| 137 | +executing kernel. The currently executing kernel must have been launched with a |
| 138 | +`sycl::range` or `sycl::nd_range` argument. |
| 139 | + |
| 140 | +_Returns_: A `sycl::id` instance representing the current work-item in the |
| 141 | +global iteration space. |
| 142 | + |
| 143 | +[source,c++] |
| 144 | +---- |
| 145 | +template <int Dimensions> |
| 146 | +item<Dimensions, false> get_item(); |
| 147 | +---- |
| 148 | +_Preconditions_: `Dimensions` must match the dimensionality of the currently |
| 149 | +executing kernel. The currently executing kernel must have been launched with a |
| 150 | +`sycl::range` or `sycl::nd_range` argument. |
| 151 | + |
| 152 | +_Returns_: A `sycl::item` instance representing the current work-item in the |
| 153 | +global iteration space. |
| 154 | + |
| 155 | +NOTE: The `offset` parameter to `parallel_for` is deprecated in SYCL 2020, as |
| 156 | +is the ability of an `item` to carry an offset. This extension returns an |
| 157 | +`item` where the `WithOffset` template parameter is set to `false` to prevent |
| 158 | +usage of the new queries in conjunction with deprecated functionality. The |
| 159 | +return type of `get_item()` is expected to change when the `offset` parameter |
| 160 | +is removed in a future version of the SYCL specification. |
| 161 | + |
| 162 | +[source,c++] |
| 163 | +---- |
| 164 | +template <int Dimensions> |
| 165 | +nd_item<Dimensions> get_nd_item(); |
| 166 | +---- |
| 167 | +_Preconditions_: `Dimensions` must match the dimensionality of the currently |
| 168 | +executing kernel. The currently executing kernel must have been launched with a |
| 169 | +`sycl::nd_range` argument. |
| 170 | + |
| 171 | +_Returns_: A `sycl::nd_item` instance representing the current work-item in a |
| 172 | +`sycl::nd_range`. |
| 173 | + |
| 174 | +[source,c++] |
| 175 | +---- |
| 176 | +template <int Dimensions> |
| 177 | +group<Dimensions> get_group(); |
| 178 | +---- |
| 179 | +_Preconditions_: `Dimensions` must match the dimensionality of the currently |
| 180 | +executing kernel. The currently executing kernel must have been launched with a |
| 181 | +`sycl::nd_range` argument. |
| 182 | + |
| 183 | +_Returns_: A `sycl::group` instance representing the work-group to which the |
| 184 | +current work-item belongs. |
| 185 | + |
| 186 | +[source,c++] |
| 187 | +---- |
| 188 | +sub_group get_sub_group(); |
| 189 | +---- |
| 190 | +_Preconditions_: The currently executing kernel must have been launched with a |
| 191 | +`sycl::nd_range` argument. |
| 192 | + |
| 193 | +_Returns_: A `sycl::sub_group` instance representing the sub-group to which the |
| 194 | +current work-item belongs. |
| 195 | + |
| 196 | +== Issues |
| 197 | + |
| 198 | +. Can undefined behavior be avoided or detected? |
| 199 | +-- |
| 200 | +*UNRESOLVED*: Good run-time errors would likely require support for device-side |
| 201 | +assertions or exceptions, while good compile-time errors would likely require |
| 202 | +some additional compiler modifications and/or kernel properties. |
| 203 | +-- |
| 204 | + |
| 205 | +//. asd |
| 206 | +//+ |
| 207 | +//-- |
| 208 | +//*RESOLUTION*: Not resolved. |
| 209 | +//-- |
0 commit comments