GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSTypes.hh
Go to the documentation of this file.
1 #ifndef GUARD_GGEMS_TOOLS_GGEMSTYPES_HH
2 #define GUARD_GGEMS_TOOLS_GGEMSTYPES_HH
3 
4 // ************************************************************************
5 // * This file is part of GGEMS. *
6 // * *
7 // * GGEMS is free software: you can redistribute it and/or modify *
8 // * it under the terms of the GNU General Public License as published by *
9 // * the Free Software Foundation, either version 3 of the License, or *
10 // * (at your option) any later version. *
11 // * *
12 // * GGEMS is distributed in the hope that it will be useful, *
13 // * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 // * GNU General Public License for more details. *
16 // * *
17 // * You should have received a copy of the GNU General Public License *
18 // * along with GGEMS. If not, see <https://www.gnu.org/licenses/>. *
19 // * *
20 // ************************************************************************
21 
34 #define FALSE 0
35 #define TRUE 1
37 #define CL_HPP_TARGET_OPENCL_VERSION 120
38 #define CL_HPP_MINIMUM_OPENCL_VERSION 120
40 #ifdef __OPENCL_C_VERSION__ // On OpenCL device
41 #define GGchar char
42 #define GGchar2 char2
43 #define GGchar3 char3
44 #define GGchar4 char4
45 #define GGchar8 char8
46 #define GGchar16 char16
48 #define GGuchar uchar
49 #define GGuchar2 uchar2
50 #define GGuchar3 uchar3
51 #define GGuchar4 uchar4
52 #define GGuchar8 uchar8
53 #define GGuchar16 uchar16
55 #define GGshort short
56 #define GGshort2 short2
57 #define GGshort3 short3
58 #define GGshort4 short4
59 #define GGshort8 short8
60 #define GGshort16 short16
62 #define GGushort ushort
63 #define GGushort2 ushort2
64 #define GGushort3 ushort3
65 #define GGushort4 ushort4
66 #define GGushort8 ushort8
67 #define GGushort16 ushort16
69 #define GGint int
70 #define GGint2 int2
71 #define GGint3 int3
72 #define GGint4 int4
73 #define GGint8 int8
74 #define GGint16 int16
76 #define GGuint uint
77 #define GGuint2 uint2
78 #define GGuint3 uint3
79 #define GGuint4 uint4
80 #define GGuint8 uint8
81 #define GGuint16 uint16
83 #define GGlong long
84 #define GGlong2 long2
85 #define GGlong3 long3
86 #define GGlong4 long4
87 #define GGlong8 long8
88 #define GGlong16 long16
90 #define GGulong ulong
91 #define GGulong2 ulong2
92 #define GGulong3 ulong3
93 #define GGulong4 ulong4
94 #define GGulong8 ulong8
95 #define GGulong16 ulong16
97 #define GGsize GGulong
99 #define GGfloat float
100 #define GGfloat2 float2
101 #define GGfloat3 float3
102 #define GGfloat4 float4
103 #define GGfloat8 float8
104 #define GGfloat16 float16
106 #if defined(cl_khr_fp64) // Khronos extension available?
107 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
108 #elif defined(cl_amd_fp64) // AMD extension available?
109 #pragma OPENCL EXTENSION cl_amd_fp64 : enable
110 #endif
111 
112 #define GGdouble double
113 #define GGdouble2 double2
114 #define GGdouble3 double3
115 #define GGdouble4 double4
116 #define GGdouble8 double8
117 #define GGdouble16 double16
119 #ifdef DOSIMETRY_DOUBLE_PRECISION
120 #define GGDosiType GGdouble
122 #if defined(cl_khr_int64_base_atomics)
123 #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable
124 #else
125 #error "Int64 atomic operation not available on your OpenCL device!!! Please recompile GGEMS setting DOSIMETRY_DOUBLE_PRECISION to OFF."
126 #endif
127 
128 #else
129 #define GGDosiType GGfloat
130 #endif
131 
135 
142 inline void AtomicAddFloat(volatile global GGDosiType* address, GGfloat val)
143 {
144  union {
145  GGuint u32;
146  GGfloat f32;
147  } next, expected, current;
148 
149  current.f32 = *address;
150 
151  do {
152  expected.f32 = current.f32;
153  next.f32 = expected.f32 + val;
154  current.u32 = atomic_cmpxchg((volatile global GGuint*)address, expected.u32, next.u32);
155  } while(current.u32 != expected.u32);
156 }
157 
161 
168 #ifdef DOSIMETRY_DOUBLE_PRECISION
169 inline void AtomicAddDouble(volatile global GGDosiType* address, GGdouble val)
170 {
171  union {
172  GGulong u64;
173  GGdouble f64;
174  } next, expected, current;
175 
176  current.f64 = *address;
177 
178  do {
179  expected.f64 = current.f64;
180  next.f64 = expected.f64 + val;
181  current.u64 = atom_cmpxchg((volatile global GGulong*)address, expected.u64, next.u64);
182  } while(current.u64 != expected.u64);
183 }
184 #endif
185 
186 #else
187 
188 #ifdef __APPLE__
189 #include <OpenCL/opencl.hpp>
190 #else
191 #include <CL/cl.hpp>
192 #endif
193 
194 #define GGbool cl_bool
196 #define GGchar cl_char
197 #define GGchar2 cl_char2
198 #define GGchar3 cl_char3
199 #define GGchar4 cl_char4
200 #define GGchar8 cl_char8
201 #define GGchar16 cl_char16
203 #define GGuchar cl_uchar
204 #define GGuchar2 cl_uchar2
205 #define GGuchar3 cl_uchar3
206 #define GGuchar4 cl_uchar4
207 #define GGuchar8 cl_uchar8
208 #define GGuchar16 cl_uchar16
210 #define GGshort cl_short
211 #define GGshort2 cl_short2
212 #define GGshort3 cl_short3
213 #define GGshort4 cl_short4
214 #define GGshort8 cl_short8
215 #define GGshort16 cl_short16
217 #define GGushort cl_ushort
218 #define GGushort2 cl_ushort2
219 #define GGushort3 cl_ushort3
220 #define GGushort4 cl_ushort4
221 #define GGushort8 cl_ushort8
222 #define GGushort16 cl_ushort16
224 #define GGint cl_int
225 #define GGint2 cl_int2
226 #define GGint3 cl_int3
227 #define GGint4 cl_int4
228 #define GGint8 cl_int8
229 #define GGint16 cl_int16
231 #define GGuint cl_uint
232 #define GGuint2 cl_uint2
233 #define GGuint3 cl_uint3
234 #define GGuint4 cl_uint4
235 #define GGuint8 cl_uint8
236 #define GGuint16 cl_uint16
238 #define GGlong cl_long
239 #define GGlong2 cl_long2
240 #define GGlong3 cl_long3
241 #define GGlong4 cl_long4
242 #define GGlong8 cl_long8
243 #define GGlong16 cl_long16
245 #define GGulong cl_ulong
246 #define GGulong2 cl_ulong2
247 #define GGulong3 cl_ulong3
248 #define GGulong4 cl_ulong4
249 #define GGulong8 cl_ulong8
250 #define GGulong16 cl_ulong16
252 #define GGsize std::size_t
258 typedef struct GGsize2_t {
267 typedef struct GGsize3_t {
273 #define GGfloat cl_float
274 #define GGfloat2 cl_float2
275 #define GGfloat3 cl_float3
276 #define GGfloat4 cl_float4
277 #define GGfloat8 cl_float8
278 #define GGfloat16 cl_float16
280 #define GGdouble cl_double
281 #define GGdouble2 cl_double2
282 #define GGdouble3 cl_double3
283 #define GGdouble4 cl_double4
284 #define GGdouble8 cl_double8
285 #define GGdouble16 cl_double16
287 #ifdef DOSIMETRY_DOUBLE_PRECISION
288 #define GGDosiType GGdouble
289 #else
290 #define GGDosiType GGfloat
291 #endif
292 
293 #endif
294 
295 #endif // End of GUARD_GGEMS_TOOLS_GGEMSTYPES_HH
GGDosiType
#define GGDosiType
Definition: GGEMSTypes.hh:290
GGsize3_t
Structure storing 3 GGsize values.
Definition: GGEMSTypes.hh:267
GGulong
#define GGulong
Definition: GGEMSTypes.hh:245
GGsize2_t::x_
GGsize x_
Definition: GGEMSTypes.hh:259
GGsize2_t::y_
GGsize y_
Definition: GGEMSTypes.hh:260
GGsize3
struct GGsize3_t GGsize3
GGsize2
struct GGsize2_t GGsize2
GGsize
#define GGsize
Definition: GGEMSTypes.hh:252
GGsize3_t::z_
GGsize z_
Definition: GGEMSTypes.hh:270
GGsize3_t::x_
GGsize x_
Definition: GGEMSTypes.hh:268
GGdouble
#define GGdouble
Definition: GGEMSTypes.hh:280
GGuint
#define GGuint
Definition: GGEMSTypes.hh:231
GGfloat
#define GGfloat
Definition: GGEMSTypes.hh:273
GGsize3_t::y_
GGsize y_
Definition: GGEMSTypes.hh:269