Skip to main content

Crate oxigdal_gpu

Crate oxigdal_gpu 

Source
Expand description

GPU-accelerated geospatial operations for OxiGDAL.

This crate provides GPU acceleration for raster operations using WGPU, enabling 10-100x speedup for large-scale geospatial data processing.

§Features

  • Cross-platform GPU support: Vulkan, Metal, DX12, DirectML, WebGPU
  • Backend-specific optimizations: CUDA, Vulkan, Metal, DirectML
  • Multi-GPU support: Distribute work across multiple GPUs
  • Advanced memory management: Memory pooling, staging buffers, VRAM budget tracking
  • Element-wise operations: Add, subtract, multiply, divide, etc.
  • Statistical operations: Parallel reduction, histogram, min/max, advanced statistics
  • Resampling: Nearest neighbor, bilinear, bicubic, Lanczos interpolation
  • Convolution: Gaussian blur, edge detection, FFT-based, custom filters
  • Pipeline API: Chain operations without CPU transfers
  • Pure Rust: No C/C++ dependencies
  • Safe: Comprehensive error handling, no unwrap()

§Quick Start

use oxigdal_gpu::*;

// Initialize GPU context
let gpu = GpuContext::new().await?;

// Create compute pipeline
let data: Vec<f32> = vec![1.0; 1024 * 1024];
let result = ComputePipeline::from_data(&gpu, &data, 1024, 1024)?
    .gaussian_blur(2.0)?
    .multiply(1.5)?
    .clamp(0.0, 255.0)?
    .read_blocking()?;

§GPU Backend Selection

use oxigdal_gpu::*;

// Auto-select best backend for platform
let gpu = GpuContext::new().await?;

// Or specify backend explicitly
let config = GpuContextConfig::new()
    .with_backend(BackendPreference::Vulkan)
    .with_power_preference(GpuPowerPreference::HighPerformance);

let gpu = GpuContext::with_config(config).await?;

§NDVI Computation Example

use oxigdal_gpu::*;

let gpu = GpuContext::new().await?;

// Load multispectral imagery (R, G, B, NIR bands)
let bands_data: Vec<Vec<f32>> = vec![
    vec![0.0; 512 * 512], // Red
    vec![0.0; 512 * 512], // Green
    vec![0.0; 512 * 512], // Blue
    vec![0.0; 512 * 512], // NIR
];

// Create GPU raster buffer
let raster = GpuRasterBuffer::from_bands(
    &gpu,
    512,
    512,
    &bands_data,
    wgpu::BufferUsages::STORAGE,
)?;

// Compute NDVI
let pipeline = MultibandPipeline::new(&gpu, &raster)?;
let ndvi = pipeline.ndvi()?;

// Apply threshold and export
let vegetation = ndvi
    .threshold(0.3, 1.0, 0.0)?
    .read_blocking()?;

§Performance

GPU acceleration provides significant speedups for large rasters:

OperationCPU (single-thread)GPUSpeedup
Element-wise ops100 ms1 ms100x
Gaussian blur500 ms5 ms100x
Resampling200 ms10 ms20x
Statistics150 ms2 ms75x

§Error Handling

All GPU operations return GpuResult<T> and handle errors gracefully:

use oxigdal_gpu::*;

match GpuContext::new().await {
    Ok(gpu) => {
        // Use GPU acceleration
    }
    Err(e) if e.should_fallback_to_cpu() => {
        // Fallback to CPU implementation
        println!("GPU not available, using CPU: {}", e);
    }
    Err(e) => {
        eprintln!("GPU error: {}", e);
    }
}

Re-exports§

pub use algebra::AlgebraOp;
pub use algebra::BandExpression;
pub use algebra::GpuAlgebra;
pub use buffer::GpuBuffer;
pub use buffer::GpuRasterBuffer;
pub use compute::ComputePipeline;
pub use compute::MultibandPipeline;
pub use context::BackendPreference;
pub use context::GpuContext;
pub use context::GpuContextConfig;
pub use context::GpuPowerPreference;
pub use error::GpuError;
pub use error::GpuResult;
pub use kernels::convolution::Filters;
pub use kernels::convolution::gaussian_blur;
pub use kernels::raster::ElementWiseOp;
pub use kernels::raster::RasterKernel;
pub use kernels::raster::ScalarOp;
pub use kernels::raster::UnaryOp;
pub use kernels::resampling::ResamplingMethod;
pub use kernels::resampling::resize;
pub use kernels::statistics::HistogramParams;
pub use kernels::statistics::ReductionOp;
pub use kernels::statistics::Statistics;
pub use kernels::statistics::compute_statistics;
pub use memory::MemoryPool;
pub use memory::MemoryPoolConfig;
pub use memory::StagingBufferManager;
pub use memory::VramBudgetManager;
pub use multi_gpu::DistributionStrategy;
pub use multi_gpu::InterGpuTransfer;
pub use multi_gpu::MultiGpuConfig;
pub use multi_gpu::MultiGpuManager;
pub use multi_gpu::WorkDistributor;
pub use reprojection::GpuReprojector;
pub use reprojection::ReprojectionConfig;
pub use reprojection::ResampleMethod;
pub use webgpu_compat::GpuCapabilities;
pub use webgpu_compat::ShaderRegistry;

Modules§

algebra
GPU-accelerated raster algebra operations.
backends
Backend-specific optimizations for different GPU APIs.
buffer
GPU buffer management for OxiGDAL.
compositing
Tile compositing pipeline for the GPU rendering layer.
compute
GPU compute pipeline for chaining operations.
context
GPU context management for OxiGDAL.
error
GPU error types for OxiGDAL.
kernels
GPU kernels for raster operations.
memory
Advanced GPU memory management for OxiGDAL.
multi_gpu
Multi-GPU support for distributed GPU computing.
reprojection
GPU-accelerated raster reprojection using wgpu compute shaders.
shader_reload
Shader hot-reload support for the GPU rendering pipeline.
shaders
WGSL shader management for OxiGDAL GPU operations.
webgpu_compat
WebGPU compatibility layer for WASM targets.

Constants§

VERSION
Library version.

Functions§

get_available_adapters
Get information about available GPU adapters.
is_gpu_available
Check if GPU is available on the current system.