Hi, everyone!
I am a novice of brms. I have a big dataset and I need to run a multilevel negbinomial model.
I had tried “within-chain parallelization”, but that seems to be not fast enough for my big dataset. Because I have a GPU (NVIDIA GeForce RTX 2060 SUPER), I want to speedup my model by using the “opencl” function in brms, but I got the error messages:
Error in opencl(c(0, 0)) : could not find function “opencl”.
My code is as below:
fit <- brm(value ~ hour*period+offset(n)+(1|id)+(0+hour|id),
family=negbinomial,
data = data,
warmup = 500, iter = 1000,
cores=2,chains = 2, opencl = opencl(c(0, 0)),
backend="cmdstanr")
My question is: do I need to install and library any extra packages for using “opencl” function in brms? (I tried to install.packages(“OpenCL”), but it failed…)
PS: I had installed NVIDIA driver/Cuda/NVIDIA GPU Computing SDK, and I found the path of:
- “opencl.h” : “C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4/include/CL”
- “OpenCL.lib”: “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\lib\x64”
But I don’t know how to use them in R/brms.
- Operating System: Windows 10 pro
- brms Version: 2.15.0
Looking forward to your kind reply!
Best,
Jacob
you need the dev version of brms from github.
Thanks for your prompt reply. I will try the dev version of brms!
Paul Buerkner via The Stan Forums <mc_stan@discoursemail.com>于2021年8月14日 周六下午1:23写道:
I just reinstall the dev version of brms from github.
Now, it has the “opencl” function, thank you!
However, I got another error message:
#######################################
stan/lib/stan_math/stan/math/opencl/rev/digamma.hpp:23:8: required from here
stan/lib/stan_math/stan/math/opencl/kernel_generator/multi_result_kernel.hpp:321:67: error: ‘make_assignment_pair’ was not declared in this scope
std::get(results_), std::get(exprs.expressions_))…));
^
stan/lib/stan_math/stan/math/opencl/kernel_generator/multi_result_kernel.hpp:321:72: error: ‘assignment_impl’ was not declared in this scope
std::get(results_), std::get(exprs.expressions_))…));
^
At global scope:
cc1plus.exe: warning: unrecognized command line option “-Wno-ignored-attributes”
cc1plus.exe: warning: unrecognized command line option “-Wno-ignored-attributes”
cc1plus.exe: warning: unrecognized command line option “-Wno-int-in-bool-context”
mingw32-make.exe: *** [src/cmdstan/main_opencl.o] Error 1
Error: An error occured during compilation! See the message above for more information.
#######################################
May I ask for more suggestions about this issue? Thanks again!
I found the solution:
At first, I upgrade my R to 4.1.1, and reinstall:
rtools 4.0
brms 2.15.9
cmdstanr 0.4.0.9000
cmdstan 2.27.0
Then, I got another error like “mingw32-make.exe: *** [make/program:25: stan/src/stan/model/model_header_opencl.hpp.gch] Error 1”
Then I run the below code:
#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)
Then I succeed! Now, I can use my GPU to speed up my model!
Hope to help someone else!
Best,
Jacob
2 Likes