assertOpenCL  September 19, 2018

assert() are not available in OpenCL. Here an implementation similar to the classic C implementation. A difference is that instead to exit when an assertion failed a message is printed (if at least OpenCL 1.2) and the first assertion (or the last) is transmitted to the host program (see examples of use with C/C++, Java, Scala and Python).

There are also some PRINT() macros to use printf() function when it is available and that do nothing if not.

Main absolute links:

assertOpenCL library files:

Example of use:

Examples of host program:

Additional tools:

Be careful with *_r() and *_r0() versions of assert*() when you have some barriers in your kernel. If at least one work-item reach the barrier, then all barriers have to reach it. See the official documentation of OpenCL to understand the constraints: barrier.


License: GPLv3

Copyright (C) 2018 Olivier Pirson
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see


Olivier Pirson