Skip to content

Commit fac94e4

Browse files
AnastasiaStulovamantogniniTopotunasvenvh
authored
C++ for OpenCL 2021 (i.e OpenCL 3.0-compatible) (#616)
Added a new version of C++ for OpenCL aligned with OpenCL 3 that makes the same feature optional. The main summary of new content: - Updated intro to explain the main concept of the new language version. - Misc small updates to differences to C++ and OpenCL C sections. - Added new predefined version macros. - Updated address space section to detail the behavior without generic address space and program scope features. - Changed section references and their format from OpenCL v2.0 to OpenCL 3.0. Co-authored-by: Marco Antognini <antognini.marco@gmail.com> Co-authored-by: Justas Janickas <Justas.Janickas@arm.com> Co-authored-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
1 parent d5f4027 commit fac94e4

7 files changed

Lines changed: 284 additions & 156 deletions

File tree

CXX_for_OpenCL.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Creative Commons Attribution 4.0 International License; see
33
// http://creativecommons.org/licenses/by/4.0/
44

5-
= The C++ for OpenCL 1.0 Programming Language Documentation
5+
= The C++ for OpenCL 1.0 and 2021 Programming Language Documentation
66
:R: pass:q,r[^(R)^]
77
Khronos{R} OpenCL Working Group
88
:data-uri:

cxx4opencl/address_spaces.txt

Lines changed: 222 additions & 120 deletions
Large diffs are not rendered by default.

cxx4opencl/diff2cxx.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ feature test macros.]
2929
Simultaneous initialization of static local objects performed by
3030
different work-items is not guaranteed to be free from race-conditions.
3131
Whether an implementation provides such a guarantee is indicated by the
32-
presence of the `__cpp_threadsafe_static_init` feature test
32+
presence of the `+__cpp_threadsafe_static_init+` feature test
3333
macro{fn-feature-macro}.
3434

3535
The list above only contains extra restrictions that are not detailed in OpenCL
36-
C. As OpenCL restricts a number of C features, the same restrictions are
37-
inherited by C++ for OpenCL. The detailed list of C feature restrictions
38-
is provided in `OpenCL C v2.0 section 6.9`.
36+
C specification. As OpenCL restricts a number of C features, the same restrictions
37+
are inherited by C++ for OpenCL. The detailed list of C feature restrictions
38+
is provided in `OpenCL C 3.0 section 6.11`.

cxx4opencl/diff2openclc.txt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ encouraged to define `NULL` as an alias to pointer literal `nullptr`.
102102

103103
{cpp}17 does not support `restrict` and therefore {cpp} for OpenCL
104104
can not support it either. Some compilers might provide extensions
105-
with some functionality of `restrict` in {cpp}, e.g. `__restrict`
105+
with some functionality of `restrict` in {cpp}, e.g. `+__restrict+`
106106
in Clang.
107107

108108
This feature only affects optimizations and the source
109109
code can be modified by removing it. As a workaround to avoid manual
110110
modifications, macro substitutions can be used to either remove the
111111
keyword during the preprocessing by defining `restrict` as an empty
112112
macro or mapping it to another similar compiler features, e.g.
113-
`__restrict` in Clang. This can be done in headers or using `-D`
113+
`+__restrict+` in Clang. This can be done in headers or using `-D`
114114
compilation flag.
115115

116116
===== Limitations of goto statements
@@ -136,7 +136,7 @@ The ternary selection operator (`?:`) inherits its behaviour from both
136136
`(exp1 ? exp2 : exp3)`. If all three expressions are scalar values,
137137
the {cpp}17 rules for ternary operator are followed. If the result is
138138
a vector value, then this is equivalent to calling
139-
`select(exp3, exp2, exp1)` as described in `OpenCL C v2.0 s6.13.6`.
139+
`select(exp3, exp2, exp1)` as described in `OpenCL C 3.0 s6.15.6`.
140140
The rules from OpenCL C impose limitation that `exp1` cannot be a
141141
vector of float values. However, `exp1` can be evaluated to a scalar
142142
float as it is contextually convertible to bool in {cpp}.
@@ -149,32 +149,39 @@ in OpenCL specific behavior.
149149
===== Variadic macros
150150

