Skip to content

Commit 6e809bf

Browse files
committed
Merge branch 'dev' into gpu_clusterizer
2 parents cc6c05c + 8b6b16c commit 6e809bf

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

GPU/Common/GPUCommonMath.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <cmath>
2626
#include <algorithm>
2727
#include <atomic>
28+
#include <limits>
29+
#include <cstring>
2830
#endif
2931

3032
#if !defined(GPUCA_GPUCODE_COMPILEKERNELS) && (!defined(GPUCA_GPUCODE_DEVICE) || defined(__CUDACC__) || defined(__HIPCC__))
@@ -83,9 +85,14 @@ class GPUCommonMath
8385
GPUd() static float Modf(float x, float y);
8486
GPUd() static bool Finite(float x);
8587
GPUd() static bool IsNaN(float x);
88+
GPUd() static bool FiniteRelaxed(float x); // always true if not using NO_FAST_MATH
89+
GPUd() static bool IsNaNRelaxed(float x); // always true if not using NO_FAST_MATH
90+
GPUd() static float QuietNaN();
8691
GPUd() static uint32_t Clz(uint32_t val);
8792
GPUd() static uint32_t Popcount(uint32_t val);
8893

94+
GPUd() static void memcpy(void* dst, const void* src, size_t size);
95+
8996
GPUhdni() static float Hypot(float x, float y);
9097
GPUhdni() static float Hypot(float x, float y, float z);
9198
GPUhdni() static float Hypot(float x, float y, float z, float w);
@@ -181,6 +188,23 @@ typedef GPUCommonMath CAMath;
181188
#define CHOICE(c1, c2, c3) (c1) // Select first option for Host
182189
#endif // clang-format on
183190

191+
GPUdi() void GPUCommonMath::memcpy(void* dst, const void* src, size_t size)
192+
{
193+
#ifndef GPUCA_GPUCODE_DEVICE
194+
std::memcpy(dst, src, size);
195+
#elif defined(__CUDACC__) || defined(__HIPCC__)
196+
::memcpy(dst, src, size);
197+
#elif defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
198+
__builtin_memcpy(dst, src, size);
199+
#else
200+
char* d = (char*)dst;
201+
const char* s = (const char*)src;
202+
for (size_t i = 0; i < size; i++) {
203+
d[i] = s[i];
204+
}
205+
#endif
206+
}
207+
184208
template <int32_t I, class T>
185209
GPUdi() constexpr T GPUCommonMath::nextMultipleOf(T val)
186210
{
@@ -222,11 +246,12 @@ GPUdi() uint32_t GPUCommonMath::Float2UIntReint(const float& x)
222246
GPUdi() uint32_t GPUCommonMath::Float2UIntRn(float x) { return (uint32_t)(int32_t)(x + 0.5f); }
223247
GPUdi() float GPUCommonMath::Floor(float x) { return CHOICE(floorf(x), floorf(x), floor(x)); }
224248

249+
GPUdi() bool GPUCommonMath::Finite(float x) { return CHOICE(std::isfinite(x), isfinite(x), isfinite(x)); }
250+
GPUdi() bool GPUCommonMath::IsNaN(float x) { return CHOICE(std::isnan(x), isnan(x), isnan(x)); }
251+
GPUdi() float GPUCommonMath::QuietNaN() { return CHOICE(std::numeric_limits<float>::quiet_NaN(), __builtin_nanf(""), nan(0u)); }
225252
#ifdef GPUCA_NO_FAST_MATH
226253
GPUdi() float GPUCommonMath::Round(float x) { return CHOICE(roundf(x), roundf(x), round(x)); }
227254
GPUdi() int32_t GPUCommonMath::Float2IntRn(float x) { return (int32_t)Round(x); }
228-
GPUdi() bool GPUCommonMath::Finite(float x) { return CHOICE(std::isfinite(x), isfinite(x), true); } // Fixme: fix these 2 for OpenCL
229-
GPUdi() bool GPUCommonMath::IsNaN(float x) { return CHOICE(std::isnan(x), isnan(x), false); }
230255
GPUhdi() float GPUCommonMath::Sqrt(float x) { return CHOICE(sqrtf(x), (float)sqrt((double)x), sqrt(x)); }
231256
GPUdi() float GPUCommonMath::ATan(float x) { return CHOICE((float)atan((double)x), (float)atan((double)x), atan(x)); }
232257
GPUhdi() float GPUCommonMath::ATan2(float y, float x) { return CHOICE((float)atan2((double)y, (double)x), (float)atan2((double)y, (double)x), atan2(y, x)); }
@@ -238,10 +263,11 @@ GPUdi() float GPUCommonMath::ASin(float x) { return CHOICE((float)asin((double)x
238263
GPUdi() float GPUCommonMath::ACos(float x) { return CHOICE((float)acos((double)x), (float)acos((double)x), acos(x)); }
239264
GPUdi() float GPUCommonMath::Log(float x) { return CHOICE((float)log((double)x), (float)log((double)x), log(x)); }
240265
GPUdi() float GPUCommonMath::Exp(float x) { return CHOICE((float)exp((double)x), (float)exp((double)x), exp(x)); }
266+
GPUdi() bool GPUCommonMath::FiniteRelaxed(float x) { return Finite(x); }
267+
GPUdi() bool GPUCommonMath::IsNaNRelaxed(float x) { return IsNaN(x); }
241268
#else
242269
GPUdi() float GPUCommonMath::Round(float x) { return CHOICE(roundf(x), rintf(x), rint(x)); }
243270
GPUdi() int32_t GPUCommonMath::Float2IntRn(float x) { return CHOICE((int32_t)Round(x), __float2int_rn(x), (int32_t)Round(x)); }
244-
GPUdi() bool GPUCommonMath::Finite(float x) { return CHOICE(std::isfinite(x), true, true); }
245271
GPUhdi() float GPUCommonMath::Sqrt(float x) { return CHOICE(sqrtf(x), sqrtf(x), sqrt(x)); }
246272
GPUdi() float GPUCommonMath::ATan(float x) { return CHOICE(atanf(x), atanf(x), atan(x)); }
247273
GPUhdi() float GPUCommonMath::ATan2(float y, float x) { return CHOICE(atan2f(y, x), atan2f(y, x), atan2(y, x)); }
@@ -253,6 +279,8 @@ GPUdi() float GPUCommonMath::ASin(float x) { return CHOICE(asinf(x), asinf(x), a
253279
GPUdi() float GPUCommonMath::ACos(float x) { return CHOICE(acosf(x), acosf(x), acos(x)); }
254280
GPUdi() float GPUCommonMath::Log(float x) { return CHOICE(logf(x), logf(x), log(x)); }
255281
GPUdi() float GPUCommonMath::Exp(float x) { return CHOICE(expf(x), expf(x), exp(x)); }
282+
GPUdi() bool GPUCommonMath::FiniteRelaxed(float x) { return true; }
283+
GPUdi() bool GPUCommonMath::IsNaNRelaxed(float x) { return false; }
256284
#endif
257285

258286
GPUhdi() void GPUCommonMath::SinCos(float x, float& s, float& c)

0 commit comments

Comments
 (0)