the CUDA Programming Guide said that any atomic operation can be implemented using atomicCAS()
, and gives an example of atomic double add:
__device__ float single(double *address,double val)
{
unsigned long long int *address_as_ull =(unsigned long long int*)address;
unsigned long long int assumed;
unsigned long long int old = *address_as_ull;
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);
}
now,I face the problem that:
I want to write a function that can operate two variables address atomically.
for example: atomic add about two variable
input
double *address_1, int *address_2
double val_1,int val_2
result
*address_1 = *address_1+val_1;
*address_2 = *address_2+val_2;
how can I deal with the problem? thanks.