151151
{cpp} for OpenCL eliminates the restriction on variadic macros from
152-
`OpenCL C v2.0 s6.9.e`.
152+
`OpenCL C 3.0 s6.11.f`.
153153
Variadic macros can be used normally as per {cpp}17 `[cpp.replace]`.
154154

155155
===== Predefined macros
156156

157-
The macro `+__OPENCL_C_VERSION__+` described in `OpenCL C v2.0 s6.10`,
157+
The macro `+__OPENCL_C_VERSION__+` described in `OpenCL C 3.0 s6.12`,
158158
is not defined.
159159

160160
The following new predefined macros are added in {cpp} for OpenCL:
161161

162-
* `+__OPENCL_CPP_VERSION__+` set to value `100`.
163-
* `+__CL_CPP_VERSION_1_0__+` also set to `100` and can be used for
162+
* `+__OPENCL_CPP_VERSION__+` set to integer value reflecting the C++
163+
for OpenCL version the translation unit is compiled for. The value
164+
`100` corresponds to the language version 1.0 and `202100` corresponds
165+
to the version 2021.
166+
* `+__CL_CPP_VERSION_1_0__+` set to `100` and can be used for
167+
convenience instead of a literal.
168+
* `+__CL_CPP_VERSION_2021__+` set to `202100` and can be used for
164169
convenience instead of a literal.
165170

166171
===== Atomic operations
167172

168-
{cpp} for OpenCL relaxes restriction from `OpenCL C v2.0 s6.13.11` to
173+
{cpp} for OpenCL relaxes restriction from `OpenCL C 3.0 s6.15.12` to
169174
atomic types allowing them to be used by builtin operators, and not
170-
only by builtin functions.
175+
only by builtin functions. This relaxation does not apply to
176+
{cpp} for OpenCL version 2021 if the sequential consistency memory model
177+
(i.e. `+__opencl_c_atomic_order_seq_cst+` feature) is not supported.
171178

172179
Operators on atomic types behave as described in {cpp}17
173180
sections `[atomics.types.int]` `[atomics.types.pointer]`
174181
`[atomics.types.float]`.
175-
176182
[source,c]
177183
----------
184+
// Assumes support of sequential consistency memory model.
178185
atomic_int acnt;
179186
acnt++; // equivalent to atomic_fetch_add(&acnt, 1);
180187
----------

cxx4opencl/intro.txt

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,65 @@
55
[[intro]]
66
== Introduction
77

