GPU Seminar


Linear Bernoulli Factory
This code will simulate a variate \( {\rm B} \sim {\rm Bernoulli}(f(p)) \) where \( f(p) = min(2p, 1-\omega) \).

This code generates Bernoulli random variables with success probability \( Cp \) where \( C>1 \), using the Bernoulli factory algorithm presented in Huber (2013) (arXiv:1308.1562v1). In this simulation, \( p= {\mathbb P}(Z>2) \), where \( Z\sim {\rm N}(0,1) \). The Matlab file BF.m first simulates \( {\rm Bernoulli} (p)\) variables and \( {\rm Uniform}(0,1) \) variables which will be needed in the algorithm and sends them to the GPU. The Matlab code then calls the CUDA file containing the Bernoulli factory algorithm. To call the kernel from Matlab, the CUDA code must first be compiled as a PTX file. The CUDA file implements the Bernoulli factory algorithm to generate \( H \) \( {\rm Bernoulli}(Cp) \) random variables across \( H \) different blocks. BF.m