@@ -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,63 @@ 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+ KHR_ICD_TRACE ("failed query platform extensions\n" );
216+ free (vendor );
217+ continue ;
218+ }
219+ extensions = (char * )malloc (extensionsSize );
220+ if (!extensions )
221+ {
222+ KHR_ICD_TRACE ("failed to allocate memory\n" );
223+ free (vendor );
224+ continue ;
225+ }
226+ result = KHR_ICD2_DISPATCH (platforms [i ])-> clGetPlatformInfo (
227+ platforms [i ],
228+ CL_PLATFORM_EXTENSIONS ,
229+ extensionsSize ,
230+ extensions ,
211231 NULL );
232+ if (CL_SUCCESS != result )
233+ {
234+ KHR_ICD_TRACE ("failed query platform extensions\n" );
235+ free (extensions );
236+ free (vendor );
237+ continue ;
238+ }
239+
240+ if (strstr (extensions , "cl_khr_icd_unloadable" ))
241+ {
242+ KHR_ICD_TRACE ("found cl_khr_icd_unloadable extension support\n" );
243+ free (extensions );
244+ result = KHR_ICD2_DISPATCH (platforms [i ])-> clGetPlatformInfo (
245+ platforms [i ],
246+ CL_PLATFORM_UNLOADABLE_KHR ,
247+ sizeof (vendor -> unloadable ),
248+ & vendor -> unloadable ,
249+ NULL );
250+ if (vendor -> unloadable )
251+ {
252+ KHR_ICD_TRACE ("platform is unloadable\n" );
253+ }
254+ if (CL_SUCCESS != result )
255+ {
256+ KHR_ICD_TRACE ("found cl_khr_icd_unloadable but clGetPlatformInfo CL_PLATFORM_UNLOADABLE_KHR query failed\n" );
257+ free (vendor );
258+ continue ;
259+ }
260+ }
212261
262+ // call clGetPlatformInfo on the returned platform to get the suffix
213263 result = KHR_ICD2_DISPATCH (platforms [i ])-> clGetPlatformInfo (
214264 platforms [i ],
215265 CL_PLATFORM_ICD_SUFFIX_KHR ,
@@ -218,12 +268,14 @@ void khrIcdVendorAdd(const char *libraryName)
218268 & suffixSize );
219269 if (CL_SUCCESS != result )
220270 {
271+ KHR_ICD_TRACE ("failed query platform ICD suffix\n" );
221272 free (vendor );
222273 continue ;
223274 }
224275 suffix = (char * )malloc (suffixSize );
225276 if (!suffix )
226277 {
278+ KHR_ICD_TRACE ("failed to allocate memory\n" );
227279 free (vendor );
228280 continue ;
229281 }
@@ -232,17 +284,18 @@ void khrIcdVendorAdd(const char *libraryName)
232284 CL_PLATFORM_ICD_SUFFIX_KHR ,
233285 suffixSize ,
234286 suffix ,
235- NULL );
287+ NULL );
236288 if (CL_SUCCESS != result )
237289 {
290+ KHR_ICD_TRACE ("failed query platform ICD suffix\n" );
238291 free (suffix );
239292 free (vendor );
240293 continue ;
241294 }
242295
243296 // populate vendor data
244297 vendor -> library = khrIcdOsLibraryLoad (libraryName );
245- if (!vendor -> library )
298+ if (!vendor -> library )
246299 {
247300 free (suffix );
248301 free (vendor );
0 commit comments