OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1719 Discussions

A macro for neatly error-checking OpenCL API functions.

allanmac1
Beginner
503 Views

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);

 

0 Kudos
1 Reply
allanmac1
Beginner
503 Views

There appears to be no way to edit a "first post".

Typo: 

Simply adding two ellipses parentheses will give you OpenCL API error checking for those functions that return a cl_int error code.

I was thinking too much about vararg ellipses!

0 Kudos
Reply