Cannot complile and then use GPU

I’m following this vignette Running Stan on the GPU with OpenCL • cmdstanr , but I cannot compile.

> mod_cl <- cmdstan_model("~/dtSTAN/GPU_example/model.stan",
+                         cpp_options = list(stan_opencl = TRUE))
Compiling Stan program...
stanc: option '--use-opencl' cannot be repeated
Usage: stanc [OPTION]… [MODEL_FILE]
Try 'stanc --help' for more information.
make: *** [make/program:66: /tmp/RtmpAU4L5R/model-578b4397dcb1.hpp] Error 124
Error: An error occured during compilation! See the message above for more information.

Using an already compiled model work, tho. I just updated cmdstan.

I have no idea if this is right or not, but the message option '--use-opencl' cannot be repeated makes me wonder if you have --use-opencl in make/local, such that it’s getting repeated?

This is the content of “make/local” file

STAN_OPENCL=true
OPENCL_PLATFORM_ID=0
OPENCL_DEVICE_ID=0

If I compile the model without cpp_options

mod_cl <- cmdstan_model("~/dtSTAN/GPU_example/model.stan")

and then add cpp_options

mod_cl <- cmdstan_model("~/dtSTAN/GPU_example/model.stan",
+                         cpp_options = list(stan_opencl = TRUE))
Model executable is up to date!

The example seem to work

fit_cl <- mod_cl$sample(data = mdata, chains = 4, parallel_chains = 4,
+                         opencl_ids = c(0, 0), refresh = 0)
Running MCMC with 4 parallel chains...

Chain 1 finished in 35.6 seconds.
Chain 4 finished in 35.8 seconds.
Chain 2 finished in 40.3 seconds.
Chain 3 finished in 40.3 seconds.

All 4 chains finished successfully.
Mean chain execution time: 38.0 seconds.
Total execution time: 43.0 seconds.

The issue appears to be that cmdstanr is over-processing its arguments before calling cmdstan’s makefiles

CmdStan already does this for you:

1 Like

Is GPU used by default now? I mean if opencl is enabled when installing it.

Edit: Only works as described in my previous reply.

I opened Remove stanc flags munging for `cpp_options$stan_opencl` · Issue #1111 · stan-dev/cmdstanr · GitHub to report the issue