ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
kernel_compat.h
Go to the documentation of this file.
1#ifndef KERNEL_COMPAT_H_
2#define KERNEL_COMPAT_H_
3
17// atomicAdd for double precision - required for CUDA architectures < 600 (pre-Pascal)
18#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 600 && !defined(__CUDA_ON_DCU)
19static __inline__ __device__ double atomicAdd(double* address, double val)
20{
21 unsigned long long int* address_as_ull = (unsigned long long int*)address;
22 unsigned long long int old = *address_as_ull, assumed;
23 do
24 {
25 assumed = old;
26 old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val + __longlong_as_double(assumed)));
27 // Note: uses integer comparison to avoid hang in case of NaN (since NaN != NaN)
28 } while (assumed != old);
29 return __longlong_as_double(old);
30}
31#endif
32
33#endif // KERNEL_COMPAT_H_