xref: /aosp_15_r20/external/OpenCL-CLHPP/README.md (revision 6fee86a4f833e4f32f25770a262884407554133d)
1*6fee86a4SJeremy Kemp# OpenCL<sup>TM</sup> API C++ bindings
2*6fee86a4SJeremy Kemp
3*6fee86a4SJeremy KempDoxgen documentation for the bindings is available here:
4*6fee86a4SJeremy Kemp
5*6fee86a4SJeremy Kemp  http://khronosgroup.github.io/OpenCL-CLHPP/
6*6fee86a4SJeremy Kemp
7*6fee86a4SJeremy KempComponents:
8*6fee86a4SJeremy Kemp
9*6fee86a4SJeremy Kemp  * `include/CL/opencl.hpp`:
10*6fee86a4SJeremy Kemp    The latest, maintained, version of the C++ bindings. It should work with all
11*6fee86a4SJeremy Kemp    versions of OpenCL (including 1.x). This is what most users will want.
12*6fee86a4SJeremy Kemp
13*6fee86a4SJeremy Kemp  * `include/CL/cl2.hpp`:
14*6fee86a4SJeremy Kemp    Includes `opencl.hpp` and emits a warning, for backwards compability.
15*6fee86a4SJeremy Kemp
16*6fee86a4SJeremy Kemp  * `docs`:
17*6fee86a4SJeremy Kemp    Doxygen file used to generate HTML documentation for `opencl.hpp`.
18*6fee86a4SJeremy Kemp
19*6fee86a4SJeremy Kemp  * `examples`:
20*6fee86a4SJeremy Kemp    A simple example application using the very basic features of the bindings.
21*6fee86a4SJeremy Kemp
22*6fee86a4SJeremy Kemp  * `tests`:
23*6fee86a4SJeremy Kemp    A (very small, incomplete) set of regression tests. Building the tests
24*6fee86a4SJeremy Kemp    requires Python, Ruby, and CMock. For the last one we use
25*6fee86a4SJeremy Kemp    [CMock top-of-tree from Github](https://github.com/ThrowTheSwitch/CMock),
26*6fee86a4SJeremy Kemp    as the latest (at the time this was written) released CMock version,
27*6fee86a4SJeremy Kemp    v2.5.3, has some issues.
28*6fee86a4SJeremy Kemp
29*6fee86a4SJeremy Kemp  * `CMakeLists.txt`:
30*6fee86a4SJeremy Kemp    Build system for the examples and tests and logic for the bindings
31*6fee86a4SJeremy Kemp    installation.
32*6fee86a4SJeremy Kemp
33*6fee86a4SJeremy Kemp## Build Instructions
34*6fee86a4SJeremy Kemp
35*6fee86a4SJeremy Kemp> While the C++ Headers 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.
36*6fee86a4SJeremy Kemp
37*6fee86a4SJeremy Kemp### Dependencies
38*6fee86a4SJeremy Kemp
39*6fee86a4SJeremy KempThe C++ Headers require:
40*6fee86a4SJeremy Kemp
41*6fee86a4SJeremy Kemp- the [OpenCL Headers](https://github.com/KhronosGroup/OpenCL-Headers/).
42*6fee86a4SJeremy Kemp  - It is recommended to install the headers via CMake, however a convenience shorthand is provided. Providing `OPENCL_CLHPP_HEADERS_DIR` to CMake, one may specify the location of OpenCL Headers. By default, the C++ Headers will look for OpenCL Headers under `${OPENCL_DIST_DIR}/include`.
43*6fee86a4SJeremy Kemp- the [OpenCL-ICD-Loader](https://github.com/KhronosGroup/OpenCL-ICD-Loader/) when building the examples
44*6fee86a4SJeremy Kemp  - It is recommended to install the ICD loader via CMake, however a convenience shorthand is provided. Providing `OPENCL_CLHPP_LOADER_DIR` to CMake, one may specify the location of the OpenCL ICD loader. By default, the C++ headers will look for OpenCL ICD loader under `${OPENCL_DIST_DIR}/lib`.
45*6fee86a4SJeremy Kemp- The C++ Headers uses CMake for its build system.
46*6fee86a4SJeremy KempIf CMake is not provided by your build system or OS package manager, please consult the [CMake website](https://cmake.org).
47*6fee86a4SJeremy Kemp- The unit tests require [CMock](https://github.com/ThrowTheSwitch/CMock). To get this external dependency, use `--recursive` when cloning
48*6fee86a4SJeremy Kempthe repository, or run `git submodule update --init --recursive`.
49*6fee86a4SJeremy Kemp- Generating the mock input requires [Ruby](https://www.ruby-lang.org/en/).
50*6fee86a4SJeremy Kemp- Generating the docs requires Doxygen. When it is available, you can generate HTML documentation by building the `docs` target.
51*6fee86a4SJeremy Kemp
52*6fee86a4SJeremy Kemp### Example Build
53*6fee86a4SJeremy Kemp
54*6fee86a4SJeremy Kemp1. Clone this repo, the OpenCL ICD Loader and the OpenCL Headers:
55*6fee86a4SJeremy Kemp
56*6fee86a4SJeremy Kemp        git clone --recursive https://github.com/KhronosGroup/OpenCL-CLHPP
57*6fee86a4SJeremy Kemp        git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader
58*6fee86a4SJeremy Kemp        git clone https://github.com/KhronosGroup/OpenCL-Headers
59*6fee86a4SJeremy Kemp
60*6fee86a4SJeremy Kemp1. Install OpenCL Headers CMake package
61*6fee86a4SJeremy Kemp
62*6fee86a4SJeremy Kemp        cmake -D CMAKE_INSTALL_PREFIX=./OpenCL-Headers/install -S ./OpenCL-Headers -B ./OpenCL-Headers/build
63*6fee86a4SJeremy Kemp        cmake --build ./OpenCL-Headers/build --target install
64*6fee86a4SJeremy Kemp
65*6fee86a4SJeremy Kemp1. Build and install OpenCL ICD Loader CMake package. _(Note that `CMAKE_PREFIX_PATH` need to be an absolute path. Update as needed.)_
66*6fee86a4SJeremy Kemp
67*6fee86a4SJeremy Kemp        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
68*6fee86a4SJeremy Kemp        cmake --build ./OpenCL-ICD-Loader/build --target install
69*6fee86a4SJeremy Kemp
70*6fee86a4SJeremy Kemp1. Build and install OpenCL C++ Headers CMake package.
71*6fee86a4SJeremy Kemp
72*6fee86a4SJeremy Kemp        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
73*6fee86a4SJeremy Kemp        cmake --build ./OpenCL-CLHPP/build --target install
74*6fee86a4SJeremy Kemp
75*6fee86a4SJeremy Kemp### Example Use
76*6fee86a4SJeremy Kemp
77*6fee86a4SJeremy KempExample CMake invocation
78*6fee86a4SJeremy Kemp
79*6fee86a4SJeremy Kemp```bash
80*6fee86a4SJeremy Kempcmake -D CMAKE_PREFIX_PATH="/chosen/install/prefix/of/headers;/chosen/install/prefix/of/loader;/chosen/install/prefix/of/cppheaders" /path/to/opencl/app
81*6fee86a4SJeremy Kemp```
82*6fee86a4SJeremy Kemp
83*6fee86a4SJeremy Kempand sample `CMakeLists.txt`
84*6fee86a4SJeremy Kemp
85*6fee86a4SJeremy Kemp```cmake
86*6fee86a4SJeremy Kempcmake_minimum_required(VERSION 3.0)
87*6fee86a4SJeremy Kempcmake_policy(VERSION 3.0...3.18.4)
88*6fee86a4SJeremy Kempproject(proj)
89*6fee86a4SJeremy Kempadd_executable(app main.cpp)
90*6fee86a4SJeremy Kempfind_package(OpenCLHeaders REQUIRED)
91*6fee86a4SJeremy Kempfind_package(OpenCLICDLoader REQUIRED)
92*6fee86a4SJeremy Kempfind_package(OpenCLHeadersCpp REQUIRED)
93*6fee86a4SJeremy Kemptarget_link_libraries(app PRIVATE OpenCL::Headers OpenCL::OpenCL OpenCL::HeadersCpp)
94*6fee86a4SJeremy Kemp```
95