Skip to main content

Crate barracuda

Crate barracuda 

Source
Expand description

§barraCuda: Hardware-Agnostic Tensor Compute

Deep Debt Excellence: Zero duplication, pure capability-based compute

§Philosophy

  • ✅ Hardware-Agnostic: One API, works on any device (GPU/CPU/NPU/TPU)
  • ✅ Pure WGSL: WGSL shaders ONLY (wgpu handles all backends)
  • ✅ Automatic Fallback: wgpu uses CPU when GPU unavailable
  • ✅ Zero Duplication: Single WGSL implementation per operation
  • ✅ Runtime Discovery: wgpu selects best available backend
  • ✅ Simple: No separate CPU code, no trait abstractions
  • Zero unsafe: #![forbid(unsafe_code)] — all former FFI evolved to safe Rust

§Architecture

User Code: Tensor<f32>
    ↓
Operation (WGSL shader)
    ↓
WgpuDevice
    ↓
wgpu Backend Selection (automatic):
├── Vulkan (NVIDIA, AMD, Intel GPU)
├── Metal (Apple GPU)
├── DX12 (Windows GPU)
└── Software Rasterizer (CPU fallback)

Same WGSL code runs on ALL backends!

§Example

ⓘ
use barracuda::prelude::*;

// Auto-discovers best device (GPU if available, CPU fallback)
let x = Tensor::randn([128, 256])?;
let y = Tensor::randn([256, 512])?;

// Operations execute on discovered device (WGSL on GPU, Rayon on CPU)
let z = x.matmul(&y)?;
let activated = z.relu()?;
let normalized = activated.softmax(0)?;

tracing::info!("Device: {}", x.device().name());
// "NVIDIA GeForce RTX 4090" or "AMD Radeon RX 7900" or "CPU (16 cores)"

§Deep Debt Elimination

Before (architectural debt):

  • Separate CPU and GPU implementations
  • User must choose backend explicitly
  • WGSL shaders existed but weren’t used by operations
  • Duplication: Same logic in CPU and WGSL

After (unified):

  • Single Tensor API works everywhere
  • Automatic device discovery and fallback
  • All WGSL shaders properly utilized
  • Zero duplication: One implementation per op

Re-exports§

pub use ops::sparse_matmul_quantized::sparse_matmul_quantized;
pub use ops::bio::AniBatchF64;
pub use ops::bio::BatchFitnessGpu;
pub use ops::bio::Dada2Buffers;
pub use ops::bio::Dada2Dimensions;
pub use ops::bio::Dada2DispatchArgs;
pub use ops::bio::Dada2EStepGpu;
pub use ops::bio::DnDsBatchF64;
pub use ops::bio::FelsensteinGpu;
pub use ops::bio::FelsensteinResult;
pub use ops::bio::FlatForest;
pub use ops::bio::FlatTree;
pub use ops::bio::GillespieConfig;
pub use ops::bio::GillespieGpu;
pub use ops::bio::GillespieModel;
pub use ops::bio::GillespieResult;
pub use ops::bio::HillGateGpu;
pub use ops::bio::HmmBatchForwardF64;
pub use ops::bio::HmmForwardArgs;
pub use ops::bio::KmerHistogramGpu;
pub use ops::bio::LocusVarianceGpu;
pub use ops::bio::MultiObjFitnessGpu;
pub use ops::bio::PairwiseHammingGpu;
pub use ops::bio::PairwiseJaccardGpu;
pub use ops::bio::PairwiseL2Gpu;
pub use ops::bio::PangenomeClassifyGpu;
pub use ops::bio::PhyloTree;
pub use ops::bio::QualityConfig;
pub use ops::bio::QualityFilterGpu;
pub use ops::bio::RfBatchInferenceGpu;
pub use ops::bio::SmithWatermanGpu;
pub use ops::bio::SnpCallingF64;
pub use ops::bio::SpatialPayoffGpu;
pub use ops::bio::SwConfig;
pub use ops::bio::SwResult;
pub use ops::bio::SwarmNnGpu;
pub use ops::bio::TaxonomyFcGpu;
pub use ops::bio::TreeInferenceGpu;
pub use ops::bio::UniFracConfig;
pub use ops::bio::UniFracPropagateGpu;
pub use device::driver_profile::PrecisionRoutingAdvice;
pub use ops::rk45_adaptive::Rk45DispatchArgs;

Modules§

activations
Activation functions for neural networks and signal processing.
auto_tensor
Auto-Tensor - Scheduler-Aware Tensor Operations
benchmarks
BarraCuda vs CUDA Benchmarking Framework
cast
Safe numeric cast helpers for GPU compute.
compute_graph
Compute Graph - Lazy Execution for Operation Batching
cpu_conv_pool
CPU implementations of Conv2D, MaxPool2D, and AvgPool2D.
cpu_executor
CPU Executor - Native Rust Implementation with SIMD
device
Device module - Unified Hardware Abstraction
discovery
Capability-based primal discovery and response parsing.
dispatch
Auto-dispatch system for CPU/GPU routing
env_keys
Named constants for environment variable keys. Named constants for environment variable keys used in production code.
error
Error types for barraCuda
esn_v2
Hardware-Agnostic Echo State Network (ESN) API
genomics
High-level Bioinformatics and Genomics API
gpu_executor
GPU Executor - WGSL Shader Implementation via wgpu
health
Health domain primitives — pharmacokinetics, microbiome, biosignal processing.
interpolate
Interpolation methods
linalg
Linear algebra operations for scientific computing
math
CPU-only math functions (convenience alias for special).
multi_gpu
Multi-GPU Workload Distribution
nautilus
Nautilus Shell — evolutionary reservoir computing via board ensembles.
nn
High-level Neural Network Training API
npu
NPU Backend Module
npu_executor
NPU Executor - Neuromorphic Processor Implementation via Akida
numerical
Numerical methods for differentiation, integration, and ODEs
ops
Operations module - Pure WGSL operations
optimize
Optimization algorithms for parameter fitting and model calibration
pde
Partial Differential Equation Solvers
pipeline
Multi-Kernel Pipeline — GPU Operation Chaining Without CPU Round-Trips
prelude
Prelude: Common imports for using barracuda.
provenance
Cross-Spring Provenance Tags (L-005)
resource_quota
Resource Quota Management for GPU Compute
rng
Deterministic CPU PRNG for reproducible simulations.
runtime
Tokio runtime bridging utilities.
sample
Sampling strategies for parameter space exploration
scheduler
Unified Scheduler - Automatic Hardware Selection
session
TensorSession — Automatic Operation Batching
shaders
WGSL Shader Infrastructure
snn
High-level Spiking Neural Network (SNN) API
special
Special mathematical functions
spectral
Spectral theory for discrete Schrödinger operators.
staging
Staging Buffers for Unidirectional Compute Pipelines
stats
Statistical functions
surrogate
Surrogate modeling for expensive function approximation
tensor
Unified Tensor abstraction — hardware-agnostic tensor compute.
timeseries
High-level Time Series Analysis API
tolerances
Centralized validation tolerances with mathematical justification.
unified_hardware
Unified Hardware Base — Universal Compute Abstraction
unified_math
Unified Math Base - Hardware-Agnostic Mathematical Primitives
utils
Utility functions for barracuda operations
validation
Validation harness for barracuda validation binaries.
vision
High-level Computer Vision API
workload
Analyzes workloads and selects optimal compute device (CPU, GPU, NPU) based on validated performance data from 96+ actual hardware tests.

Macros§

require
Unwrap a Result or record failure and early-return from the caller.