Created
May 25, 2020 05:30
-
-
Save HViktorTsoi/aac95284f8781a1a93f5dc79ee1cd991 to your computer and use it in GitHub Desktop.
atomic min CAS, cuda implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__device__ float customAtomicMin( unsigned long long int* address, unsigned long long int newVal ) | |
{ | |
unsigned long long int old = *address, assumed; | |
if( *((float*)&old ) <= *((float*)&newVal) ) | |
return *((float*)&old); | |
do | |
{ | |
assumed = old; | |
if( *((float*)&assumed) <= *((float*)&newVal) ) | |
{ | |
break; | |
} | |
old = atomicCAS( address, assumed, newVal ); | |
} | |
while( assumed != old ); | |
return *((float*)&old); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment