cmdstanr/OpenCL error

Dear All,

I am trying to follow this post to try and use GPU acceleration.

I have installed and successfully used CUDA (with Tensorflow, Jax), which I belive comes with OpenCL. I also installed OpenCL for Intel.

However, when I am trying to compile the model with opencl I get this error:

Compiling Stan program...
C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lOpenCL
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe: *** [make/program:59: C:\Users\...\Local\Temp\Rtmpwdg91H\model-2370c5f41fd.exe] Error 1
Error: An error occured during compilation! See the message above for more information.

My session:

R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] cmdstanr_0.4.0

loaded via a namespace (and not attached):
 [1] processx_3.5.2  compiler_4.1.1  backports_1.2.1 R6_2.5.1        tools_4.1.1     knitr_1.33      checkmate_2.0.0
 [8] jsonlite_1.7.2  xfun_0.25       ps_1.6.0    

I realize it is likely to be a mingw error, not a Stan-specific one and searched extensively for a solution. Nonetheless, if someone is able to suggest a fix, I would be grateful.

Many thanks!

Hi, this isnt a mingw error. The issue is that on Windows, you need to additionally point to where the OpenCL lib is, if its not automatically found (which it seems it is not in your case).

Run the following R script, where you replace the path_to_opencl_lib to your path to the OpenCL.lib file:

path_to_opencl_lib <- "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.3/lib/x64"
cpp_options = list(
  paste0("LDFLAGS+= -L\"",path_to_opencl_lib,"\" -lOpenCL")
)

cmdstan_make_local(cpp_options = cpp_options)
rebuild_cmdstan(cores=4)

If you are using CUDA, the location should be in a simillar location (depending on the version).

We have an issue to mention this more prominently in the OpenCL vignette, but haven’t gotten to this unfortunately :/

2 Likes

Thank you, Rok. This worked perfectly and I successfully ran the example.

1 Like

Fantastic, great to hear!