1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! # Perdix - High-Performance GPU-Accelerated Ring Buffer
//!
//! Perdix is a zero-copy, lock-free SPSC (Single Producer Single Consumer) ring buffer
//! designed for ultra-low latency streaming between GPU producers and CPU consumers.
//! Optimized for AI text streaming workloads with ANSI formatting support.
//!
//! ## Key Features
//!
//! - **Zero-Copy Architecture**: CUDA unified memory eliminates CPU-GPU memcpy overhead
//! - **Lock-Free Design**: Atomic sequence numbers ensure ordering without locks
//! - **Sub-Microsecond Latency**: <1μs producer-to-consumer communication
//! - **Multi-Backend Support**: CUDA, WebGPU, and CPU fallback implementations
//! - **Runtime Compilation**: NVRTC for dynamic kernel generation (bypasses toolchain conflicts)
//! - **Production Ready**: Comprehensive error handling and recovery mechanisms
//!
//! ## Performance Characteristics
//!
//! - **Throughput**: 2-3 GB/s sustained
//! - **Message Rate**: >10M messages/second
//! - **Memory Layout**: Cache-aligned 256-byte slots
//! - **Batch Processing**: Warp-level batching reduces atomic contention
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use perdix::{Buffer, AgentType};
//!
//! // Create a ring buffer with 4096 slots
//! let mut buffer = Buffer::new(4096).expect("Failed to create buffer");
//!
//! // Split into producer and consumer
//! let (mut producer, mut consumer) = buffer.split_mut();
//!
//! // Producer writes messages (can be from GPU or CPU)
//! producer.try_produce(b"Hello from Perdix!", AgentType::Assistant);
//!
//! // Consumer reads messages
//! if let Some(message) = consumer.try_consume() {
//! println!("Received: {}", message.as_str());
//! }
//! ```
//!
//! ## Architecture Overview
//!
//! ```text
//! ┌─────────────┐ ┌─────────────────┐ ┌─────────────┐
//! │ GPU Kernel │────▶│ Ring Buffer │◀────│ CPU Reader │
//! │ Producer │ │ (Unified Mem) │ │ Consumer │
//! └─────────────┘ └─────────────────┘ └─────────────┘
//! ▲
//! Zero-Copy Shared Memory
//! ```
//!
//! ## Usage Modes
//!
//! ### Interactive REPL Mode
//! ```bash
//! cargo run --features cuda --bin perdix -- --repl
//! ```
//!
//! ### Continuous Streaming Mode
//! ```bash
//! cargo run --features cuda --bin perdix -- --stream
//! ```
//!
//! ### Performance Benchmarking
//! ```bash
//! cargo run --features cuda --bin perdix -- --benchmark
//! ```
//!
//! ## Feature Flags
//!
//! - `cuda`: Enable NVIDIA CUDA acceleration (recommended for production)
//! - `webgpu`: Enable WebGPU backend (experimental, cross-platform)
//! - `runtime`: Enable runtime kernel compilation via NVRTC
//!
//! ## Safety and Error Handling
//!
//! Perdix enforces memory safety through Rust's ownership system while providing
//! high-performance GPU interop. All FFI boundaries are documented with safety
//! requirements and error codes.
// Re-export key types
pub use ;
pub use ;
pub use GpuProducer;
pub use ;