Run the batch LOWESS fit on the GPU via wgpu (Vulkan/Metal/DX12) 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 a default build of fastlowess-java — it requires building the native library 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#

FeatureCPUGPUNotes
Batch fitting✅✅
Streaming/Online✅❌GPU optimized for static batch data
All weight/robustness/scaling methods✅✅
Confidence/prediction intervals✅✅
Cross-validation (k-fold, LOOCV)✅✅
Custom per-observation weights✅✅

Checking Availability#

Before requesting backend("gpu"), check whether the currently loaded native library was built with GPU support:

if (!FastLowess.gpuEnabled()) {
    throw new IllegalStateException("this build of fastlowess_java was not compiled with the gpu feature");
}

Requesting the GPU backend when it isn’t available throws a clear RuntimeException from the Lowess constructor, rather than a raw crash.


Building with GPU Support#

Unlike the Python, Node.js, and R bindings, the Java binding does not ship a one-time GPU installer. Build the native library from source with the gpu Cargo feature instead:

cargo build -p fastlowess-java --release --features gpu

Since NativeBridge loads the shared library by path (via the fastlowess.native.dir system property), simply point it at the GPU-enabled build — no application rebuild is required, unlike Go’s static-linking approach.


Usage#

Once GPU support is available, request it by setting backend on the batch options:

Options options = Options.builder()
        .backend("gpu")
        .confidenceIntervals(0.95)
        .build();

try (Lowess model = new Lowess(options)) {
    Result result = model.fit(x, y);
}

If GPU support isn’t available, the Lowess constructor throws a RuntimeException pointing at how to build a GPU-enabled library, rather than crashing.

Hardware Requirements#

The GPU backend leverages wgpu and supports:

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

It requires a device supporting compute shaders. If no compatible GPU is found at runtime, the Lowess constructor throws a RuntimeException.

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