scirs2_graph/gpu/mod.rs
1//! GPU-accelerated and parallel graph algorithms.
2//!
3//! This module provides parallel graph traversal and shortest-path algorithms
4//! designed with a GPU-ready interface. When the `wgpu` feature is enabled and
5//! a compatible wgpu adapter is present, BFS and Bellman-Ford SSSP dispatch to
6//! real GPU compute shaders. Otherwise, all operations fall back to
7//! CPU-parallel implementations using atomic compare-and-swap.
8//!
9//! # Algorithms
10//!
11//! - [`algorithms::gpu_bfs`] — Parallel BFS (level-synchronous, frontier-based)
12//! - [`algorithms::gpu_sssp_bellman_ford`] — Bellman-Ford SSSP (GPU-friendly, detects
13//! negative cycles in CPU path)
14//! - [`algorithms::gpu_sssp_delta_stepping`] — Delta-stepping SSSP (dispatches
15//! Bellman-Ford GPU kernel; true bucket-based delta-stepping planned for Wave 76)
16//!
17//! # Graph Format
18//!
19//! Algorithms in this module accept graphs in **Compressed Sparse Row (CSR)** format
20//! for BFS/Bellman-Ford, or adjacency-list format for delta-stepping. CSR is the
21//! preferred format for GPU workloads due to coalesced memory access.
22//!
23//! ```rust,no_run
24//! use scirs2_graph::gpu::algorithms::{gpu_bfs, GpuBfsConfig};
25//!
26//! // 3-node path: 0 -> 1 -> 2
27//! let row_ptr = vec![0, 1, 2, 2];
28//! let col_idx = vec![1, 2];
29//! let config = GpuBfsConfig::default();
30//! let dist = gpu_bfs(&row_ptr, &col_idx, 0, &config).expect("bfs failed");
31//! assert_eq!(dist[0], 0);
32//! assert_eq!(dist[1], 1);
33//! assert_eq!(dist[2], 2);
34//! ```
35
36pub mod algorithms;
37pub(crate) mod parallel;
38
39#[cfg(feature = "wgpu")]
40pub(crate) mod wgpu_shaders;
41
42pub use algorithms::{
43 gpu_bfs, gpu_sssp_bellman_ford, gpu_sssp_delta_stepping, GpuBfsConfig, GpuGraphBackend,
44};