Package: nmathopencl 0.8.2.9000

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

Authors:Kjell Nygren [aut, cre], The R Core Team [ctb, cph], The R Foundation [cph], Ross Ihaka [ctb, cph], Robert Gentleman [ctb, cph], Morten Welinder [ctb, cph], Martin Maechler [ctb], Catherine Loader [ctb], Claus Ekstrøm [ctb], Peter Ruckdeschel [ctb], Alfred H. Morris, Jr. [ctb], Armido R. Didonato [ctb], The Khronos Group Inc [cph]

nmathopencl_0.8.2.9000.tar.gz
nmathopencl_0.8.2.9000.zip(r-4.7)nmathopencl_0.8.2.9000.zip(r-4.6)nmathopencl_0.8.2.9000.zip(r-4.5)
nmathopencl_0.8.2.9000.tgz(r-4.6-x86_64)nmathopencl_0.8.2.9000.tgz(r-4.6-arm64)nmathopencl_0.8.2.9000.tgz(r-4.5-x86_64)nmathopencl_0.8.2.9000.tgz(r-4.5-arm64)
nmathopencl_0.8.2.9000.tar.gz(r-4.7-arm64)nmathopencl_0.8.2.9000.tar.gz(r-4.7-x86_64)nmathopencl_0.8.2.9000.tar.gz(r-4.6-arm64)nmathopencl_0.8.2.9000.tar.gz(r-4.6-x86_64)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
nmathopencl/json (API)

