Skip to content

OpenCL GPU Routines

bgoodri edited this page Apr 14, 2018 · 25 revisions

OpenCL is an open-source framework for writing programs that utilize a platform with heterogeneous hardware. Stan uses OpenCL to design the GPU routines for the Cholesky Decomposition and it's derivative. Other routines will be available in the future. These routines are suitable for programs which require solving large NxM matrices (N>600) such as algorithms that utilize large covariance matrices.

Requirements

Users must have a valid OpenCL driver installed on their computer and a compiler which supports compilation of OpenCL. Mac's should already have the OpenCL driver installed. While the GPU code has not been tested on windows, you can attempt to run the program by installing the OpenCL drivers as specified in this guide. You can check if you system is set up properly using the clinfo program. Ubuntu users with an Nvidia device can get the OpenCL driver through the nvidia-cuda-toolkit using

apt update
apt install nvidia-cuda-toolkit clinfo

Those with AMD devices can install the OpenCL driver available through

apt install -y libclc-amdgcn mesa-opencl-icd clinfo

If your device is not supported by the current drivers available you can try Paulo Miguel PPA

add-apt-repository ppa:paulo-miguel-dias/mesa 
apt-get update
apt-get install libclc-amdgcn mesa-opencl-icd

Users can check that their installation is valid by running clinfo.

Setting up the Math Library to run with a GPU

To turn on GPU computation:

  1. Check and record what device and platform you would like to use with clinfo and record the device and platform index.
  2. Open a text file called make/local; if it does not exist, create one.
  3. Add these lines to the make/local file:
STAN_OPENCL=true
OPENCL_DEVICE_ID=${CHOSEN_INDEX}
OPENCL_PLATFORM_ID=${CHOSEN_INDEX}

where the user will replace ${CHOSEN_INDEX} with the index of the device and platform they would like to use.

Running Tests with OpenCL

Once you have done the above step, runTests.py should execute with the GPU enabled. All tests will match the phrase *_opencl_* and tests can be filtered such as

./runTests.py test/unit -f opencl
Clone this wiki locally