Skip to content

Building and Installing

James Price edited this page Apr 25, 2021 · 24 revisions

This page provides information about building Oclgrind from source. Binary packages for various operating systems are released periodically on the GitHub Releases page. Releases are also available on Debian/Ubuntu systems via apt-get install oclgrind, and on macOS via Homebrew.

Prerequisites

To build this project, you will need LLVM and Clang 11.0 (or newer) development libraries and headers. If you build LLVM from source, it is recommended to enable optimizations to significantly improve the performance of Oclgrind (set CMAKE_BUILD_TYPE to Release or RelWithDebInfo).

You will need to use a compiler that supports C++11. Python should also be available in order to run the test suite.

Building Oclgrind on Linux or OS X

The recommended method of building Oclgrind is via CMake.

When configuring the CMake build, you may be prompted to supply a value for the LLVM_DIR parameter (this shouldn't be necessary if LLVM is installed in a standard system location). This should be set to the directory containing your LLVM installation's LLVMConfig.cmake file (typically either ${LLVM_ROOT}/lib/cmake/llvm or ${LLVM_ROOT}/share/llvm/cmake/). If Clang is installed separately to LLVM, then you may also be prompted to supply a path for the CLANG_ROOT parameter, which should be the root of your Clang installation (containing the bin/, lib/ and include/ directories).

A typical CMake command-line might look like this:

cmake ${OCLGRIND_SOURCE} \
      -DCMAKE_BUILD_TYPE=RelWithDebInfo \
      -DCMAKE_INSTALL_PREFIX=${INSTALL_ROOT} \
      -DLLVM_DIR=${LLVM_ROOT}/lib/cmake/llvm

where ${OCLGRIND_SOURCE} is the path to the root directory containing the Oclgrind source code, ${LLVM_ROOT} is the path to the LLVM installation, and ${INSTALL_ROOT} is the desired installation root directory (this can be omitted if installing to system directories).

Next, build and install with make:

make
make test
make install

If installing to a non-system location, you should add the bin/ directory to the PATH environment variable in order to make use of the oclgrind command. If you wish to use Oclgrind via the OpenCL ICD loader (optional), then you should create an ICD loading point by copying the oclgrind.icd file from the build directory to /etc/OpenCL/vendors/.

Building Oclgrind on Windows

Building Oclgrind on Windows requires Visual Studio 2013 (or newer), and Windows 7 (or newer). Compiling against recent versions of LLVM may require Visual Studio 2015.

When configuring the CMake build, you may be prompted to supply a value for the LLVM_DIR parameter. This should be set to the directory containing your LLVM installation's LLVMConfig.cmake file (for example C:\Program Files\LLVM\lib\cmake\llvm). If Clang is installed separately to LLVM, then you may also be prompted to supply a path in the CLANG_ROOT parameter, which should be the root of your Clang installation (containing the bin/, lib/ and include/ directories).

You should add the bin directory of the Oclgrind installation to the PATH environment variable in order to make use of the oclgrind command. If you wish to use Oclgrind via the OpenCL ICD loader (optional), then you should also create an ICD loading point. To do this, you should add a REG_DWORD value to the Windows Registry under one or both of the registry keys below, with the name set to the absolute path of the oclgrind-rt-icd.dll library and the value set to 0.

Key for 32-bit machines or 64-bit apps on a 64-bit machine: HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors

Key for 32-bit apps on a 64-bit machine: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Khronos\OpenCL\Vendors

CMake will generate a RUN_TESTS project in Visual Studio which can be used to verify that Oclgrind is working correctly. It is recommended to run this after installing Oclgrind so that the precompiled headers can be used during the tests.

Additional Notes

If you wish to use the OpenCL ICD loader and it is not already present on your system, you can download and build the sources from here.

On macOS, you can link OpenCL applications against the ICD loader by specifying -lOpenCL in your linker flags, instead of -framework OpenCL. Apple's OpenCL implementation does not yet support the OpenCL ICD interface, and so applications linked in this way will not be able to use the Apple OpenCL platform.

If you encounter any problems whilst building Oclgrind, please raise an issue on the GitHub Issues page: https://github.com/jrprice/Oclgrind/issues