Skip to contents

Overview

The batch Lowess type can execute on a GPU-accelerated backend powered by wgpu (Vulkan / Metal / DX12 / GLES on Android). The GPU backend reimplements almost the entire LOWESS pipeline — local regression fitting, robustness iterations, interval bounds, and cross-validation — as compute shaders, so all anchor points are fitted in parallel.

Batch only. GPU support applies to the batch Lowess type only. StreamingLowess and OnlineLowess remain CPU-only.

GPU acceleration is worth enabling for roughly 10K+ points. For smaller inputs the CPU backend (optionally with parallel = TRUE) is typically faster once GPU dispatch overhead is accounted for.


Supported Features on GPU

Feature CPU GPU
Batch fitting ✅ ✅
Streaming / Online ✅ ❌
All weight / robustness / scaling methods ✅ ✅
Confidence / prediction intervals ✅ ✅
Cross-validation (k-fold, LOOCV) ✅ ✅
Unsorted inputs and return_sorted ✅ ✅
Custom per-observation weights ✅ ✅

GPU fits preserve Batch output ordering for unsorted input and return_sorted. Custom per-observation weights are applied in GPU fit and cross-validation candidate kernels. Each compute pipeline binds only its own resources, so compatible adapter limits depend on the largest individual GPU pass rather than all shader bindings combined.


Checking GPU Availability

Returns TRUE if the currently loaded library was built with GPU support, FALSE otherwise.


Installing GPU Support

GPU support is opt-in and not included in standard CRAN / R-universe builds. Install it with a one-time download:

library(rfastlowess)

install_gpu()          # interactive — prompts for confirmation
install_gpu(yes = TRUE) # non-interactive

install_gpu() downloads a prebuilt GPU-enabled library from the gpu-builds release — a single perpetual release holding GPU artifacts for every version, so individual version release pages stay uncluttered — and copies it into the installed package’s libs/ directory.

Prebuilt R GPU libraries are built for Linux x86_64/ARM64 with glibc or musl (Alpine), macOS x86_64/ARM64, and Windows x86_64/ARM64. The installer selects a matching R architecture and the libc linked by R, and verifies GPU support in the candidate library after confirmation. On Windows, the library is installed in a versioned sidecar directory, leaving the loaded CPU DLL untouched; after restarting R, the package activates the matching sidecar’s native routines. Other platforms require atomic replacement of the installed library. Local candidates use the platform’s canonical library filename, regardless of their original filename extension.

Downloads must match the SHA-256 digest published in GitHub release metadata before any native code is executed. Missing digests cause installation to fail closed. Candidate probes have a 30-second timeout and require a matching package version, native ABI contract, and registered argument counts. GPU artifacts built before this contract was introduced must be rebuilt.

On Windows, a broken newest sidecar is skipped in favor of an older compatible one. Activated sidecars remain mapped until R exits, so unloading the namespace cannot invalidate finalizers belonging to live models. Probing isolates crashes but is not a security sandbox: install only trusted local native libraries.

Restart R after installation.

Alternatively, build from source with GPU support:

make -f bindings/r/Makefile WITH_GPU=1

Using the GPU Backend

Once GPU support is installed, pass backend = "gpu" to Lowess():

library(rfastlowess)
set.seed(42)
n <- 100000
x <- seq(0, 2 * pi, length.out = n)
y <- sin(x) + rnorm(n, sd = 0.3)

model <- Lowess(
    fraction  = 0.5,
    iterations = 3,
    backend   = "gpu"
)
result <- fit(model, x, y)

Performance Guidelines

Scenario Recommendation
n < 10K CPU (parallel = TRUE)
n 10K–100K Try both; GPU wins for larger fractions
n > 100K GPU backend recommended
fraction = 0.5, n ≥ 50K GPU outperforms CPU-parallel
fraction = 0.1, n ≥ 250K GPU crossover point

At n = 1M (fraction = 0.5, 3 iterations), the GPU backend is approximately 6.6× faster than CPU-parallel.


Fallback Behaviour

If backend = "gpu" is requested but GPU support is not installed, an informative error is raised pointing to install_gpu(). No silent fallback to CPU occurs.

sessionInfo()
#> R version 4.6.1 (2026-06-24)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.5 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> time zone: UTC
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] rfastlowess_5.0.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.39     desc_1.4.3        R6_2.6.1          fastmap_1.2.0    
#>  [5] xfun_0.61         cachem_1.1.0      knitr_1.52        htmltools_0.5.9  
#>  [9] rmarkdown_2.32    lifecycle_1.0.5   cli_3.6.6         sass_0.4.10      
#> [13] pkgdown_2.2.1     textshaping_1.0.5 jquerylib_0.1.4   systemfonts_1.3.2
#> [17] compiler_4.6.1    tools_4.6.1       ragg_1.5.2        bslib_0.12.0     
#> [21] evaluate_1.0.5    yaml_2.3.12       otel_0.2.0        jsonlite_2.0.0   
#> [25] rlang_1.3.0       fs_2.1.0          htmlwidgets_1.6.4