nmathopencl
'OpenCL'-Ported R 'Mathlib' for GPU-Accelerated Packages
Ships statistical and mathematical routines from R internal 'nmath' ('Mathlib') as 'OpenCL' C sources under directory 'inst/cl/', with R wrappers that use the GPU when 'OpenCL' is available at compile time and fall back to 'stats' equivalents otherwise. Aimed at package developers building custom kernels (for example Bayesian GLMs via suggested package 'glmbayes') using 'opencltools' kernel loaders and related helpers. Contains translated shims, an illustrative GLM-related kernel subsystem, vignettes, and optional GPU acceleration. The ported routines are translated from the 'nmath' ('Mathlib') and 'Rmath' sources of R Core Team (2026) "R: A Language and Environment for Statistical Computing" <doi:10.32614/R.manuals>. 'OpenCL' GPU execution follows the standard described in Stone, Gohara, and Shi (2010) <doi:10.1109/MCSE.2010.69>. The likelihood subgradient simulation methodology implemented by the illustrative GLM kernel subsystem is described in Nygren and Nygren (2006) <doi:10.1198/016214506000000357>.
README
# Headers for `LinkingTo: nmathopencl`
Installed as `include/nmathopencl/` when **nmathopencl** is installed. Downstream
packages that call GPU nmath from C/C++ should use the **C API**:
```cpp
#include <nmathopencl/nmathopencl_capi.h>
if (nmathopencl_has_opencl()) {
SEXP out = nmathopencl_dnorm_opencl(x, mean, sd, give_log, parallel, verbose);
}
```
## Requirements
- **`Imports: nmathopencl, opencltools`** — DLLs must be loaded; `*_opencl` uses
opencltools for kernel source loading at runtime.
- **`LinkingTo: nmathopencl`** — supplies `-I` for this header only.
- **No `PKG_LIBS`** for C API-only use (symbols resolve via `R_GetCCallable`).
- **`nmathopencl_api_version()`** — call for ABI compatibility checks (currently `1`).
- OpenCL SDK/system `-I` / `-lOpenCL` in your own `configure` when you compile
GPU code paths (`USE_OPENCL`); Khronos headers are **not** bundled here.
## Kernel loading and device utilities
Use **opencltools** (`#include <opencltools/opencltools_capi.h>`), not this header.
## Regenerating
From the package root:
```bash
Rscript tools/generate_nmathopencl_capi.R
Rcpp::compileAttributes()
```
Source of truth for signatures: `src/export_wrappers.cpp` (GPU `*_opencl_cpp_export` only).
Versions across snapshots
| Version | Repository | File | Size |
|---|---|---|---|
0.8.2 |
rolling linux/jammy R-4.5 | nmathopencl_0.8.2.tar.gz |
2.4 MiB |
0.8.2 |
rolling linux/noble R-4.5 | nmathopencl_0.8.2.tar.gz |
2.5 MiB |
0.8.2 |
rolling source/ R- | nmathopencl_0.8.2.tar.gz |
2.1 MiB |
0.8.2 |
latest linux/jammy R-4.5 | nmathopencl_0.8.2.tar.gz |
2.4 MiB |
0.8.2 |
latest linux/noble R-4.5 | nmathopencl_0.8.2.tar.gz |
2.5 MiB |
0.8.2 |
latest source/ R- | nmathopencl_0.8.2.tar.gz |
2.1 MiB |
0.8.2 |
2026-04-23 source/ R- | nmathopencl_0.8.2.tar.gz |
0 B |
Dependencies (latest)
Depends
Imports
- stats
- Rcpp (>= 1.1.1)
- RcppParallel
- Rdpack (>= 0.11-0)
- opencltools (>= 0.8.1)