aprender-orchestrate 0.31.2

Sovereign AI orchestration: autonomous agents, ML serving, code analysis, and transpilation pipelines
Documentation
//! Pepita: Sovereign AI Kernel Interfaces Demo
//!
//! This example demonstrates pepita's kernel interfaces and distributed
//! computing primitives for Sovereign AI workloads.
//!
//! # Features Demonstrated
//!
//! - **io_uring**: Linux async I/O interface (no syscall overhead per operation)
//! - **ublk**: Userspace block device driver
//! - **blk_mq**: Multi-queue block layer
//! - **zram**: Compressed RAM block device (3-4x compression)
//! - **MicroVM**: KVM-based lightweight VMs (<100ms boot)
//! - **Work-Stealing Scheduler**: Blumofe-Leiserson algorithm
//!
//! # Running
//!
//! ```bash
//! cargo run --example pepita_kernel_demo
//! ```
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │                    Sovereign Infrastructure                      │
//! ├─────────────┬─────────────┬─────────────┬───────────────────────┤
//! │   MicroVM   │    zram     │   virtio    │       SIMD/GPU        │
//! │  (KVM)      │ (compressed)│  (vsock)    │   (AVX-512/wgpu)      │
//! └─────────────┴─────────────┴─────────────┴───────────────────────┘
//! ┌─────────────────────────────────────────────────────────────────┐
//! │                    Kernel Interfaces (no_std)                    │
//! ├─────────────┬─────────────┬─────────────┬───────────────────────┤
//! │  io_uring   │    ublk     │   blk_mq    │       memory          │
//! │ (async I/O) │(block dev)  │ (multiqueue)│   (DMA/pages)         │
//! └─────────────┴─────────────┴─────────────┴───────────────────────┘
//! ```

