Created
March 17, 2025 13:07
-
-
Save tomix1024/92396ecc5480964d6626b101abbf12b9 to your computer and use it in GitHub Desktop.
CUDA float atomicMax
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
| // 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