Skip to content

Commit 5d5351b

Browse files
author
Mike Kinsner
authored
[SYCL][Doc] Function-type kernel attribute extension (#1494)
Initial extension that replaces function attributes on device functions for kernel attributes, with function-type attributes that apply directly to a kernel function. Signed-off-by: Michael Kinsner <[email protected]>
1 parent 2b88867 commit 5d5351b

File tree

2 files changed

+225
-0
lines changed

2 files changed

+225
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SYCL_INTEL_attribute_style
2+
3+
Extension that deprecates use of function attributes (left-sided) applied to
4+
device functions for kernel attributes, and introduces instead function-type
5+
attributes (right-sided) for kernel attributes that apply directly to kernel functions.
6+
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
= SYCL_INTEL_attribute_style
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+
13+
:blank: pass:[ +]
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+
// This is necessary for asciidoc, but not for asciidoctor
21+
:cpp: C++
22+
23+
== Introduction
24+
IMPORTANT: This specification is a draft.
25+
26+
NOTE: Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM)
27+
are trademarks of The Khronos Group Inc. OpenCL(TM) is a trademark
28+
of Apple Inc. used by permission by Khronos.
29+
30+
NOTE: This document is better viewed when rendered as html with asciidoctor.
31+
GitHub does not render image icons.
32+
33+
This document describes an extension that deprecates use of function attributes
34+
(left-sided) for kernel attributes, and introduces use of function-type
35+
attributes (right-sided) for kernel attributes. This allows SYCL kernel
36+
attributes to be applied directly to kernels defined as lambdas, and no longer requires
37+
propagation of attributes across call trees (which left-sided function attributes require).
38+
39+
== Name Strings
40+
41+
+SYCL_INTEL_attribute_style+
42+
43+
== Notice
44+
45+
Copyright (c) 2020 Intel Corporation. All rights reserved.
46+
47+
== Status
48+
49+
Working Draft
50+
51+
This is a preview extension specification, intended to provide early access
52+
to a feature for review and community feedback. When the feature matures,
53+
this specification may be released as a formal extension.
54+
55+
Because the interfaces defined by this specification are not final and are
56+
subject to change they are not intended to be used by shipping software products.
57+
58+
== Version
59+
60+
Built On: {docdate} +
61+
Revision: 1
62+
63+
== Contact
64+
Michael Kinsner, Intel (michael 'dot' kinsner 'at' intel 'dot' com)
65+
66+
== Dependencies
67+
68+
This extension is written against the SYCL 1.2.1 specification, Revision 6.
69+
70+
== Overview
71+
72+
SYCL 1.2.1 defines kernel attributes as applying to device functions (functions called
73+
by kernels), and describes a call tree-based propagation scheme in which the attributes would
74+
propagate to calling kernels. This extension instead enables attributes to be applied
75+
directly to kernel functions, avoiding complex and error prone call tree propagation, and
76+
making it clear to which kernel an attribute applies.
77+
78+
A kernel attribute applied to the function as required by SYCL 1.2.1 looks like:
79+
80+
[source,c++]
81+
----
82+
[[attrib]] void foo1() {};
83+
84+
class f {
85+
[[attrib]] void foo2() {};
86+
};
87+
----
88+
89+
where `attrib` is a placeholder for any of the kernel attributes defined by the SYCL specification or extensions.
90+
91+
This extension deprecates the SYCL 1.2.1 attribute style (attribute applied to
92+
a device function) and instead defines kernel attributes as attributes that apply to the
93+
function type. The location of the resulting attributes looks like:
94+
95+
[source,c++]
96+
----
97+
void bar1() [[attrib]] {};
98+
99+
class f {
100+
void bar2() [[attrib]] {};
101+
};
102+
103+
class KernelFunctor {
104+
public:
105+
void operator()(sycl::item<1> item) [[attrib]] {};
106+
};
107+
108+
auto bar3 = []()[[attrib]]{}; // Works on lambdas. operator() type
109+
----
110+
111+
The function type attributes have an effect when applied to a kernel function,
112+
do not propagate up or down call trees unless specified by a specific attribute,
113+
and the effect when applied to non-kernel functions or non-functions is implementation defined.
114+
115+
== Modifications of SYCL 1.2.1 Specification
116+
117+
=== Modify Section 6.7 (Attributes)
118+
119+
==== Rename the section
120+
121+
Rename Section 6.7 from "Attributes" to "Kernel attributes".
122+
123+
==== Replace the entire section with:
124+
125+
The SYCL programming interface defines attributes that augment the
126+
information available while generating the device code for a particular platform.
127+
The attributes in Table 1 are defined in the `sycl::` namespace
128+
and are applied to the function-type of kernel function declarations using
129+
{cpp}11 attribute specifier syntax.
130+
131+
A given attribute-token shall appear at most once in each attribute-list. The
132+
first declaration of a function shall specify an attribute if any declaration
133+
of that function specifies the same attribute. If a function is declared with
134+
an attribute in one translation unit and the same function is declared without
135+
the same attribute in another translation unit, the program is ill-formed and
136+
no diagnostic is required.
137+
138+
If there are any conflicts between different kernel attributes, then the behavior
139+
is undefined. The attributes have an effect when applied to a device function and no
140+
effect otherwise (i.e. no effect on non-device functions and on anything other than a
141+
function). If an attribute is applied to a device function that is not a kernel function
142+
(but that is potentially called from a kernel function), then the effect is implementation defined.
143+
It is implementation defined whether any diagnostic is produced when an attribute is applied
144+
to anything other than the function-type of a kernel function declaration.
145+
146+
.Attributes supported by the SYCL programming interface
147+
[cols="2*"]
148+
|===
149+
|`reqd_work_group_size(dim0)`
150+
`reqd_work_group_size(dim0, dim1)`
151+
`reqd_work_group_size(dim0, dim1, dim2)`
152+
|Indicates that the kernel must be launched with the specified work-group size. The sizes
153+
are written in row-major format. Each argument to the attribute must be an integral
154+
constant expression. The dimensionality of the attribute variant used must match the
155+
dimensionality of the work-group used to invoke the kernel.
156+
157+
SYCL device compilers should give a compilation error if the required work-group size
158+
is unsupported. If the kernel is submitted for execution using an incompatible
159+
work-group size, the SYCL runtime must throw an `nd_range_error`.
160+
161+
|`work_group_size_hint(dim0)`
162+
`work_group_size_hint(dim0, dim1)`
163+
`work_group_size_hint(dim0, dim1, dim2)`
164+
|Hint to the compiler on the work-group size most likely to be used when launching the kernel
165+
at runtime. Each argument must be an integral constant expression, and the number of dimensional
166+
values defined provide additional information to the compiler on the dimensionality most likely
167+
to be used when launching the kernel at runtime. The effect of this attribute, if any, is
168+
implementation defined.
169+
170+
|`vec_type_hint(<type>)`
171+
|Hint to the compiler on the vector computational width of of the kernel. The argument must be
172+
one of the vector types defined in section 4.10.2. This attribute is deprecated by this
173+
extension (available for use, but will be removed in the future and is not recommended for
174+
use in new code).
175+
|===
176+
177+
178+
179+
==== Add new sub-section 6.7.1: Deprecated attribute syntax
180+
The SYCL 1.2.1 specification defined two mechanisms for kernel attributes to be specified,
181+
which are deprecated by this extension. Deprecation means that the syntaxes are supported,
182+
but will be removed in the future, and are therefore not recommended for use. Specifically,
183+
the following two attribute syntaxes defined by the SYCL 1.2.1 specification are deprecated:
184+
185+
1. The `attribute` syntax defined by the OpenCL C specification within device
186+
code (`__attribute__\((attrib))`).
187+
2. {cpp}11 attribute specifier syntax (`\[[attrib]]`) applied to device functions
188+
(not the function-type), including automatic propagation of the attribute to any
189+
caller of those device functions.
190+
191+
192+
== Issues
193+
194+
None.
195+
196+
//. asd
197+
//+
198+
//--
199+
//*RESOLUTION*: Not resolved.
200+
//--
201+
202+
== Revision History
203+
204+
[cols="5,15,15,70"]
205+
[grid="rows"]
206+
[options="header"]
207+
|========================================
208+
|Rev|Date|Author|Changes
209+
|1|2020-04-08|Michael Kinsner|*Initial public working draft*
210+
|========================================
211+
212+
//************************************************************************
213+
//Other formatting suggestions:
214+
//
215+
//* Use *bold* text for host APIs, or [source] syntax highlighting.
216+
//* Use +mono+ text for device APIs, or [source] syntax highlighting.
217+
//* Use +mono+ text for extension names, types, or enum values.
218+
//* Use _italics_ for parameters.
219+
//************************************************************************

0 commit comments

Comments
 (0)