Skip to content

Commit 4a794df

Browse files
author
Mike Kinsner
authored
[SYCL][Docs] Align kernel_args_restrict extension with SYCL 2020 to inherit critical fixes (#5793)
Align kernel_args_restrict extension with fixes that we factored into SYCL2020, but didn't make it into this extension. Inherit the correct attribute location for function objects. Signed-off-by: Michael Kinsner <[email protected]>
1 parent 58eabc6 commit 4a794df

File tree

1 file changed

+81
-92
lines changed

1 file changed

+81
-92
lines changed
Lines changed: 81 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
= SYCL_INTEL_kernel_restrict_all
1+
= sycl_intel_kernel_restrict_all
2+
23
:source-highlighter: coderay
34
:coderay-linenums-mode: table
45

@@ -8,138 +9,126 @@
89
:toc: left
910
:encoding: utf-8
1011
:lang: en
11-
12-
:blank: pass:[ +]
12+
:dpcpp: pass:[DPC++]
1313

1414
// Set the default source code type in this document to C++,
1515
// for syntax highlighting purposes. This is needed because
1616
// docbook uses c++ and html5 uses cpp.
1717
:language: {basebackend@docbook:c++:cpp}
1818

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+
3219

3320
== Notice
3421

35-
Copyright (c) 2019 Intel Corporation. All rights reserved.
22+
[%hardbreaks]
23+
Copyright (C) 2022 Intel Corporation. All rights reserved.
3624

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.
3828

39-
Working Draft
4029

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
4231

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:
4433

45-
== Version
34+
https://github.com/intel/llvm/issues
4635

47-
Built On: {docdate} +
48-
Revision: 1
49-
50-
== Contact
51-
Michael Kinsner, Intel (michael 'dot' kinsner 'at' intel 'dot' com)
5236

5337
== Dependencies
5438

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.
5842

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
6244

63-
== Add new paragraphs to end of section 6.7 (Attributes)
45+
This extension is implemented and fully supported by {dpcpp}.
6446

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
6648

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.
6855

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.
7059

71-
== Example uses
60+
=== Example uses
7261

7362
[source,c++,Restrict on lambda,linenums]
7463
----
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+
});
8574
----
8675

87-
[source,c++,Restrict on functor,linenums]
76+
[source,c++,Restrict on function object,linenums]
8877
----
8978
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+
}
9787
};
9888
----
9989

10090

10191

102-
== Issues
103-
104-
None.
92+
== Specification
10593

106-
//. Title
107-
//+
108-
//--
109-
//*RESOLUTION*: Description
110-
//--
111-
112-
== Feature test macro
94+
=== Feature test macro
11395

11496
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.
121103

122104
[%header,cols="1,5"]
123105
|===
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.
126111
|===
127112

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

Comments
 (0)