Skip to content

Instantly share code, notes, and snippets.

@HViktorTsoi
Created May 25, 2020 05:30
Show Gist options
  • Save HViktorTsoi/aac95284f8781a1a93f5dc79ee1cd991 to your computer and use it in GitHub Desktop.
Save HViktorTsoi/aac95284f8781a1a93f5dc79ee1cd991 to your computer and use it in GitHub Desktop.
atomic min CAS, cuda implementation
__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