assertOpenCL
September 19, 2018
|
C-like assert alternative (because assert doesn't exist in OpenCL), with necessary helper macros to transmit information to the host. More...
Go to the source code of this file.
Macros | |
#define | ASSERT_DECLARE_UNIQUE_PARAMS __global unsigned long* const assert_result_, __global float* const assert_result_float_ |
Declare extra parameters in the signature (without other params) of kernel function or other functions that use assertions. More... | |
#define | ASSERT_DECLARE_PARAMS , ASSERT_DECLARE_UNIQUE_PARAMS |
Declare extra parameters in the signature (with other params) of kernel function or other functions that use assertions. More... | |
#define | ASSERT_UNIQUE_PARAMS assert_result_, assert_result_float_ |
Transmit the extra parameters in the calling of a function with ASSERT_DECLARE_UNIQUE_PARAM. More... | |
#define | ASSERT_PARAMS , ASSERT_UNIQUE_PARAMS |
Transmit the extra parameters in the calling of a function with ASSERT_DECLARE_PARAM. More... | |
#define | assert_reset |
Clear previous assertions setting. More... | |
#define | assert(test) assert_n_x(test, 0, 0.0) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value 0 and 0.0, and print (if at least OpenCL 1.2) an assertion message. More... | |
#define | assert_n(test, integer_value) assert_n_x(test, integer_value, 0.0) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value integer_value and 0.0, and print (if at least OpenCL 1.2) an assertion message. More... | |
#define | assert_x(test, float_value) assert_n_x(test, 0, float_value) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value 0 and float_value, and print (if at least OpenCL 1.2) an assertion message. More... | |
#define | assert_n_x(test, integer_value, float_value) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value integer_value and float_value, and print (if at least OpenCL 1.2) an assertion message. More... | |
#define | assert_r(test) |
Like assert() but if assertion failed then return. More... | |
#define | assert_n_r(test, integer_value) |
Like assert_n() but if assertion failed then return. More... | |
#define | assert_x_r(test, float_value) |
Like assert_x() but if assertion failed then return. More... | |
#define | assert_n_x_r(test, integer_value, float_value) |
Like assert_n_x() but if assertion failed then return. More... | |
#define | assert_r0(test) |
Like assert() but if assertion failed then return 0. More... | |
#define | assert_n_r0(test, integer_value) |
Like assert_n() but if assertion failed then return 0. More... | |
#define | assert_x_r0(test, float_value) |
Like assert_x() but if assertion failed then return 0. More... | |
#define | assert_n_x_r0(test, integer_value, float_value) |
Like assert_n_x() but if assertion failed then return 0. More... | |
#define | last_assert(test) last_assert_n_x(test, 0, 0.0) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value 0 and 0.0, and print (if at least OpenCL 1.2) an assertion message. More... | |
#define | last_assert_n(test, integer_value) last_assert_n_x(test, integer_value, 0.0) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value integer_value and 0.0, and print (if at least OpenCL 1.2) an assertion message. More... | |
#define | last_assert_x(test, float_value) last_assert_n_x(test, 0, float_value) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value 0 and float_value, and print (if at least OpenCL 1.2) an assertion message. More... | |
#define | last_assert_n_x(test, integer_value, float_value) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value integer_value and float_value, and print (if at least OpenCL 1.2) an assertion message. More... | |
#define | last_assert_r(test) |
Like last_assert() but if assertion failed then return. More... | |
#define | last_assert_n_r(test, integer_value) |
Like last_assert_n() but if assertion failed then return. More... | |
#define | last_assert_x_r(test, float_value) |
Like last_assert_x() but if assertion failed then return. More... | |
#define | last_assert_n_x_r(test, integer_value, float_value) |
Like last_assert_n_x() but if assertion failed then return. More... | |
#define | last_assert_r0(test) |
Like last_assert() but if assertion failed then return 0. More... | |
#define | last_assert_n_r0(test, integer_value) |
Like last_assert_n() but if assertion failed then return 0. More... | |
#define | last_assert_x_r0(test, float_value) |
Like last_assert_x() but if assertion failed then return 0. More... | |
#define | last_assert_n_x_r0(test, integer_value, float_value) |
Like last_assert_n_x() but if assertion failed then return 0. More... | |
#define | ASSERT_CL_ |
Functions | |
bool | assert_fct_ (const bool test, __constant char *const filename, const unsigned int line, __constant char *const assertion, const unsigned long integer_value, const float float_value, __global unsigned long *const assert_result, __global float *const assert_result_float) |
Generic function called by all assert*() macros in debug mode. More... | |
bool | last_assert_fct_ (const bool test, __constant char *const filename, const unsigned int line, __constant char *const assertion, const unsigned long integer_value, const float float_value, __global unsigned long *const assert_result, __global float *const assert_result_float) |
Generic function called by all last_assert*() macros in debug mode. Similar to assert_fct_() but sets results transmit to the host for each assert that fails instead only the first. More... | |
C-like assert alternative (because assert doesn't exist in OpenCL), with necessary helper macros to transmit information to the host.
If macro NDEBUG is defined or macro NASSERT is defined then these assert*() macros are simply ignored.
The behavior is similar of C assert but instead abort when an assertion failed a message is printed (if at least OpenCL 1.2) and two buffers are used to transmit the information of the first assertion failed to the host program.
See examples of use in examples/kernel/example.cl
C assert documentation: https://en.cppreference.com/w/c/error/assert
Piece of assertOpenCL — GPLv3 — Copyright (C) 2018 Olivier Pirson — http://www.opimedia.be/ — September 16, 2018
Definition in file assert.cl.
#define assert | ( | test | ) | assert_n_x(test, 0, 0.0) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value 0 and 0.0, and print (if at least OpenCL 1.2) an assertion message.
(If assertions are disabled then do nothing.)
test | the result of the assertion |
#define ASSERT_DECLARE_PARAMS , ASSERT_DECLARE_UNIQUE_PARAMS |
#define ASSERT_DECLARE_UNIQUE_PARAMS __global unsigned long* const assert_result_, __global float* const assert_result_float_ |
Declare extra parameters in the signature (without other params) of kernel function or other functions that use assertions.
assert_result_ is two int on 64 bits that will contain the line number and the integer value. assert_result_float_ is one float on 32 bits that will contain the floating value.
#define assert_n | ( | test, | |
integer_value | |||
) | assert_n_x(test, integer_value, 0.0) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value integer_value and 0.0, and print (if at least OpenCL 1.2) an assertion message.
(If assertions are disabled then do nothing.)
test | the result of the assertion |
integer_value |
#define assert_n_r | ( | test, | |
integer_value | |||
) |
Like assert_n() but if assertion failed then return.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
integer_value |
#define assert_n_r0 | ( | test, | |
integer_value | |||
) |
Like assert_n() but if assertion failed then return 0.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
integer_value |
#define assert_n_x | ( | test, | |
integer_value, | |||
float_value | |||
) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value integer_value and float_value, and print (if at least OpenCL 1.2) an assertion message.
(If assertions are disabled then do nothing.)
test | the result of the assertion |
integer_value | |
float_value |
#define assert_n_x_r | ( | test, | |
integer_value, | |||
float_value | |||
) |
Like assert_n_x() but if assertion failed then return.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
integer_value | |
float_value |
#define assert_n_x_r0 | ( | test, | |
integer_value, | |||
float_value | |||
) |
Like assert_n_x() but if assertion failed then return 0.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
integer_value | |
float_value |
#define ASSERT_PARAMS , ASSERT_UNIQUE_PARAMS |
#define assert_r | ( | test | ) |
Like assert() but if assertion failed then return.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
#define assert_r0 | ( | test | ) |
Like assert() but if assertion failed then return 0.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
#define assert_reset |
#define ASSERT_UNIQUE_PARAMS assert_result_, assert_result_float_ |
#define assert_x | ( | test, | |
float_value | |||
) | assert_n_x(test, 0, float_value) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value 0 and float_value, and print (if at least OpenCL 1.2) an assertion message.
(If assertions are disabled then do nothing.)
test | the result of the assertion |
float_value |
#define assert_x_r | ( | test, | |
float_value | |||
) |
Like assert_x() but if assertion failed then return.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
float_value |
#define assert_x_r0 | ( | test, | |
float_value | |||
) |
Like assert_x() but if assertion failed then return 0.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
float_value |
#define last_assert | ( | test | ) | last_assert_n_x(test, 0, 0.0) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value 0 and 0.0, and print (if at least OpenCL 1.2) an assertion message.
(If assertions are disabled then do nothing.)
test | the result of the assertion |
#define last_assert_n | ( | test, | |
integer_value | |||
) | last_assert_n_x(test, integer_value, 0.0) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value integer_value and 0.0, and print (if at least OpenCL 1.2) an assertion message.
(If assertions are disabled then do nothing.)
test | the result of the assertion |
integer_value |
#define last_assert_n_r | ( | test, | |
integer_value | |||
) |
Like last_assert_n() but if assertion failed then return.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
integer_value |
#define last_assert_n_r0 | ( | test, | |
integer_value | |||
) |
Like last_assert_n() but if assertion failed then return 0.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
integer_value |
#define last_assert_n_x | ( | test, | |
integer_value, | |||
float_value | |||
) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value integer_value and float_value, and print (if at least OpenCL 1.2) an assertion message.
(If assertions are disabled then do nothing.)
test | the result of the assertion |
integer_value | |
float_value |
#define last_assert_n_x_r | ( | test, | |
integer_value, | |||
float_value | |||
) |
Like last_assert_n_x() but if assertion failed then return.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
integer_value | |
float_value |
#define last_assert_n_x_r0 | ( | test, | |
integer_value, | |||
float_value | |||
) |
Like last_assert_n_x() but if assertion failed then return 0.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
integer_value | |
float_value |
#define last_assert_r | ( | test | ) |
Like last_assert() but if assertion failed then return.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
#define last_assert_r0 | ( | test | ) |
Like last_assert() but if assertion failed then return 0.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
#define last_assert_x | ( | test, | |
float_value | |||
) | last_assert_n_x(test, 0, float_value) |
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_float with value 0 and float_value, and print (if at least OpenCL 1.2) an assertion message.
(If assertions are disabled then do nothing.)
test | the result of the assertion |
float_value |
#define last_assert_x_r | ( | test, | |
float_value | |||
) |
Like last_assert_x() but if assertion failed then return.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
float_value |
#define last_assert_x_r0 | ( | test, | |
float_value | |||
) |
Like last_assert_x() but if assertion failed then return 0.
Be careful if you have some barriers: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
test | the result of the assertion |
float_value |
bool assert_fct_ | ( | const bool | test, |
__constant char *const | filename, | ||
const unsigned int | line, | ||
__constant char *const | assertion, | ||
const unsigned long | integer_value, | ||
const float | float_value, | ||
__global unsigned long *const | assert_result, | ||
__global float *const | assert_result_float | ||
) |
Generic function called by all assert*() macros in debug mode.
If test is true then do nothing and return true. Else init (if they are still null) assert_result and assert_result_float, print (if at least OpenCL 1.2) an assertion message and return false.
test | the result of the assertion |
filename | the filename of the OpenCL file |
line | the line number of the assertion in filename to store in assert_result[0] |
assertion | the string representation of the assertion checked |
integer_value | a integer value to store in assert_result[1] |
float_value | a float value to store in assert_result_float[0] |
assert_result | |
assert_result_float |
bool last_assert_fct_ | ( | const bool | test, |
__constant char *const | filename, | ||
const unsigned int | line, | ||
__constant char *const | assertion, | ||
const unsigned long | integer_value, | ||
const float | float_value, | ||
__global unsigned long *const | assert_result, | ||
__global float *const | assert_result_float | ||
) |
Generic function called by all last_assert*() macros in debug mode. Similar to assert_fct_() but sets results transmit to the host for each assert that fails instead only the first.
If test is true then do nothing and return true. Else set assert_result and assert_result_float, print (if at least OpenCL 1.2) an assertion message and return false.
test | the result of the assertion |
filename | the filename of the OpenCL file |
line | the line number of the assertion in filename to store in assert_result[0] |
assertion | the string representation of the assertion checked |
integer_value | a integer value to store in assert_result[1] |
float_value | a float value to store in assert_result_float[0] |
assert_result | |
assert_result_float |