fastlowess-cpp
High-performance LOWESS smoothing
Loading...
Searching...
No Matches
GPU Backend

GPU Backend

Run the batch LOWESS fit on the GPU via wgpu (Vulkan/Metal/DX12, GLES on Android) instead of the CPU.

Overview

The batch Lowess type can execute on a GPU-accelerated backend powered by wgpu. It reimplements almost the entire LOWESS pipeline — local regression fitting, robustness iterations, interval bounds, and cross-validation — as WGSL compute shaders, so all anchor points are fit in parallel instead of one at a time on CPU cores.

This is worth enabling for high-throughput processing of large datasets (roughly 10k+ points); for smaller inputs the CPU backend (optionally with parallel = true) is typically faster once you account for GPU dispatch overhead. See BENCHMARKS.md for crossover points measured on real hardware.

‍Batch only. GPU support applies to the batch Lowess type only. StreamingLowess/OnlineLowess remain CPU-only — the Rust core documents GPU as optimized for static batch data, not incremental chunk/point processing.

GPU support is opt-in and not included in prebuilt C++ releases — download a prebuilt GPU-enabled build via the one-time installer below, or build from source with the gpu Cargo feature.

Supported Features

  • Weight Functions: All standard kernels (tricube, epanechnikov, gaussian, uniform, biweight, triangle, cosine).
  • Robustness Methods: bisquare, huber, and talwar robustness weighting.
  • Scaling Methods: Residual scaling using mad (Median Absolute Deviation), mar (Median Absolute Residual), and mean (Mean Absolute Residual).
  • Interval Bounds: GPU-native computation of standard errors, confidence intervals, and prediction intervals.
  • Optimization:
    • Parallel Fitting: Local regression for all anchor points is computed in parallel.
    • Robustness Loops: Iterative weight updates and convergence checks occur entirely on the GPU.
    • Distance-based Skipping: Support for the delta parameter to accelerate smoothing on dense grids.
  • Validation: GPU-accelerated kfold and loocv cross-validation.

Feature Comparison

Feature CPU GPU Notes
Batch fitting ✅ ✅
Streaming/Online ✅ ❌ GPU optimized for static batch data
All weight/robustness/scaling methods ✅ ✅
Confidence/prediction intervals ✅ ✅
Cross-validation (k-fold, LOOCV) ✅ ✅
Unsorted inputs and sorted-output option ✅ ✅ GPU results preserve Batch output ordering.
Custom per-observation weights ✅ ✅ Applied in GPU fit and CV candidate kernels.

Each compute pipeline now binds only its own resources, so adapter limits are based on the largest individual GPU pass rather than the union of all shader bindings.


Checking Availability

Before requesting backend = "gpu", check whether the currently loaded library was built with GPU support. Requesting the GPU backend when it isn't available raises a clear error pointing at fastlowess::gpu::install(), rather than a raw panic.

#include <fastlowess.hpp>
fastlowess::gpu::available();
C++ wrapper for fastLowess library.

Installing GPU Support

This binding ships a one-time installer that downloads a prebuilt GPU-enabled build from the gpu-builds release (built by .github/workflows/release-gpu.yml) — a single perpetual release holding GPU artifacts for every version, so individual version release pages stay uncluttered; the source version is embedded in each asset's filename instead. Building from source with the gpu Cargo feature is always available as an alternative.

#include <fastlowess.hpp>
fastlowess::gpu::install(); // prompts for confirmation via curl, then downloads

Non-interactively: fastlowess::gpu::install(/*yes=*/true). Requires curl on PATH (ships with Linux, macOS, and Windows 10+). A running process cannot swap the backend of a library it already linked against — after downloading, relink/rebuild your application against the downloaded library (or dlopen/LoadLibrary it manually) and restart.

Build from source instead:

cd bindings/cpp
cargo build --release --features gpu

Usage

Once GPU support is available, request it by setting the backend option on the batch constructor.

#include <fastlowess.hpp>
opts.fraction = 0.5;
opts.backend = "gpu";
opts.intervals.confidence = 0.95;
fastlowess::Lowess model(opts);
auto result = model.fit(x, y);
Batch LOWESS model.
Definition fastlowess.hpp:804
double confidence
Definition fastlowess.hpp:91
Options for configuring LOWESS smoothing.
Definition fastlowess.hpp:194
IntervalsOptions intervals
Definition fastlowess.hpp:205
std::string backend
Execution backend: "cpu" (default) or "gpu" (requires the library to be built with the gpu Cargo feat...
Definition fastlowess.hpp:215
double fraction
Smoothing fraction (0, 1].
Definition fastlowess.hpp:195

If GPU support isn't available, requesting backend = "gpu" raises a runtime error pointing at fastlowess::gpu::install() rather than a raw Rust panic.

Hardware Requirements

The GPU backend leverages wgpu and supports:

  • Vulkan (Linux/Windows)
  • Metal (macOS/iOS)
  • DirectX 12 (Windows)
  • GLES (Android)

It requires a device supporting compute shaders. If no compatible GPU is found at runtime, model construction raises an error.

Performance Considerations

The GPU backend is optimized for large datasets (N > 100,000) and provides parallelization through compute shaders. For smaller datasets, the CPU backend (backend = "cpu", the default) is faster.