Simply adding two parentheses cl(...)
gives you error checking for OpenCL API functions that return a cl_int error code.
The second cl_ok(err)
macro is for error checking API functions that initialize their error code as an argument.
The header also includes a useful function for converting OpenCL errors to strings:
char const * clGetErrorString(cl_int const err);
Example 1:
cl(Finish(command_queue));
cl_ulong start_time,end_time;
cl(GetEventProfilingInfo(start == NULL ? end : start,
CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&start_time,NULL));
cl(GetEventProfilingInfo(end,
CL_PROFILING_COMMAND_END, sizeof(cl_ulong),&end_time, NULL));
elapsed_ns += end_time - start_time;
if (start != NULL)
cl(ReleaseEvent(start));
cl(ReleaseEvent(end));
Example 2:
cl_program program = clCreateProgramWithSource(context,
1,
strings,
strings_sizeof,
&err);
cl_ok(err);
char const * const options =
"-cl-std=CL2.0 -cl-fast-relaxed-math "
"-cl-no-signed-zeros -cl-mad-enable "
"-cl-denorms-are-zero "
"-cl-kernel-arg-info";
cl(BuildProgram(program,
1,
&device_id,
options,
NULL,
NULL));