Skip to content

OpenCL GPU Routines

Steve Bronder 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. Ubuntu users can install the OpenCL driver available in ocl-icd-opencl-dev through

sudo apt update
sudo apt install libclc-amdgcn mesa-opencl-icd clinfo

Users can check that their installation is valid by running the 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 tests/unit -f opencl
Clone this wiki locally