Cannot compile example Open CL model (Win 10 cmdstan 2.27)

Hi!

I was trying to run the example Open CL /cmdstanr (https://mc-stan.org/cmdstanr/articles/opencl.html, but ran into an error:

Code:

library(cmdstanr)

# Generate some fake data
n <- 250000
k <- 20
X <- matrix(rnorm(n * k), ncol = k)
y <- rbinom(n, size = 1, prob = plogis(3 * X[,1] - 2 * X[,2] + 1))
mdata <- list(k = k, n = n, y = y, X = X)


# Compile the model with STAN_OPENCL=TRUE
mod_cl <- cmdstan_model("open_cl/simple_model.stan",
                        cpp_options = list(stan_opencl = TRUE))

Error:

Compiling Stan program...
In file included from stan/src/stan/model/model_header.hpp:18:
stan/src/stan/services/util/create_rng.hpp:35:1: internal compiler error: in gt_pch_note_object, at ggc-common.c:276
 }  // namespace stan
 ^
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://github.com/r-windows> for instructions.
mingw32-make.exe: *** [make/program:25: stan/src/stan/model/model_header_opencl.hpp.gch] Error 1
Error: An error occured during compilation! See the message above for more information.

I can compile regular (non Open CL) Stan programs without problem. I have tried reinstalling cmdstan, as well as rebuilding the cmdstan installation as per the advice in this thread https://discourse.mc-stan.org/t/opencl-cmdstanr-windows-error/22375/3 .

Happy for any suggestions for how to fix this!

Operating System: Win 10 x64 (build 19043)
Interface Version: R 4.1.0 cmdstanr_0.4.0 cmdstan 2.27.0
Compiler/Toolkit: RTools 4.0

$ make -v
GNU Make 4.2.1
Built for x86_64-pc-msys

Hi,

this is an issue with precompiled headers that we use speedup compilation but seem to be problematic with OpenCL on Windows.

First update to the development version of cmdstanr with

remotes::install_github("stan-dev/cmdstanr")

and then run:

cpp_options = list(
  "PRECOMPILED_HEADERS"=FALSE
)

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

and try again.

Also see windows openCL compilation issue · Issue #493 · stan-dev/cmdstanr · GitHub for a similar report.

1 Like

Thanks for the quick reply! It didn’t fully solve the issue, I got the

cannot find -lOpenCL

error instead. But the GitHub thread you linked helped and I could use the rest of the solution found there.

In full this worked:

remotes::install_github("stan-dev/cmdstanr")

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

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

Thanks again!

1 Like