This package provides a function rand_binomial! to produce CuArrays with binomially distributed entries, analogous to CUDA.rand_poisson! for Poisson-distributed ones.
Use the built-in package manager:
import Pkg; Pkg.add("BinomialGPU")Sample CuArrays with binomial random variates in-place:
using CUDA, BinomialGPU
A = CUDA.zeros(Int, 16)
rand_binomial!(A, count = 10, prob = 0.5)The function currently also supports broadcast over arrays of parameters of the same size as the one to be filled:
A = CUDA.zeros(Int, 8)
counts = [1,2,4,8,16,32,64,128]
probs = CUDA.rand(8)
rand_binomial!(A, count = counts, prob = probs)as well as broadcasts over arrays of parameters whose dimensions are a prefix of the dimensions of A, e.g.
A = CUDA.zeros(Int, (2, 4, 8))
counts = rand(1:128, 2, 4)
probs = CUDA.rand(2)
rand_binomial!(A, count = counts, prob = probs)- The sampler is fast: it is about one order of magnitude faster than other samplers. But it is still an open question whether it can be made faster, whether there are other samplers with competitive speed, and it shows some non-intuitive behavior:
- The functionality to draw random numbers within CUDA.jl kernels is still under development. A new function
rand()has recently become available, but it hasn't been tried within this package. See issue #7. - The speed is faster in Julia 1.5.4 than in the current Julia 1.6 release candidate. See issue #8.
- The speed is slower when using optimal thread allocation than when defaulting to 256 threads. See issue #2
- Are there any other samplers that are comparably fast or faster? I compared the following: sample an array of size
(1024, 1024)withcount = 128andprobof size(1024, 1024)with uniformly drawn entries. Timings on an RTX2070 card: BinomialGPU.jl 1.4ms, PyTorch 11ms, CuPy 18ms, tensorflow 400ms. Please let me know if you know samplers that are not yet listed.
- The functionality to draw random numbers within CUDA.jl kernels is still under development. A new function