assertOpenCL  September 19, 2018
Macros | Functions
assert.cl File Reference

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...
 

Detailed Description

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.

Macro Definition Documentation

◆ assert

#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.)

Parameters
testthe result of the assertion

Definition at line 162 of file assert.cl.

◆ ASSERT_CL_

#define ASSERT_CL_

Definition at line 542 of file assert.cl.

◆ ASSERT_DECLARE_PARAMS

#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.

Definition at line 124 of file assert.cl.

◆ 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.

Definition at line 118 of file assert.cl.

◆ assert_n

#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.)

Parameters
testthe result of the assertion
integer_value

Definition at line 177 of file assert.cl.

◆ assert_n_r

#define assert_n_r (   test,
  integer_value 
)
Value:
{ \
if (!assert_n(test, integer_value)) { \
return; \
} \
}
#define assert_n(test, integer_value)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:177

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

Parameters
testthe result of the assertion
integer_value

Definition at line 239 of file assert.cl.

◆ assert_n_r0

#define assert_n_r0 (   test,
  integer_value 
)
Value:
{ \
if (!assert_n(test, integer_value)) { \
return 0; \
} \
}
#define assert_n(test, integer_value)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:177

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

Parameters
testthe result of the assertion
integer_value

Definition at line 304 of file assert.cl.

◆ assert_n_x

#define assert_n_x (   test,
  integer_value,
  float_value 
)
Value:
assert_fct_(test, __FILE__, __LINE__, #test, \
integer_value, float_value, \
assert_result_, assert_result_float_)
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.
Definition: assert.cl:569

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

Parameters
testthe result of the assertion
integer_value
float_value

Definition at line 208 of file assert.cl.

◆ assert_n_x_r

#define assert_n_x_r (   test,
  integer_value,
  float_value 
)
Value:
{ \
if (!assert_n_x(test, integer_value, float_value)) { \
return; \
} \
}
#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_f...
Definition: assert.cl:208

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

Parameters
testthe result of the assertion
integer_value
float_value

Definition at line 272 of file assert.cl.

◆ assert_n_x_r0

#define assert_n_x_r0 (   test,
  integer_value,
  float_value 
)
Value:
{ \
if (!assert_n_x(test, integer_value, float_value)) { \
return 0; \
} \
}
#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_f...
Definition: assert.cl:208

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

Parameters
testthe result of the assertion
integer_value
float_value

Definition at line 337 of file assert.cl.

◆ ASSERT_PARAMS

#define ASSERT_PARAMS   , ASSERT_UNIQUE_PARAMS

Transmit the extra parameters in the calling of a function with ASSERT_DECLARE_PARAM.

Definition at line 136 of file assert.cl.

◆ assert_r

#define assert_r (   test)
Value:
{ \
if (!assert(test)) { \
return; \
} \
}
#define assert(test)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:162

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

Parameters
testthe result of the assertion

Definition at line 223 of file assert.cl.

◆ assert_r0

#define assert_r0 (   test)
Value:
{ \
if (!assert(test)) { \
return 0; \
} \
}
#define assert(test)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:162

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

Parameters
testthe result of the assertion

Definition at line 288 of file assert.cl.

◆ assert_reset

#define assert_reset
Value:
{ \
assert_result_[0] = 0; \
assert_result_[1] = 0; \
assert_result_float_[0] = 0.0; \
barrier(CLK_GLOBAL_MEM_FENCE); \
}

Clear previous assertions setting.

Definition at line 142 of file assert.cl.

◆ ASSERT_UNIQUE_PARAMS

#define ASSERT_UNIQUE_PARAMS   assert_result_, assert_result_float_

Transmit the extra parameters in the calling of a function with ASSERT_DECLARE_UNIQUE_PARAM.

Definition at line 130 of file assert.cl.

◆ assert_x

#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.)

Parameters
testthe result of the assertion
float_value

Definition at line 192 of file assert.cl.

◆ assert_x_r

#define assert_x_r (   test,
  float_value 
)
Value:
{ \
if (!assert_x(test, float_value)) { \
return; \
} \
}
#define assert_x(test, float_value)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:192

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

Parameters
testthe result of the assertion
float_value

Definition at line 255 of file assert.cl.

◆ assert_x_r0

#define assert_x_r0 (   test,
  float_value 
)
Value:
{ \
if (!assert_x(test, float_value)) { \
return 0; \
} \
}
#define assert_x(test, float_value)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:192

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

