1# OpenCL<sup>TM</sup> ICD Loader 2 3This repo contains the source code and tests for the Khronos official OpenCL ICD Loader. 4 5## CI Build Status 6 7[](https://github.com/KhronosGroup/OpenCL-ICD-Loader/actions?query=workflow%3AWindows) 8[](https://github.com/KhronosGroup/OpenCL-ICD-Loader/actions?query=workflow%3ALinux) 9[](https://github.com/KhronosGroup/OpenCL-ICD-Loader/actions?query=workflow%3AMacOS) 10 11## Introduction 12 13OpenCL defines an *Installable Client Driver* (ICD) mechanism to allow developers to build applications against an *Installable Client Driver* loader (ICD loader) rather than linking their applications against a specific OpenCL implementation. 14The ICD Loader is responsible for: 15 16* Exporting OpenCL API entry points 17* Enumerating OpenCL implementations 18* Forwarding OpenCL API calls to the correct implementation 19 20This repo contains the source code and tests for the Khronos official OpenCL ICD Loader. 21 22Note that this repo does not contain an OpenCL implementation (ICD). 23You will need to obtain and install an OpenCL implementation for your OpenCL device that supports the OpenCL ICD extension `cl_khr_icd` to run an application using the OpenCL ICD Loader. 24 25The OpenCL *Installable Client Driver* extension (`cl_khr_icd`) is described in the OpenCL extensions specification, which may be found on the [Khronos OpenCL Registry](https://www.khronos.org/registry/OpenCL/). 26 27## Build Instructions 28 29> While the ICD Loader can be built and installed in isolation, it is part of the [OpenCL SDK](https://github.com/KhronosGroup/OpenCL-SDK). If looking for streamlined build experience and a complete development package, refer to the SDK build instructions instead of the following guide. 30 31### Dependencies 32 33The OpenCL ICD Loader requires: 34- the [OpenCL Headers](https://github.com/KhronosGroup/OpenCL-Headers/). 35 - It is recommended to install the headers via CMake, however a convenience shorthand is provided. Providing `OPENCL_ICD_LOADER_HEADERS_DIR` to CMake, one may specify the location of OpenCL Headers. By default, the OpenCL ICD Loader will look for OpenCL Headers in the inc directory. 36- The OpenCL ICD Loader uses CMake for its build system. 37If CMake is not provided by your build system or OS package manager, please consult the [CMake website](https://cmake.org). 38 39### Example Build 40 41For most Windows and Linux usages, the following steps are sufficient to build the OpenCL ICD Loader: 42 431. Clone this repo and the OpenCL Headers: 44 45 git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader 46 git clone https://github.com/KhronosGroup/OpenCL-Headers 47 481. Install OpenCL Headers CMake package 49 50 cmake -D CMAKE_INSTALL_PREFIX=./OpenCL-Headers/install -S ./OpenCL-Headers -B ./OpenCL-Headers/build 51 cmake --build ./OpenCL-Headers/build --target install 52 531. Build and install OpenCL ICD Loader CMake package. _(Note that `CMAKE_PREFIX_PATH` need to be an absolute path. Update as needed.)_ 54 55 cmake -D CMAKE_PREFIX_PATH=/absolute/path/to/OpenCL-Headers/install -D CMAKE_INSTALL_PREFIX=./OpenCL-ICD-Loader/install -S ./OpenCL-ICD-Loader -B ./OpenCL-ICD-Loader/build 56 cmake --build ./OpenCL-ICD-Loader/build --target install 57 58Notes: 59 60* For x64 Windows builds, you need to instruct the default Visual Studio generator by adding `-A x64` to all your command-lines. 61 62* Some users may prefer to use a CMake GUI frontend, such as `cmake-gui` or `ccmake`, vs. the command-line CMake. 63 64### Example Use 65 66Example CMake invocation 67 68```bash 69cmake -D CMAKE_PREFIX_PATH="/chosen/install/prefix/of/headers;/chosen/install/prefix/of/loader" /path/to/opencl/app 70``` 71 72and sample `CMakeLists.txt` 73 74```cmake 75cmake_minimum_required(VERSION 3.0) 76cmake_policy(VERSION 3.0...3.18.4) 77project(proj) 78add_executable(app main.cpp) 79find_package(OpenCLHeaders REQUIRED) 80find_package(OpenCLICDLoader REQUIRED) 81target_link_libraries(app PRIVATE OpenCL::Headers OpenCL::OpenCL) 82``` 83 84## OpenCL ICD Loader Tests 85 86OpenCL ICD Loader Tests can be run using `ctest` from the `build` directory. CTest which is a companion to CMake. The OpenCL ICD Loader Tests can also be run directly by executing `icd_loader_test[.exe]` executable from the bin folder. 87 88_(Note that running the tests manually requires setting up it's env manually, by setting `OCL_ICD_FILENAMES` to the full path of `libOpenCLDriverStub.so`/`OpenCLDriverStub.dll`, something otherwise done by CTest.)_ 89 90## Registering ICDs 91 92The method to installing an ICD is operating system dependent. 93 94### Registering an ICD on Linux 95 96Install your ICD by creating a file with the full path to the library of your implementation in `/etc/OpenCL/vendors` for eg.: 97 98 echo full/path/to/libOpenCLDriverStub.so > /etc/OpenCL/vendors/test.icd 99 100### Registering an ICD on Windows 101 102Install your ICD by adding a `REG_DWORD` value to the registry keys: 103 104 // For 32-bit operating systems, or 64-bit tests on a 64-bit operating system: 105 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors 106 107 // For 32-bit tests on a 64-bit operating system: 108 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Khronos\OpenCL\Vendors 109 110 // The name of the REG_DWORD value should be the full path to the library of your implementation, for eg. 111 // OpenCLDriverStub.dll, and the data for this value should be 0. 112 113## About Layers 114 115Layers have been added as an experimental feature in the OpenCL ICD Loader. We do not 116expect the API or ABI to change significantly, but the OpenCL Working Group reserves 117the right to do so. The layer support can also be completely deactivated during 118configuration by using the `ENABLE_OPENCL_LAYERS` (`ON` by default) cmake variable: 119 120```bash 121cmake -DENABLE_OPENCL_LAYERS=OFF 122``` 123 124For now, runtime configuration of layers is done using the `OPENCL_LAYERS` environment 125variable. A colon (Linux) or semicolon (Windows) list of layers to use can be provided 126through this environment variable. 127 128We are looking for feedback. 129 130## Support 131 132Please create a GitHub issue to report an issue or ask questions. 133 134## Contributing 135 136Contributions to the OpenCL ICD Loader are welcomed and encouraged. 137You will be prompted with a one-time "click-through" CLA dialog as part of submitting your pull request or other contribution to GitHub. 138 139## Table of Debug Environment Variables 140 141The following debug environment variables are available for use with the OpenCL ICD loader: 142 143| Environment Variable | Behavior | Example Format | 144|:---------------------------------:|---------------------|----------------------| 145| OCL_ICD_FILENAMES | Specifies a list of additional ICDs to load. The ICDs will be enumerated first, before any ICDs discovered via default mechanisms. | `export OCL_ICD_FILENAMES=libVendorA.so:libVendorB.so`<br/><br/>`set OCL_ICD_FILENAMES=vendor_a.dll;vendor_b.dll` | 146| OCL_ICD_VENDORS | On Linux and Android, specifies a directory to scan for ICDs to enumerate in place of the default `/etc/OpenCL/vendors'. | `export OCL_ICD_VENDORS=/my/local/icd/search/path` | 147| OPENCL_LAYERS | Specifies a list of layers to load. | `export OPENCL_LAYERS=libLayerA.so:libLayerB.so`<br/><br/>`set OPENCL_LAYERS=libLayerA.dll;libLayerB.dll` | 148| OPENCL_LAYER_PATH | On Linux and Android, specifies a directory to scan for layers to enumerate in place of the default `/etc/OpenCL/layers'. | `export OPENCL_LAYER_PATH=/my/local/layers/search/path` | 149| OCL_ICD_ENABLE_TRACE | Enable the trace mechanism | `export OCL_ICD_ENABLE_TRACE=True`<br/><br/>`set OCL_ICD_ENABLE_TRACE=True`<br/>`true, T, 1 can also be used here.` | 150