assertOpenCL  September 19, 2018
print.cl
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file OpenCL/print.cl
3  * \brief
4  * Helper macros to use printf() function during development
5  * when it is available (from OpenCL 1.2).
6  *
7  * If before OpenCL 1.2 or macro NDEBUG is defined or macro NPRINT is defined
8  * then these PRINT*() macros are simply ignored.
9  *
10  * See examples of use in examples/kernel/example.cl
11  *
12  * Official printf() function documentation:
13  * https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/printfFunction.html
14  *
15  * Piece of assertOpenCL
16  * --- GPLv3 --- Copyright (C) 2018 Olivier Pirson
17  * --- http://www.opimedia.be/
18  * --- September 16, 2018
19  */
20 
21 #ifdef NDEBUG
22 # ifndef DOXYGEN
23 # define NPRINT
24 # endif
25 #endif
26 
27 #if __OPENCL_C_VERSION__ < 120 // CL_VERSION_1_2
28 # ifndef DOXYGEN
29 # define NPRINT
30 # endif
31 #endif
32 
33 
34 
35 #undef PRINT
36 #undef PRINT1
37 #undef PRINT2
38 #undef PRINT3
39 #undef PRINT4
40 #undef PRINT5
41 #undef PRINT6
42 #undef PRINT7
43 #undef PRINT8
44 #undef PRINT9
45 
46 
47 
48 #ifdef NPRINT
49 # define PRINT(str) ((void)0)
50 
51 # define PRINT1(format, a) ((void)0)
52 # define PRINT2(format, a, b) ((void)0)
53 # define PRINT3(format, a, b, c) ((void)0)
54 # define PRINT4(format, a, b, c, d) ((void)0)
55 # define PRINT5(format, a, b, c, d, e) ((void)0)
56 # define PRINT6(format, a, b, c, d, e, f) ((void)0)
57 # define PRINT7(format, a, b, c, d, e, f, g) ((void)0)
58 # define PRINT8(format, a, b, c, d, e, f, g, h) ((void)0)
59 # define PRINT9(format, a, b, c, d, e, f, g, h, i) ((void)0)
60 
61 #else
62 /** \brief
63  * printf() function without paramters.
64  *
65  * @return int
66  */
67 # define PRINT(str) (printf(str))
68 
69 
70 /** \brief
71  * printf() function with 1 paramter.
72  *
73  * @return int
74  */
75 # define PRINT1(format, a) (printf(format, a))
76 
77 
78 /** \brief
79  * printf() function with 2 paramters.
80  *
81  * @return int
82  */
83 # define PRINT2(format, a, b) (printf(format, a, b))
84 
85 
86 /** \brief
87  * printf() function with 3 paramters.
88  *
89  * @return int
90  */
91 # define PRINT3(format, a, b, c) (printf(format, a, b, c))
92 
93 
94 /** \brief
95  * printf() function with 4 paramters.
96  *
97  * @return int
98  */
99 # define PRINT4(format, a, b, c, d) (printf(format, a, b, c, d))
100 
101 
102 /** \brief
103  * printf() function with 5 paramters.
104  *
105  * @return int
106  */
107 # define PRINT5(format, a, b, c, d, e) (printf(format, a, b, c, d, e))
108 
109 
110 /** \brief
111  * printf() function with 6 paramters.
112  *
113  * @return int
114  */
115 # define PRINT6(format, a, b, c, d, e, f) (printf(format, a, b, c, d, e, f))
116 
117 
118 /** \brief
119  * printf() function with 7 paramters.
120  *
121  * @return int
122  */
123 # define PRINT7(format, a, b, c, d, e, f, g) (printf(format, a, b, c, d, e, f, g))
124 
125 
126 /** \brief
127  * printf() function with 8 paramters.
128  *
129  * @return int
130  */
131 # define PRINT8(format, a, b, c, d, e, f, g, h) (printf(format, a, b, c, d, e, f, g, h))
132 
133 
134 /** \brief
135  * printf() function with 9 paramters.
136  *
137  * @return int
138  */
139 # define PRINT9(format, a, b, c, d, e, f, g, h, i) (printf(format, a, b, c, d, e, f, g, h, i))
140 #endif