1. 程式人生 > >錯誤:no instance of overloaded function "atomicMin" matches the argument list

錯誤:no instance of overloaded function "atomicMin" matches the argument list

復現論文實驗的時候,出現automicMin函式找不到的錯誤:

sssp.cu(196): error: no instance of overloaded function "atomicMin" matches the argument list

argument types are: (float *, float)

nvidia GPU 只支援整數型的操作,sm_35之後也只支援64位整數引數,如果需要使用float型的原子操作,可以用如下函式代替:

__device__ static float atomicMin(float* address, float val)

{

int* address_as_i = (int*) address;

int old = *address_as_i, assumed;

do {

assumed = old;

old = ::atomicCAS(address_as_i, assumed,

__float_as_int(::fminf(val, __int_as_float(assumed))));

} while (assumed != old);

return __int_as_float(old);

}