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