|
1 |
| -= SYCL_INTEL_kernel_restrict_all |
| 1 | += sycl_intel_kernel_restrict_all |
| 2 | + |
2 | 3 | :source-highlighter: coderay
|
3 | 4 | :coderay-linenums-mode: table
|
4 | 5 |
|
|
8 | 9 | :toc: left
|
9 | 10 | :encoding: utf-8
|
10 | 11 | :lang: en
|
11 |
| - |
12 |
| -:blank: pass:[ +] |
| 12 | +:dpcpp: pass:[DPC++] |
13 | 13 |
|
14 | 14 | // Set the default source code type in this document to C++,
|
15 | 15 | // for syntax highlighting purposes. This is needed because
|
16 | 16 | // docbook uses c++ and html5 uses cpp.
|
17 | 17 | :language: {basebackend@docbook:c++:cpp}
|
18 | 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 |
| -NOTE: This document is better viewed when rendered as html with asciidoctor. GitHub does not render image icons. |
25 |
| - |
26 |
| -This document describes an extension that adds a function type attribute which has the same effect as adding the C99 `restrict` attribute to all pointer arguments when applied to a kernel function. |
27 |
| - |
28 |
| - |
29 |
| -== Name Strings |
30 |
| - |
31 |
| -+SYCL_INTEL_kernel_restrict_all+ |
32 | 19 |
|
33 | 20 | == Notice
|
34 | 21 |
|
35 |
| -Copyright (c) 2019 Intel Corporation. All rights reserved. |
| 22 | +[%hardbreaks] |
| 23 | +Copyright (C) 2022 Intel Corporation. All rights reserved. |
36 | 24 |
|
37 |
| -== Status |
| 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. |
38 | 28 |
|
39 |
| -Working Draft |
40 | 29 |
|
41 |
| -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. |
| 30 | +== Contact |
42 | 31 |
|
43 |
| -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. |
| 32 | +To report problems with this extension, please open a new issue at: |
44 | 33 |
|
45 |
| -== Version |
| 34 | +https://github.com/intel/llvm/issues |
46 | 35 |
|
47 |
| -Built On: {docdate} + |
48 |
| -Revision: 1 |
49 |
| - |
50 |
| -== Contact |
51 |
| -Michael Kinsner, Intel (michael 'dot' kinsner 'at' intel 'dot' com) |
52 | 36 |
|
53 | 37 | == Dependencies
|
54 | 38 |
|
55 |
| -This extension is written against the SYCL 1.2.1 specification, Revision v1.2.1-5. |
56 |
| - |
57 |
| -== Overview |
| 39 | +This extension is written against the SYCL 2020 revision 4 specification. All |
| 40 | +references below to the "core SYCL specification" or to section numbers in the |
| 41 | +SYCL specification refer to that revision. |
58 | 42 |
|
59 |
| -This extension adds a function type attribute that has the same effect as adding the C99 (or equivalently OpenCL C kernel language) `restrict` attribute to all pointers and the pointer member of any accessors, that are function arguments, lambda captures, or functor members, of the callable to which the attribute was applied. The attribute can be applied to kernel lambdas, function call operators of a functor, or arbitrary functions (the effect on arbitrary functions, if any, is implementaton defined), to provide the compiler with additional information for optimization. |
60 |
| - |
61 |
| -A new attribute is added by this extension because there is no clear location on which to manually annotate C99 `restrict` on lambda captures, functor members, or accessors. |
| 43 | +== Status |
62 | 44 |
|
63 |
| -== Add new paragraphs to end of section 6.7 (Attributes) |
| 45 | +This extension is implemented and fully supported by {dpcpp}. |
64 | 46 |
|
65 |
| -The attribute `intel::kernel_args_restrict` is legal on device functions, and can be ignored on non-device functions. When applied to a lambda or function call operator (of a functor) that defines a kernel, the attribute is a hint to the compiler equivalent to specifying the C99 `restrict` attribute on all pointer arguments or the pointer member of any accessors, which are a function argument, lambda capture, or functor member, of the callable to which the attribute was applied. This effect is equivalent to annotating `restrict` on *all* kernel pointer arguments in an OpenCL or SPIR-V kernel, if the callable is a kernel. If `intel::kernel_args_restrict` is applied to a function called from a device kernel, the effect is implementation defined. The attribute forms an unchecked assertion, in that implementations do not need to check/confirm the pre-condition in any way. If a user applies `intel::kernel_args_restrict` to a kernel, but there is in fact aliasing between kernel pointer arguments at runtime, the behavior is undefined. |
| 47 | +== Overview |
66 | 48 |
|
67 |
| -The attribute-token `intel::kernel_args_restrict` shall appear at most once in each _attribute-list_ and no _attribute-argument-clause_ shall be present. The attribute may be applied to the _function-type_ in a function declaration. The first declaration of a function shall specify the `intel::kernel_args_restrict` attribute if any declaration of that function specifies the `intel::kernel_args_restrict` attribute. If a function is declared with the `intel::kernel_args_restrict` attribute in one translation unit and the same function is declared without the `intel::kernel_args_restrict` attribute in another translation unit, the program is ill-formed and no diagnostic is required. |
| 49 | +This extension adds a kernel function attribute that has similar effect as |
| 50 | +the C99 `restrict` type qualifier. When a kernel is decorated with this |
| 51 | +attribute, all pointers and accessors (treated as if each accessor was a |
| 52 | +pointer) that are captured as kernel arguments |
| 53 | +are assumed to point to disjoint objects in memory. This provides the |
| 54 | +compiler with additional information for optimization. |
68 | 55 |
|
69 |
| -The `intel::kernel_args_restrict` attribute has an effect when applied to a function, and no effect otherwise. |
| 56 | +A new attribute is added by this extension because there is no clear location |
| 57 | +on which to manually annotate C99 `restrict` on lambda captures, function |
| 58 | +object members, or accessors. |
70 | 59 |
|
71 |
| -== Example uses |
| 60 | +=== Example uses |
72 | 61 |
|
73 | 62 | [source,c++,Restrict on lambda,linenums]
|
74 | 63 | ----
|
75 |
| - Q.submit([&](handler &cgh) { |
76 |
| - auto acc1 = out_buf_1.get_access<access::mode::write>(cgh); |
77 |
| - auto acc2 = out_buf_2.get_access<access::mode::write>(cgh); |
78 |
| - cgh.parallel_for<class lambda_foo>( |
79 |
| - range<1>(N), [=](id<1> wiid) [[intel::kernel_args_restrict]] { |
80 |
| - int id = wiid[0]; |
81 |
| - acc1[id]=id; |
82 |
| - acc2[id]=id*2; |
83 |
| - }); |
84 |
| - }); |
| 64 | +Q.submit([&](handler &cgh) { |
| 65 | + auto acc1 = out_buf_1.get_access<access::mode::write>(cgh); |
| 66 | + auto acc2 = out_buf_2.get_access<access::mode::write>(cgh); |
| 67 | + cgh.parallel_for<class lambda_foo>( |
| 68 | + range<1>(N), [=](id<1> wiid) [[intel::kernel_args_restrict]] { |
| 69 | + int id = wiid[0]; |
| 70 | + acc1[id]=id; |
| 71 | + acc2[id]=id*2; |
| 72 | + }); |
| 73 | +}); |
85 | 74 | ----
|
86 | 75 |
|
87 |
| -[source,c++,Restrict on functor,linenums] |
| 76 | +[source,c++,Restrict on function object,linenums] |
88 | 77 | ----
|
89 | 78 | class functor_foo {
|
90 |
| - ... |
91 |
| - void operator()(item<1> item) [[intel::kernel_args_restrict]] |
92 |
| - { |
93 |
| - int id = item[0]; |
94 |
| - buf1_m[id]=id; |
95 |
| - buf2_m[id]=id*2; |
96 |
| - } |
| 79 | + ... |
| 80 | + [[intel::kernel_args_restrict]] |
| 81 | + void operator()(item<1> item) |
| 82 | + { |
| 83 | + int id = item[0]; |
| 84 | + buf1_m[id]=id; |
| 85 | + buf2_m[id]=id*2; |
| 86 | + } |
97 | 87 | };
|
98 | 88 | ----
|
99 | 89 |
|
100 | 90 |
|
101 | 91 |
|
102 |
| -== Issues |
103 |
| - |
104 |
| -None. |
| 92 | +== Specification |
105 | 93 |
|
106 |
| -//. Title |
107 |
| -//+ |
108 |
| -//-- |
109 |
| -//*RESOLUTION*: Description |
110 |
| -//-- |
111 |
| -
|
112 |
| -== Feature test macro |
| 94 | +=== Feature test macro |
113 | 95 |
|
114 | 96 | This extension provides a feature-test macro as described in the core SYCL
|
115 |
| -specification section 6.3.3 "Feature test macros". Therefore, an implementation |
116 |
| -supporting this extension must predefine the macro `SYCL_EXT_INTEL_KERNEL_ARGS_RESTRICT` |
117 |
| -to one of the values defined in the table below. Applications can test for the |
118 |
| -existence of this macro to determine if the implementation supports this |
119 |
| -feature, or applications can test the macro’s value to determine which of the |
120 |
| -extension’s APIs the implementation supports. |
| 97 | +specification. An implementation supporting this extension must predefine the |
| 98 | +macro `SYCL_EXT_INTEL_KERNEL_ARGS_RESTRICT` to one of the values defined in the table |
| 99 | +below. Applications can test for the existence of this macro to determine if |
| 100 | +the implementation supports this feature, or applications can test the macro's |
| 101 | +value to determine which of the extension's features the implementation |
| 102 | +supports. |
121 | 103 |
|
122 | 104 | [%header,cols="1,5"]
|
123 | 105 | |===
|
124 |
| -|Value |Description |
125 |
| -|1 |Initial extension version. Base features are supported. |
| 106 | +|Value |
| 107 | +|Description |
| 108 | + |
| 109 | +|1 |
| 110 | +|Initial version of this extension. |
126 | 111 | |===
|
127 | 112 |
|
128 |
| -== Revision History |
129 |
| -
|
130 |
| -[cols="5,15,15,70"] |
131 |
| -[grid="rows"] |
132 |
| -[options="header"] |
133 |
| -|======================================== |
134 |
| -|Rev|Date|Author|Changes |
135 |
| -|1|2019-11-11|Michael Kinsner|*Initial public working draft* |
136 |
| -|======================================== |
137 |
| -
|
138 |
| -//************************************************************************ |
139 |
| -//Other formatting suggestions: |
140 |
| -// |
141 |
| -//* Use *bold* text for host APIs, or [source] syntax highlighting. |
142 |
| -//* Use +mono+ text for device APIs, or [source] syntax highlighting. |
143 |
| -//* Use +mono+ text for extension names, types, or enum values. |
144 |
| -//* Use _italics_ for parameters. |
145 |
| -//************************************************************************ |
| 113 | + |
| 114 | +=== Add new entry to Table 180 in section 5.8.1 (Kernel attributes) |
| 115 | + |
| 116 | +[width="100%",options="header",separator="@",cols="65%,35%"] |
| 117 | +|==== |
| 118 | +@ SYCL attribute @ Description |
| 119 | +a@ |
| 120 | +[source] |
| 121 | +---- |
| 122 | +intel::kernel_args_restrict |
| 123 | +---- |
| 124 | + a@ Hint to the compiler equivalent to specifying the C99 `restrict` |
| 125 | + attribute on all pointers and accessors (treated as if each accessor was a |
| 126 | + pointer) that are captured as kernel arguments. |
| 127 | + |
| 128 | +The attribute forms an unchecked assertion, in that implementations do not need |
| 129 | +to check/confirm the pre-condition in any way. If a user applies `intel::kernel_args_restrict` |
| 130 | +to a kernel, but there is in fact aliasing between accessors and/or pointers at runtime, |
| 131 | +the behavior is undefined. |
| 132 | + |
| 133 | +|==== |
| 134 | + |
0 commit comments