Skip to content

Commit 41945cd

Browse files
committed
Add rules for OpenCL kernel arguments
And also update the example to follow those rules.
1 parent 8c1f356 commit 41945cd

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

sycl/doc/extensions/proposed/sycl_ext_oneapi_kernel_compiler_opencl.asciidoc

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:encoding: utf-8
1111
:lang: en
1212
:dpcpp: pass:[DPC++]
13+
:endnote: —{nbsp}end{nbsp}note
1314

1415
// Set the default source code type in this document to C++,
1516
// for syntax highlighting purposes. This is needed because
@@ -142,6 +143,48 @@ There is no mechanism to decorate an OpenCL C kernel with a type-name, so the
142143
forms of `kernel_bundle::has_kernel` or `kernel_bundle::get_kernel` that take a
143144
type-name are not useful for kernels defined in OpenCL C.
144145

146+
=== Kernel argument restrictions
147+
148+
When a kernel is defined in OpenCL C and invoked from SYCL via a `kernel`
149+
object, the arguments to the kernel are restricted to certain types.
150+
In general, the host application passes an argument value via
151+
`handler::set_arg` using one type and the kernel receives the argument value
152+
as a corresponding OpenCL C type.
153+
The following table lists the set of valid types for these kernel arguments:
154+
155+
156+
[%header,cols="1,1"]
157+
|===
158+
|Type in SYCL host code
159+
|Type in OpenCL C kernel
160+
161+
|One of the OpenCL scalar types (e.g. `cl_int`, `cl_float`, etc.)
162+
|The corresponding OpenCL C type (e.g. `int`, `float`, etc.)
163+
164+
|A USM pointer.
165+
|A `+__global+` pointer of the corresponding type.
166+
167+
|A class (or struct) that is device copyable in SYCL whose elements are
168+
composed of OpenCL scalar types or USM pointers.
169+
|A class (or struct) passed by value whose elements have the corresponding
170+
OpenCL C types.
171+
172+
|An `accessor` with `target::device` whose `DataT` is an OpenCL scalar type,
173+
a USM pointer, or a device copyable class (or struct) whose elements are
174+
composed of these types.
175+
|A `+__global+` pointer to the first element of the accessor's buffer.
176+
The pointer has the corresponding OpenCL C type.
177+
178+
[_Note:_ The accessor's size is not passed as a kernel argument, so the host
179+
code must pass a separate argument with the size if this is desired.
180+
_{endnote}_]
181+
182+
|A `local_accessor` whose `DataT` is an OpenCL scalar type, a USM pointer, or a
183+
device copyable class (or struct) whose elements are composed of these types.
184+
|A `+__local+` pointer to the first element of the accessor's local memory.
185+
The pointer has the corresponding OpenCL C type.
186+
|===
187+
145188

146189
== Example
147190

@@ -150,6 +193,7 @@ kernel as a string and then compiles and launches it.
150193

151194
```
152195
#include <sycl/sycl.hpp>
196+
#include <OpenCL/opencl.h>
153197
namespace syclex = sycl::ext::oneapi::experimental;
154198

155199
int main() {
@@ -179,8 +223,8 @@ int main() {
179223
sycl::kernel k = kb_exe.ext_oneapi_get_kernel("my_kernel");
180224

181225
constexpr int N = 4;
182-
int input[N] = {0, 1, 2, 3};
183-
int output[N] = {};
226+
cl_int input[N] = {0, 1, 2, 3};
227+
cl_int output[N] = {};
184228

185229
sycl::buffer inputbuf(input, sycl::range{N});
186230
sycl::buffer outputbuf(output, sycl::range{N});
@@ -245,13 +289,6 @@ their source string.
245289
Currently, the online_compiler does support this case (but it provides no way
246290
to query about optional features or extensions).
247291

248-
* There should be a more formal definition of the kernel arguments that can be
249-
passed.
250-
For example, can the application pass a `local_accessor` as an argument to an
251-
OpenCL C kernel?
252-
We should have a complete list of allowed arguments and describe how each is
253-
passed from the SYCL host code.
254-
255292
* Do we need to document some restrictions on the OpenCL C
256293
https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#work-item-functions[
257294
work-item functions] that the kernel can call, which depends on how the

0 commit comments

Comments
 (0)