-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathicd_dispatch_generated.c.mako
487 lines (463 loc) · 13.6 KB
/
icd_dispatch_generated.c.mako
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
<%
# APIs to skip - they need to be done "manually":
apiskip = {
'clGetPlatformIDs', # to query platforms
'clGetExtensionFunctionAddress', # to return ICD-aware extensions
'clGetExtensionFunctionAddressForPlatform', # to return ICD-aware extensions
}
apiinit = {
'clCreateContextFromType',
'clGetGLContextInfoKHR',
}
# Handles, and mappings to errors when handles are invalid:
apihandles = {
'cl_command_queue' : 'CL_INVALID_COMMAND_QUEUE',
'cl_context' : 'CL_INVALID_CONTEXT',
'cl_device_id' : 'CL_INVALID_DEVICE',
'cl_event' : 'CL_INVALID_EVENT',
'cl_kernel' : 'CL_INVALID_KERNEL',
'cl_mem' : 'CL_INVALID_MEM_OBJECT',
'cl_platform_id' : 'CL_INVALID_PLATFORM',
'cl_program' : 'CL_INVALID_PROGRAM',
'cl_sampler' : 'CL_INVALID_SAMPLER',
}
%>/*
* Copyright (c) 2012-2020 The Khronos Group Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* OpenCL is a trademark of Apple Inc. used under license by Khronos.
*/
#include "icd_dispatch.h"
#include "icd.h"
#ifdef __cplusplus
extern "C" {
#endif
///////////////////////////////////////////////////////////////////////////////
// Core APIs:
%for apis in coreapis.values():
%for api in apis:
%if not api.Name in apiskip:
<%
handle = api.Params[0]
if handle.Type in apihandles:
invalid = apihandles[handle.Type]
else:
invalid = 'NULL'
%>
%for disp in [0, 1]:
% if disp == 1:
#if defined(CL_ENABLE_LAYERS)
% endif
${("", "static ")[disp]}CL_API_ENTRY ${api.RetType} CL_API_CALL ${api.Name + ("", "_disp")[disp]}(
%for i, param in enumerate(api.Params):
% if i < len(api.Params)-1:
${param.Type} ${param.Name}${param.TypeEnd},
% else:
${param.Type} ${param.Name}${param.TypeEnd})
% endif
%endfor
{
%if api.Name in apiinit:
khrIcdInitialize();
%endif
%if disp == 0:
#if defined(CL_ENABLE_LAYERS)
if (khrFirstLayer)
% if api.Name == "clSVMFree":
{
khrFirstLayer->dispatch.${api.Name}(
% else:
return khrFirstLayer->dispatch.${api.Name}(
% endif
%for i, param in enumerate(api.Params):
% if i < len(api.Params)-1:
${param.Name},
% else:
${param.Name});
% endif
%endfor
% if api.Name == "clSVMFree":
}
else
% endif
#endif // defined(CL_ENABLE_LAYERS)
%endif
%if api.RetType in apihandles or api.RetType == "void*":
## clCreateContext is a special case, since it calls through
## the dispatch table via the first "device":
% if api.Name == "clCreateContext":
if (${api.Params[1].Name} == 0 || ${api.Params[2].Name} == NULL) {
KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(NULL, CL_INVALID_VALUE);
}
KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(${api.Params[2].Name}[0], CL_INVALID_DEVICE);
## clCreateContextFromType is a special case, since it calls
## through a platform passed via properties:
% elif api.Name == "clCreateContextFromType":
cl_platform_id platform = NULL;
khrIcdContextPropertiesGetPlatform(properties, &platform);
KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(platform, CL_INVALID_PLATFORM);
## These APIs are special cases because they return a void*, but
## do not nave an errcode_ret:
% elif api.Name == "clSVMAlloc" or api.Name == "clGetExtensionFunctionAddressForPlatform":
KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(${handle.Name}, NULL);
% else:
KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(${handle.Name}, ${invalid});
% endif
%elif api.Name == "clSVMFree":
## clSVMFree has no return value or errcode_ret:
if (${handle.Name} != NULL)
## clWaitForEvents is a special case, since it calls through
## the dispatch table via the first "event":
%elif api.Name == "clWaitForEvents":
if (${api.Params[0].Name} == 0 || ${api.Params[1].Name} == NULL) {
return CL_INVALID_VALUE;
}
KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(${api.Params[1].Name}[0], CL_INVALID_EVENT);
%elif api.Name == "clUnloadCompiler":
// Nothing!
%else:
KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(${handle.Name}, ${invalid});
%endif
%if api.Name == "clCreateContext":
return ${api.Params[2].Name}[0]->dispatch->${api.Name}(
%elif api.Name == "clWaitForEvents":
return ${api.Params[1].Name}[0]->dispatch->${api.Name}(
%elif api.Name == "clCreateContextFromType":
return platform->dispatch->${api.Name}(
%elif api.Name == "clSVMFree":
${handle.Name}->dispatch->${api.Name}(
%elif api.Name == "clUnloadCompiler":
return CL_SUCCESS;
%else:
return ${handle.Name}->dispatch->${api.Name}(
%endif:
%for i, param in enumerate(api.Params):
% if i < len(api.Params)-1:
${param.Name},
% elif param.Name: # for clUnloadCompiler
${param.Name});
% endif
%endfor
}
% if disp == 1:
#endif // defined(CL_ENABLE_LAYERS)
% endif
///////////////////////////////////////////////////////////////////////////////
%endfor
%else:
#if defined(CL_ENABLE_LAYERS)
extern CL_API_ENTRY ${api.RetType} CL_API_CALL ${api.Name + "_disp"}(
%for i, param in enumerate(api.Params):
% if i < len(api.Params)-1:
${param.Type} ${param.Name}${param.TypeEnd},
% else:
${param.Type} ${param.Name}${param.TypeEnd}) ${api.Suffix};
% endif
%endfor
#endif // defined(CL_ENABLE_LAYERS)
%endif
%endfor
%endfor
<%
icdextensions = [
'cl_ext_device_fission',
'cl_khr_d3d10_sharing',
'cl_khr_d3d11_sharing',
'cl_khr_dx9_media_sharing',
'cl_khr_egl_event',
'cl_khr_egl_image',
'cl_khr_gl_event',
'cl_khr_gl_sharing',
'cl_khr_subgroups'
]
win32extensions = {
'cl_khr_d3d10_sharing',
'cl_khr_d3d11_sharing',
'cl_khr_dx9_media_sharing',
}
%>
%for extension in icdextensions:
<%
apis = extapis[extension]
%>// ${extension}
%if extension in win32extensions:
#if defined(_WIN32)
%endif
%for api in apis:
<%
handle = api.Params[0]
if handle.Type in apihandles:
invalid = apihandles[handle.Type]
else:
invalid = 'NULL'
%>
%for disp in [0, 1]:
% if disp == 1:
#if defined(CL_ENABLE_LAYERS)
% endif
${("", "static ")[disp]}CL_API_ENTRY ${api.RetType} CL_API_CALL ${api.Name + ("", "_disp")[disp]}(
%for i, param in enumerate(api.Params):
% if i < len(api.Params)-1:
${param.Type} ${param.Name}${param.TypeEnd},
% else:
${param.Type} ${param.Name}${param.TypeEnd})
% endif
%endfor
{
%if disp == 0:
#if defined(CL_ENABLE_LAYERS)
if (khrFirstLayer)
return khrFirstLayer->dispatch.${api.Name}(
%for i, param in enumerate(api.Params):
% if i < len(api.Params)-1:
${param.Name},
% else:
${param.Name});
% endif
%endfor
#endif // defined(CL_ENABLE_LAYERS)
%endif
%if api.RetType in apihandles or api.RetType == "void*":
% if False:
// api.Name == "clXXX": # There are currently no API special cases here.
% else:
KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(${handle.Name}, ${invalid});
% endif
%else:
% if api.Name == "clGetGLContextInfoKHR":
cl_platform_id platform = NULL;
khrIcdContextPropertiesGetPlatform(properties, &platform);
KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(platform, CL_INVALID_PLATFORM);
% else:
KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(${handle.Name}, ${invalid});
% endif
%endif
%if api.Name == "clGetGLContextInfoKHR":
return platform->dispatch->${api.Name}(
%else:
return ${handle.Name}->dispatch->${api.Name}(
%endif
%for i, param in enumerate(api.Params):
% if i < len(api.Params)-1:
${param.Name},
% elif param.Name: # for clUnloadCompiler
${param.Name});
% endif
%endfor
}
% if disp == 1:
#endif // defined(CL_ENABLE_LAYERS)
% endif
%endfor
%endfor
%if extension in win32extensions:
#endif // defined(_WIN32)
%endif
///////////////////////////////////////////////////////////////////////////////
%endfor
#if defined(CL_ENABLE_LAYERS)
struct _cl_icd_dispatch khrMasterDispatch = {
&clGetPlatformIDs_disp,
&clGetPlatformInfo_disp,
&clGetDeviceIDs_disp,
&clGetDeviceInfo_disp,
&clCreateContext_disp,
&clCreateContextFromType_disp,
&clRetainContext_disp,
&clReleaseContext_disp,
&clGetContextInfo_disp,
&clCreateCommandQueue_disp,
&clRetainCommandQueue_disp,
&clReleaseCommandQueue_disp,
&clGetCommandQueueInfo_disp,
&clSetCommandQueueProperty_disp,
&clCreateBuffer_disp,
&clCreateImage2D_disp,
&clCreateImage3D_disp,
&clRetainMemObject_disp,
&clReleaseMemObject_disp,
&clGetSupportedImageFormats_disp,
&clGetMemObjectInfo_disp,
&clGetImageInfo_disp,
&clCreateSampler_disp,
&clRetainSampler_disp,
&clReleaseSampler_disp,
&clGetSamplerInfo_disp,
&clCreateProgramWithSource_disp,
&clCreateProgramWithBinary_disp,
&clRetainProgram_disp,
&clReleaseProgram_disp,
&clBuildProgram_disp,
&clUnloadCompiler_disp,
&clGetProgramInfo_disp,
&clGetProgramBuildInfo_disp,
&clCreateKernel_disp,
&clCreateKernelsInProgram_disp,
&clRetainKernel_disp,
&clReleaseKernel_disp,
&clSetKernelArg_disp,
&clGetKernelInfo_disp,
&clGetKernelWorkGroupInfo_disp,
&clWaitForEvents_disp,
&clGetEventInfo_disp,
&clRetainEvent_disp,
&clReleaseEvent_disp,
&clGetEventProfilingInfo_disp,
&clFlush_disp,
&clFinish_disp,
&clEnqueueReadBuffer_disp,
&clEnqueueWriteBuffer_disp,
&clEnqueueCopyBuffer_disp,
&clEnqueueReadImage_disp,
&clEnqueueWriteImage_disp,
&clEnqueueCopyImage_disp,
&clEnqueueCopyImageToBuffer_disp,
&clEnqueueCopyBufferToImage_disp,
&clEnqueueMapBuffer_disp,
&clEnqueueMapImage_disp,
&clEnqueueUnmapMemObject_disp,
&clEnqueueNDRangeKernel_disp,
&clEnqueueTask_disp,
&clEnqueueNativeKernel_disp,
&clEnqueueMarker_disp,
&clEnqueueWaitForEvents_disp,
&clEnqueueBarrier_disp,
&clGetExtensionFunctionAddress_disp,
&clCreateFromGLBuffer_disp,
&clCreateFromGLTexture2D_disp,
&clCreateFromGLTexture3D_disp,
&clCreateFromGLRenderbuffer_disp,
&clGetGLObjectInfo_disp,
&clGetGLTextureInfo_disp,
&clEnqueueAcquireGLObjects_disp,
&clEnqueueReleaseGLObjects_disp,
&clGetGLContextInfoKHR_disp,
/* cl_khr_d3d10_sharing */
#if defined(_WIN32)
&clGetDeviceIDsFromD3D10KHR_disp,
&clCreateFromD3D10BufferKHR_disp,
&clCreateFromD3D10Texture2DKHR_disp,
&clCreateFromD3D10Texture3DKHR_disp,
&clEnqueueAcquireD3D10ObjectsKHR_disp,
&clEnqueueReleaseD3D10ObjectsKHR_disp,
#else
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
#endif
/* OpenCL 1.1 */
&clSetEventCallback_disp,
&clCreateSubBuffer_disp,
&clSetMemObjectDestructorCallback_disp,
&clCreateUserEvent_disp,
&clSetUserEventStatus_disp,
&clEnqueueReadBufferRect_disp,
&clEnqueueWriteBufferRect_disp,
&clEnqueueCopyBufferRect_disp,
/* cl_ext_device_fission */
&clCreateSubDevicesEXT_disp,
&clRetainDeviceEXT_disp,
&clReleaseDeviceEXT_disp,
/* cl_khr_gl_event */
&clCreateEventFromGLsyncKHR_disp,
/* OpenCL 1.2 */
&clCreateSubDevices_disp,
&clRetainDevice_disp,
&clReleaseDevice_disp,
&clCreateImage_disp,
&clCreateProgramWithBuiltInKernels_disp,
&clCompileProgram_disp,
&clLinkProgram_disp,
&clUnloadPlatformCompiler_disp,
&clGetKernelArgInfo_disp,
&clEnqueueFillBuffer_disp,
&clEnqueueFillImage_disp,
&clEnqueueMigrateMemObjects_disp,
&clEnqueueMarkerWithWaitList_disp,
&clEnqueueBarrierWithWaitList_disp,
&clGetExtensionFunctionAddressForPlatform_disp,
&clCreateFromGLTexture_disp,
/* cl_khr_d3d11_sharing */
#if defined(_WIN32)
&clGetDeviceIDsFromD3D11KHR_disp,
&clCreateFromD3D11BufferKHR_disp,
&clCreateFromD3D11Texture2DKHR_disp,
&clCreateFromD3D11Texture3DKHR_disp,
&clCreateFromDX9MediaSurfaceKHR_disp,
&clEnqueueAcquireD3D11ObjectsKHR_disp,
&clEnqueueReleaseD3D11ObjectsKHR_disp,
#else
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
#endif
/* cl_khr_dx9_media_sharing */
#if defined(_WIN32)
&clGetDeviceIDsFromDX9MediaAdapterKHR_disp,
&clEnqueueAcquireDX9MediaSurfacesKHR_disp,
&clEnqueueReleaseDX9MediaSurfacesKHR_disp,
#else
NULL,
NULL,
NULL,
#endif
/* cl_khr_egl_image */
&clCreateFromEGLImageKHR_disp,
&clEnqueueAcquireEGLObjectsKHR_disp,
&clEnqueueReleaseEGLObjectsKHR_disp,
/* cl_khr_egl_event */
&clCreateEventFromEGLSyncKHR_disp,
/* OpenCL 2.0 */
&clCreateCommandQueueWithProperties_disp,
&clCreatePipe_disp,
&clGetPipeInfo_disp,
&clSVMAlloc_disp,
&clSVMFree_disp,
&clEnqueueSVMFree_disp,
&clEnqueueSVMMemcpy_disp,
&clEnqueueSVMMemFill_disp,
&clEnqueueSVMMap_disp,
&clEnqueueSVMUnmap_disp,
&clCreateSamplerWithProperties_disp,
&clSetKernelArgSVMPointer_disp,
&clSetKernelExecInfo_disp,
/* cl_khr_sub_groups */
&clGetKernelSubGroupInfoKHR_disp,
/* OpenCL 2.1 */
&clCloneKernel_disp,
&clCreateProgramWithIL_disp,
&clEnqueueSVMMigrateMem_disp,
&clGetDeviceAndHostTimer_disp,
&clGetHostTimer_disp,
&clGetKernelSubGroupInfo_disp,
&clSetDefaultDeviceCommandQueue_disp,
/* OpenCL 2.2 */
&clSetProgramReleaseCallback_disp,
&clSetProgramSpecializationConstant_disp,
/* OpenCL 3.0 */
&clCreateBufferWithProperties_disp,
&clCreateImageWithProperties_disp,
&clSetContextDestructorCallback_disp
};
#endif // defined(CL_ENABLE_LAYERS)
#ifdef __cplusplus
}
#endif