2727#include < atomic>
2828#endif
2929
30+ #if !defined(GPUCA_GPUCODE_COMPILEKERNELS) && (!defined(GPUCA_GPUCODE_DEVICE) || defined(__CUDACC__) || defined(__HIPCC__))
31+ #include < cstdint>
32+ #endif
33+
3034#if !defined(__OPENCL__) || defined(__OPENCLCPP__)
3135namespace GPUCA_NAMESPACE
3236{
@@ -75,13 +79,13 @@ class GPUCommonMath
7579 GPUd () static CONSTEXPR float Pi () { return 3 .1415927f ; }
7680 GPUd () static float Round (float x);
7781 GPUd () static float Floor (float x);
78- GPUd () static unsigned int Float2UIntReint (const float & x);
79- GPUd () static unsigned int Float2UIntRn (float x);
80- GPUd () static int Float2IntRn (float x);
82+ GPUd () static uint32_t Float2UIntReint (const float & x);
83+ GPUd () static uint32_t Float2UIntRn (float x);
84+ GPUd () static int32_t Float2IntRn (float x);
8185 GPUd () static float Modf (float x, float y);
8286 GPUd () static bool Finite (float x);
83- GPUd () static unsigned int Clz (unsigned int val);
84- GPUd () static unsigned int Popcount (unsigned int val);
87+ GPUd () static uint32_t Clz (uint32_t val);
88+ GPUd () static uint32_t Popcount (uint32_t val);
8589
8690 GPUhdni () static float Hypot (float x, float y);
8791 GPUhdni () static float Hypot (float x, float y, float z);
@@ -137,10 +141,10 @@ class GPUCommonMath
137141 {
138142 GPUCommonMath::AtomicMinInternal (addr, val);
139143 }
140- GPUd () static int Mul24 (int a, int b);
144+ GPUd () static int32_t Mul24 (int32_t a, int32_t b);
141145 GPUd () static float FMulRZ (float a, float b);
142146
143- template <int I, class T >
147+ template <int32_t I, class T >
144148 GPUd () CONSTEXPR static T nextMultipleOf (T val);
145149
146150#ifdef GPUCA_NOCOMPAT
@@ -163,11 +167,11 @@ class GPUCommonMath
163167
164168 private:
165169 template <class S , class T >
166- GPUd () static unsigned int AtomicExchInternal (S* addr, T val);
170+ GPUd () static uint32_t AtomicExchInternal (S* addr, T val);
167171 template <class S , class T >
168172 GPUd () static bool AtomicCASInternal (S* addr, T cmp, T val);
169173 template <class S , class T >
170- GPUd () static unsigned int AtomicAddInternal (S* addr, T val);
174+ GPUd () static uint32_t AtomicAddInternal (S* addr, T val);
171175 template <class S , class T >
172176 GPUd () static void AtomicMaxInternal (S* addr, T val);
173177 template <class S , class T >
@@ -185,7 +189,7 @@ typedef GPUCommonMath CAMath;
185189 #define CHOICE (c1, c2, c3 ) (c1) // Select first option for Host
186190#endif // clang-format on
187191
188- template <int I, class T >
192+ template <int32_t I, class T >
189193GPUdi () CONSTEXPR T GPUCommonMath::nextMultipleOf (T val)
190194{
191195 if CONSTEXPR (I & (I - 1 )) {
@@ -212,23 +216,23 @@ GPUdi() float2 GPUCommonMath::MakeFloat2(float x, float y)
212216
213217GPUdi () float GPUCommonMath::Modf (float x, float y) { return CHOICE (fmodf (x, y), fmodf (x, y), fmod (x, y)); }
214218
215- GPUdi () unsigned int GPUCommonMath::Float2UIntReint (const float & x)
219+ GPUdi () uint32_t GPUCommonMath::Float2UIntReint (const float & x)
216220{
217221#if defined(GPUCA_GPUCODE_DEVICE) && (defined(__CUDACC__) || defined(__HIPCC__))
218222 return __float_as_uint (x);
219223#elif defined(GPUCA_GPUCODE_DEVICE) && (defined(__OPENCL__) || defined(__OPENCLCPP__))
220224 return as_uint (x);
221225#else
222- return reinterpret_cast <const unsigned int &>(x);
226+ return reinterpret_cast <const uint32_t &>(x);
223227#endif
224228}
225229
226- GPUdi () unsigned int GPUCommonMath::Float2UIntRn (float x) { return (unsigned int )( int )(x + 0 .5f ); }
230+ GPUdi () uint32_t GPUCommonMath::Float2UIntRn (float x) { return (uint32_t )( int32_t )(x + 0 .5f ); }
227231GPUdi () float GPUCommonMath::Floor (float x) { return CHOICE (floorf (x), floorf (x), floor (x)); }
228232
229233#ifdef GPUCA_NO_FAST_MATH
230234GPUdi () float GPUCommonMath::Round(float x) { return CHOICE (roundf (x), roundf (x), round (x)); }
231- GPUdi () int GPUCommonMath::Float2IntRn(float x) { return (int )Round (x); }
235+ GPUdi () int32_t GPUCommonMath::Float2IntRn(float x) { return (int32_t )Round (x); }
232236GPUdi () bool GPUCommonMath::Finite(float x) { return CHOICE (std::isfinite (x), isfinite (x), true ); }
233237GPUhdi () float GPUCommonMath::Sqrt(float x) { return CHOICE (sqrtf (x), (float )sqrt ((double )x), sqrt (x)); }
234238GPUdi () float GPUCommonMath::ATan(float x) { return CHOICE ((float )atan ((double )x), (float )atan ((double )x), atan (x)); }
@@ -243,7 +247,7 @@ GPUdi() float GPUCommonMath::Log(float x) { return CHOICE((float)log((double)x),
243247GPUdi () float GPUCommonMath::Exp(float x) { return CHOICE ((float )exp ((double )x), (float )exp ((double )x), exp (x)); }
244248#else
245249GPUdi () float GPUCommonMath::Round(float x) { return CHOICE (roundf (x), rintf (x), rint (x)); }
246- GPUdi () int GPUCommonMath::Float2IntRn(float x) { return CHOICE ((int )Round (x), __float2int_rn (x), (int )Round (x)); }
250+ GPUdi () int32_t GPUCommonMath::Float2IntRn(float x) { return CHOICE ((int32_t )Round (x), __float2int_rn (x), (int32_t )Round (x)); }
247251GPUdi () bool GPUCommonMath::Finite(float x) { return CHOICE (std::isfinite (x), true , true ); }
248252GPUhdi () float GPUCommonMath::Sqrt(float x) { return CHOICE (sqrtf (x), sqrtf (x), sqrt (x)); }
249253GPUdi () float GPUCommonMath::ATan(float x) { return CHOICE (atanf (x), atanf (x), atan (x)); }
@@ -283,12 +287,12 @@ GPUhdi() void GPUCommonMath::SinCosd(double x, double& s, double& c)
283287#endif
284288}
285289
286- GPUdi () unsigned int GPUCommonMath::Clz (unsigned int x)
290+ GPUdi () uint32_t GPUCommonMath::Clz (uint32_t x)
287291{
288292#if (defined(__GNUC__) || defined(__clang__) || defined(__CUDACC__) || defined(__HIPCC__)) && (!defined(__OPENCL__) || defined(__OPENCLCPP__))
289293 return x == 0 ? 32 : CHOICE (__builtin_clz (x), __clz (x), __builtin_clz (x)); // use builtin if available
290294#else
291- for (int i = 31 ; i >= 0 ; i--) {
295+ for (int32_t i = 31 ; i >= 0 ; i--) {
292296 if (x & (1u << i)) {
293297 return (31 - i);
294298 }
@@ -297,7 +301,7 @@ GPUdi() unsigned int GPUCommonMath::Clz(unsigned int x)
297301#endif
298302}
299303
300- GPUdi () unsigned int GPUCommonMath::Popcount (unsigned int x)
304+ GPUdi () uint32_t GPUCommonMath::Popcount (uint32_t x)
301305{
302306#if (defined(__GNUC__) || defined(__clang__) || defined(__CUDACC__) || defined(__HIPCC__)) && (!defined(__OPENCL__) /* || defined(__OPENCLCPP__)*/ ) // TODO: remove OPENCLCPP workaround when reported SPIR-V bug is fixed
303307 // use builtin if available
@@ -404,7 +408,7 @@ GPUdi() float GPUCommonMath::InvSqrt(float _x)
404408#else
405409 union {
406410 float f;
407- int i;
411+ int32_t i;
408412 } x = {_x};
409413 const float xhalf = 0 .5f * x.f ;
410414 x.i = 0x5f3759df - (x.i >> 1 );
@@ -428,7 +432,7 @@ GPUhdi() double GPUCommonMath::Abs<double>(double x)
428432#endif
429433
430434template <>
431- GPUhdi () int GPUCommonMath::Abs<int >( int x)
435+ GPUhdi () int32_t GPUCommonMath::Abs<int32_t >( int32_t x)
432436{
433437 return CHOICE (abs (x), abs (x), abs (x));
434438}
@@ -448,7 +452,7 @@ GPUhdi() float GPUCommonMath::Copysign(float x, float y)
448452}
449453
450454template <class S , class T >
451- GPUdi () unsigned int GPUCommonMath::AtomicExchInternal (S* addr, T val)
455+ GPUdi () uint32_t GPUCommonMath::AtomicExchInternal (S* addr, T val)
452456{
453457#if defined(GPUCA_GPUCODE) && defined(__OPENCLCPP__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CPP_CLANG_C11_ATOMICS))
454458 return ::atomic_exchange (addr, val);
@@ -457,7 +461,7 @@ GPUdi() unsigned int GPUCommonMath::AtomicExchInternal(S* addr, T val)
457461#elif defined(GPUCA_GPUCODE) && (defined(__CUDACC__) || defined(__HIPCC__))
458462 return ::atomicExch (addr, val);
459463#elif defined(WITH_OPENMP)
460- unsigned int old;
464+ uint32_t old;
461465 __atomic_exchange (addr, &val, &old, __ATOMIC_SEQ_CST);
462466 return old;
463467#else
@@ -482,7 +486,7 @@ GPUdi() bool GPUCommonMath::AtomicCASInternal(S* addr, T cmp, T val)
482486}
483487
484488template <class S , class T >
485- GPUdi () unsigned int GPUCommonMath::AtomicAddInternal (S* addr, T val)
489+ GPUdi () uint32_t GPUCommonMath::AtomicAddInternal (S* addr, T val)
486490{
487491#if defined(GPUCA_GPUCODE) && defined(__OPENCLCPP__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CPP_CLANG_C11_ATOMICS))
488492 return ::atomic_fetch_add (addr, val);
@@ -538,9 +542,9 @@ GPUdii() void GPUCommonMath::AtomicMaxInternal(GPUglobalref() GPUgeneric() GPUAt
538542 val = 0 .f ;
539543 }
540544 if (val >= 0 ) {
541- AtomicMaxInternal ((GPUAtomic (int )*)addr, __float_as_int (val));
545+ AtomicMaxInternal ((GPUAtomic (int32_t )*)addr, __float_as_int (val));
542546 } else {
543- AtomicMinInternal ((GPUAtomic (unsigned int )*)addr, __float_as_uint (val));
547+ AtomicMinInternal ((GPUAtomic (uint32_t )*)addr, __float_as_uint (val));
544548 }
545549}
546550template <>
@@ -550,9 +554,9 @@ GPUdii() void GPUCommonMath::AtomicMinInternal(GPUglobalref() GPUgeneric() GPUAt
550554 val = 0 .f ;
551555 }
552556 if (val >= 0 ) {
553- AtomicMinInternal ((GPUAtomic (int )*)addr, __float_as_int (val));
557+ AtomicMinInternal ((GPUAtomic (int32_t )*)addr, __float_as_int (val));
554558 } else {
555- AtomicMaxInternal ((GPUAtomic (unsigned int )*)addr, __float_as_uint (val));
559+ AtomicMaxInternal ((GPUAtomic (uint32_t )*)addr, __float_as_uint (val));
556560 }
557561}
558562#endif
0 commit comments