cuda float atomic操作
Posted redips
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cuda float atomic操作相关的知识,希望对你有一定的参考价值。
atomic add.用第二个,暂时还没弄明白
#ifdef FLOAT #define T float #else #define T int #endif #ifdef FORUM __device__ inline void atomicAdd(float *address, float val){ int i_val = __float_as_int(val); int tmp0 = 0; int tmp1; while( (tmp1 = atomicCAS((int *)address, tmp0, i_val)) != tmp0) { tmp0 = tmp1; i_val = __float_as_int(val + __int_as_float(tmp1)); } } #else __device__ inline float atomicAdd(float* address, float value){ float old = value; float ret=atomicExch(address, 0.0f); float new_old=ret+old; while ((old = atomicExch(address, new_old))!=0.0f){ new_old = atomicExch(address, 0.0f); new_old += old; } return ret; }; #endif
atomic min
__device__ float fatomicMin(float *addr,float value){ float old = *addr, assumed; if(old<=value) return old; do { assumed = old; old = atomicCAS((int*)addr, __float_as_int(assumed), __float_as_int(MIN(value, assumed))); }while(old!=assumed); return old; };
以上是关于cuda float atomic操作的主要内容,如果未能解决你的问题,请参考以下文章
Atom编辑器折腾记_(15)JS代码片段补全(插件:javascript-snippets)