trueno_gpu/lib.rs
1//! # trueno-gpu: Pure Rust PTX Generation for NVIDIA CUDA
2//!
3//! Generate PTX assembly directly from Rust - no LLVM, no nvcc, no external dependencies.
4//!
5//! ## Philosophy
6//!
7//! **Own the Stack** - Build everything from first principles for complete control,
8//! auditability, and reproducibility.
9//!
10//! ## Quick Start
11//!
12//! ```rust
13//! use trueno_gpu::ptx::{PtxModule, PtxKernel, PtxType};
14//!
15//! // Build a vector addition kernel
16//! let module = PtxModule::new()
17//! .version(8, 0)
18//! .target("sm_70")
19//! .address_size(64);
20//!
21//! let ptx_source = module.emit();
22//! assert!(ptx_source.contains(".version 8.0"));
23//! ```
24//!
25//! ## Modules
26//!
27//! - [`ptx`] - PTX code generation (builder pattern)
28//! - [`driver`] - CUDA driver API (minimal FFI, optional)
29//! - [`kernels`] - Hand-optimized GPU kernels
30//! - [`memory`] - GPU memory management
31//! - [`backend`] - Multi-backend abstraction
32
33// APR-MONO: missing_docs relaxed to the workspace policy (`missing_docs = "allow"`, doc
34// coverage checked separately) now that this ex-repo crate is linted in-tree.
35#![allow(missing_docs)]
36#![warn(rust_2018_idioms)]
37#![deny(unsafe_op_in_unsafe_fn)]
38// ============================================================================
39// Development-phase lint allows - to be addressed incrementally
40// ============================================================================
41// Allow dead code during development - will be used as API expands
42#![allow(dead_code)]
43// APR-MONO: workspace pedantic allows (API consistency)
44#![allow(clippy::trivially_copy_pass_by_ref)]
45#![allow(clippy::unnecessary_wraps)]
46// Allow precision loss in non-critical floating point calculations
47#![allow(clippy::cast_precision_loss)]
48// Allow possible truncation - we handle 64-bit correctly
49#![allow(clippy::cast_possible_truncation)]
50// Allow format push string - not a critical performance path
51#![allow(clippy::format_push_string)]
52// Allow doc markdown for code references - these are placeholders
53#![allow(clippy::doc_markdown)]
54// Allow missing errors doc during initial development
55#![allow(clippy::missing_errors_doc)]
56// Allow unnecessary literal bound for backend trait
57#![allow(clippy::unnecessary_literal_bound)]
58// Allow manual div_ceil - will use std when stabilized
59#![allow(clippy::manual_div_ceil)]
60// Allow missing panics doc during initial development
61#![allow(clippy::missing_panics_doc)]
62// Allow cast_lossless - we intentionally use as for u32->u64
63#![allow(clippy::cast_lossless)]
64// Allow uninlined format args - stylistic preference
65#![allow(clippy::uninlined_format_args)]
66// Allow map_unwrap_or - more readable with map().unwrap_or()
67#![allow(clippy::map_unwrap_or)]
68// Allow redundant closure for method calls - clearer intent
69#![allow(clippy::redundant_closure_for_method_calls)]
70// Allow unused self - methods will use self as API expands
71#![allow(clippy::unused_self)]
72// Allow expect_used in tests and non-critical paths
73#![allow(clippy::expect_used)]
74// Allow too_many_lines during development - will be refactored
75#![allow(clippy::too_many_lines)]
76// Allow needless_range_loop - clearer intent in some algorithms
77#![allow(clippy::needless_range_loop)]
78// Allow float_cmp in tests where exact comparison is intended
79#![allow(clippy::float_cmp)]
80// Allow unused comparisons - some are defensive checks
81#![allow(unused_comparisons)]
82// Allow unwrap_used in tests
83#![allow(clippy::unwrap_used)]
84// Allow cast_sign_loss - we know values are positive
85#![allow(clippy::cast_sign_loss)]
86// Allow field_reassign_with_default - clearer test setup
87#![allow(clippy::field_reassign_with_default)]
88// Allow panic in tests
89#![allow(clippy::panic)]
90// Allow manual_range_contains - clearer in assertions
91#![allow(clippy::manual_range_contains)]
92// Allow default_constructed_unit_structs
93#![allow(clippy::default_constructed_unit_structs)]
94// Allow clone_on_copy - clearer intent
95#![allow(clippy::clone_on_copy)]
96// Allow absurd_extreme_comparisons - defensive checks
97#![allow(clippy::absurd_extreme_comparisons)]
98// Allow no_effect_underscore_binding - intentional in tests
99#![allow(clippy::no_effect_underscore_binding)]
100// Allow must_use_candidate - methods may return values not always needed
101#![allow(clippy::must_use_candidate)]
102// Allow manual_find - clearer intent in some cases
103#![allow(clippy::manual_find)]
104// Allow type_complexity - complex return types for tuples
105#![allow(clippy::type_complexity)]
106// Allow range_plus_one - clearer in some contexts
107#![allow(clippy::range_plus_one)]
108// Allow map_clone - clearer intent
109#![allow(clippy::map_clone)]
110// Allow manual_is_multiple_of - not yet stabilized
111#![allow(clippy::manual_is_multiple_of)]
112// Allow items_after_statements - const definitions in kernels
113#![allow(clippy::items_after_statements)]
114// Allow doc_lazy_continuation - doc formatting
115#![allow(clippy::doc_lazy_continuation)]
116// Allow useless_vec in tests - clearer intent
117#![allow(clippy::useless_vec)]
118// Allow similar names - k_h vs kt_h are semantically distinct (key vs key-transposed)
119#![allow(clippy::similar_names)]
120// Allow many single char names - standard matrix notation (a, b, m, n, k)
121#![allow(clippy::many_single_char_names)]
122// Allow doc nested refdefs - acceptable in list items
123#![allow(clippy::doc_nested_refdefs)]
124// Allow cloned instead of copied - semantic clarity
125#![allow(clippy::cloned_instead_of_copied)]
126// Allow too many arguments - GPU APIs require many parameters
127#![allow(clippy::too_many_arguments)]
128// Allow explicit lifetimes - clearer for complex lifetime relationships
129#![allow(clippy::elidable_lifetime_names)]
130// Allow manual slice size calculation - clearer intent
131#![allow(clippy::manual_slice_size_calculation)]
132#![allow(clippy::large_stack_arrays)]
133
134pub mod backend;
135/// CUDA driver FFI — feature-gated behind `cuda`. Default build has zero unsafe.
136/// Will be deleted entirely once memory/resident is migrated to wgpu (§26 Phase 3).
137#[cfg(feature = "cuda")]
138pub mod driver;
139/// PMAT-291: Tensor compute graph for GPU inference (reduces 430 dispatches to ~15)
140pub mod graph;
141/// PTX kernel generators — feature-gated behind `cuda`. Safe Rust (no unsafe blocks)
142/// but produces PTX text that requires CUDA driver to execute. Dead code without `cuda`.
143#[cfg(feature = "cuda")]
144pub mod kernels;
145/// GPU memory management — feature-gated behind `cuda` (uses driver FFI).
146#[cfg(feature = "cuda")]
147pub mod memory;
148pub mod monitor;
149/// PTX instruction builder — feature-gated behind `cuda`. Safe Rust.
150#[cfg(feature = "cuda")]
151pub mod ptx;
152
153/// Error types for trueno-gpu operations
154pub mod error;
155
156/// E2E visual testing framework for GPU kernels
157pub mod testing;
158
159pub use error::{GpuError, Result};
160pub use monitor::{cuda_device_count, cuda_monitoring_available, CudaDeviceInfo, CudaMemoryInfo};
161
162// NOTE: ComputeBrick is available from the trueno crate, not trueno-gpu
163// This is because trueno optionally depends on trueno-gpu (not vice versa)
164// Usage: `use trueno::brick::{ComputeBrick, ComputeBackend, TokenBudget};`
165// See: trueno/src/brick.rs for the full brick architecture
166
167#[cfg(test)]
168mod tests {
169 #[test]
170 fn test_crate_compiles() {
171 // Smoke test - crate compiles
172 let _ = super::error::Result::<()>::Ok(());
173 }
174}