Why hasnt atomicAdd()
for doubles been implemented explicitly as a part of CUDA 4.0 or higher?
From the appendix F Page 97 of the CUDA programming guide 4.1 the following versions of atomicAdd have been implemented.
int atomicAdd(int* address, int val);
unsigned int atomicAdd(unsigned int* address,
unsigned int val);
unsigned long long int atomicAdd(unsigned long long int* address,
unsigned long long int val);
float atomicAdd(float* address, float val)
The same page goes on to give a small implementation of atomicAdd for doubles as follows which I have just started using in my project.
__device__ double atomicAdd(double* address, double val)
{
unsigned long long int* address_as_ull =
(unsigned long long int*)address;
unsigned long long int old = *address_as_ull, assumed;
do {
assumed = old;
old = atomicCAS(address_as_ull, assumed,
__double_as_longlong(val +
__longlong_as_double(assumed)));
} while (assumed != old);
return __longlong_as_double(old);
}
Why not define the above code as a part of CUDA ?