MyNixOS website logo
Description

Parallel Random Number Generation on GPU.

Builds on 'gpuR' and utilizes the 'clRNG' ('OpenCL') library to provide efficient tools to generate independent random numbers in parallel on a GPU and save the results as 'R' objects, ensuring high-quality random numbers even when 'R' is used interactively or in an ad-hoc manner. Includes Fisher's simulation method adapted from Patefield, William M (1981) <doi:10.2307/2346669> and 'MRG31k3p' Random Number Generator from 'clRNG' library by Advanced Micro Devices, Inc. (2015) <https://github.com/clMathLibraries/clRNG>.

This clrng R package is built as a tool set for parallel random number generation on GPUs. It is dependent on the gpuR package and utilize the MRG31k3p RNG from the clRNG, an OpenCL library by Pierre L’Ecuyer.

Installing drivers

The clrng and gpuR packages require GPU drivers and opencl. This can be tricky. Although the package is only officially supported on unix, it should work on any computer where openCL is available.

Check you have a GPU

lspci -kv

Below are some instructions for installing the required drivers for Ubuntu.

Nvidia

See the Nvidia installation guide

If you're lucky, the following will work.

sudo apt install nvidia-driver-535
sudo reboot
sudo apt-get install cuda

Check you've installed the drivers correctly.

nvidia-smi

Install openCL

sudo apt install -y nvidia-opencl-dev clinfo

check openCL is working

clinfo

AMD

See the AMD rocm install guide

sudo apt install amdgpu-dkms
sudo apt install rocm
sudo reboot

Check the drivers

/opt/rocm/bin/rocm-smi

... and openCL

/opt/rocm/bin/clinfo

Amazon AWS

Start an instance with

  • g3s.xlarge
  • ubuntu server 22.04
  • create security group, allow ssh traffic from anywhere, https from anywhere
  • 20gb storage

Make sure the software is up to date

sudo apt update
sudo apt dist-upgrade
sudo reboot

Install a version of the kernel with the DRM module

sudo apt install -y linux-headers-virtual linux-source linux-image-extra-virtual
sudo apt autoremove
sudo apt clean
sudo reboot

Set up the nvidia software repository

wget -O /tmp/cuda-keyring.deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i /tmp/cuda-keyring.deb
sudo apt update

Install cuda

sudo apt install -y cuda
sudo apt autoremove
sudo apt clean
sudo reboot

Check the driver is working

nvidia-smi

Install openCL

sudo apt install -y nvidia-opencl-dev clinfo

Check openCL is working

clinfo

Digital Research Alliance of Canada cloud

Free for academics in Canada: info

Start an instance with

  • g1-8gb-c4-22gb
  • Ubuntu

Update and reboot

sudo apt update
sudo apt dist-upgrade
sudo reboot

Add the repository for GPU drivers

wget -O /tmp/arbutus-cloud-repo_all.deb http://repo.arbutus.cloud.computecanada.ca/pulp/deb/ubuntu22/pool/main/arbutus-cloud-repo_0.2_all.deb
sudo dpkg -i /tmp/arbutus-cloud-repo_all.deb 

Install drivers

sudo apt --yes install nvidia-vgpu-kmod nvidia-vgpu-tools nvidia-vgpu-gridd
sudo reboot

Check the driver is working

nvidia-smi

Install openCL

sudo apt-get install --yes opencl-headers clinfo ocl-icd-opencl-dev 

Check openCL is working

clinfo

R and packages

Add R repositories

sudo add-apt-repository --yes "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
sudo add-apt-repository --yes ppa:c2d4u.team/c2d4u4.0+

Install R

sudo apt --yes install r-cran-devtools r-cran-rcppeigen r-cran-bh r-cran-testthat r-cran-knitr r-cran-assertive
sudo apt-get clean

Set up some folders for R, including a personal library.

mkdir ~/.R 
echo 'MAKEFLAGS = -j4' > ~/.R/Makevars
R -e 'dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)'

Install the GPU packages!

devtools::install_github("eborgnine/gpuR")
devtools::install_github("ruoyongxu/clrng")

openCL on CPU

It is possible to install openCL for use with a CPU rather than a GPU. This could be useful for development and testing, but the code will run considerably slower than on a GPU.

sudo apt install intel-opencl-icd
sudo apt install opencl-dev clinfo
clinfo
library('gpuR')
listContexts()
setContext(grep("cpu", listContexts()$device_type)[1])
Metadata

Version

0.0.5

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows