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>.

Version: 0.8.2
Depends: MASS, R (≥ 3.5.0)
Imports: stats, Rcpp (≥ 1.1.1), RcppParallel, Rdpack (≥ 0.11-0), opencltools (≥ 0.8.1)
LinkingTo: Rcpp, RcppArmadillo, RcppParallel, opencltools
Suggests: glmbayes (≥ 0.9.3), knitr, rmarkdown, testthat (≥ 3.0.0), spelling
Published: 2026-06-21
DOI: 10.32614/CRAN.package.nmathopencl (may not be active yet)
Author: Kjell Nygren [aut, cre], The R Core Team [ctb, cph] (R 'Mathlib' sources and derived/adapted routines), The R Foundation [cph] (Portions of R 'Mathlib' and R source code), Ross Ihaka [ctb, cph] (R 'Mathlib'), Robert Gentleman [ctb, cph] (Portions of R 'Mathlib'), Morten Welinder [ctb, cph] (Portions of R 'Mathlib' (pgamma, phyper, ebd0)), Martin Maechler [ctb] (Portions of R 'Mathlib'), Catherine Loader [ctb] (Author of the dbinom/bd0/stirlerr density routines in R 'Mathlib' ported here), Claus Ekstrøm [ctb] (Author of the noncentral t density (dnt) in R 'Mathlib' ported here), Peter Ruckdeschel [ctb] (Author of the noncentral F density (dnf) in R 'Mathlib' ported here), Alfred H. Morris, Jr. [ctb] (ACM TOMS 708 incomplete beta code (toms708) ported here), Armido R. Didonato [ctb] (ACM TOMS 708 incomplete beta code (toms708) ported here), The Khronos Group Inc [cph] ('OpenCL' API headers in inst/include/CL (Apache License 2.0))
Maintainer: Kjell Nygren <kjell.a.nygren at gmail.com>
BugReports: https://github.com/knygren/nmathopencl/issues
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
Copyright: see file COPYRIGHTS
URL: https://github.com/knygren/nmathopencl, https://knygren.r-universe.dev/nmathopencl
NeedsCompilation: yes
SystemRequirements: Optional 'OpenCL' support. If available, GPU acceleration will be used; otherwise, computation runs on CPU.
Language: en-US
Citation: nmathopencl citation info
Materials: README, NEWS
CRAN checks: nmathopencl results

Documentation:

Reference manual: nmathopencl.html , nmathopencl.pdf
Vignettes: Chapter 00: nmathopencl — Package Overview (source, R code)
Chapter 01: Setting Up OpenCL and Enabling GPU Acceleration (source, R code)
Chapter 02: Adding USE_OPENCL and has_opencl() to Your Package (source, R code)
Chapter 03: Structure of nmath Kernel Programs (source, R code)
Chapter 04: The nmath OpenCL Library (source, R code)
Chapter 05: Kernels, Kernel Runners, and Kernel Wrappers (source, R code)
Chapter 06: Integrating Kernel Wrappers into Your Codebase (source, R code)
Chapter 07: Kernels — Writing and Using OpenCL Kernel Files (source, R code)
Chapter 08: Kernel Loading — load_kernel_source and load_kernel_library (source, R code)
Chapter 09: Generic OpenCL Kernel Runners (openclPort layer) (source, R code)
Chapter 10: Case Study — Building Custom GLM Kernels (ex_glmbayes) (source, R code)
Chapter 11: Testing, Debugging, and Benchmarking GPU Kernels (source, R code)
Chapter 12: The nmathopencl R API — Distribution Functions on the GPU (source, R code)

Downloads:

Package source: nmathopencl_0.8.2.tar.gz
Windows binaries: r-devel: not available, r-release: not available, r-oldrel: not available
macOS binaries: r-release (arm64): nmathopencl_0.8.2.tgz, r-oldrel (arm64): not available, r-release (x86_64): not available, r-oldrel (x86_64): not available

Linking:

Please use the canonical form https://CRAN.R-project.org/package=nmathopencl to link to this page.

mirror server hosted at Truenetwork, Russian Federation.