1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // cl_stubs.cpp: Stubs for CL entry points.
7
8 #include "libANGLE/cl_utils.h"
9 #include "libGLESv2/cl_stubs_autogen.h"
10
11 #include "libGLESv2/proc_table_cl.h"
12
13 #include "libANGLE/CLBuffer.h"
14 #include "libANGLE/CLCommandQueue.h"
15 #include "libANGLE/CLContext.h"
16 #include "libANGLE/CLDevice.h"
17 #include "libANGLE/CLEvent.h"
18 #include "libANGLE/CLImage.h"
19 #include "libANGLE/CLKernel.h"
20 #include "libANGLE/CLMemory.h"
21 #include "libANGLE/CLPlatform.h"
22 #include "libANGLE/CLProgram.h"
23 #include "libANGLE/CLSampler.h"
24
25 #define WARN_NOT_SUPPORTED(command) \
26 do \
27 { \
28 static bool sWarned = false; \
29 if (!sWarned) \
30 { \
31 sWarned = true; \
32 WARN() << "OpenCL command " #command " is not (yet) supported"; \
33 } \
34 } while (0)
35
36 #define CL_RETURN_ERROR(command) \
37 do \
38 { \
39 if (IsError(command)) \
40 { \
41 ERR() << "failed with error code: " << cl::gClErrorTls; \
42 } \
43 return cl::gClErrorTls; \
44 } while (0)
45
46 #define CL_RETURN_OBJ(command) \
47 do \
48 { \
49 auto obj = command; \
50 if (cl::gClErrorTls != CL_SUCCESS) \
51 { \
52 ERR() << "failed with error code: " << cl::gClErrorTls; \
53 return nullptr; \
54 } \
55 return obj; \
56 } while (0)
57
58 #define CL_RETURN_PTR(ptrOut, command) \
59 do \
60 { \
61 void *ptrOut = nullptr; \
62 if (IsError(command)) \
63 { \
64 ERR() << "failed with error code: " << cl::gClErrorTls; \
65 return nullptr; \
66 } \
67 return ptrOut; \
68 } while (0)
69
70 namespace cl
71 {
72
IcdGetPlatformIDsKHR(cl_uint num_entries,cl_platform_id * platforms,cl_uint * num_platforms)73 cl_int IcdGetPlatformIDsKHR(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
74 {
75 CL_RETURN_ERROR((Platform::GetPlatformIDs(num_entries, platforms, num_platforms)));
76 }
77
GetPlatformIDs(cl_uint num_entries,cl_platform_id * platforms,cl_uint * num_platforms)78 cl_int GetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
79 {
80 CL_RETURN_ERROR(Platform::GetPlatformIDs(num_entries, platforms, num_platforms));
81 }
82
GetPlatformInfo(cl_platform_id platform,PlatformInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)83 cl_int GetPlatformInfo(cl_platform_id platform,
84 PlatformInfo param_name,
85 size_t param_value_size,
86 void *param_value,
87 size_t *param_value_size_ret)
88 {
89 CL_RETURN_ERROR(Platform::CastOrDefault(platform)->getInfo(param_name, param_value_size,
90 param_value, param_value_size_ret));
91 }
92
GetDeviceIDs(cl_platform_id platform,DeviceType device_type,cl_uint num_entries,cl_device_id * devices,cl_uint * num_devices)93 cl_int GetDeviceIDs(cl_platform_id platform,
94 DeviceType device_type,
95 cl_uint num_entries,
96 cl_device_id *devices,
97 cl_uint *num_devices)
98 {
99 CL_RETURN_ERROR(Platform::CastOrDefault(platform)->getDeviceIDs(device_type, num_entries,
100 devices, num_devices));
101 }
102
GetDeviceInfo(cl_device_id device,DeviceInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)103 cl_int GetDeviceInfo(cl_device_id device,
104 DeviceInfo param_name,
105 size_t param_value_size,
106 void *param_value,
107 size_t *param_value_size_ret)
108 {
109 CL_RETURN_ERROR(device->cast<Device>().getInfo(param_name, param_value_size, param_value,
110 param_value_size_ret));
111 }
112
CreateSubDevices(cl_device_id in_device,const cl_device_partition_property * properties,cl_uint num_devices,cl_device_id * out_devices,cl_uint * num_devices_ret)113 cl_int CreateSubDevices(cl_device_id in_device,
114 const cl_device_partition_property *properties,
115 cl_uint num_devices,
116 cl_device_id *out_devices,
117 cl_uint *num_devices_ret)
118 {
119 CL_RETURN_ERROR(in_device->cast<Device>().createSubDevices(properties, num_devices, out_devices,
120 num_devices_ret));
121 }
122
RetainDevice(cl_device_id device)123 cl_int RetainDevice(cl_device_id device)
124 {
125 Device &dev = device->cast<Device>();
126 if (!dev.isRoot())
127 {
128 dev.retain();
129 }
130 return CL_SUCCESS;
131 }
132
ReleaseDevice(cl_device_id device)133 cl_int ReleaseDevice(cl_device_id device)
134 {
135 Device &dev = device->cast<Device>();
136 if (!dev.isRoot() && dev.release())
137 {
138 delete &dev;
139 }
140 return CL_SUCCESS;
141 }
142
SetDefaultDeviceCommandQueue(cl_context context,cl_device_id device,cl_command_queue command_queue)143 cl_int SetDefaultDeviceCommandQueue(cl_context context,
144 cl_device_id device,
145 cl_command_queue command_queue)
146 {
147 WARN_NOT_SUPPORTED(SetDefaultDeviceCommandQueue);
148 return CL_INVALID_OPERATION;
149 }
150
GetDeviceAndHostTimer(cl_device_id device,cl_ulong * device_timestamp,cl_ulong * host_timestamp)151 cl_int GetDeviceAndHostTimer(cl_device_id device,
152 cl_ulong *device_timestamp,
153 cl_ulong *host_timestamp)
154 {
155 WARN_NOT_SUPPORTED(GetDeviceAndHostTimer);
156 return CL_INVALID_OPERATION;
157 }
158
GetHostTimer(cl_device_id device,cl_ulong * host_timestamp)159 cl_int GetHostTimer(cl_device_id device, cl_ulong *host_timestamp)
160 {
161 WARN_NOT_SUPPORTED(GetHostTimer);
162 return CL_INVALID_OPERATION;
163 }
164
CreateContext(const cl_context_properties * properties,cl_uint num_devices,const cl_device_id * devices,void (CL_CALLBACK * pfn_notify)(const char * errinfo,const void * private_info,size_t cb,void * user_data),void * user_data)165 cl_context CreateContext(const cl_context_properties *properties,
166 cl_uint num_devices,
167 const cl_device_id *devices,
168 void(CL_CALLBACK *pfn_notify)(const char *errinfo,
169 const void *private_info,
170 size_t cb,
171 void *user_data),
172 void *user_data)
173 {
174 CL_RETURN_OBJ(Platform::CreateContext(properties, num_devices, devices, pfn_notify, user_data));
175 }
176
CreateContextFromType(const cl_context_properties * properties,DeviceType device_type,void (CL_CALLBACK * pfn_notify)(const char * errinfo,const void * private_info,size_t cb,void * user_data),void * user_data)177 cl_context CreateContextFromType(const cl_context_properties *properties,
178 DeviceType device_type,
179 void(CL_CALLBACK *pfn_notify)(const char *errinfo,
180 const void *private_info,
181 size_t cb,
182 void *user_data),
183 void *user_data)
184 {
185 CL_RETURN_OBJ(Platform::CreateContextFromType(properties, device_type, pfn_notify, user_data));
186 }
187
RetainContext(cl_context context)188 cl_int RetainContext(cl_context context)
189 {
190 context->cast<Context>().retain();
191 return CL_SUCCESS;
192 }
193
ReleaseContext(cl_context context)194 cl_int ReleaseContext(cl_context context)
195 {
196 Context &ctx = context->cast<Context>();
197 if (ctx.release())
198 {
199 delete &ctx;
200 }
201 return CL_SUCCESS;
202 }
203
GetContextInfo(cl_context context,ContextInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)204 cl_int GetContextInfo(cl_context context,
205 ContextInfo param_name,
206 size_t param_value_size,
207 void *param_value,
208 size_t *param_value_size_ret)
209 {
210 CL_RETURN_ERROR(context->cast<Context>().getInfo(param_name, param_value_size, param_value,
211 param_value_size_ret));
212 }
213
SetContextDestructorCallback(cl_context context,void (CL_CALLBACK * pfn_notify)(cl_context context,void * user_data),void * user_data)214 cl_int SetContextDestructorCallback(cl_context context,
215 void(CL_CALLBACK *pfn_notify)(cl_context context,
216 void *user_data),
217 void *user_data)
218 {
219 WARN_NOT_SUPPORTED(SetContextDestructorCallback);
220 return CL_INVALID_OPERATION;
221 }
222
CreateCommandQueueWithProperties(cl_context context,cl_device_id device,const cl_queue_properties * properties)223 cl_command_queue CreateCommandQueueWithProperties(cl_context context,
224 cl_device_id device,
225 const cl_queue_properties *properties)
226 {
227 CL_RETURN_OBJ(context->cast<Context>().createCommandQueueWithProperties(device, properties));
228 }
229
RetainCommandQueue(cl_command_queue command_queue)230 cl_int RetainCommandQueue(cl_command_queue command_queue)
231 {
232 command_queue->cast<CommandQueue>().retain();
233 return CL_SUCCESS;
234 }
235
ReleaseCommandQueue(cl_command_queue command_queue)236 cl_int ReleaseCommandQueue(cl_command_queue command_queue)
237 {
238 CommandQueue &queue = command_queue->cast<CommandQueue>();
239 const cl_int err = queue.onRelease();
240 if (queue.release())
241 {
242 delete &queue;
243 }
244 return err;
245 }
246
GetCommandQueueInfo(cl_command_queue command_queue,CommandQueueInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)247 cl_int GetCommandQueueInfo(cl_command_queue command_queue,
248 CommandQueueInfo param_name,
249 size_t param_value_size,
250 void *param_value,
251 size_t *param_value_size_ret)
252 {
253 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().getInfo(param_name, param_value_size,
254 param_value, param_value_size_ret));
255 }
256
CreateBuffer(cl_context context,MemFlags flags,size_t size,void * host_ptr)257 cl_mem CreateBuffer(cl_context context, MemFlags flags, size_t size, void *host_ptr)
258 {
259 CL_RETURN_OBJ(context->cast<Context>().createBuffer(nullptr, flags, size, host_ptr));
260 }
261
CreateBufferWithProperties(cl_context context,const cl_mem_properties * properties,MemFlags flags,size_t size,void * host_ptr)262 cl_mem CreateBufferWithProperties(cl_context context,
263 const cl_mem_properties *properties,
264 MemFlags flags,
265 size_t size,
266 void *host_ptr)
267 {
268 CL_RETURN_OBJ(context->cast<Context>().createBuffer(properties, flags, size, host_ptr));
269 }
270
CreateSubBuffer(cl_mem buffer,MemFlags flags,cl_buffer_create_type buffer_create_type,const void * buffer_create_info)271 cl_mem CreateSubBuffer(cl_mem buffer,
272 MemFlags flags,
273 cl_buffer_create_type buffer_create_type,
274 const void *buffer_create_info)
275 {
276 CL_RETURN_OBJ(
277 buffer->cast<Buffer>().createSubBuffer(flags, buffer_create_type, buffer_create_info));
278 }
279
CreateImage(cl_context context,MemFlags flags,const cl_image_format * image_format,const cl_image_desc * image_desc,void * host_ptr)280 cl_mem CreateImage(cl_context context,
281 MemFlags flags,
282 const cl_image_format *image_format,
283 const cl_image_desc *image_desc,
284 void *host_ptr)
285 {
286 CL_RETURN_OBJ(
287 context->cast<Context>().createImage(nullptr, flags, image_format, image_desc, host_ptr));
288 }
289
CreateImageWithProperties(cl_context context,const cl_mem_properties * properties,MemFlags flags,const cl_image_format * image_format,const cl_image_desc * image_desc,void * host_ptr)290 cl_mem CreateImageWithProperties(cl_context context,
291 const cl_mem_properties *properties,
292 MemFlags flags,
293 const cl_image_format *image_format,
294 const cl_image_desc *image_desc,
295 void *host_ptr)
296 {
297 CL_RETURN_OBJ(context->cast<Context>().createImage(properties, flags, image_format, image_desc,
298 host_ptr));
299 }
300
CreatePipe(cl_context context,MemFlags flags,cl_uint pipe_packet_size,cl_uint pipe_max_packets,const cl_pipe_properties * properties)301 cl_mem CreatePipe(cl_context context,
302 MemFlags flags,
303 cl_uint pipe_packet_size,
304 cl_uint pipe_max_packets,
305 const cl_pipe_properties *properties)
306 {
307 WARN_NOT_SUPPORTED(CreatePipe);
308 cl::gClErrorTls = CL_INVALID_OPERATION;
309 return 0;
310 }
311
RetainMemObject(cl_mem memobj)312 cl_int RetainMemObject(cl_mem memobj)
313 {
314 memobj->cast<Memory>().retain();
315 return CL_SUCCESS;
316 }
317
ReleaseMemObject(cl_mem memobj)318 cl_int ReleaseMemObject(cl_mem memobj)
319 {
320 Memory &memory = memobj->cast<Memory>();
321 if (memory.release())
322 {
323 delete &memory;
324 }
325 return CL_SUCCESS;
326 }
327
GetSupportedImageFormats(cl_context context,MemFlags flags,MemObjectType image_type,cl_uint num_entries,cl_image_format * image_formats,cl_uint * num_image_formats)328 cl_int GetSupportedImageFormats(cl_context context,
329 MemFlags flags,
330 MemObjectType image_type,
331 cl_uint num_entries,
332 cl_image_format *image_formats,
333 cl_uint *num_image_formats)
334 {
335 CL_RETURN_ERROR(context->cast<Context>().getSupportedImageFormats(
336 flags, image_type, num_entries, image_formats, num_image_formats));
337 }
338
GetMemObjectInfo(cl_mem memobj,MemInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)339 cl_int GetMemObjectInfo(cl_mem memobj,
340 MemInfo param_name,
341 size_t param_value_size,
342 void *param_value,
343 size_t *param_value_size_ret)
344 {
345 CL_RETURN_ERROR(memobj->cast<Memory>().getInfo(param_name, param_value_size, param_value,
346 param_value_size_ret));
347 }
348
GetImageInfo(cl_mem image,ImageInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)349 cl_int GetImageInfo(cl_mem image,
350 ImageInfo param_name,
351 size_t param_value_size,
352 void *param_value,
353 size_t *param_value_size_ret)
354 {
355 CL_RETURN_ERROR(image->cast<Image>().getInfo(param_name, param_value_size, param_value,
356 param_value_size_ret));
357 }
358
GetPipeInfo(cl_mem pipe,PipeInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)359 cl_int GetPipeInfo(cl_mem pipe,
360 PipeInfo param_name,
361 size_t param_value_size,
362 void *param_value,
363 size_t *param_value_size_ret)
364 {
365 WARN_NOT_SUPPORTED(GetPipeInfo);
366 return CL_INVALID_MEM_OBJECT;
367 }
368
SetMemObjectDestructorCallback(cl_mem memobj,void (CL_CALLBACK * pfn_notify)(cl_mem memobj,void * user_data),void * user_data)369 cl_int SetMemObjectDestructorCallback(cl_mem memobj,
370 void(CL_CALLBACK *pfn_notify)(cl_mem memobj, void *user_data),
371 void *user_data)
372 {
373 CL_RETURN_ERROR(memobj->cast<Memory>().setDestructorCallback(pfn_notify, user_data));
374 }
375
SVMAlloc(cl_context context,SVM_MemFlags flags,size_t size,cl_uint alignment)376 void *SVMAlloc(cl_context context, SVM_MemFlags flags, size_t size, cl_uint alignment)
377 {
378 WARN_NOT_SUPPORTED(SVMAlloc);
379 return 0;
380 }
381
SVMFree(cl_context context,void * svm_pointer)382 void SVMFree(cl_context context, void *svm_pointer)
383 {
384 WARN_NOT_SUPPORTED(SVMFree);
385 }
386
CreateSamplerWithProperties(cl_context context,const cl_sampler_properties * sampler_properties)387 cl_sampler CreateSamplerWithProperties(cl_context context,
388 const cl_sampler_properties *sampler_properties)
389 {
390 CL_RETURN_OBJ(context->cast<Context>().createSamplerWithProperties(sampler_properties));
391 }
392
RetainSampler(cl_sampler sampler)393 cl_int RetainSampler(cl_sampler sampler)
394 {
395 sampler->cast<Sampler>().retain();
396 return CL_SUCCESS;
397 }
398
ReleaseSampler(cl_sampler sampler)399 cl_int ReleaseSampler(cl_sampler sampler)
400 {
401 Sampler &smplr = sampler->cast<Sampler>();
402 if (smplr.release())
403 {
404 delete &smplr;
405 }
406 return CL_SUCCESS;
407 }
408
GetSamplerInfo(cl_sampler sampler,SamplerInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)409 cl_int GetSamplerInfo(cl_sampler sampler,
410 SamplerInfo param_name,
411 size_t param_value_size,
412 void *param_value,
413 size_t *param_value_size_ret)
414 {
415 CL_RETURN_ERROR(sampler->cast<Sampler>().getInfo(param_name, param_value_size, param_value,
416 param_value_size_ret));
417 }
418
CreateProgramWithSource(cl_context context,cl_uint count,const char ** strings,const size_t * lengths)419 cl_program CreateProgramWithSource(cl_context context,
420 cl_uint count,
421 const char **strings,
422 const size_t *lengths)
423 {
424 CL_RETURN_OBJ(context->cast<Context>().createProgramWithSource(count, strings, lengths));
425 }
426
CreateProgramWithBinary(cl_context context,cl_uint num_devices,const cl_device_id * device_list,const size_t * lengths,const unsigned char ** binaries,cl_int * binary_status)427 cl_program CreateProgramWithBinary(cl_context context,
428 cl_uint num_devices,
429 const cl_device_id *device_list,
430 const size_t *lengths,
431 const unsigned char **binaries,
432 cl_int *binary_status)
433 {
434 CL_RETURN_OBJ(context->cast<Context>().createProgramWithBinary(
435 num_devices, device_list, lengths, binaries, binary_status));
436 }
437
CreateProgramWithBuiltInKernels(cl_context context,cl_uint num_devices,const cl_device_id * device_list,const char * kernel_names)438 cl_program CreateProgramWithBuiltInKernels(cl_context context,
439 cl_uint num_devices,
440 const cl_device_id *device_list,
441 const char *kernel_names)
442 {
443 CL_RETURN_OBJ(context->cast<Context>().createProgramWithBuiltInKernels(num_devices, device_list,
444 kernel_names));
445 }
446
CreateProgramWithIL(cl_context context,const void * il,size_t length)447 cl_program CreateProgramWithIL(cl_context context, const void *il, size_t length)
448 {
449 CL_RETURN_OBJ(context->cast<Context>().createProgramWithIL(il, length));
450 }
451
RetainProgram(cl_program program)452 cl_int RetainProgram(cl_program program)
453 {
454 program->cast<Program>().retain();
455 return CL_SUCCESS;
456 }
457
ReleaseProgram(cl_program program)458 cl_int ReleaseProgram(cl_program program)
459 {
460 Program &prog = program->cast<Program>();
461 if (prog.release())
462 {
463 delete &prog;
464 }
465 return CL_SUCCESS;
466 }
467
BuildProgram(cl_program program,cl_uint num_devices,const cl_device_id * device_list,const char * options,void (CL_CALLBACK * pfn_notify)(cl_program program,void * user_data),void * user_data)468 cl_int BuildProgram(cl_program program,
469 cl_uint num_devices,
470 const cl_device_id *device_list,
471 const char *options,
472 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
473 void *user_data)
474 {
475 CL_RETURN_ERROR(
476 program->cast<Program>().build(num_devices, device_list, options, pfn_notify, user_data));
477 }
478
CompileProgram(cl_program program,cl_uint num_devices,const cl_device_id * device_list,const char * options,cl_uint num_input_headers,const cl_program * input_headers,const char ** header_include_names,void (CL_CALLBACK * pfn_notify)(cl_program program,void * user_data),void * user_data)479 cl_int CompileProgram(cl_program program,
480 cl_uint num_devices,
481 const cl_device_id *device_list,
482 const char *options,
483 cl_uint num_input_headers,
484 const cl_program *input_headers,
485 const char **header_include_names,
486 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
487 void *user_data)
488 {
489 CL_RETURN_ERROR(program->cast<Program>().compile(num_devices, device_list, options,
490 num_input_headers, input_headers,
491 header_include_names, pfn_notify, user_data));
492 }
493
LinkProgram(cl_context context,cl_uint num_devices,const cl_device_id * device_list,const char * options,cl_uint num_input_programs,const cl_program * input_programs,void (CL_CALLBACK * pfn_notify)(cl_program program,void * user_data),void * user_data)494 cl_program LinkProgram(cl_context context,
495 cl_uint num_devices,
496 const cl_device_id *device_list,
497 const char *options,
498 cl_uint num_input_programs,
499 const cl_program *input_programs,
500 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
501 void *user_data)
502 {
503 CL_RETURN_OBJ(context->cast<Context>().linkProgram(num_devices, device_list, options,
504 num_input_programs, input_programs,
505 pfn_notify, user_data));
506 }
507
SetProgramReleaseCallback(cl_program program,void (CL_CALLBACK * pfn_notify)(cl_program program,void * user_data),void * user_data)508 cl_int SetProgramReleaseCallback(cl_program program,
509 void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
510 void *user_data)
511 {
512 WARN_NOT_SUPPORTED(SetProgramReleaseCallback);
513 return CL_INVALID_OPERATION;
514 }
515
SetProgramSpecializationConstant(cl_program program,cl_uint spec_id,size_t spec_size,const void * spec_value)516 cl_int SetProgramSpecializationConstant(cl_program program,
517 cl_uint spec_id,
518 size_t spec_size,
519 const void *spec_value)
520 {
521 WARN_NOT_SUPPORTED(SetProgramSpecializationConstant);
522 return CL_INVALID_OPERATION;
523 }
524
UnloadPlatformCompiler(cl_platform_id platform)525 cl_int UnloadPlatformCompiler(cl_platform_id platform)
526 {
527 CL_RETURN_ERROR(platform->cast<Platform>().unloadCompiler());
528 }
529
GetProgramInfo(cl_program program,ProgramInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)530 cl_int GetProgramInfo(cl_program program,
531 ProgramInfo param_name,
532 size_t param_value_size,
533 void *param_value,
534 size_t *param_value_size_ret)
535 {
536 CL_RETURN_ERROR(program->cast<Program>().getInfo(param_name, param_value_size, param_value,
537 param_value_size_ret));
538 }
539
GetProgramBuildInfo(cl_program program,cl_device_id device,ProgramBuildInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)540 cl_int GetProgramBuildInfo(cl_program program,
541 cl_device_id device,
542 ProgramBuildInfo param_name,
543 size_t param_value_size,
544 void *param_value,
545 size_t *param_value_size_ret)
546 {
547 CL_RETURN_ERROR(program->cast<Program>().getBuildInfo(device, param_name, param_value_size,
548 param_value, param_value_size_ret));
549 }
550
CreateKernel(cl_program program,const char * kernel_name)551 cl_kernel CreateKernel(cl_program program, const char *kernel_name)
552 {
553 CL_RETURN_OBJ(program->cast<Program>().createKernel(kernel_name));
554 }
555
CreateKernelsInProgram(cl_program program,cl_uint num_kernels,cl_kernel * kernels,cl_uint * num_kernels_ret)556 cl_int CreateKernelsInProgram(cl_program program,
557 cl_uint num_kernels,
558 cl_kernel *kernels,
559 cl_uint *num_kernels_ret)
560 {
561 CL_RETURN_ERROR(program->cast<Program>().createKernels(num_kernels, kernels, num_kernels_ret));
562 }
563
CloneKernel(cl_kernel source_kernel)564 cl_kernel CloneKernel(cl_kernel source_kernel)
565 {
566 CL_RETURN_OBJ(source_kernel->cast<Kernel>().clone(););
567 }
568
RetainKernel(cl_kernel kernel)569 cl_int RetainKernel(cl_kernel kernel)
570 {
571 kernel->cast<Kernel>().retain();
572 return CL_SUCCESS;
573 }
574
ReleaseKernel(cl_kernel kernel)575 cl_int ReleaseKernel(cl_kernel kernel)
576 {
577 Kernel &krnl = kernel->cast<Kernel>();
578 if (krnl.release())
579 {
580 delete &krnl;
581 }
582 return CL_SUCCESS;
583 }
584
SetKernelArg(cl_kernel kernel,cl_uint arg_index,size_t arg_size,const void * arg_value)585 cl_int SetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
586 {
587 CL_RETURN_ERROR(kernel->cast<Kernel>().setArg(arg_index, arg_size, arg_value));
588 }
589
SetKernelArgSVMPointer(cl_kernel kernel,cl_uint arg_index,const void * arg_value)590 cl_int SetKernelArgSVMPointer(cl_kernel kernel, cl_uint arg_index, const void *arg_value)
591 {
592 WARN_NOT_SUPPORTED(SetKernelArgSVMPointer);
593 return CL_INVALID_OPERATION;
594 }
595
SetKernelExecInfo(cl_kernel kernel,KernelExecInfo param_name,size_t param_value_size,const void * param_value)596 cl_int SetKernelExecInfo(cl_kernel kernel,
597 KernelExecInfo param_name,
598 size_t param_value_size,
599 const void *param_value)
600 {
601 WARN_NOT_SUPPORTED(SetKernelExecInfo);
602 return CL_INVALID_OPERATION;
603 }
604
GetKernelInfo(cl_kernel kernel,KernelInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)605 cl_int GetKernelInfo(cl_kernel kernel,
606 KernelInfo param_name,
607 size_t param_value_size,
608 void *param_value,
609 size_t *param_value_size_ret)
610 {
611 CL_RETURN_ERROR(kernel->cast<Kernel>().getInfo(param_name, param_value_size, param_value,
612 param_value_size_ret));
613 }
614
GetKernelArgInfo(cl_kernel kernel,cl_uint arg_index,KernelArgInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)615 cl_int GetKernelArgInfo(cl_kernel kernel,
616 cl_uint arg_index,
617 KernelArgInfo param_name,
618 size_t param_value_size,
619 void *param_value,
620 size_t *param_value_size_ret)
621 {
622 CL_RETURN_ERROR(kernel->cast<Kernel>().getArgInfo(arg_index, param_name, param_value_size,
623 param_value, param_value_size_ret));
624 }
625
GetKernelWorkGroupInfo(cl_kernel kernel,cl_device_id device,KernelWorkGroupInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)626 cl_int GetKernelWorkGroupInfo(cl_kernel kernel,
627 cl_device_id device,
628 KernelWorkGroupInfo param_name,
629 size_t param_value_size,
630 void *param_value,
631 size_t *param_value_size_ret)
632 {
633 CL_RETURN_ERROR(kernel->cast<Kernel>().getWorkGroupInfo(device, param_name, param_value_size,
634 param_value, param_value_size_ret));
635 }
636
GetKernelSubGroupInfo(cl_kernel kernel,cl_device_id device,KernelSubGroupInfo param_name,size_t input_value_size,const void * input_value,size_t param_value_size,void * param_value,size_t * param_value_size_ret)637 cl_int GetKernelSubGroupInfo(cl_kernel kernel,
638 cl_device_id device,
639 KernelSubGroupInfo param_name,
640 size_t input_value_size,
641 const void *input_value,
642 size_t param_value_size,
643 void *param_value,
644 size_t *param_value_size_ret)
645 {
646 WARN_NOT_SUPPORTED(GetKernelSubGroupInfo);
647 return CL_INVALID_OPERATION;
648 }
649
WaitForEvents(cl_uint num_events,const cl_event * event_list)650 cl_int WaitForEvents(cl_uint num_events, const cl_event *event_list)
651 {
652 CL_RETURN_ERROR(
653 (*event_list)->cast<Event>().getContext().waitForEvents(num_events, event_list));
654 }
655
GetEventInfo(cl_event event,EventInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)656 cl_int GetEventInfo(cl_event event,
657 EventInfo param_name,
658 size_t param_value_size,
659 void *param_value,
660 size_t *param_value_size_ret)
661 {
662 CL_RETURN_ERROR(event->cast<Event>().getInfo(param_name, param_value_size, param_value,
663 param_value_size_ret));
664 }
665
CreateUserEvent(cl_context context)666 cl_event CreateUserEvent(cl_context context)
667 {
668 CL_RETURN_OBJ(context->cast<Context>().createUserEvent());
669 }
670
RetainEvent(cl_event event)671 cl_int RetainEvent(cl_event event)
672 {
673 event->cast<Event>().retain();
674 return CL_SUCCESS;
675 }
676
ReleaseEvent(cl_event event)677 cl_int ReleaseEvent(cl_event event)
678 {
679 Event &evt = event->cast<Event>();
680 if (evt.release())
681 {
682 delete &evt;
683 }
684 return CL_SUCCESS;
685 }
686
SetUserEventStatus(cl_event event,cl_int execution_status)687 cl_int SetUserEventStatus(cl_event event, cl_int execution_status)
688 {
689 CL_RETURN_ERROR(event->cast<Event>().setUserEventStatus(execution_status));
690 }
691
SetEventCallback(cl_event event,cl_int command_exec_callback_type,void (CL_CALLBACK * pfn_notify)(cl_event event,cl_int event_command_status,void * user_data),void * user_data)692 cl_int SetEventCallback(cl_event event,
693 cl_int command_exec_callback_type,
694 void(CL_CALLBACK *pfn_notify)(cl_event event,
695 cl_int event_command_status,
696 void *user_data),
697 void *user_data)
698 {
699 CL_RETURN_ERROR(
700 event->cast<Event>().setCallback(command_exec_callback_type, pfn_notify, user_data));
701 }
702
GetEventProfilingInfo(cl_event event,ProfilingInfo param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)703 cl_int GetEventProfilingInfo(cl_event event,
704 ProfilingInfo param_name,
705 size_t param_value_size,
706 void *param_value,
707 size_t *param_value_size_ret)
708 {
709 CL_RETURN_ERROR(event->cast<Event>().getProfilingInfo(param_name, param_value_size, param_value,
710 param_value_size_ret));
711 }
712
Flush(cl_command_queue command_queue)713 cl_int Flush(cl_command_queue command_queue)
714 {
715 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().flush());
716 }
717
Finish(cl_command_queue command_queue)718 cl_int Finish(cl_command_queue command_queue)
719 {
720 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().finish());
721 }
722
EnqueueReadBuffer(cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_read,size_t offset,size_t size,void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)723 cl_int EnqueueReadBuffer(cl_command_queue command_queue,
724 cl_mem buffer,
725 cl_bool blocking_read,
726 size_t offset,
727 size_t size,
728 void *ptr,
729 cl_uint num_events_in_wait_list,
730 const cl_event *event_wait_list,
731 cl_event *event)
732 {
733 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueReadBuffer(
734 buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event));
735 }
736
EnqueueReadBufferRect(cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_read,const size_t * buffer_origin,const size_t * host_origin,const size_t * region,size_t buffer_row_pitch,size_t buffer_slice_pitch,size_t host_row_pitch,size_t host_slice_pitch,void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)737 cl_int EnqueueReadBufferRect(cl_command_queue command_queue,
738 cl_mem buffer,
739 cl_bool blocking_read,
740 const size_t *buffer_origin,
741 const size_t *host_origin,
742 const size_t *region,
743 size_t buffer_row_pitch,
744 size_t buffer_slice_pitch,
745 size_t host_row_pitch,
746 size_t host_slice_pitch,
747 void *ptr,
748 cl_uint num_events_in_wait_list,
749 const cl_event *event_wait_list,
750 cl_event *event)
751 {
752 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueReadBufferRect(
753 buffer, blocking_read, cl::MemOffsets{buffer_origin[0], buffer_origin[1], buffer_origin[2]},
754 cl::MemOffsets{host_origin[0], host_origin[1], host_origin[2]},
755 cl::Coordinate{region[0], region[1], region[2]}, buffer_row_pitch, buffer_slice_pitch,
756 host_row_pitch, host_slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event));
757 }
758
EnqueueWriteBuffer(cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_write,size_t offset,size_t size,const void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)759 cl_int EnqueueWriteBuffer(cl_command_queue command_queue,
760 cl_mem buffer,
761 cl_bool blocking_write,
762 size_t offset,
763 size_t size,
764 const void *ptr,
765 cl_uint num_events_in_wait_list,
766 const cl_event *event_wait_list,
767 cl_event *event)
768 {
769 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueWriteBuffer(
770 buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list,
771 event));
772 }
773
EnqueueWriteBufferRect(cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_write,const size_t * buffer_origin,const size_t * host_origin,const size_t * region,size_t buffer_row_pitch,size_t buffer_slice_pitch,size_t host_row_pitch,size_t host_slice_pitch,const void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)774 cl_int EnqueueWriteBufferRect(cl_command_queue command_queue,
775 cl_mem buffer,
776 cl_bool blocking_write,
777 const size_t *buffer_origin,
778 const size_t *host_origin,
779 const size_t *region,
780 size_t buffer_row_pitch,
781 size_t buffer_slice_pitch,
782 size_t host_row_pitch,
783 size_t host_slice_pitch,
784 const void *ptr,
785 cl_uint num_events_in_wait_list,
786 const cl_event *event_wait_list,
787 cl_event *event)
788 {
789 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueWriteBufferRect(
790 buffer, blocking_write,
791 cl::MemOffsets{buffer_origin[0], buffer_origin[1], buffer_origin[2]},
792 cl::MemOffsets{host_origin[0], host_origin[1], host_origin[2]},
793 cl::Coordinate{region[0], region[1], region[2]}, buffer_row_pitch, buffer_slice_pitch,
794 host_row_pitch, host_slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event));
795 }
796
EnqueueFillBuffer(cl_command_queue command_queue,cl_mem buffer,const void * pattern,size_t pattern_size,size_t offset,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)797 cl_int EnqueueFillBuffer(cl_command_queue command_queue,
798 cl_mem buffer,
799 const void *pattern,
800 size_t pattern_size,
801 size_t offset,
802 size_t size,
803 cl_uint num_events_in_wait_list,
804 const cl_event *event_wait_list,
805 cl_event *event)
806 {
807 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueFillBuffer(
808 buffer, pattern, pattern_size, offset, size, num_events_in_wait_list, event_wait_list,
809 event));
810 }
811
EnqueueCopyBuffer(cl_command_queue command_queue,cl_mem src_buffer,cl_mem dst_buffer,size_t src_offset,size_t dst_offset,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)812 cl_int EnqueueCopyBuffer(cl_command_queue command_queue,
813 cl_mem src_buffer,
814 cl_mem dst_buffer,
815 size_t src_offset,
816 size_t dst_offset,
817 size_t size,
818 cl_uint num_events_in_wait_list,
819 const cl_event *event_wait_list,
820 cl_event *event)
821 {
822 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueCopyBuffer(
823 src_buffer, dst_buffer, src_offset, dst_offset, size, num_events_in_wait_list,
824 event_wait_list, event));
825 }
826
EnqueueCopyBufferRect(cl_command_queue command_queue,cl_mem src_buffer,cl_mem dst_buffer,const size_t * src_origin,const size_t * dst_origin,const size_t * region,size_t src_row_pitch,size_t src_slice_pitch,size_t dst_row_pitch,size_t dst_slice_pitch,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)827 cl_int EnqueueCopyBufferRect(cl_command_queue command_queue,
828 cl_mem src_buffer,
829 cl_mem dst_buffer,
830 const size_t *src_origin,
831 const size_t *dst_origin,
832 const size_t *region,
833 size_t src_row_pitch,
834 size_t src_slice_pitch,
835 size_t dst_row_pitch,
836 size_t dst_slice_pitch,
837 cl_uint num_events_in_wait_list,
838 const cl_event *event_wait_list,
839 cl_event *event)
840 {
841 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueCopyBufferRect(
842 src_buffer, dst_buffer, cl::MemOffsets{src_origin[0], src_origin[1], src_origin[2]},
843 cl::MemOffsets{dst_origin[0], dst_origin[1], dst_origin[2]},
844 cl::Coordinate{region[0], region[1], region[2]}, src_row_pitch, src_slice_pitch,
845 dst_row_pitch, dst_slice_pitch, num_events_in_wait_list, event_wait_list, event));
846 }
847
EnqueueReadImage(cl_command_queue command_queue,cl_mem image,cl_bool blocking_read,const size_t * origin,const size_t * region,size_t row_pitch,size_t slice_pitch,void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)848 cl_int EnqueueReadImage(cl_command_queue command_queue,
849 cl_mem image,
850 cl_bool blocking_read,
851 const size_t *origin,
852 const size_t *region,
853 size_t row_pitch,
854 size_t slice_pitch,
855 void *ptr,
856 cl_uint num_events_in_wait_list,
857 const cl_event *event_wait_list,
858 cl_event *event)
859 {
860 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueReadImage(
861 image, blocking_read, cl::MemOffsets{origin[0], origin[1], origin[2]},
862 cl::Coordinate{region[0], region[1], region[2]}, row_pitch, slice_pitch, ptr,
863 num_events_in_wait_list, event_wait_list, event));
864 }
865
EnqueueWriteImage(cl_command_queue command_queue,cl_mem image,cl_bool blocking_write,const size_t * origin,const size_t * region,size_t input_row_pitch,size_t input_slice_pitch,const void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)866 cl_int EnqueueWriteImage(cl_command_queue command_queue,
867 cl_mem image,
868 cl_bool blocking_write,
869 const size_t *origin,
870 const size_t *region,
871 size_t input_row_pitch,
872 size_t input_slice_pitch,
873 const void *ptr,
874 cl_uint num_events_in_wait_list,
875 const cl_event *event_wait_list,
876 cl_event *event)
877 {
878 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueWriteImage(
879 image, blocking_write, cl::MemOffsets{origin[0], origin[1], origin[2]},
880 cl::Coordinate{region[0], region[1], region[2]}, input_row_pitch, input_slice_pitch, ptr,
881 num_events_in_wait_list, event_wait_list, event));
882 }
883
EnqueueFillImage(cl_command_queue command_queue,cl_mem image,const void * fill_color,const size_t * origin,const size_t * region,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)884 cl_int EnqueueFillImage(cl_command_queue command_queue,
885 cl_mem image,
886 const void *fill_color,
887 const size_t *origin,
888 const size_t *region,
889 cl_uint num_events_in_wait_list,
890 const cl_event *event_wait_list,
891 cl_event *event)
892 {
893 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueFillImage(
894 image, fill_color, cl::MemOffsets{origin[0], origin[1], origin[2]},
895 cl::Coordinate{region[0], region[1], region[2]}, num_events_in_wait_list, event_wait_list,
896 event));
897 }
898
EnqueueCopyImage(cl_command_queue command_queue,cl_mem src_image,cl_mem dst_image,const size_t * src_origin,const size_t * dst_origin,const size_t * region,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)899 cl_int EnqueueCopyImage(cl_command_queue command_queue,
900 cl_mem src_image,
901 cl_mem dst_image,
902 const size_t *src_origin,
903 const size_t *dst_origin,
904 const size_t *region,
905 cl_uint num_events_in_wait_list,
906 const cl_event *event_wait_list,
907 cl_event *event)
908 {
909 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueCopyImage(
910 src_image, dst_image, cl::MemOffsets{src_origin[0], src_origin[1], src_origin[2]},
911 cl::MemOffsets{dst_origin[0], dst_origin[1], dst_origin[2]},
912 cl::Coordinate{region[0], region[1], region[2]}, num_events_in_wait_list, event_wait_list,
913 event));
914 }
915
EnqueueCopyImageToBuffer(cl_command_queue command_queue,cl_mem src_image,cl_mem dst_buffer,const size_t * src_origin,const size_t * region,size_t dst_offset,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)916 cl_int EnqueueCopyImageToBuffer(cl_command_queue command_queue,
917 cl_mem src_image,
918 cl_mem dst_buffer,
919 const size_t *src_origin,
920 const size_t *region,
921 size_t dst_offset,
922 cl_uint num_events_in_wait_list,
923 const cl_event *event_wait_list,
924 cl_event *event)
925 {
926 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueCopyImageToBuffer(
927 src_image, dst_buffer, cl::MemOffsets{src_origin[0], src_origin[1], src_origin[2]},
928 cl::Coordinate{region[0], region[1], region[2]}, dst_offset, num_events_in_wait_list,
929 event_wait_list, event));
930 }
931
EnqueueCopyBufferToImage(cl_command_queue command_queue,cl_mem src_buffer,cl_mem dst_image,size_t src_offset,const size_t * dst_origin,const size_t * region,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)932 cl_int EnqueueCopyBufferToImage(cl_command_queue command_queue,
933 cl_mem src_buffer,
934 cl_mem dst_image,
935 size_t src_offset,
936 const size_t *dst_origin,
937 const size_t *region,
938 cl_uint num_events_in_wait_list,
939 const cl_event *event_wait_list,
940 cl_event *event)
941 {
942 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueCopyBufferToImage(
943 src_buffer, dst_image, src_offset,
944 cl::MemOffsets{dst_origin[0], dst_origin[1], dst_origin[2]},
945 cl::Coordinate{region[0], region[1], region[2]}, num_events_in_wait_list, event_wait_list,
946 event));
947 }
948
EnqueueMapBuffer(cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_map,MapFlags map_flags,size_t offset,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)949 void *EnqueueMapBuffer(cl_command_queue command_queue,
950 cl_mem buffer,
951 cl_bool blocking_map,
952 MapFlags map_flags,
953 size_t offset,
954 size_t size,
955 cl_uint num_events_in_wait_list,
956 const cl_event *event_wait_list,
957 cl_event *event)
958 {
959 CL_RETURN_PTR(ptrOut, command_queue->cast<CommandQueue>().enqueueMapBuffer(
960 buffer, blocking_map, map_flags, offset, size,
961 num_events_in_wait_list, event_wait_list, event, ptrOut));
962 }
963
EnqueueMapImage(cl_command_queue command_queue,cl_mem image,cl_bool blocking_map,MapFlags map_flags,const size_t * origin,const size_t * region,size_t * image_row_pitch,size_t * image_slice_pitch,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)964 void *EnqueueMapImage(cl_command_queue command_queue,
965 cl_mem image,
966 cl_bool blocking_map,
967 MapFlags map_flags,
968 const size_t *origin,
969 const size_t *region,
970 size_t *image_row_pitch,
971 size_t *image_slice_pitch,
972 cl_uint num_events_in_wait_list,
973 const cl_event *event_wait_list,
974 cl_event *event)
975 {
976 CL_RETURN_PTR(
977 ptrOut, command_queue->cast<CommandQueue>().enqueueMapImage(
978 image, blocking_map, map_flags, cl::MemOffsets{origin[0], origin[1], origin[2]},
979 cl::Coordinate{region[0], region[1], region[2]}, image_row_pitch,
980 image_slice_pitch, num_events_in_wait_list, event_wait_list, event, ptrOut));
981 }
982
EnqueueUnmapMemObject(cl_command_queue command_queue,cl_mem memobj,void * mapped_ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)983 cl_int EnqueueUnmapMemObject(cl_command_queue command_queue,
984 cl_mem memobj,
985 void *mapped_ptr,
986 cl_uint num_events_in_wait_list,
987 const cl_event *event_wait_list,
988 cl_event *event)
989 {
990 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueUnmapMemObject(
991 memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event));
992 }
993
EnqueueMigrateMemObjects(cl_command_queue command_queue,cl_uint num_mem_objects,const cl_mem * mem_objects,MemMigrationFlags flags,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)994 cl_int EnqueueMigrateMemObjects(cl_command_queue command_queue,
995 cl_uint num_mem_objects,
996 const cl_mem *mem_objects,
997 MemMigrationFlags flags,
998 cl_uint num_events_in_wait_list,
999 const cl_event *event_wait_list,
1000 cl_event *event)
1001 {
1002 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueMigrateMemObjects(
1003 num_mem_objects, mem_objects, flags, num_events_in_wait_list, event_wait_list, event));
1004 }
1005
EnqueueNDRangeKernel(cl_command_queue command_queue,cl_kernel kernel,cl_uint work_dim,const size_t * global_work_offset,const size_t * global_work_size,const size_t * local_work_size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1006 cl_int EnqueueNDRangeKernel(cl_command_queue command_queue,
1007 cl_kernel kernel,
1008 cl_uint work_dim,
1009 const size_t *global_work_offset,
1010 const size_t *global_work_size,
1011 const size_t *local_work_size,
1012 cl_uint num_events_in_wait_list,
1013 const cl_event *event_wait_list,
1014 cl_event *event)
1015 {
1016 cl::NDRange ndrange(work_dim, global_work_offset, global_work_size, local_work_size);
1017 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueNDRangeKernel(
1018 kernel, ndrange, num_events_in_wait_list, event_wait_list, event));
1019 }
1020
EnqueueNativeKernel(cl_command_queue command_queue,void (CL_CALLBACK * user_func)(void *),void * args,size_t cb_args,cl_uint num_mem_objects,const cl_mem * mem_list,const void ** args_mem_loc,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1021 cl_int EnqueueNativeKernel(cl_command_queue command_queue,
1022 void(CL_CALLBACK *user_func)(void *),
1023 void *args,
1024 size_t cb_args,
1025 cl_uint num_mem_objects,
1026 const cl_mem *mem_list,
1027 const void **args_mem_loc,
1028 cl_uint num_events_in_wait_list,
1029 const cl_event *event_wait_list,
1030 cl_event *event)
1031 {
1032 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueNativeKernel(
1033 user_func, args, cb_args, num_mem_objects, mem_list, args_mem_loc, num_events_in_wait_list,
1034 event_wait_list, event));
1035 }
1036
EnqueueMarkerWithWaitList(cl_command_queue command_queue,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1037 cl_int EnqueueMarkerWithWaitList(cl_command_queue command_queue,
1038 cl_uint num_events_in_wait_list,
1039 const cl_event *event_wait_list,
1040 cl_event *event)
1041 {
1042 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueMarkerWithWaitList(
1043 num_events_in_wait_list, event_wait_list, event));
1044 }
1045
EnqueueBarrierWithWaitList(cl_command_queue command_queue,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1046 cl_int EnqueueBarrierWithWaitList(cl_command_queue command_queue,
1047 cl_uint num_events_in_wait_list,
1048 const cl_event *event_wait_list,
1049 cl_event *event)
1050 {
1051 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueBarrierWithWaitList(
1052 num_events_in_wait_list, event_wait_list, event));
1053 }
1054
EnqueueSVMFree(cl_command_queue command_queue,cl_uint num_svm_pointers,void * svm_pointers[],void (CL_CALLBACK * pfn_free_func)(cl_command_queue queue,cl_uint num_svm_pointers,void * svm_pointers[],void * user_data),void * user_data,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1055 cl_int EnqueueSVMFree(cl_command_queue command_queue,
1056 cl_uint num_svm_pointers,
1057 void *svm_pointers[],
1058 void(CL_CALLBACK *pfn_free_func)(cl_command_queue queue,
1059 cl_uint num_svm_pointers,
1060 void *svm_pointers[],
1061 void *user_data),
1062 void *user_data,
1063 cl_uint num_events_in_wait_list,
1064 const cl_event *event_wait_list,
1065 cl_event *event)
1066 {
1067 WARN_NOT_SUPPORTED(EnqueueSVMFree);
1068 return CL_INVALID_OPERATION;
1069 }
1070
EnqueueSVMMemcpy(cl_command_queue command_queue,cl_bool blocking_copy,void * dst_ptr,const void * src_ptr,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1071 cl_int EnqueueSVMMemcpy(cl_command_queue command_queue,
1072 cl_bool blocking_copy,
1073 void *dst_ptr,
1074 const void *src_ptr,
1075 size_t size,
1076 cl_uint num_events_in_wait_list,
1077 const cl_event *event_wait_list,
1078 cl_event *event)
1079 {
1080 WARN_NOT_SUPPORTED(EnqueueSVMMemcpy);
1081 return CL_INVALID_OPERATION;
1082 }
1083
EnqueueSVMMemFill(cl_command_queue command_queue,void * svm_ptr,const void * pattern,size_t pattern_size,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1084 cl_int EnqueueSVMMemFill(cl_command_queue command_queue,
1085 void *svm_ptr,
1086 const void *pattern,
1087 size_t pattern_size,
1088 size_t size,
1089 cl_uint num_events_in_wait_list,
1090 const cl_event *event_wait_list,
1091 cl_event *event)
1092 {
1093 WARN_NOT_SUPPORTED(EnqueueSVMMemFill);
1094 return CL_INVALID_OPERATION;
1095 }
1096
EnqueueSVMMap(cl_command_queue command_queue,cl_bool blocking_map,MapFlags flags,void * svm_ptr,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1097 cl_int EnqueueSVMMap(cl_command_queue command_queue,
1098 cl_bool blocking_map,
1099 MapFlags flags,
1100 void *svm_ptr,
1101 size_t size,
1102 cl_uint num_events_in_wait_list,
1103 const cl_event *event_wait_list,
1104 cl_event *event)
1105 {
1106 WARN_NOT_SUPPORTED(EnqueueSVMMap);
1107 return CL_INVALID_OPERATION;
1108 }
1109
EnqueueSVMUnmap(cl_command_queue command_queue,void * svm_ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1110 cl_int EnqueueSVMUnmap(cl_command_queue command_queue,
1111 void *svm_ptr,
1112 cl_uint num_events_in_wait_list,
1113 const cl_event *event_wait_list,
1114 cl_event *event)
1115 {
1116 WARN_NOT_SUPPORTED(EnqueueSVMUnmap);
1117 return CL_INVALID_OPERATION;
1118 }
1119
EnqueueSVMMigrateMem(cl_command_queue command_queue,cl_uint num_svm_pointers,const void ** svm_pointers,const size_t * sizes,MemMigrationFlags flags,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1120 cl_int EnqueueSVMMigrateMem(cl_command_queue command_queue,
1121 cl_uint num_svm_pointers,
1122 const void **svm_pointers,
1123 const size_t *sizes,
1124 MemMigrationFlags flags,
1125 cl_uint num_events_in_wait_list,
1126 const cl_event *event_wait_list,
1127 cl_event *event)
1128 {
1129 WARN_NOT_SUPPORTED(EnqueueSVMMigrateMem);
1130 return CL_INVALID_OPERATION;
1131 }
1132
GetExtensionFunctionAddressForPlatform(cl_platform_id platform,const char * func_name)1133 void *GetExtensionFunctionAddressForPlatform(cl_platform_id platform, const char *func_name)
1134 {
1135 return GetExtensionFunctionAddress(func_name);
1136 }
1137
SetCommandQueueProperty(cl_command_queue command_queue,CommandQueueProperties properties,cl_bool enable,cl_command_queue_properties * old_properties)1138 cl_int SetCommandQueueProperty(cl_command_queue command_queue,
1139 CommandQueueProperties properties,
1140 cl_bool enable,
1141 cl_command_queue_properties *old_properties)
1142 {
1143 CL_RETURN_ERROR(
1144 command_queue->cast<CommandQueue>().setProperty(properties, enable, old_properties));
1145 }
1146
CreateImage2D(cl_context context,MemFlags flags,const cl_image_format * image_format,size_t image_width,size_t image_height,size_t image_row_pitch,void * host_ptr)1147 cl_mem CreateImage2D(cl_context context,
1148 MemFlags flags,
1149 const cl_image_format *image_format,
1150 size_t image_width,
1151 size_t image_height,
1152 size_t image_row_pitch,
1153 void *host_ptr)
1154 {
1155 CL_RETURN_OBJ(context->cast<Context>().createImage2D(flags, image_format, image_width,
1156 image_height, image_row_pitch, host_ptr));
1157 }
1158
CreateImage3D(cl_context context,MemFlags flags,const cl_image_format * image_format,size_t image_width,size_t image_height,size_t image_depth,size_t image_row_pitch,size_t image_slice_pitch,void * host_ptr)1159 cl_mem CreateImage3D(cl_context context,
1160 MemFlags flags,
1161 const cl_image_format *image_format,
1162 size_t image_width,
1163 size_t image_height,
1164 size_t image_depth,
1165 size_t image_row_pitch,
1166 size_t image_slice_pitch,
1167 void *host_ptr)
1168 {
1169 CL_RETURN_OBJ(context->cast<Context>().createImage3D(flags, image_format, image_width,
1170 image_height, image_depth, image_row_pitch,
1171 image_slice_pitch, host_ptr));
1172 }
1173
EnqueueMarker(cl_command_queue command_queue,cl_event * event)1174 cl_int EnqueueMarker(cl_command_queue command_queue, cl_event *event)
1175 {
1176 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueMarker(event));
1177 }
1178
EnqueueWaitForEvents(cl_command_queue command_queue,cl_uint num_events,const cl_event * event_list)1179 cl_int EnqueueWaitForEvents(cl_command_queue command_queue,
1180 cl_uint num_events,
1181 const cl_event *event_list)
1182 {
1183 CL_RETURN_ERROR(
1184 command_queue->cast<CommandQueue>().enqueueWaitForEvents(num_events, event_list));
1185 }
1186
EnqueueBarrier(cl_command_queue command_queue)1187 cl_int EnqueueBarrier(cl_command_queue command_queue)
1188 {
1189 CL_RETURN_ERROR(IsError(command_queue->cast<CommandQueue>().enqueueBarrier()));
1190 }
1191
UnloadCompiler()1192 cl_int UnloadCompiler()
1193 {
1194 Platform *const platform = Platform::GetDefault();
1195 if (platform == nullptr)
1196 {
1197 return CL_SUCCESS;
1198 }
1199 CL_RETURN_ERROR(platform->unloadCompiler());
1200 }
1201
GetExtensionFunctionAddress(const char * func_name)1202 void *GetExtensionFunctionAddress(const char *func_name)
1203 {
1204 if (func_name == nullptr)
1205 {
1206 return nullptr;
1207 }
1208 const ProcTable &procTable = GetProcTable();
1209 const auto it = procTable.find(func_name);
1210 return it != procTable.cend() ? it->second : nullptr;
1211 }
1212
CreateCommandQueue(cl_context context,cl_device_id device,CommandQueueProperties properties)1213 cl_command_queue CreateCommandQueue(cl_context context,
1214 cl_device_id device,
1215 CommandQueueProperties properties)
1216 {
1217 CL_RETURN_OBJ(context->cast<Context>().createCommandQueue(device, properties));
1218 }
1219
CreateSampler(cl_context context,cl_bool normalized_coords,AddressingMode addressing_mode,FilterMode filter_mode)1220 cl_sampler CreateSampler(cl_context context,
1221 cl_bool normalized_coords,
1222 AddressingMode addressing_mode,
1223 FilterMode filter_mode)
1224 {
1225 CL_RETURN_OBJ(
1226 context->cast<Context>().createSampler(normalized_coords, addressing_mode, filter_mode));
1227 }
1228
EnqueueTask(cl_command_queue command_queue,cl_kernel kernel,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)1229 cl_int EnqueueTask(cl_command_queue command_queue,
1230 cl_kernel kernel,
1231 cl_uint num_events_in_wait_list,
1232 const cl_event *event_wait_list,
1233 cl_event *event)
1234 {
1235 CL_RETURN_ERROR(command_queue->cast<CommandQueue>().enqueueTask(kernel, num_events_in_wait_list,
1236 event_wait_list, event));
1237 }
1238
1239 } // namespace cl
1240