samedi 29 août 2020

Why get I the same numbers with random array using Numba xoroshiro128p?

Why get I the same numbers with random array using Numba xoroshiro128p? I want the same as with Numpy random array ( np.random.rand(12) ).

from numba import cuda
from numba.cuda.random import create_xoroshiro128p_states, xoroshiro128p_uniform_float32

import numpy as np

@cuda.jit
def rand_array(rng_states, out):
    thread_id = cuda.grid(1)
    x = xoroshiro128p_uniform_float32(rng_states, thread_id)
    out[thread_id] = x


threads_per_block = 4
blocks = 3 
rng_states = create_xoroshiro128p_states(threads_per_block * blocks, seed=1)
out = np.zeros(threads_per_block * blocks, dtype=np.float32)

rand_array[blocks, threads_per_block](rng_states, out)

rar = np.random.rand(12).reshape(blocks, threads_per_block)

print(out.reshape(blocks,threads_per_block))
print()
print(rar.reshape(blocks,threads_per_block))

Every time I run it, I see the same numbers. Yet the numpy function works well. Thank you in advance for your help!




Aucun commentaire:

Enregistrer un commentaire