Performance of random.Generator instance

16 views
Skip to first unread message

Addison Howe

unread,
Mar 27, 2023, 5:34:59 PM3/27/23
to CuPy User Group
Hi, 
I'm curious about the use of cupy.random.Generator to construct a random number generator. In numpy, it seems like the best practice is to construct a random number generator with rng=np.random.default_rng(seed) and to pass that to stochastic functions. Doing so appears to be more efficient than using functions in np.random. With the equivalent in cupy, however, there appears to be a significant loss in performance.

I'm currently testing the following:

     rng = cp.random.default_rng()
     rng.standard_normal(size=(100, 100, 100))

compared to

     cp.random.standard_normal(size=(100, 100, 100))

The latter appears to be an order of magnitude slower.

Any ideas why this is the case? 

Kenichi Maehashi

unread,
Mar 29, 2023, 6:12:14 AM3/29/23
to CuPy User Group
`cupy.random.default_rng` is a relatively new interface in CuPy ("New Random Generator API"), and the code path is completely different from legacy `cupy.random.<distribution_name>`  functions ("Legacy Random Generation".)
The new API utilizes cuRAND's device API.
Not sure why you see the performance loss, though. Could you file an issue with detailed environment information and the benchmark results?
2023年3月28日火曜日 6:34:59 UTC+9 addi...@gmail.com:
Reply all
Reply to author
Forward
0 new messages