KhronosGroup / OpenCL-CLHPP

Khronos OpenCL-CLHPP
Apache License 2.0
375 stars 130 forks source link

OpenCLTM API C++ bindings

Doxgen documentation for the bindings is available here:

http://khronosgroup.github.io/OpenCL-CLHPP/

Components:

Build Instructions

While the C++ Headers can be built and installed in isolation, it is part of the OpenCL SDK. If looking for streamlined build experience and a complete development package, refer to the SDK build instructions instead of the following guide.

Dependencies

The C++ Headers require:

Example Build

  1. Clone this repo, the OpenCL ICD Loader and the OpenCL Headers:

    git clone --recursive https://github.com/KhronosGroup/OpenCL-CLHPP
    git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader
    git clone https://github.com/KhronosGroup/OpenCL-Headers
  2. Install OpenCL Headers CMake package

    cmake -D CMAKE_INSTALL_PREFIX=./OpenCL-Headers/install -S ./OpenCL-Headers -B ./OpenCL-Headers/build 
    cmake --build ./OpenCL-Headers/build --target install
  3. Build and install OpenCL ICD Loader CMake package. _(Note that CMAKE_PREFIX_PATH need to be an absolute path. Update as needed.)_

    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 
    cmake --build ./OpenCL-ICD-Loader/build --target install
  4. Build and install OpenCL C++ Headers CMake package.

    cmake -D CMAKE_PREFIX_PATH="/absolute/path/to/OpenCL-Headers/install;/absolute/path/to/OpenCL-ICD-Loader/install" -D CMAKE_INSTALL_PREFIX=./OpenCL-CLHPP/install -S ./OpenCL-CLHPP -B ./OpenCL-CLHPP/build 
    cmake --build ./OpenCL-CLHPP/build --target install

Example Use

Example CMake invocation

cmake -D CMAKE_PREFIX_PATH="/chosen/install/prefix/of/headers;/chosen/install/prefix/of/loader;/chosen/install/prefix/of/cppheaders" /path/to/opencl/app

and sample CMakeLists.txt

cmake_minimum_required(VERSION 3.0)
cmake_policy(VERSION 3.0...3.18.4)
project(proj)
add_executable(app main.cpp)
find_package(OpenCLHeaders REQUIRED)
find_package(OpenCLICDLoader REQUIRED)
find_package(OpenCLHeadersCpp REQUIRED)
target_link_libraries(app PRIVATE OpenCL::Headers OpenCL::OpenCL OpenCL::HeadersCpp)