Skip to content

Commit ba1efbf

Browse files
committed
Implement cl_khr_icd_unloadable proposal.
1 parent 5c9be3b commit ba1efbf

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

loader/icd.c

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

test/driver_stub/cl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ clIcdGetPlatformIDsKHR(cl_uint num_entries,
19681968
#else
19691969
stub_platform->name = "ICD_LOADER_TEST_OPENCL_STUB";
19701970
#endif
1971-
stub_platform->extensions = "cl_khr_icd cl_khr_gl cl_khr_d3d10";
1971+
stub_platform->extensions = "cl_khr_icd cl_khr_icd_unloadable cl_khr_gl cl_khr_d3d10";
19721972
stub_platform->suffix = "ilts";
19731973
initialized = CL_TRUE;
19741974
}

0 commit comments

Comments
 (0)