Created
July 24, 2015 15:06
-
-
Save sklam/2b9574b51c6bd2e6cf9e to your computer and use it in GitHub Desktop.
numba cuda random device function
This file contains 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
MAX32 = uint32(0xffffffff) | |
@cuda.jit("(uint64[::1], uint64)", device=True) | |
def cuda_xorshift(states, id): | |
x = states[id] | |
x ^= x >> 12 | |
x ^= x << 25 | |
x ^= x >> 27 | |
states[id] = x | |
return uint64(x) * uint64(2685821657736338717) | |
@cuda.jit("float32(uint64[::1], uint64)", device=True) | |
def cuda_xorshift_float(states, id): | |
return float32(float32(MAX32 & cuda_xorshift(states, id)) / float32(MAX32)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
states
is an array of random number states.If you assume one state per thread, the
id
will be the global thread id.