# Install 'nmathopencl' in R:
install.packages('nmathopencl', repos = c('https://knygren.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/knygren/nmathopencl/issues

Uses libs:
  • openblas– Optimized BLAS
  • c++– GNU Standard C++ Library v3

On CRAN:

Conda:

openblascpp

8.05 score 2 stars 3 packages 8 scripts 47 downloads 129 exports 8 dependencies

Last updated from:1ab9e527b4. Checks:12 OK, 1 FAIL. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-arm64OK519
linux-devel-x86_64OK533
source / vignettesOK650
linux-release-arm64OK495
linux-release-x86_64OK515
macos-release-arm64OK229
macos-release-x86_64OK307
macos-oldrel-arm64OK176
macos-oldrel-x86_64OK288
windows-develOK344
windows-releaseOK352
windows-oldrelOK295
wasm-releaseFAIL563

Exports:attach_cross_library_tagsattach_kernel_call_tagsattach_kernel_dependency_tagsbeta_openclchoose_opencldbeta_opencldbinom_opencldbinom_raw_opencldcauchy_opencldchisq_opencldexp_opencldf_opencldgamma_opencldgeom_opencldhyper_opencldigamma_opencldlnorm_opencldlogis_opencldnbeta_opencldnbinom_mu_opencldnbinom_opencldnorm_opencldpois_opencldpois_raw_opencldt_opencldunif_opencldweibull_openclEx_EnvelopeEvalEx_EnvelopeOptEx_EnvelopeSizeEx_glmb_Standardize_ModelEx_glmbfamfuncexp_rand_openclextract_library_subsetfmax2_openclfmin2_openclfprec_openclfround_openclfsign_openclftrunc_openclgammafn_openclimax2_openclimin2_opencllbeta_opencllchoose_opencllgamma1p_opencllgammafn_openclload_library_for_kernellog1mexp_opencllog1pexp_opencllog1pmx_opencllogspace_add_opencllogspace_sub_opencllogspace_sum_openclnmathopencl_has_openclnmathopencl_opencl_device_infonmathopencl_opencl_fp64_availablenmathopencl_opencl_reset_device_selectionnorm_rand_openclpbeta_openclpbinom_openclpcauchy_openclpchisq_openclpentagamma_openclpexp_openclpf_openclpgamma_openclpgeom_openclphyper_openclplnorm_openclplogis_openclpnbinom_mu_openclpnbinom_openclpnorm_openclport_to_opencl_configurepow1p_openclppois_openclpsigamma_openclpt_openclptukey_openclpunif_openclpweibull_openclqbinom_openclqcauchy_openclqchisq_openclqexp_openclqf_openclqgeom_openclqhyper_openclqlnorm_openclqlogis_openclqnbinom_mu_openclqnbinom_openclqnorm_openclqpois_openclqt_openclqtukey_openclqunif_openclqweibull_openclr_check_user_interrupt_openclr_pow_di_openclr_pow_openclr_unif_index_openclrbeta_openclrbinom_openclrcauchy_openclrchisq_openclrexp_openclrf_openclrgamma_openclrgeom_openclrhyper_openclrlnorm_openclrlogis_openclrmultinom_openclrnbinom_mu_openclrnbinom_openclrnorm_openclrpois_openclrt_openclrunif_openclrweibull_openclsign_openclstage_kernel_dependency_sorttetragamma_opencltrigamma_openclunif_rand_opencluse_opencl_configurewrite_kernel_dependency_index

Dependencies:jsonliteMASSopencltoolsrbibutilsRcppRcppArmadilloRcppParallelRdpack

Chapter 12: The nmathopencl R API --- Distribution Functions on the GPU
Overview | Checking availability | Normal distribution | Distribution families | Gamma | Binomial | Poisson | Beta | Additional families | Noncentral distributions | Special functions and math support | R extension utilities (R_ext) | RNG core | Fallback behavior in detail | Performance notes

Last update: 2026-06-11
Started: 2025-08-21

Chapter 00: nmathopencl --- Package Overview
What is nmathopencl? | Three-layer architecture | C++ layout inside the package DLL | Related packages | R-side API families | Checking OpenCL availability | Vignette guide

Last update: 2026-06-04
Started: 2025-08-21

Chapter 01: Setting Up OpenCL and Enabling GPU Acceleration
Overview | When you load nmathopencl | What the message means | opencltools as imported dependency | What "compiling with OpenCL" means | Enabling OpenCL for nmathopencl | Step 1: Read the load message | Step 2: If OpenCL is not enabled at all | Step 3: If opencltools is enabled but nmathopencl is not | Verifying the setup | Validating GPU calls with the exported wrappers | Troubleshooting common failures | nmathopencl_has_opencl() returns FALSE after driver installation | Compilation fails with CL/cl.h: No such file or directory | Runtime error: clGetPlatformIDs: CL_PLATFORM_NOT_FOUND_KHR | PATH warnings from opencltools::diagnose_glmbayes() | For package developers: next steps

Last update: 2026-06-04
Started: 2020-07-05

Chapter 03: Structure of nmath Kernel Programs
Why "programs" rather than compiled objects | No #include on the device | The four-layer program structure | Layer 0: OPENCL.cl --- the global configuration header | Layer 1: The upstream shim layer | Type stubs | Capability macros | Runtime no-ops | Math declarations | The design principle | Layer 2: The nmath library and its annotation scheme | @provides and @depends annotations | Only the required subset is loaded | Layer 3: The kernel function | Assembling the program in C++ | What this means for downstream developers

Last update: 2026-06-04
Started: 2020-07-05

Chapter 05: Kernels, Kernel Runners, and Kernel Wrappers
Introduction | How this chapter is organized | The computation in the example: GLM log-posterior over a grid | Serial vs. parallel execution: the fundamental concept | The serial (CPU) mental model | The parallel (GPU) mental model | When OpenCL is not available | Summary | The kernel wrapper | General description | Example: f2_f3_opencl from ex_glmbayes | Step 1 — Convert C++ input types to flat std::vector | Step 2 — Allocate output buffers | Step 3 — Select the kernel and assemble the program string | Step 4 — Dispatch to the runner | Step 5 — Convert outputs from plain C++ back to the required return types | The kernel runner | Example: f2_f3_kernel_runner from ex_glmbayes | Step 1 — Select a device | Step 2 — Create a context and command queue | Step 3 — Compile the program on-device | Step 4 — Allocate device buffers and transfer input data | Step 5 — Bind kernel arguments | Step 6 — Launch the kernel | Step 7 — Read results back to the host (blocking) | Step 8 — Release all resources | The kernel (*.cl) | Example: f2_f3_binomial_logit from ex_glmbayes | The kernel signature | The parallel execution body | The complete call chain | CRAN safety: how the architecture prevents build failures | Applying the pattern in your package | File layout | Type conversion reference | Headers and DESCRIPTION

Last update: 2026-06-04
Started: 2020-07-05

Chapter 06: Integrating Kernel Wrappers into Your Codebase
Introduction | The two integration patterns | Pattern 1: wrapper with a direct R interface | Pattern 2: wrapper as an internal C++ component | Pattern 1 in detail: dnorm_opencl | The R wrapper | The .opencl_try_or_fallback helper | The C++ kernel wrapper | Pattern 2 in detail: f2_f3_opencl | The exported R function | The C++ dispatcher | Why a dedicated CPU implementation? | Choosing between the two patterns | Naming conventions | Summary

Last update: 2026-06-04
Started: 2020-07-05

Chapter 09: Generic OpenCL Kernel Runners (openclPort layer)
The openclPort namespace | opencl_dbl_scalar_kernel_runner | Declaration | Arguments | What it does | Argument layout contract | Example: calling the runner from a kernel wrapper | Error-handling utilities | opencl_status_name | opencl_status_hint | opencl_read_platform_info_str / opencl_read_device_info_str | opencl_make_context_error | Other utilities in openclPort | Rcpp -> std::vector conversion | Device probing (C++ / openclPort) | OpenCL build configuration | Using openclPort from a downstream package

Last update: 2026-06-04
Started: 2020-07-05

Chapter 10: Case Study --- Building Custom GLM Kernels (ex_glmbayes)
Overview | Step 1 --- Identify the nmath functions your kernel needs | Step 2 --- Extract the minimal nmath subset | Step 3 --- Write the kernel files | Step 4 --- Write the kernel runner (C++) | Step 5 --- Write the kernel wrapper (C++) | Why load_library_for_kernel() rather than load_kernel_library()? | Step 6 --- Write the Rcpp export wrappers (C++ and R) | Step 7 --- Implement the CPU fallback | File inventory | OpenCL source (inst/cl/) | C++ source (src/) | C++ headers (src/) | R source (R/) | Adapting this pattern for a new package

Last update: 2026-06-04
Started: 2020-07-05

Chapter 11: Testing, Debugging, and Benchmarking GPU Kernels
Correctness testing | Debugging kernel failures | Benchmarking

Last update: 2026-06-04
Started: 2020-07-05

Chapter 02: Adding USE_OPENCL and has_opencl() to Your Package
Overview | Why a static src/Makevars breaks CRAN | The configure → USE_OPENCL → has_opencl() chain | Adding has_opencl() to your package | C++ side | R side | Case 1: New package with no existing src/Makevars | Case 2: Existing package with a static src/Makevars | What is preserved | Caveats | Guarding OpenCL code in C++ | Testing the CPU-only path before CRAN submission | DESCRIPTION dependencies | Migration note

Last update: 2026-06-04
Started: 2020-07-05

Chapter 04: The nmath OpenCL Library
What is inst/cl/nmath/? | Annotation scheme | File families | Infrastructure / header files | Core math helpers | Density functions (d*) | CDF functions (p*) | Quantile functions (q*) | Random-variate generators (r*) | Special functions | Additional utilities | Cycle-breaking artifacts | The ex_glmbayes_nmath/ subset | Porting fidelity

Last update: 2026-06-04
Started: 2020-07-05

Chapter 07: Kernels --- Writing and Using OpenCL Kernel Files
What is a kernel? | Anatomy of a simple kernel | Standard argument layout | The *_ex_kernel.cl variants | Kernel file index | Density kernels | CDF kernels | Quantile kernels | Random-variate kernels | Special function kernels | Math support kernels | RNG core kernels | Utility kernels | Bessel kernels (standard and extended) | Program assembly | Writing a custom kernel

Last update: 2026-06-04
Started: 2020-07-05

Chapter 08: Kernel Loading --- load_kernel_source and load_kernel_library
The assembly problem | opencltools::load_kernel_source() | opencltools::load_kernel_library() | The annotation format | The topological sort algorithm | Verbose output | Cycle detection and breaking | Assembling a complete program | Using libraries from another package | Dependency index --- faster, kernel-specific loading | Building the index --- write_kernel_dependency_index() | Loading with the index --- load_library_for_kernel() (R) | Extracting a subset --- extract_library_subset() | C++ equivalent --- openclPort::load_library_for_kernel() | Error messages

Last update: 2026-06-04
Started: 2020-07-05

Readme and manuals

Help Manual

Help pageTopics
nmathopencl: OpenCL-Ported R Math Library for GPU-Accelerated Packagesnmathopencl-package nmathopencl
Attach Cross-Library Dependency Tags to Kernel Filesattach_cross_library_tags
Attach Library Call Tags to Kernel Filesattach_kernel_call_tags
Attach Dependency Tags to a Dependency-Ordered Kernel Libraryattach_kernel_dependency_tags
The Beta Distribution (OpenCL)dbeta_opencl dnbeta_opencl pbeta_opencl rbeta_opencl
The Binomial Distribution (OpenCL)dbinom_opencl dbinom_raw_opencl pbinom_opencl qbinom_opencl rbinom_opencl
The Cauchy Distribution (OpenCL)dcauchy_opencl pcauchy_opencl qcauchy_opencl rcauchy_opencl
The Chi-squared Distribution (OpenCL)dchisq_opencl pchisq_opencl qchisq_opencl rchisq_opencl
The Exponential Distribution (OpenCL)dexp_opencl pexp_opencl qexp_opencl rexp_opencl
The F Distribution (OpenCL)df_opencl pf_opencl qf_opencl rf_opencl
The Gamma Distribution (OpenCL)dgamma_opencl pgamma_opencl rgamma_opencl
The Geometric Distribution (OpenCL)dgeom_opencl pgeom_opencl qgeom_opencl rgeom_opencl
The Hypergeometric Distribution (OpenCL)dhyper_opencl phyper_opencl qhyper_opencl rhyper_opencl
The Lognormal Distribution (OpenCL)dlnorm_opencl plnorm_opencl qlnorm_opencl rlnorm_opencl
The Logistic Distribution (OpenCL)dlogis_opencl plogis_opencl qlogis_opencl rlogis_opencl
The Negative Binomial Distribution (OpenCL)dnbinom_mu_opencl dnbinom_opencl pnbinom_mu_opencl pnbinom_opencl qnbinom_mu_opencl qnbinom_opencl rnbinom_mu_opencl rnbinom_opencl
The Normal Distribution (OpenCL)dnorm_opencl pnorm_opencl qnorm_opencl rnorm_opencl
The Poisson Distribution (OpenCL)dpois_opencl dpois_raw_opencl ppois_opencl qpois_opencl rpois_opencl
The Student t Distribution (OpenCL)dt_opencl pt_opencl qt_opencl rt_opencl
The Uniform Distribution (OpenCL)dunif_opencl punif_opencl qunif_opencl runif_opencl
The Weibull Distribution (OpenCL)dweibull_opencl pweibull_opencl qweibull_opencl rweibull_opencl
Evaluate Negative Log-Likelihood and GradientsEx_EnvelopeEval
Envelope Sizing and OptimizationEx_EnvelopeSize
Standardize A Non-Gaussian ModelEx_glmb_Standardize_Model
Return family functions used during simulation and post processingEx_glmbfamfunc print.Ex_glmbfamfunc
Extract a Minimal Library Subset for a Set of Kernelsextract_library_subset
Special Functions (OpenCL)beta_opencl choose_opencl digamma_opencl gammafn_opencl lbeta_opencl lchoose_opencl lgammafn_opencl pentagamma_opencl psigamma_opencl tetragamma_opencl trigamma_opencl
Envelope Evaluation UtilitiesglmbayesEnvelopeExample
Math Support Functions (OpenCL)fmax2_opencl fmin2_opencl fprec_opencl fround_opencl fsign_opencl ftrunc_opencl imax2_opencl imin2_opencl sign_opencl
Load a Minimal OpenCL Library Subset for a Single Kernelload_library_for_kernel
GPU and OpenCL diagnostics for 'nmathopencl'gpu_diagnostics nmathopencl_has_opencl nmathopencl_opencl_device_info nmathopencl_opencl_fp64_available nmathopencl_opencl_reset_device_selection
OpenCL-backed RNG Core linkage checksexp_rand_opencl norm_rand_opencl r_unif_index_opencl unif_rand_opencl
Port an existing static src/Makevars to use OpenCL configure scriptsport_to_opencl_configure
The Studentized Range Distribution (OpenCL)ptukey_opencl qtukey_opencl
OpenCL-backed R_ext runtime utility linkage checksr_check_user_interrupt_opencl
OpenCL-backed R Math runtime linkage checkslgamma1p_opencl log1mexp_opencl log1pexp_opencl log1pmx_opencl logspace_add_opencl logspace_sub_opencl logspace_sum_opencl pow1p_opencl r_pow_di_opencl r_pow_opencl
The Multinomial Distribution (OpenCL linkage subset)rmultinom_opencl
Stage Kernel Library Dependency Sort Resultsstage_kernel_dependency_sort
Set up OpenCL configure scripts in a downstream R packageuse_opencl_configure
Build and save a kernel dependency indexwrite_kernel_dependency_index