@@ -84,7 +84,7 @@ void khrIcdVendorAdd(const char *libraryName)
8484 KHRicdVendor *vendorIterator = NULL;
8585
8686 // require that the library name be valid
87- if (!libraryName)
87+ if (!libraryName)
8888 {
8989 goto Done;
9090 }
@@ -155,6 +155,8 @@ void khrIcdVendorAdd(const char *libraryName)
155155 for (i = 0; i < platformCount; ++i)
156156 {
157157 KHRicdVendor* vendor = NULL;
158+ char *extensions;
159+ size_t extensionsSize;
158160 char *suffix;
159161 size_t suffixSize;
160162
@@ -201,15 +203,61 @@ void khrIcdVendorAdd(const char *libraryName)
201203 }
202204#endif
203205
204- // call clGetPlatformInfo on the returned platform to get the suffix
205-
206- KHR_ICD2_DISPATCH(platforms[i])->clGetPlatformInfo(
206+ // call clGetPlatformInfo on the returned platform to get the supported extensions
207+ result = KHR_ICD2_DISPATCH(platforms[i])->clGetPlatformInfo(
207208 platforms[i],
208- CL_PLATFORM_UNLOADABLE_KHR,
209- sizeof(vendor->unloadable),
210- &vendor->unloadable,
209+ CL_PLATFORM_EXTENSIONS,
210+ 0,
211+ NULL,
212+ &extensionsSize);
213+ if (CL_SUCCESS != result)
214+ {
215+ free(vendor);
216+ continue;
217+ }
218+ extensions = (char *)malloc(extensionsSize);
219+ if (!extensions)
220+ {
221+ KHR_ICD_TRACE("failed to allocate memory\n");
222+ free(vendor);
223+ continue;
224+ }
225+ result = KHR_ICD2_DISPATCH(platforms[i])->clGetPlatformInfo(
226+ platforms[i],
227+ CL_PLATFORM_EXTENSIONS,
228+ extensionsSize,
229+ extensions,
211230 NULL);
231+ if (CL_SUCCESS != result)
232+ {
233+ free(extensions);
234+ free(vendor);
235+ continue;
236+ }
237+
238+ if (strstr(extensions, "cl_khr_icd_unloadable"))
239+ {
240+ KHR_ICD_TRACE("found cl_khr_icd_unloadable extension support\n");
241+ free(extensions);
242+ result = KHR_ICD2_DISPATCH(platforms[i])->clGetPlatformInfo(
243+ platforms[i],
244+ CL_PLATFORM_UNLOADABLE_KHR,
245+ sizeof(vendor->unloadable),
246+ &vendor->unloadable,
247+ NULL);
248+ if (vendor->unloadable)
249+ {
250+ KHR_ICD_TRACE("platform is unloadable\n");
251+ }
252+ if (CL_SUCCESS != result)
253+ {
254+ KHR_ICD_TRACE("found cl_khr_icd_unloadable but clGetPlatformInfo CL_PLATFORM_UNLOADABLE_KHR query failed\n");
255+ free(vendor);
256+ continue;
257+ }
258+ }
212259
260+ // call clGetPlatformInfo on the returned platform to get the suffix
213261 result = KHR_ICD2_DISPATCH(platforms[i])->clGetPlatformInfo(
214262 platforms[i],
215263 CL_PLATFORM_ICD_SUFFIX_KHR,
@@ -218,12 +266,14 @@ void khrIcdVendorAdd(const char *libraryName)
218266 &suffixSize);
219267 if (CL_SUCCESS != result)
220268 {
269+ KHR_ICD_TRACE("failed query platform ICD suffix\n");
221270 free(vendor);
222271 continue;
223272 }
224273 suffix = (char *)malloc(suffixSize);
225274 if (!suffix)
226275 {
276+ KHR_ICD_TRACE("failed to allocate memory\n");
227277 free(vendor);
228278 continue;
229279 }
@@ -232,17 +282,18 @@ void khrIcdVendorAdd(const char *libraryName)
232282 CL_PLATFORM_ICD_SUFFIX_KHR,
233283 suffixSize,
234284 suffix,
235- NULL);
285+ NULL);
236286 if (CL_SUCCESS != result)
237287 {
288+ KHR_ICD_TRACE("failed query platform ICD suffix\n");
238289 free(suffix);
239290 free(vendor);
240291 continue;
241292 }
242293
243294 // populate vendor data
244295 vendor->library = khrIcdOsLibraryLoad(libraryName);
245- if (!vendor->library)
296+ if (!vendor->library)
246297 {
247298 free(suffix);
248299 free(vendor);
0 commit comments