2 * Copyright (c) 2016-2019 The Khronos Group Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * OpenCL is a trademark of Apple Inc. used under license by Khronos.
22 #ifndef CL_USE_DEPRECATED_OPENCL_1_0_APIS
23 #define CL_USE_DEPRECATED_OPENCL_1_0_APIS
26 #ifndef CL_USE_DEPRECATED_OPENCL_1_1_APIS
27 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
30 #ifndef CL_USE_DEPRECATED_OPENCL_1_2_APIS
31 #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
35 #include <CL/cl_ext.h>
45 typedef CL_API_ENTRY cl_int (CL_API_CALL *pfn_clIcdGetPlatformIDs)(
47 cl_platform_id *platforms,
48 cl_uint *num_platforms) CL_API_SUFFIX__VERSION_1_0;
50 typedef CL_API_ENTRY cl_int (CL_API_CALL *pfn_clGetPlatformInfo)(
51 cl_platform_id platform,
52 cl_platform_info param_name,
53 size_t param_value_size,
55 size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0;
57 typedef CL_API_ENTRY void *(CL_API_CALL *pfn_clGetExtensionFunctionAddress)(
58 const char *function_name) CL_API_SUFFIX__VERSION_1_0;
60 typedef struct KHRicdVendorRec KHRicdVendor;
65 * Data for a single ICD vendor platform.
67 struct KHRicdVendorRec
69 // the loaded library object (true type varies on Linux versus Windows)
72 // the extension suffix for this platform
75 // function pointer to the ICD platform IDs extracted from the library
76 pfn_clGetExtensionFunctionAddress clGetExtensionFunctionAddress;
78 // the platform retrieved from clGetIcdPlatformIDsKHR
79 cl_platform_id platform;
81 // next vendor in the list vendors
86 extern KHRicdVendor * khrIcdVendors;
92 // read vendors from system configuration and store the data
93 // loaded into khrIcdState. this will call the OS-specific
94 // function khrIcdEnumerateVendors. this is called at every
95 // dispatch function which may be a valid first call into the
96 // API (e.g, getPlatformIDs, etc).
97 void khrIcdInitialize(void);
99 // go through the list of vendors (in /etc/OpenCL.conf or through
100 // the registry) and call khrIcdVendorAdd for each vendor encountered
101 // n.b, this call is OS-specific
102 void khrIcdOsVendorsEnumerateOnce(void);
104 // add a vendor's implementation to the list of libraries
105 void khrIcdVendorAdd(const char *libraryName);
107 // dynamically load a library. returns NULL on failure
108 // n.b, this call is OS-specific
109 void *khrIcdOsLibraryLoad(const char *libraryName);
111 // get a function pointer from a loaded library. returns NULL on failure.
112 // n.b, this call is OS-specific
113 void *khrIcdOsLibraryGetFunctionAddress(void *library, const char *functionName);
116 // n.b, this call is OS-specific
117 void khrIcdOsLibraryUnload(void *library);
119 // parse properties and determine the platform to use from them
120 void khrIcdContextPropertiesGetPlatform(
121 const cl_context_properties *properties,
122 cl_platform_id *outPlatform);
124 // internal tracing macros
127 #define KHR_ICD_TRACE(...) \
130 fprintf(stderr, "KHR ICD trace at %s:%d: ", __FILE__, __LINE__); \
131 fprintf(stderr, __VA_ARGS__); \
134 #define KHR_ICD_WIDE_TRACE(...) \
137 fwprintf(stderr, L"KHR ICD trace at %hs:%d: ", __FILE__, __LINE__); \
138 fwprintf(stderr, __VA_ARGS__); \
141 #define KHR_ICD_WIDE_TRACE(...)
143 #define KHR_ICD_ASSERT(x) \
148 fprintf(stderr, "KHR ICD assert at %s:%d: %s failed", __FILE__, __LINE__, #x); \
152 #define KHR_ICD_TRACE(...)
153 #define KHR_ICD_WIDE_TRACE(...)
154 #define KHR_ICD_ASSERT(x)
157 // if handle is NULL then return invalid_handle_error_code
158 #define KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(handle,invalid_handle_error_code) \
163 return invalid_handle_error_code; \
167 // if handle is NULL then set errcode_ret to invalid_handle_error and return NULL
168 // (NULL being an invalid handle)
169 #define KHR_ICD_VALIDATE_HANDLE_RETURN_HANDLE(handle,invalid_handle_error) \
176 *errcode_ret = invalid_handle_error; \