Expand description
§OptiRS TPU - TPU Coordination and Pod Management
Version: 0.3.2 Status: Working CPU-reference implementation; no vendor TPU runtime
optirs-tpu provides TPU-style coordination, pod management, and an XLA-shaped
compilation pipeline for OptiRS, built on
SciRS2’s abstractions.
⚠️ Hardware note: there is no Google TPU (or other XLA vendor) runtime linked
into this crate — that is proprietary and not distributable as pure Rust. Every
algorithm below (graph optimization, shape inference, checkpointing, …) is a
real implementation that runs and is tested on the CPU reference executor;
tpu_backend and fault_tolerance document, function by function, exactly
where a real vendor runtime would be required and return an explicit
error::TpuError/error::OptimError there instead of a fabricated result.
§What is real today
TPUOptimizerwraps anyoptirs_core::Optimizer(also implementing that trait itself) and drives it through a compile → execute → profile pipeline;tpu_stepperforms the real update, not a stub.- XLA-shaped compiler pipeline (
xla): a genuine computation-graph builder with producer/consumer dependency tracking, dead-code elimination (with a fail-safe against deleting undeclared-output graphs), constant folding, common-subexpression elimination, kernel-fusion legality checks, a real (non-bump) memory allocator with free/coalescing, and shape inference for reshape/convolution/dot/broadcast. tpu_backend::TPUBackend: the run side – device selection, memory pools, retry policy, profiling. It owns no compiler of its own:xla::XLACompileris the single graph-to-binary path and this backend drives it, so a program’s FLOP count, time estimate and memory footprint all come from the graph that was actually compiled. Register a graph withregister_computationbefore executing it; an id with no registered graph is an error rather than a synthesized binary. Execution evaluates that graph throughxla::execution::ReferenceExecutor, and every device memory reservation it makes is recorded into the same profile the compile step opened.coordination::PodCoordinator: device/channel topology, barrier synchronization, load balancing, and fault detection over real in-process state (nosleep-and-report-success placeholders).fault_tolerance: checkpoints are serialized to disk with a SHA-256 integrity hash and verified on restore; rollback and replication go through that same verified path.synchronization: barriers with a correctly-signaled condvar predicate, plus ring all-reduce/broadcast/reduce-scatter collectives.
§What is not implemented
- Executing on real TPU silicon (needs a vendor runtime — see the hardware note above).
- Cross-device workload migration (
fault_tolerance::migrate_workloadreturnsErrrather than fabricate a live migration). - Most of
pod_coordination’scommunication,topologyandresource_scheduling/load_balancing/gradient_aggregation/batch_coordination/performancesubmodules are still data-only scaffolding: real types with derives, no methods, nothing wired to a caller yet. A few pieces ofpod_coordinationare real today —pod_coordination::coordination::coordinator::TPUPodCoordinatordelegates to the realcoordination::PodCoordinator, andsynchronization::clocks::protocols::NtpSynchronizerimplements genuine RFC 5905 clock-offset estimation — consult each module’s own doc comments for its individual status.
§Example
use optirs_core::optimizers::SGD;
use optirs_tpu::{TPUConfig, TPUOptimizer};
let base_optimizer = SGD::new(0.01f32);
let mut tpu_opt = TPUOptimizer::new(base_optimizer, TPUConfig::default())?;
// Runs the real compile/execute pipeline on the CPU reference backend.
let updated = tpu_opt.tpu_step(¶ms, &grads)?;§Architecture
Built on SciRS2 abstractions:
- Numeric:
scirs2_core::ndarray,scirs2_core::numeric::Float - Errors:
scirs2_core::error::CoreError(re-exported here aserror::OptimError)
§Contributing
Match the existing standard: no fabricated success values or hardcoded
placeholder outputs. Where a capability genuinely requires hardware or a
vendor runtime this crate does not have, return a descriptive Err rather
than simulate one — see FaultToleranceManager::migrate_workload in
fault_tolerance for the pattern.
Re-exports§
pub use coordination::PodCoordinator;pub use tpu_backend::DeviceId;
Modules§
- coordination
- TPU Pod Coordination and Management
- error
- fault_
tolerance - monitoring
- pod_
coordination - TPU Pod Coordination Module
- synchronization
- TPU Synchronization and Communication Primitives
- tpu_
backend - xla
Structs§
- Compilation
Metrics - XLA compilation metrics
- Memory
Usage Stats - Memory usage statistics
- Profile
Event - One event recorded by the profiler, readable via
TPUOptimizer::profile_timeline. - TPUConfig
- TPU configuration for optimization
- TPUOptimizer
- TPU-optimized optimizer wrapper
- TPUPerformance
Metrics - TPU performance metrics
- TPUTopology
Info - TPU topology information
- Utilization
Metrics - TPU utilization metrics
- XLAShape
- XLA tensor shape
Enums§
- PodTopology
- TPU pod topologies
- Profile
Event Type - Profile event types.
- TPUMemory
Optimization - TPU memory optimization strategies
- TPUVersion
- TPU versions with different capabilities
- XLAOptimization
Level - XLA optimization levels