4242 #define GPUCA_CHOICE (c1, c2, c3 ) (c1) // Select first option for Host
4343#endif // clang-format on
4444
45- namespace o2
46- {
47- namespace gpu
45+ namespace o2 ::gpu
4846{
4947
5048class GPUCommonMath
@@ -250,7 +248,7 @@ GPUdi() uint32_t GPUCommonMath::Float2UIntReint(const float& x)
250248#endif
251249}
252250
253- # ifdef GPUCA_DETERMINISTIC_MODE
251+ GPUCA_DETERMINISTIC_CODE ( // clang-format off
254252GPUdi () constexpr float GPUCommonMath::Round(float x) { return GPUCA_CHOICE (roundf (x), roundf (x), round (x)); }
255253GPUdi () constexpr int32_t GPUCommonMath::Float2IntRn(float x) { return (int32_t )Round (x); }
256254GPUhdi () constexpr float GPUCommonMath::Sqrt(float x) { return GPUCA_CHOICE (sqrtf (x), (float )sqrt ((double )x), sqrt (x)); }
@@ -266,7 +264,7 @@ GPUdi() constexpr float GPUCommonMath::Log(float x) { return GPUCA_CHOICE((float
266264GPUdi () constexpr float GPUCommonMath::Exp(float x) { return GPUCA_CHOICE ((float )exp ((double )x), (float )exp ((double )x), exp (x)); }
267265GPUdi () constexpr bool GPUCommonMath::Finite(float x) { return GPUCA_CHOICE (std::isfinite (x), isfinite (x), isfinite (x)); }
268266GPUdi () constexpr bool GPUCommonMath::IsNaN(float x) { return GPUCA_CHOICE (std::isnan (x), isnan (x), isnan (x)); }
269- # else
267+ , // !GPUCA_DETERMINISTIC_CODE
270268GPUdi () constexpr float GPUCommonMath::Round(float x) { return GPUCA_CHOICE (roundf (x), rintf (x), rint (x)); }
271269GPUdi () constexpr int32_t GPUCommonMath::Float2IntRn(float x) { return GPUCA_CHOICE ((int32_t )Round (x), __float2int_rn (x), (int32_t )Round (x)); }
272270GPUhdi () constexpr float GPUCommonMath::Sqrt(float x) { return GPUCA_CHOICE (sqrtf (x), sqrtf (x), sqrt (x)); }
@@ -282,20 +280,22 @@ GPUdi() constexpr float GPUCommonMath::Log(float x) { return GPUCA_CHOICE(logf(x
282280GPUdi () constexpr float GPUCommonMath::Exp(float x) { return GPUCA_CHOICE (expf (x), expf (x), exp (x)); }
283281GPUdi () constexpr bool GPUCommonMath::Finite(float x) { return true ; }
284282GPUdi () constexpr bool GPUCommonMath::IsNaN(float x) { return false ; }
285- # endif
283+ ) // clang-format on
286284
287285GPUhdi () void GPUCommonMath::SinCos (float x, float & s, float & c)
288286{
289- #if defined(GPUCA_DETERMINISTIC_MODE) && !defined(__OPENCL__)
290- s = sin ((double )x);
291- c = cos ((double )x);
292- #elif !defined(GPUCA_GPUCODE_DEVICE) && defined(__APPLE__)
293- __sincosf (x, &s, &c);
287+ GPUCA_DETERMINISTIC_CODE ( // clang-format off
288+ s = sin ((double )x);
289+ c = cos ((double )x);
290+ , // !GPUCA_DETERMINISTIC_CODE
291+ #if !defined(GPUCA_GPUCODE_DEVICE) && defined(__APPLE__)
292+ __sincosf (x, &s, &c);
294293#elif !defined(GPUCA_GPUCODE_DEVICE) && (defined(__GNU_SOURCE__) || defined(_GNU_SOURCE) || defined(GPUCA_GPUCODE))
295- sincosf (x, &s, &c);
294+ sincosf (x, &s, &c);
296295#else
297- GPUCA_CHOICE ((void )((s = sinf (x)) + (c = cosf (x))), sincosf (x, &s, &c), s = sincos (x, &c));
296+ GPUCA_CHOICE ((void )((s = sinf (x)) + (c = cosf (x))), sincosf (x, &s, &c), s = sincos (x, &c));
298297#endif
298+ ) // clang-format on
299299}
300300
301301GPUhdi () void GPUCommonMath::SinCosd (double x, double & s, double & c)
@@ -392,22 +392,26 @@ GPUdi() T GPUCommonMath::MaxWithRef(T x, T y, T z, T w, S refX, S refY, S refZ,
392392
393393GPUdi () float GPUCommonMath::InvSqrt (float _x)
394394{
395- #if defined(GPUCA_DETERMINISTIC_MODE) || defined(__OPENCL__)
396- return 1 .f / Sqrt (_x);
397- #elif defined(__CUDACC__) || defined(__HIPCC__)
398- return __frsqrt_rn (_x);
399- #elif defined(__FAST_MATH__)
400- return 1 .f / sqrtf (_x);
395+ GPUCA_DETERMINISTIC_CODE ( // clang-format off
396+ return 1 .f / Sqrt (_x);
397+ , // !GPUCA_DETERMINISTIC_CODE
398+ #if defined(__CUDACC__) || defined(__HIPCC__)
399+ return __frsqrt_rn (_x);
400+ #elif defined(__OPENCL__) && defined(__clang__)
401+ return 1 .f / sqrt (_x);
402+ #elif !defined(__OPENCL__) && (defined(__FAST_MATH__) || defined(__clang__))
403+ return 1 .f / sqrtf (_x);
401404#else
402- union {
403- float f;
404- int32_t i;
405- } x = {_x};
406- const float xhalf = 0 .5f * x.f ;
407- x.i = 0x5f3759df - (x.i >> 1 );
408- x.f = x.f * (1 .5f - xhalf * x.f * x.f );
409- return x.f ;
405+ union {
406+ float f;
407+ int32_t i;
408+ } x = {_x};
409+ const float xhalf = 0 .5f * x.f ;
410+ x.i = 0x5f3759df - (x.i >> 1 );
411+ x.f = x.f * (1 .5f - xhalf * x.f * x.f );
412+ return x.f ;
410413#endif
414+ ) // clang-format on
411415}
412416
413417template <>
@@ -540,7 +544,6 @@ GPUdii() void GPUCommonMath::AtomicMinInternal(GPUglobalref() GPUgeneric() GPUAt
540544
541545#undef GPUCA_CHOICE
542546
543- } // namespace gpu
544- } // namespace o2
547+ } // namespace o2::gpu
545548
546549#endif // GPUCOMMONMATH_H
0 commit comments