Dear POCL maintainers,
I extended the khronos-icd-loader.patch in the POCL source to load the
OpenCL ICD files in guaranteed order, using scandir() with alphasort.
Loading the drivers in a guaranteed order is needed for some other
OpenCL implementations. I use the AMD and NVIDIA OpenCL drivers, or
Intel and NVIDIA OpenCL drivers, in the same process. If the NVIDIA
driver is loaded first (instead of second), the process segfaults
upon subsequently loading the AMD or Intel driver. Since existing
OpenCL loaders use readdir(), the load order is unpredictable from
machine to machine.
Maybe you could include the updated patch in the POCL source?
Did you think of submitting your patch to Khronos upstream?
It would be very useful to have the environment variable implemented
in as many libOpenCL.so out there as possible, since it enables users
to load non-root-installed OpenCL drivers.
(Note that I removed the unneeded "/" from the default vendorPath.)
Regards,
Peter
Patch for the Khronos-distributed http://www.khronos.org/registry/cl/ ICD Loader
to make it usable for regression testing in pocl development:
- Allow overriding the .icd search path with env OCL_ICD_VENDORS (like ocl-icd does)
- Do not fail in case the directory contains non .icd files.
- Allow paths without '/' suffix.
- Load drivers in guaranteed order.
--- icd/icd_linux.c
+++ icd/icd_linux.c
@@ -55,21 +55,26 @@
// go through the list of vendors in the two configuration files
void khrIcdOsVendorsEnumerate(void)
{
- DIR *dir = NULL;
- struct dirent *dirEntry = NULL;
- char *vendorPath = "/etc/OpenCL/vendors/";
-
- // open the directory
- dir = opendir(vendorPath);
- if (NULL == dir)
+ struct dirent **dirEntries = NULL;
+ int i;
+ char *vendorPath = getenv("OCL_ICD_VENDORS");
+ if (vendorPath == NULL || strncmp(vendorPath, "", 1) == 0)
+ {
+ vendorPath = "/etc/OpenCL/vendors";
+ }
+
+ // read the directory in guaranteed order
+ const int numEntries = scandir(vendorPath, &dirEntries, NULL, alphasort);
+ if (numEntries < 0)
{
KHR_ICD_TRACE("Failed to open path %s\n", vendorPath);
goto Cleanup;
}
// attempt to load all files in the directory
- for (dirEntry = readdir(dir); dirEntry; dirEntry = readdir(dir) )
+ for (i = 0; i < numEntries; ++i)
{
+ const struct dirent *dirEntry = dirEntries[i];
switch(dirEntry->d_type)
{
case DT_UNKNOWN:
@@ -85,21 +90,21 @@
// make sure the file name ends in .icd
if (strlen(extension) > strlen(dirEntry->d_name) )
{
- break;
+ continue;
}
if (strcmp(dirEntry->d_name + strlen(dirEntry->d_name) - strlen(extension), extension) )
{
- break;
+ continue;
}
// allocate space for the full path of the vendor library name
- fileName = malloc(strlen(dirEntry->d_name) + strlen(vendorPath) + 1);
+ fileName = malloc(strlen(dirEntry->d_name) + strlen(vendorPath) + 2);
if (!fileName)
{
KHR_ICD_TRACE("Failed allocate space for ICD file path\n");
break;
}
- sprintf(fileName, "%s%s", vendorPath, dirEntry->d_name);
+ sprintf(fileName, "%s/%s", vendorPath, dirEntry->d_name);
// open the file and read its contents
fin = fopen(fileName, "r");
@@ -146,9 +151,13 @@
Cleanup:
// free resources and exit
- if (dir)
+ if (dirEntries)
{
- closedir(dir);
+ for (i = 0; i < numEntries; ++i)
+ {
+ free(dirEntries[i]);
+ }
+ free(dirEntries);
}
}
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and
AppDynamics. Performance Central is your source for news, insights,
analysis and resources for efficient Application Performance Management.
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
pocl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pocl-devel