Skip to main content

trueno_graph/
lib.rs

1//! trueno-graph: GPU-first embedded graph database
2//!
3//! # Overview
4//!
5//! trueno-graph provides GPU-accelerated graph storage and algorithms for code analysis.
6//! Built on PAIML's proven infrastructure (trueno, trueno-db, aprender).
7//!
8//! # Quick Start
9//!
10//! ```no_run
11//! use trueno_graph::{CsrGraph, NodeId};
12//!
13//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
14//! // Build graph from edge list
15//! let mut graph = CsrGraph::new();
16//! graph.add_edge(NodeId(0), NodeId(1), 1.0)?;  // main → parse_args
17//! graph.add_edge(NodeId(0), NodeId(2), 1.0)?;  // main → validate
18//!
19//! // Query neighbors (O(1) via CSR indexing)
20//! let callees = graph.outgoing_neighbors(NodeId(0))?;
21//! assert_eq!(callees.len(), 2);
22//!
23//! // Save to Parquet (requires "storage" feature, enabled by default)
24//! #[cfg(feature = "storage")]
25//! graph.write_parquet("graph.parquet").await?;
26//!
27//! // Load from disk
28//! #[cfg(feature = "storage")]
29//! let loaded = CsrGraph::read_parquet("graph.parquet").await?;
30//! # Ok(())
31//! # }
32//! ```
33//!
34//! # Architecture
35//!
36//! - **Storage**: CSR (Compressed Sparse Row) format for graphs
37//! - **Persistence**: Parquet-backed (via trueno-db patterns)
38//! - **Algorithms**: Delegates to aprender (`PageRank`, Louvain, centrality)
39//! - **Performance**: 25-250x speedups vs CPU baselines (GPU mode)
40
41#![warn(missing_docs)]
42#![warn(clippy::all)]
43#![warn(clippy::pedantic)]
44#![allow(clippy::module_name_repetitions)]
45
46pub mod algorithms;
47pub mod storage;
48
49// GPU acceleration (Phase 3 - optional)
50#[cfg(feature = "gpu")]
51pub mod gpu;
52
53// Re-export core types
54pub use algorithms::{
55    bfs, connected_components, dijkstra, dijkstra_path, find_callers, find_patterns, is_cyclic,
56    kosaraju_scc, louvain, pagerank, toposort, CommunityDetectionResult, Pattern, PatternMatch,
57    Severity,
58};
59pub use storage::{CsrGraph, NodeId};
60
61#[cfg(feature = "gpu")]
62pub use gpu::{
63    gpu_bfs, gpu_bfs_paged, GpuBfsResult, GpuCsrBuffers, GpuDevice, GpuMemoryLimits, GraphTile,
64    LruTileCache, PagingCoordinator, DEFAULT_MORSEL_SIZE,
65};
66
67// Error type
68pub use anyhow::{Error, Result};