fn main() {
    println!("===============================================================");
    println!("     Pepita: Sovereign AI Kernel Interfaces Demo");
    println!("===============================================================\n");

    // =========================================================================
    // Section 1: Core Design Principles
    // =========================================================================
    println!("+-------------------------------------------------------------+");
    println!("| Section 1: Design Principles (Iron Lotus Framework)         |");
    println!("+-------------------------------------------------------------+\n");

    println!("  Pepita follows the Iron Lotus Framework:");
    println!();
    println!("  1. First-Principles Rust");
    println!("     - Zero external dependencies in kernel mode");
    println!("     - All data structures defined from scratch");
    println!();
    println!("  2. Pure Rust Sovereignty");
    println!("     - 100% auditable codebase");
    println!("     - Zero C/C++ dependencies");
    println!("     - no_std compatible core");
    println!();
    println!("  3. Toyota Way Quality");
    println!("     - Jidoka: Built-in quality (stop on error)");
    println!("     - Poka-yoke: Error prevention");
    println!("     - Genchi Genbutsu: Go and see for yourself");
    println!();
    println!("  4. EXTREME TDD");
    println!("     - 417 tests covering all modules");
    println!("     - 95% coverage, 80% mutation score");
    println!();

    // =========================================================================
    // Section 2: Kernel Interfaces
    // =========================================================================
    println!("+-------------------------------------------------------------+");
    println!("| Section 2: Kernel Interfaces (no_std compatible)            |");
    println!("+-------------------------------------------------------------+\n");

    println!("  io_uring - Linux Async I/O");
    println!("  ─────────────────────────────────────────");
    println!("  Eliminates syscall overhead by batching I/O operations.");
    println!("  One syscall can submit hundreds of operations.");
    println!();
    println!("  ```rust");
    println!("  use pepita::io_uring::{{IoUringSqe, IoUringCqe}};");
    println!();
    println!("  // Submission queue entry");
    println!("  let sqe = IoUringSqe::new(op, fd, addr, len);");
    println!();
    println!("  // Completion queue entry");
    println!("  let cqe: IoUringCqe = /* from kernel */;");
    println!("  assert_eq!(cqe.res, 0); // Success");
    println!("  ```");
    println!();

    println!("  ublk - Userspace Block Devices");
    println!("  ─────────────────────────────────────────");
    println!("  Implement virtual disks entirely in userspace.");
    println!();
    println!("  ```rust");
    println!("  use pepita::ublk::{{UblkCtrlCmd, UBLK_U_CMD_ADD_DEV}};");
    println!();
    println!("  let cmd = UblkCtrlCmd::new(UBLK_U_CMD_ADD_DEV, dev_id);");
    println!("  ```");
    println!();

    println!("  blk_mq - Multi-Queue Block Layer");
    println!("  ─────────────────────────────────────────");
    println!("  Parallel I/O queues for NVMe-style storage.");
    println!();
    println!("  Key types: TagSetConfig, Request, RequestOp");
    println!();

    // =========================================================================
    // Section 3: Sovereign Infrastructure
    // =========================================================================
    println!("+-------------------------------------------------------------+");
    println!("| Section 3: Sovereign Infrastructure                         |");
    println!("+-------------------------------------------------------------+\n");

    println!("  zram - Compressed RAM Block Device");
    println!("  ─────────────────────────────────────────");
    println!("  3-4x compression ratio with LZ4. Zero-page optimization.");
    println!();
    println!("  ```rust");
    println!("  use pepita::zram::{{ZramDevice, ZramConfig}};");
    println!();
    println!("  let config = ZramConfig::with_size(1024 * 1024 * 1024)");
    println!("      .compressor(ZramCompressor::Lz4);");
    println!("  let device = ZramDevice::new(config)?;");
    println!();
    println!("  device.write_page(0, &data)?;");
    println!("  println!(\"Compression: {{:.2}}x\", device.stats().compression_ratio());");
    println!("  ```");
    println!();

    println!("  MicroVM - KVM-based Runtime");
    println!("  ─────────────────────────────────────────");
    println!("  Hardware-level isolation with sub-100ms boot time.");
    println!("  Docker replacement for serverless workloads.");
    println!();
    println!("  ```rust");
    println!("  use pepita::vmm::{{MicroVm, VmConfig}};");
    println!();
    println!("  let config = VmConfig::builder()");
    println!("      .vcpus(2)");
    println!("      .memory_mb(256)");
    println!("      .kernel_path(\"/boot/vmlinuz\")");
    println!("      .build()?;");
    println!();
    println!("  let vm = MicroVm::create(config)?;");
    println!("  vm.start()?;");
    println!("  ```");
    println!();

    println!("  virtio - VM Device Communication");
    println!("  ─────────────────────────────────────────");
    println!("  Standard interface for high-performance VM I/O.");
    println!();
    println!("  Key types: VirtQueue, VirtioVsock, VirtioBlock");
    println!();

    // =========================================================================
    // Section 4: Distributed Computing
    // =========================================================================
    println!("+-------------------------------------------------------------+");
    println!("| Section 4: Distributed Computing                            |");
    println!("+-------------------------------------------------------------+\n");

    println!("  Work-Stealing Scheduler (Blumofe-Leiserson)");
    println!("  ─────────────────────────────────────────");
    println!("  Each worker has a deque - pushes/pops from bottom,");
    println!("  thieves steal from top. Provably optimal load balancing.");
    println!();
    println!("  ```rust");
    println!("  use pepita::scheduler::Scheduler;");
    println!("  use pepita::task::{{Task, Priority}};");
    println!();
    println!("  let scheduler = Scheduler::with_workers(4);");
    println!();
    println!("  let task = Task::builder()");
    println!("      .binary(\"./compute\")");
    println!("      .priority(Priority::High)");
    println!("      .build()?;");
    println!();
    println!("  scheduler.submit(task).await?;");
    println!("  ```");
    println!();

    println!("  SIMD Operations");
    println!("  ─────────────────────────────────────────");
    println!("  Auto-detects AVX-512/AVX2/SSE4.1/NEON.");
    println!();
    println!("  ```rust");
    println!("  use pepita::simd::{{SimdCapabilities, SimdOps}};");
    println!();
    println!("  let caps = SimdCapabilities::detect();");
    println!("  println!(\"Best width: {{}}-bit\", caps.best_vector_width());");
    println!();
    println!("  let ops = SimdOps::new();");
    println!("  ops.vadd_f32(&a, &b, &mut c);  // SIMD accelerated");
    println!("  let dot = ops.dot_f32(&a, &b); // dot product");
    println!("  ```");
    println!();

    // =========================================================================
    // Section 5: Integration with Sovereign Stack
    // =========================================================================
    println!("+-------------------------------------------------------------+");
    println!("| Section 5: Sovereign Stack Integration                      |");
    println!("+-------------------------------------------------------------+\n");

    println!("  pepita provides low-level primitives for:");
    println!();
    println!("  ┌────────────────────────────────────────────────────────────┐");
    println!("  │ Library     │ Uses pepita for                             │");
    println!("  ├────────────────────────────────────────────────────────────┤");
    println!("  │ repartir    │ SIMD executor, MicroVM backend              │");
    println!("  │ trueno-zram │ ZRAM compression primitives                 │");
    println!("  │ trueno-ublk │ Block device interfaces                     │");
    println!("  │ realizar    │ Inference isolation via MicroVMs            │");
    println!("  └────────────────────────────────────────────────────────────┘");
    println!();

    // =========================================================================
    // Section 6: Comparison
    // =========================================================================
    println!("+-------------------------------------------------------------+");
    println!("| Section 6: Comparison with Alternatives                     |");
    println!("+-------------------------------------------------------------+\n");

    println!("  ┌───────────┬────────┬──────┬─────────────┬────────┐");
    println!("  │ Feature   │ pepita │ QEMU │ Firecracker │ Docker │");
    println!("  ├───────────┼────────┼──────┼─────────────┼────────┤");
    println!("  │ Language  │ Rust   │ C    │ Rust        │ Go/C   │");
    println!("  │ Isolation │ VM     │ VM   │ VM          │ Cgroup │");
    println!("  │ Boot time │ <100ms │ secs │ ~100ms      │ ~500ms │");
    println!("  │ Deps      │ 0      │ many │ few         │ many   │");
    println!("  │ Pure Rust │ Yes    │ No   │ Partial     │ No     │");
    println!("  │ no_std    │ Yes    │ No   │ No          │ No     │");
    println!("  └───────────┴────────┴──────┴─────────────┴────────┘");
    println!();

    // =========================================================================
    // Section 7: Use Cases
    // =========================================================================
    println!("+-------------------------------------------------------------+");
    println!("| Section 7: Sovereign AI Use Cases                           |");
    println!("+-------------------------------------------------------------+\n");

    println!("  1. Serverless Inference");
    println!("     - MicroVMs provide <100ms cold start");
    println!("     - Hardware isolation per request");
    println!("     - No container escape vectors");
    println!();
    println!("  2. High-Performance Storage");
    println!("     - ublk for custom storage backends");
    println!("     - zram for compressed working memory");
    println!("     - io_uring for async I/O batching");
    println!();
    println!("  3. Distributed Training");
    println!("     - Work-stealing scheduler for GPU tasks");
    println!("     - SIMD-accelerated gradient computation");
    println!("     - virtio for efficient VM communication");
    println!();
    println!("  4. Edge Deployment");
    println!("     - no_std core for embedded systems");
    println!("     - Zero external dependencies");
    println!("     - Minimal resource footprint");
    println!();

    println!("===============================================================");
    println!("                     Demo Complete");
    println!("===============================================================");
    println!();
    println!("For more information:");
    println!("  - crates.io: https://crates.io/crates/pepita");
    println!("  - docs.rs:   https://docs.rs/pepita");
    println!("  - GitHub:    https://github.com/paiml/pepita");
}

#[cfg(test)]
mod tests {
    #[test]
    fn test_pepita_demo_runs() {
        // Smoke test - just ensure the demo doesn't panic
        super::main();
    }
}