Skip to content

Instantly share code, notes, and snippets.

@tomix1024
Created March 17, 2025 13:07
Show Gist options
  • Select an option

  • Save tomix1024/92396ecc5480964d6626b101abbf12b9 to your computer and use it in GitHub Desktop.

Select an option

Save tomix1024/92396ecc5480964d6626b101abbf12b9 to your computer and use it in GitHub Desktop.
CUDA float atomicMax
// Implementation of atomicMax function for float
__device__ static float atomicMax(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(::fmaxf(val, __int_as_float(assumed))));
} while (assumed != old);
return __int_as_float(old);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment