GPU acceleration is an optional feature of the
glmbayes modelling stack. All modeling functions —
glmb(), lmb(), rglmb(), and
related tools — run fully on the CPU regardless of whether OpenCL is
available. No setup is needed for standard use.
OpenCL is implemented in the compiled backend
glmbayesCore (imported by glmbayes). A
CPU-only glmbayes install is normal when
glmbayesCore was built without OpenCL; enabling GPU
acceleration means reinstalling glmbayesCore from
source with OpenCL available at compile time — not rebuilding
glmbayes itself ( glmbayes has no C++
configure step).
Where GPU acceleration pays off is with large
models: high-dimensional predictor sets or large posterior
sample sizes. Envelope construction and evaluation in
glmbayesCore — gradient and log-posterior work at each
tangency grid point — is embarrassingly parallel. Passing
use_opencl = TRUE to glmb() or
lmb() can substantially reduce wall time. See
vignette("Chapter-A10", package = "glmbayesCore")
for technical detail.
This chapter is the glmbayes user checklist.
Backend-only installs should also read
vignette("Chapter-16", package = "glmbayesCore").
When glmbayes is attached interactively it checks
whether GPU acceleration appears feasible. If has_opencl()
is TRUE — meaning glmbayesCore was
compiled with OpenCL — attach is silent.
If has_opencl() is FALSE
and a GPU or OpenCL stack is detected, you may see:
Note: glmbayes provides full CPU capability in this session
(e.g. glmb(), lmb(), Prior_Setup()). GPU acceleration is recommended
for bigger models and appears available. Reinstall glmbayesCore from
source with OpenCL at compile time to enable it; see vignette("Chapter-16",
"glmbayes") for install instructions.
On a machine with no GPU and no OpenCL stack, attach is silent.
To suppress the message:
Work through these steps in order.
has_opencl() reports whether
glmbayesCore in this session was built with OpenCL. If
TRUE, pass use_opencl = TRUE to
glmb() or lmb() and you are done. Otherwise
continue.
glmbayes depends on glmbayesCore, which in turn depends on opencltools and nmathopencl. For a GPU-enabled backend, opencltools must be built with OpenCL support and the system must provide drivers, headers, and an ICD loader.
Check opencltools:
If FALSE, follow
vignette("Chapter-01", package = "opencltools"),
then reinstall opencltools (and
nmathopencl) from source:
install.packages(
c("opencltools", "nmathopencl"),
repos = c("https://cloud.r-project.org", "https://knygren.r-universe.dev"),
type = "source"
)What you need on your system (summary; details in opencltools Chapter 01):
| Component | What it provides | Needed for |
|---|---|---|
| GPU driver | Exposes hardware to the OS | Runtime |
OpenCL headers (CL/cl.h) |
Required at compile time | Source build |
| OpenCL ICD loader | Dispatches to vendor runtime | Runtime |
Reinstall glmbayesCore from source so its
configure / configure.win can enable OpenCL.
Reinstalling glmbayes alone does not compile OpenCL into the
backend.
Prebuilt CRAN / R-Universe
glmbayesCore binaries are often CPU-only. Use
type = "source" from R-Universe (or GitHub) after Step
2.
Install Rtools and, if needed, devtools:
install.packages("devtools")
install.packages(
"glmbayesCore",
repos = c("https://cloud.r-project.org", "https://knygren.r-universe.dev"),
type = "source"
)Development versions:
This combines opencltools host checks with compile-time status for glmbayesCore. Example output:
=== glmbayes OpenCL Diagnostic Report ===
...
[OK] glmbayes was compiled with OpenCL support.
The final line refers to the glmbayesCore backend (wording is historical).
Common resolutions:
clinfo outside
R; ICD vendors on Linux.Pass use_opencl = TRUE to glmb() or
lmb():
Cleveland CPU vs OpenCL illustration (not executed during vignette build):
library(glmbayes)
data("Cleveland")
ps <- Prior_Setup(
hd ~ age + sex + cp + trestbps + chol +
fbs + restecg + thalach + exang + oldpeak + slope + ca + thal,
family = binomial(logit),
data = Cleveland
)
t_cpu <- system.time({
fit_cpu <- glmb(
hd ~ age + sex + cp + trestbps + chol +
fbs + restecg + thalach + exang + oldpeak + slope + ca + thal,
family = binomial(link = "logit"),
pfamily = dNormal(mu = ps$mu, Sigma = ps$Sigma),
data = Cleveland,
n = 20000,
Gridtype = 2,
use_parallel = TRUE,
use_opencl = FALSE,
verbose = FALSE
)
})
t_gpu <- system.time({
fit_gpu <- glmb(
hd ~ age + sex + cp + trestbps + chol +
fbs + restecg + thalach + exang + oldpeak + slope + ca + thal,
family = binomial(link = "logit"),
pfamily = dNormal(mu = ps$mu, Sigma = ps$Sigma),
data = Cleveland,
n = 20000,
Gridtype = 2,
use_parallel = TRUE,
use_opencl = TRUE,
verbose = FALSE
)
})
t_cpu
t_gpu