10
10
:encoding: utf-8
11
11
:lang: en
12
12
:dpcpp: pass:[DPC++]
13
+ :endnote: —{nbsp}end{nbsp}note
13
14
14
15
// Set the default source code type in this document to C++,
15
16
// 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
142
143
forms of `kernel_bundle::has_kernel` or `kernel_bundle::get_kernel` that take a
143
144
type-name are not useful for kernels defined in OpenCL C.
144
145
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
+
145
188
146
189
== Example
147
190
@@ -150,6 +193,7 @@ kernel as a string and then compiles and launches it.
150
193
151
194
```
152
195
#include <sycl/sycl.hpp>
196
+ #include <OpenCL/opencl.h>
153
197
namespace syclex = sycl::ext::oneapi::experimental;
154
198
155
199
int main() {
@@ -179,8 +223,8 @@ int main() {
179
223
sycl::kernel k = kb_exe.ext_oneapi_get_kernel("my_kernel");
180
224
181
225
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] = {};
184
228
185
229
sycl::buffer inputbuf(input, sycl::range{N});
186
230
sycl::buffer outputbuf(output, sycl::range{N});
@@ -245,13 +289,6 @@ their source string.
245
289
Currently, the online_compiler does support this case (but it provides no way
246
290
to query about optional features or extensions).
247
291
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
-
255
292
* Do we need to document some restrictions on the OpenCL C
256
293
https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#work-item-functions[
257
294
work-item functions] that the kernel can call, which depends on how the
0 commit comments