Skip to main content

oxigdal_gpu_advanced/
lib.rs

1//! Advanced GPU computing for geospatial operations with multi-GPU support.
2//!
3//! This crate provides advanced GPU computing capabilities for OxiGDAL including:
4//! - Multi-GPU orchestration and load balancing
5//! - Advanced memory pool management
6//! - Shader compilation and optimization
7//! - GPU-accelerated terrain analysis
8//! - GPU-based ML inference
9//!
10//! # Features
11//!
12//! - **Multi-GPU Support**: Automatically detect and utilize multiple GPUs
13//! - **Memory Pooling**: Efficient GPU memory management with sub-allocation
14//! - **Shader Optimization**: Compile and optimize WGSL shaders
15//! - **Work Stealing**: Dynamic load balancing across GPUs
16//! - **GPU Affinity**: Thread-to-GPU pinning for optimal performance
17//!
18//! # Examples
19//!
20//! ```rust,no_run
21//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
22//! use oxigdal_gpu_advanced::multi_gpu::{MultiGpuManager, SelectionStrategy};
23//!
24//! // Create multi-GPU manager
25//! let manager = MultiGpuManager::new(SelectionStrategy::LeastLoaded).await?;
26//!
27//! // Print available GPUs
28//! manager.print_gpu_info();
29//!
30//! // Select best GPU for task
31//! let gpu = manager.select_gpu()?;
32//! println!("Selected GPU: {}", gpu.info.name);
33//! # Ok(())
34//! # }
35//! ```
36
37#![warn(missing_docs)]
38#![deny(clippy::unwrap_used, clippy::panic)]
39
40pub mod adaptive;
41pub mod error;
42pub mod gpu_ml;
43pub mod gpu_terrain;
44pub mod kernels;
45pub mod memory_compaction;
46pub mod memory_pool;
47pub mod multi_gpu;
48pub mod pipeline_builder;
49pub mod profiling;
50pub mod shader_compiler;
51
52// Re-exports
53pub use adaptive::{
54    AdaptiveConfig, AdaptiveSelector, Algorithm, AlgorithmStats, DeviceInfo, ExecutionStrategy,
55    TuningParams, WorkloadInfo,
56};
57pub use error::{GpuAdvancedError, Result};
58pub use gpu_ml::{ActivationType, GpuMlInference, InferenceStats, PoolType};
59pub use gpu_terrain::{GpuTerrainAnalyzer, TerrainMetrics};
60pub use kernels::{
61    EdgeDetectionKernel, FftKernel, HistogramEqKernel, KernelParams, KernelRegistry,
62    MatrixMultiplyKernel, MorphologyKernel, TextureAnalysisKernel,
63};
64pub use memory_compaction::{
65    CompactionConfig, CompactionResult, CompactionStats, CompactionStrategy, FragmentationInfo,
66    MemoryCompactor,
67};
68pub use memory_pool::{MemoryAllocation, MemoryPool, MemoryPoolStats};
69pub use multi_gpu::{
70    GpuDevice, GpuDeviceInfo, MultiGpuManager, SelectionStrategy,
71    affinity::{AffinityGuard, AffinityManager, AffinityStats},
72    device_manager::{DeviceCapabilities, DeviceFilter, DeviceManager, DevicePerformanceClass},
73    load_balancer::{LoadBalancer, LoadStats},
74    sync::{Barrier, Event, Fence, GpuSemaphore, SemaphoreGuard, SyncManager, SyncStats},
75    work_queue::{BatchSubmitter, WorkQueue, WorkStealingQueue},
76};
77pub use pipeline_builder::{
78    Pipeline, PipelineBuilder, PipelineConfig, PipelineInfo, PipelineStage,
79};
80pub use profiling::{
81    BottleneckKind, BottleneckSeverity, GpuProfiler, KernelStats, PerformanceBottleneck,
82    ProfileSession, ProfilingConfig, ProfilingMetrics, ProfilingReport,
83};
84pub use shader_compiler::{
85    CompiledShader, CompilerStats, ShaderCompiler, ShaderPreprocessor,
86    analyzer::{PerformanceClass, ShaderAnalysis, ShaderAnalyzer},
87    cache::{CacheStats, ShaderCache},
88    optimizer::{OptimizationConfig, OptimizationLevel, OptimizationMetrics, ShaderOptimizer},
89};
90
91/// Library version
92pub const VERSION: &str = env!("CARGO_PKG_VERSION");
93
94/// Library name
95pub const NAME: &str = env!("CARGO_PKG_NAME");
96
97/// Get library information
98pub fn info() -> LibraryInfo {
99    LibraryInfo {
100        name: NAME.to_string(),
101        version: VERSION.to_string(),
102        description: "Advanced GPU computing with multi-GPU support for OxiGDAL".to_string(),
103    }
104}
105
106/// Library information
107#[derive(Debug, Clone)]
108pub struct LibraryInfo {
109    /// Library name
110    pub name: String,
111    /// Library version
112    pub version: String,
113    /// Library description
114    pub description: String,
115}
116
117impl LibraryInfo {
118    /// Print library information
119    pub fn print(&self) {
120        println!("{} v{}", self.name, self.version);
121        println!("{}", self.description);
122    }
123}
124
125#[cfg(test)]
126mod tests {
127    use super::*;
128
129    #[test]
130    fn test_library_info() {
131        let info = info();
132        assert_eq!(info.name, NAME);
133        assert_eq!(info.version, VERSION);
134        assert!(!info.description.is_empty());
135    }
136
137    #[test]
138    fn test_version() {
139        assert!(!VERSION.is_empty());
140        assert!(VERSION.contains('.'));
141    }
142}