Skip to content

Commit 37716ad

Browse files
f3schclaude
andcommitted
GPUCommonMath: double functions, 64-bit bit counts, atomic load/store, host-device calls
Named double functions for GPUCommonMath::Sqrt,Sin,Cos,Tan,ASin,ACos,ATan,ATan2,Log,Copysign. Clz64, Ctz64, Popcount64: 64-bit counterparts of Clz, Ctz and Popcount on the same builtins and CUDA/HIP intrinsics. Named rather than uint64_t overloads, which would change existing calls with 64-bit arguments and make calls with int arguments ambiguous. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 3f159b8 commit 37716ad

3 files changed

Lines changed: 226 additions & 108 deletions

File tree

‎Common/MathUtils/include/MathUtils/detail/basicMath.h‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,25 @@ GPUdi() T log(T x)
9191
return o2::gpu::GPUCommonMath::Log(x);
9292
};
9393

94-
#ifndef GPUCA_GPUCODE_DEVICE // Double overloads using std namespace not visible on GPU
94+
#if !defined(GPUCA_GPUCODE_DEVICE) || defined(__CUDACC__) || defined(__HIPCC__) // Double specialisations, not for OpenCL and Metal
9595
template <>
9696
GPUhdi() double copysign(double x, double y)
9797
{
98-
return std::copysign(x, y);
98+
return o2::gpu::GPUCommonMath::Copysignd(x, y);
9999
}
100100
template <>
101101
GPUhdi() double sqrt(double x)
102102
{
103-
return std::sqrt(x);
103+
return o2::gpu::GPUCommonMath::Sqrtd(x);
104+
};
105+
template <>
106+
GPUdi() double log(double x)
107+
{
108+
return o2::gpu::GPUCommonMath::Logd(x);
104109
};
110+
#endif
111+
112+
#ifndef GPUCA_GPUCODE_DEVICE // Double overloads using std namespace not visible on GPU
105113
GPUhdi() double abs(double x)
106114
{
107115
return std::abs(x);
@@ -120,11 +128,6 @@ GPUdi() bool finite(double x)
120128
return std::isfinite(x);
121129
#endif
122130
}
123-
template <>
124-
GPUdi() double log(double x)
125-
{
126-
return std::log(x);
127-
};
128131
#endif
129132

130133
} // namespace detail

‎Common/MathUtils/include/MathUtils/detail/trigonometric.h‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ GPUhdi() constexpr T fastATan2(T y, T x)
299299
if (xx < 0) { // p1 is in the range [Pi/4, 3*Pi/4]
300300
phi0 = Pi075;
301301
tan = y1 > T(0) ? -x1 / y1 : T(0); // yy is always >=0, hence y1>=0
302-
} else { // p1 is in the range [-Pi/4, Pi/4]
302+
} else { // p1 is in the range [-Pi/4, Pi/4]
303303
phi0 = Pi025;
304304
tan = x1 > T(0) ? y1 / x1 : T(0);
305305
}
@@ -376,41 +376,41 @@ GPUdi() double pi()
376376
return o2::constants::math::PI;
377377
}
378378

379-
#ifndef GPUCA_GPUCODE_DEVICE
379+
#if !defined(GPUCA_GPUCODE_DEVICE) || defined(__CUDACC__) || defined(__HIPCC__) // Double specialisations, not for OpenCL and Metal
380380
template <>
381381
GPUdi() double tan(double x)
382382
{
383-
return std::tan(x);
383+
return o2::gpu::GPUCommonMath::Tand(x);
384384
};
385385
template <>
386386
GPUdi() double sin(double x)
387387
{
388-
return std::sin(x);
388+
return o2::gpu::GPUCommonMath::Sind(x);
389389
};
390390
template <>
391391
GPUdi() double atan2(double y, double x)
392392
{
393-
return std::atan2(y, x);
393+
return o2::gpu::GPUCommonMath::ATan2d(y, x);
394394
};
395395
template <>
396396
GPUdi() double atan(double x)
397397
{
398-
return std::atan(x);
398+
return o2::gpu::GPUCommonMath::ATand(x);
399399
};
400400
template <>
401401
GPUdi() double asin(double x)
402402
{
403-
return std::asin(x);
403+
return o2::gpu::GPUCommonMath::ASind(x);
404404
};
405405
template <>
406406
GPUdi() double acos(double x)
407407
{
408-
return std::acos(x);
408+
return o2::gpu::GPUCommonMath::ACosd(x);
409409
};
410410
template <>
411411
GPUdi() double cos(double x)
412412
{
413-
return std::cos(x);
413+
return o2::gpu::GPUCommonMath::Cosd(x);
414414
};
415415
#endif
416416

0 commit comments

Comments
 (0)