Parameters
testthe result of the assertion
float_value

Definition at line 320 of file assert.cl.

◆ last_assert

#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.)

Parameters
testthe result of the assertion

Definition at line 356 of file assert.cl.

◆ last_assert_n

#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.)

Parameters
testthe result of the assertion
integer_value

Definition at line 371 of file assert.cl.

◆ last_assert_n_r

#define last_assert_n_r (   test,
  integer_value 
)
Value:
{ \
if (!last_assert_n(test, integer_value)) { \
return; \
} \
}
#define last_assert_n(test, integer_value)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:371

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

Parameters
testthe result of the assertion
integer_value

Definition at line 433 of file assert.cl.

◆ last_assert_n_r0

#define last_assert_n_r0 (   test,
  integer_value 
)
Value:
{ \
if (!last_assert_n(test, integer_value)) { \
return 0; \
} \
}
#define last_assert_n(test, integer_value)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:371

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

Parameters
testthe result of the assertion
integer_value

Definition at line 498 of file assert.cl.

◆ last_assert_n_x

#define last_assert_n_x (   test,
  integer_value,
  float_value 
)
Value:
last_assert_fct_(test, __FILE__, __LINE__, #test, \
integer_value, float_value, \
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...
Definition: assert.cl:614

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

Parameters
testthe result of the assertion
integer_value
float_value

Definition at line 402 of file assert.cl.

◆ last_assert_n_x_r

#define last_assert_n_x_r (   test,
  integer_value,
  float_value 
)
Value:
{ \
if (!last_assert_n_x(test, integer_value, float_value)) { \
return; \
} \
}
#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_f...
Definition: assert.cl:402

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

Parameters
testthe result of the assertion
integer_value
float_value

Definition at line 466 of file assert.cl.

◆ last_assert_n_x_r0

#define last_assert_n_x_r0 (   test,
  integer_value,
  float_value 
)
Value:
{ \
if (!last_assert_n_x(test, integer_value, float_value)) { \
return 0; \
} \
}
#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_f...
Definition: assert.cl:402

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

Parameters
testthe result of the assertion
integer_value
float_value

Definition at line 531 of file assert.cl.

◆ last_assert_r

#define last_assert_r (   test)
Value:
{ \
if (!last_assert(test)) { \
return; \
} \
}
#define last_assert(test)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:356

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

Parameters
testthe result of the assertion

Definition at line 417 of file assert.cl.

◆ last_assert_r0

#define last_assert_r0 (   test)
Value:
{ \
if (!last_assert(test)) { \
return 0; \
} \
}
#define last_assert(test)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:356

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

Parameters
testthe result of the assertion

Definition at line 482 of file assert.cl.

◆ last_assert_x

#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.)

Parameters
testthe result of the assertion
float_value

Definition at line 386 of file assert.cl.

◆ last_assert_x_r

#define last_assert_x_r (   test,
  float_value 
)
Value:
{ \
if (!last_assert_x(test, float_value)) { \
return; \
} \
}
#define last_assert_x(test, float_value)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:386

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

Parameters
testthe result of the assertion
float_value

Definition at line 449 of file assert.cl.

◆ last_assert_x_r0

#define last_assert_x_r0 (   test,
  float_value 
)
Value:
{ \
if (!last_assert_x(test, float_value)) { \
return 0; \
} \
}
#define last_assert_x(test, float_value)
If test is true then do nothing. Else init (if they are still null) assert_result and assert_result_f...
Definition: assert.cl:386

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

Parameters
testthe result of the assertion
float_value

Definition at line 514 of file assert.cl.

Function Documentation

◆ assert_fct_()

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.

Parameters
testthe result of the assertion
filenamethe filename of the OpenCL file
linethe line number of the assertion in filename to store in assert_result[0]
assertionthe string representation of the assertion checked
integer_valuea integer value to store in assert_result[1]
float_valuea float value to store in assert_result_float[0]
assert_result
assert_result_float
Returns
test

Definition at line 569 of file assert.cl.

◆ last_assert_fct_()

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.

Parameters
testthe result of the assertion
filenamethe filename of the OpenCL file
linethe line number of the assertion in filename to store in assert_result[0]
assertionthe string representation of the assertion checked
integer_valuea integer value to store in assert_result[1]
float_valuea float value to store in assert_result_float[0]
assert_result
assert_result_float
Returns
test

Definition at line 614 of file assert.cl.