8-
This language is built on top of OpenCL C v2.0 and {cpp}17 enabling
8+
This language is built on top of OpenCL C 3.0 unified and {cpp}17 enabling
99
most of regular {cpp} features in OpenCL kernel code. Most functionality
1010
from {cpp} and OpenCL C is inherited. Since both OpenCL C and {cpp} are
1111
derived from C and moreover {cpp} is almost fully backward compatible with C,
1212
the main design principle of {cpp} for OpenCL is to reapply existing OpenCL
1313
concepts to {cpp}. Therefore, it is important to refer to
14-
<<opencl-spec, The OpenCL Specification, Version 2.0>> `section
14+
<<opencl-spec, The OpenCL Specification, Version 3.0>> `section
1515
3.2` and `section 3.3` detailing fundamental differences of OpenCL execution
1616
and memory models from the conventional C and {cpp} view.
1717

18-
This document describes the programming language in details. It is not
18+
This document describes the programming language in detail. It is not
1919
structured as a standalone document, but rather as an addition to OpenCL C
20-
v2.0 defined in <<openclc-spec, The OpenCL C Specification, Version 2.0>>
21-
and {cpp}17 defined in <<cpp17-spec, The C++17 Specification>>. Where necessary
22-
this document refers to the specifications of those languages accordingly.
23-
A full understanding of {cpp} for OpenCL requires familiarity with the
24-
specifications or other documentation of both languages that {cpp} for OpenCL
20+
3.0 unified specification defined in <<openclc-spec, The OpenCL C Specification,
21+
Version 3.0>> and {cpp}17 defined in <<cpp17-spec, The C++17 Specification>>.
22+
Where necessary this document refers to the specifications of those languages
23+
accordingly. A full understanding of {cpp} for OpenCL requires familiarity with
24+
the specifications or other documentation of both languages that {cpp} for OpenCL
2525
is built upon.
2626

2727
The description of {cpp} for OpenCL starts from highlighting <<diff2openclc,
2828
_the differences to OpenCL C_>> and <<diff2cxx, _the differences to {cpp}_>>.
2929

3030
The majority of content covers the behavior that is not documented in
31-
the OpenCL C v2.0 `section 6` and {cpp}17 specifications. This is mainly
31+
the `OpenCL C 3.0 s6` and {cpp}17 specifications. This is mainly
3232
related to interactions between OpenCL and {cpp} language features.
3333

34+
This document describes C++ for OpenCL language
35+
36+
* version 1.0 that is backward compatible with OpenCL 2.0; and
37+
* version 2021 that is backward compatible with OpenCL 3.0.
38+
39+
== Version differences
40+
41+
The main difference between {cpp} for OpenCL version 1.0 and version 2021
42+
comes from the difference between OpenCL 2.0 and OpenCL 3.0 with which they
43+
are respectively compatible. Support for some features of {cpp} for OpenCL 1.0
44+
has become optional as described in `OpenCL 3.0 s6.2.1`. Predefined feature
45+
macros from OpenCL C 3.0 can be used to detect which optional features are present.
46+
47+
This impacts some C++ specific semantics mainly due to optionality of the
48+
generic address space (i.e. `+__opencl_c_generic_address_space+` feature) or
49+
program scope variables (i.e. `+__opencl_c_program_scope_global_variables+`
50+
feature).
51+
3452
== The {cpp} for OpenCL Programming Language
3553

36-
This programming language inherits features from `OpenCL C v2.0,
37-
s6` as well as {cpp}17. Detailed aspects of OpenCL and {cpp} are not
38-
described in this document as they can be found in their official
39-
specifications.
54+
This programming language inherits features from `OpenCL C 3.0 s6` as well
55+
as {cpp}17. Detailed aspects of OpenCL and {cpp} are not described in this
56+
document as they can be found in their official specifications.
4057

4158
This section documents various language features of {cpp} for OpenCL that are
42-
not covered in either OpenCL or {cpp} specifications, in particular:
59+
not covered in neither OpenCL nor {cpp} specifications, in particular:
4360

4461
* any behavior that deviates from {cpp}17;
45-
* any behavior that deviates from OpenCL C v2.0;
62+
* any behavior that deviates from OpenCL C 2.0 or 3.0;
4663
* any behavior that is not governed by OpenCL C and {cpp}.
4764

48-
All language extensions to OpenCL C v2.0 or earlier are applicable to
49-
C++ for OpenCL.
65+
All language extensions to OpenCL C are applicable to C++ for OpenCL.
66+
* Extensions to OpenCL C 2.0 or earlier versions apply to C++ for OpenCL
67+
version 1.0.
68+
* Extensions to OpenCL 3.0 or earlier versions except for OpenCL 2.0, apply to
69+
C++ for OpenCL 2021.

cxx4opencl/kernel.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ Moreover the types used in parameters of the kernel functions must be:
2424
references{fn-ker-par-ref} if an implementation supports them in kernel
2525
parameters.
2626

27-
These are additional restrictions to the list detailed in `OpenCL C v2.0
28-
section 6.9`.
27+
These are additional restrictions to the list detailed in `OpenCL C 3.0 s6.11`.

cxx4opencl/references.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
== Normative References
66

7-
. [[opencl-spec]] "`The OpenCL Specification, Version 2.0`",
7+
. [[opencl-spec]] "`The OpenCL Specification, Version 3.0`",
88
https://www.khronos.org/registry/OpenCL/.
9-
. [[openclc-spec]] "`The OpenCL C Specification, Version 2.0`",
9+
. [[openclc-spec]] "`The OpenCL C Specification, Version 3.0`",
1010
https://www.khronos.org/registry/OpenCL/.
1111
. [[cpp17-spec]] "`ISO/IEC 14882:2017 - Programming languages — {CPP}`",
1212
https://www.iso.org/standard/68564.html.

0 commit comments

Comments
 (0)