Failure to load opencl.h for cmdstanr on Linux system

I’m using R 4.1.1 on a Linux server (Ubuntu 18.04.5LTS), and when I enable OpenCL from cmdstanr and try to compile the sample code in the vignette, it stops with the following error.

Compiling Stan program...
In file included from stan/lib/stan_math/stan/math/opencl/err/check_opencl.hpp:7:0,
                 from stan/lib/stan_math/stan/math/opencl/opencl_context.hpp:14,
                 from src/cmdstan/write_opencl_device.hpp:6,
                 from src/cmdstan/command.hpp:19,
                 from src/cmdstan/main.cpp:1:
stan/lib/stan_math/lib/opencl_2.0.15/include/CL/opencl.hpp:530:10: fatal error: CL/opencl.h: No such file or directory
 #include <CL/opencl.h>
compilation terminated.
make: *** [src/cmdstan/main_opencl.o] Error 1
Error: An error occured during compilation! See the message above for more information.

Since the CUDA toolkit was already installed on the system and the path where opencl.h was installed was known, I tried to install CmdStan by referring to the Windows cases (Cannot compile example Open CL model (Win 10 cmdstan 2.27); openCL cmdstanr Windows error) and specifying the path like below:

path_to_opencl_lib <- "/usr/local/cuda-11.2/targets/x86_64-linux/include/CL/"
cpp_options = list(
  "CXXFLAGS += -fpermissive",
  paste0("LDFLAGS+= -L\"",path_to_opencl_lib,"\" -lOpenCL")

install_cmdstan(cores=4, overwrite = TRUE, cpp_options = cpp_options)

But it returns another error after compiling messages and failed to intall CmdStan:

/usr/bin/ld: cannot find -lOpenCL
collect2: error: ld returned 1 exit status
make/command:12: recipe for target 'bin/diagnose' failed
make: *** [bin/diagnose] Error 1
make: *** Waiting for unfinished jobs....

Initially, I thought it was due to the OpenCL path not being linked, but since similar problems do not seem to occur on Linux systems, could there be another cause?

The OS version of the server is as follows:


And return of clinfo -l is:

Platform #0: NVIDIA CUDA
 +-- Device #0: Quadro RTX 8000
 `-- Device #1: Quadro RTX 8000

Hi all,

By looking around together with the server maintainer, we found that the opencl header file was simply not installed. After installing this header file;

sudo apt-get install -y opencl-headers

the stan code in my previous post compiled without any problems.

I would be happy if anyone else has the same problem and would like to refer to it.
Thank you very much for paying attention to my post.


Glad you got it working and thanks for reporting the solution!