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 band_math::BandMathError;
pub use band_math::band_expression_to_wgsl;
pub use band_math::parse_band_expression;
pub use buffer::BufferElementType;
pub use buffer::GpuBuffer;
pub use buffer::GpuRasterBuffer;
pub use buffer::f16_to_f32_slice;
pub use buffer::f32_to_f16_slice;
pub use buffer::from_f16_slice_native;
pub use buffer::from_f16_slice_widening;
pub use buffer::read_f16_from_f32_buffer;
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 convolution_fft::FftConvolution;
pub use convolution_fft::MAX_FFT_CONVOLUTION_SIZE;
pub use convolution_fft::complex_multiply;
pub use convolution_fft::convolve_reference;
pub use cooperative_matrix::CoopMatrixComponentType;
pub use cooperative_matrix::CoopMatrixDescriptor;
pub use cooperative_matrix::CoopMatrixDim;
pub use cooperative_matrix::CoopMatrixGemmConfig;
pub use cooperative_matrix::CoopMatrixUse;
pub use cooperative_matrix::build_cooperative_matrix_gemm_pipeline;
pub use cooperative_matrix::dispatch_cooperative_gemm;
pub use cooperative_matrix::make_gemm_wgsl;
pub use cooperative_matrix::make_gemm_wgsl_fallback;
pub use cooperative_matrix::max_cooperative_matrix_dim;
pub use cooperative_matrix::supports_cooperative_matrix;
pub use cpu_fallback::cpu;
pub use cpu_fallback::ExecutionPath;
pub use cpu_fallback::FallbackConfig;
pub use cpu_fallback::FallbackContext;
pub use cpu_fallback::FallbackResult;
pub use cpu_fallback::execute_with_fallback;
pub use cpu_fallback::execute_with_fallback_timed;
pub use error::GpuError;
pub use error::GpuResult;
pub use fft::Fft1d;
pub use fft::bit_reverse;
pub use fft::make_fft_shader_source;
pub use fft::twiddle_factor;
pub use fft::validate_size;
pub use indirect_dispatch::DispatchIndirectArgs;
pub use indirect_dispatch::IndirectDispatchBuffer;
pub use indirect_dispatch::args_for_elements;
pub use indirect_dispatch::dispatch_indirect_on_pass;
pub use indirect_dispatch::workgroup_count_1d;
pub use indirect_dispatch::workgroup_count_2d;
pub use indirect_dispatch::workgroup_count_3d;
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 pipeline_cache::PipelineCache;
pub use pipeline_cache::PipelineCacheKey;
pub use pipeline_cache::SharedPipelineCache;
pub use pipeline_cache::fnv1a_64;
pub use pipeline_cache::new_shared_pipeline_cache;
pub use profiling::GpuTimestampProfiler;
pub use profiling::PassTiming;
pub use push_constants::MAX_PUSH_CONSTANTS_SIZE_BYTES;
pub use push_constants::PushConstantRange;
pub use push_constants::PushConstantRangeDesc;
pub use push_constants::PushConstantsBuffer;
pub use push_constants::PushConstantsLayout;
pub use push_constants::build_push_constants_pipeline;
pub use push_constants::dispatch_with_push_constants;
pub use push_constants::make_push_constants_shader_source;
pub use push_constants::max_push_constants_size;
pub use push_constants::supports_push_constants;
pub use ray_march::DemRayMarcher;
pub use ray_march::RayMarchConfig;
pub use ray_march::RayMarchResult;
pub use ray_march::make_ray_march_shader_source;
pub use ray_march::normalize3;
pub use ray_march::ray_march_cpu;
pub use ray_march::sample_dem_bilinear;
pub use reprojection::GpuReprojector;
pub use reprojection::ReprojectionConfig;
pub use reprojection::ResampleMethod;
pub use shader_helpers::make_element_wise_shader_source;
pub use storage_texture::StorageTextureBinding;
pub use storage_texture::StorageTextureKernel;
pub use storage_texture::build_storage_texture_kernel;
pub use storage_texture::is_supported_storage_format;
pub use storage_texture::make_storage_texture_shader_source;
pub use storage_texture::new_storage_texture;
pub use storage_texture::read_texture_to_vec_f32;
pub use texture_compress::TextureCompressor;
pub use texture_compress::TextureFormat;
pub use texture_compress::compress_bc1_block_cpu;
pub use texture_compress::compress_bc4_block_cpu;
pub use texture_compress::dequantize_rgb565;
pub use texture_compress::nearest_index_4;
pub use texture_compress::quantize_rgb565;
pub use texture_compress::validate_texture_dimensions;
pub use texture_resample::TextureFilterMethod;
pub use texture_resample::TextureResampler;
pub use texture_resample::make_texture_resample_shader_source;
pub use texture_resample::new_input_texture_r32float;
pub use texture_resample::texture_filter_for_resampling;
pub use tiled::RasterTile;
pub use tiled::TiledConfig;
pub use tiled::auto_tile_size;
pub use tiled::execute_tiled;
pub use tiled::split_into_tiles;
pub use tiled::stitch_tiles;
pub use tiled::vram_per_tile;
pub use webgpu_compat::GpuCapabilities;
pub use webgpu_compat::ShaderRegistry;
pub use workgroup_tuner::WorkgroupTuner;
pub use half;

Modules§

algebra
GPU-accelerated raster algebra operations.
backends
Backend-specific optimizations for different GPU APIs.
band_math
Band-math expression compiler — string parser + WGSL codegen.
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.
convolution_fft
FFT-based 1D linear convolution for OxiGDAL GPU.
cooperative_matrix
Cooperative-matrix (WMMA-style tile MMA) infrastructure for oxigdal-gpu.
cpu_fallback
Automatic CPU fallback for GPU operations.
device_lost_test
CPU-only unit tests for GPU device-lost recovery machinery.
error
GPU error types for OxiGDAL.
fft
Radix-2 1D FFT GPU compute kernel for OxiGDAL.
indirect_dispatch
Indirect compute dispatch support for GPU-driven workloads.
kernels
GPU kernels for raster operations.
memory
Advanced GPU memory management for OxiGDAL.
multi_gpu
Multi-GPU support for distributed GPU computing.
pipeline_cache
Compute-pipeline cache keyed by shader hash.
profiling
GPU timestamp profiling using wgpu::Features::TIMESTAMP_QUERY.
push_constants
WGSL push constants (immediates) helper for oxigdal-gpu.
ray_march
Ray-marching WGSL shader for volumetric DEM rendering.
reprojection
GPU-accelerated raster reprojection using wgpu compute shaders.
shader_helpers
WGSL shader source helpers for OxiGDAL GPU.
shader_reload
Shader hot-reload support for the GPU rendering pipeline.
shaders
WGSL shader management for OxiGDAL GPU operations.
storage_texture
Storage-texture output kernel support for OxiGDAL GPU.
texture_compress
Multi-format texture compression (BC1 and BC4) for OxiGDAL GPU.
texture_resample
Texture-based resampling using wgpu hardware samplers.
tiled
Tiled raster processing for datasets exceeding VRAM budget.
webgpu_compat
WebGPU compatibility layer for WASM targets.
workgroup_tuner
Workgroup-size auto-tuning derived from GPU adapter limits.

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.