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.
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 -kvBelow are some instructions for installing the required drivers for Ubuntu.
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 cudaCheck you’ve installed the drivers correctly.
nvidia-smiInstall openCL
sudo apt install -y nvidia-opencl-dev clinfocheck openCL is working
clinfoSee the AMD rocm install guide
sudo apt install amdgpu-dkms
sudo apt install rocm
sudo rebootCheck the drivers
/opt/rocm/bin/rocm-smi… and openCL
/opt/rocm/bin/clinfoStart an instance with
g3s.xlargeMake sure the software is up to date
sudo apt update
sudo apt dist-upgrade
sudo rebootInstall 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 rebootSet 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 updateInstall cuda
sudo apt install -y cuda
sudo apt autoremove
sudo apt clean
sudo rebootCheck the driver is working
nvidia-smiInstall openCL
sudo apt install -y nvidia-opencl-dev clinfoCheck openCL is working
clinfoFree for academics in Canada: info
Start an instance with
g1-8gb-c4-22gbUpdate and reboot
sudo apt update
sudo apt dist-upgrade
sudo rebootAdd 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 rebootCheck the driver is working
nvidia-smiInstall openCL
sudo apt-get install --yes opencl-headers clinfo ocl-icd-opencl-dev Check openCL is working
clinfoAdd 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 cleanSet 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")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
clinfolibrary('gpuR')
listContexts()
setContext(grep("cpu", listContexts()$device_type)[1])