OpenCL clGetPlatformIDs returning CL_PLATFORM_NOT_FOUND in multi-vendor environments
0 reputation · 23 Sept 2023, 05:15 UTC
0 reputation · 23 Sept 2023, 05:15 UTC
OpenCL applications rely on the Installable Client Driver (ICD) loader to discover available platforms at runtime. In environments with a single hardware vendor, the loader typically identifies the platform without configuration. However, production environments often contain multiple GPUs or a mix of integrated and discrete graphics, which can introduce complexities in how the loader searches for .icd files.
When moving from a simplified local setup to a production system with multiple driver profiles, there is uncertainty regarding how the ICD loader prioritizes vendor files in the system path (such as /etc/OpenCL/vendors on Linux) and whether specific environment variables can override this discovery process to prevent initialization failures.
CL_PLATFORM_NOT_FOUND error despite the presence of installed drivers?34775 reputation · 23 Sept 2023, 15:27 UTC
The Khronos ICD loader treats each file in /etc/OpenCL/vendors as a pointer to a vendor library. It reads every .icd file, loads the referenced shared object, and merges the platforms that library exposes into a single list. clGetPlatformIDs returns CL_PLATFORM_NOT_FOUND only when that merged list is empty. With multiple valid profiles present, the behavior is deterministic: the loader enumerates the .icd files, loads each library independently, and concatenates the platforms they report. A conforming loader skips a library that fails to load and continues with the remaining entries rather than aborting the whole enumeration.
The confirmed, specification-aligned behavior is aggregation: the loader does not prioritize one vendor over another when multiple valid profiles exist. The likely explanation for your production failure is that the loader is finding zero valid entries, not that it is selecting the wrong vendor. Specific configurations that trigger CL_PLATFORM_NOT_FOUND despite installed drivers include:
.icd file points to a library path that no longer exists after a driver upgrade or GPU removal..icd files exist, but the referenced libraries have incompatible ABIs or missing dependencies, causing silent load failures.OCL_ICD_VENDORS redirects the loader to a directory that contains no valid .icd files, overriding the system path entirely./etc/OpenCL/vendors or the .icd files prevent the loader from reading them..icd file to confirm it contains an absolute path to an existing, loadable library.OCL_ICD_VENDORS is set in the production environment; if it is, inspect that directory instead of the system path.OCL_ICD_DEBUG=1 for the Khronos loader) to log which files and libraries are attempted.ldd on the loader and each vendor library to detect missing dependencies or symbol mismatches.clinfo or a minimal host program that calls clGetPlatformIDs to confirm the observed platform count matches the number of valid .icd entries.One caveat: some vendor or distro-patched loaders abort on the first library load failure instead of skipping it. If a single broken .icd file suppresses all platforms, you are likely using a non-conforming loader, and the fix is to remove or repair the offending entry rather than rely on skip-and-continue behavior.
Is OCL_ICD_VENDORS set in your production environment? If it is, the recommendation changes from repairing the system vendors directory to auditing the override directory instead.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.