16 #ifndef dealii_cuda_atomic_h
17 #define dealii_cuda_atomic_h
21 #ifdef DEAL_II_COMPILER_CUDA_AWARE
34 inline __device__
float
37 return atomicAdd(address, val);
47 inline __device__
double
51 # if __CUDACC_VER_MAJOR__ >= 8 && \
52 (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600)
53 return atomicAdd(address, val);
56 unsigned long long int *address_as_ull =
57 reinterpret_cast<unsigned long long int *
>(address);
58 unsigned long long int old = *address_as_ull, assumed;
62 old = atomicCAS(address_as_ull,
64 __double_as_longlong(val +
65 __longlong_as_double(assumed)));
67 while (assumed != old);
69 return __longlong_as_double(old);
80 inline __device__
float
83 int *address_as_int =
reinterpret_cast<int *
>(address);
84 int old = *address_as_int, assumed;
88 old = atomicCAS(address_as_int,
90 atomicMax(address_as_int, __float_as_int(val)));
92 while (assumed != old);
94 return __longlong_as_double(old);
104 inline __device__
double
107 unsigned long long int *address_as_ull =
108 reinterpret_cast<unsigned long long int *
>(address);
109 unsigned long long int old = *address_as_ull, assumed;
113 old = atomicCAS(address_as_ull,
115 atomicMax(address_as_ull,
116 static_cast<unsigned long long int>(
117 __double_as_longlong(val))));
119 while (assumed != old);
121 return __longlong_as_double(old);