Here are some macros that I use to error check my OpenCL API functions:
https://gist.github.com/allanmac/9328bb2d6a99b86883195f8f78fd1b93
The two macros of interest are:
#define cl(...) cl_assert((cl##__VA_ARGS__), __FILE__, __LINE__, true); #define cl_ok(err) cl_assert(err, __FILE__, __LINE__, true);
And they're used like this:
cl_program program = clCreateProgramWithBinary(context,
1,&device_id,
bins_sizeof,
bins,&status,&err);
cl_ok(err);
cl(BuildProgram(program,
1,
&device_id,
NULL,
NULL,
NULL));
Simply adding two ellipses will give you OpenCL API error checking to those OpenCL functions that return a cl_int error code.
The second "cl_ok(err)" form handles API functions that initialize an error as an argument.
Note there is also a useful function for converting OpenCL errors to strings:
char const * clGetErrorString(cl_int const err);