Minimal working example of how to add two vectors on a computation device of choice using OpenCL and C++ API. Tested on OSX. Based mainly on exercise 3 from a wonderful Hands On OpenCL course.
- OpenCL 1.1 (or greater)
- C++11 compiler
- CMake 3.7
On never OSX versions some work needs to be done to make C++ header
for OpenCl available. 2 solved the issue for me, but I had to
put cl.hpp
in
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenCL.framework/Headers
instead of /System/Library/Frameworks/OpenCL.framework/Headers/
.
To build run the following commands from the project directory.
$ cmake -H. -B_build # -DCMAKE_EXPORT_COMPILE_COMMANDS=YES if you need compile_commands.json
$ ( cd _build/ && make )
$ ./_build/vadd # needs to be run from the same directory as vadd.cl