Files
rustytorch/docs/archive/legacy/phase4.md
T
2026-03-04 00:08:42 +00:00

7.1 KiB
Raw Blame History

RustyTorch++ — Phase 4 Plan (Advanced Compilation & AutoKernel Synthesis) Objective (56 months): Outperform handtuned kernels by introducing autokernel synthesis, hardwareprofiledriven autotuning, and AOT graph compilation across CUDA/ROCm/Metal. Preserve determinism, stability, and safety, while expanding operator coverage and reducing TCO.

Reference paths

RUSTYTORCH_ROOT: /home/osobh/projects/rustytorch

RUSTG_COMPILER: /home/osobh/projects/rust/rustg (RTX 5090 sm_120 primary target)

STRATOSWARM_ROOT: /home/osobh/projects/stratoswarm (deployment in later phases)

Phase 4 builds on Phase 13 cores (compiler/runtime, tensor+autograd+graph, and ops/model zoo). Distributed training and serving remain separate tracks.

  1. Scope & NonGoals In scope

Hardware Profile DB (perSKU): latency/bandwidth, occupancy sweet spots, cache behavior, launch constraints

AutoKernel Synthesis: generate specialized kernels from IR patterns (tile/warp/vector widths, epilogue fusions)

Autotuning Engine: bandit/grid hybrid; persistent kernel cache keyed by {op, layout, shape, arch, driver}

AOT Graph Compilation: serialize compiled graphs & kernel bundles; fast load with compatibility checks

Crossbackend parity: CUDA↔ROCm↔Metal feature alignment for supported ops

Operator coverage expansion: Flashclass attention forward (and Phase 4.5: backward), FFT/convolution primitives

Safety: numerical parity checks, OOB fuzz, deterministic mode support

Out of scope (Phase 5+)

Multitenant inference scheduler and KVpaging (serving)

Full distributed optimizer sharding (handled in distributed track)

  1. Success Criteria (Exit / PhaseGate) Throughput wins: ≥2040% steptime reduction on Phase3 macrobench via synthesized/fused kernels.

Inference speedup: ≥1.5× tokens/sec singleGPU for LLMblock with synthesized attention/MLP.

Kernel cache hitrate: ≥80% across repeated runs with same shapes/layouts.

AOT load time: <100ms load of compiled graph + kernels on identical SKU/driver.

Parity & determinism: fp32 ≤1e6; bf16/fp16 ≤1e3; strict mode bitstable where declared.

Crossbackend: CUDA and ROCm produce parity on smoke suites; Metal reaches featureparity subset.

  1. Architecture Work A. Hardware Profile DB

Capture: microbenches for GEMM bandwidth, L2 behavior, register pressure thresholds, warp occupancy vs. tile

Storage: versioned profiles by {arch, driver, rustg_sha}; Prometheus export + JSON artifacts

B. AutoKernel Synthesis

Pattern library: IR → kernel templates (attention, MLP, norm epilogues, conv/FFT)

Parameter space: tile sizes, block dim, warp count, vector width, epilogue fusion choices

Synthesis flow: generate → compile (nvcc/hipcc/metal) → validate numerics → bench → select → cache

C. Autotuning Engine

Strategies: warm grid search → bandit refinement → exploitation cache

Constraints: thermal/power from NVML; walltime budget per op; earlystop

Cache keys: {op, shape, dtype, layout, arch, driver, pass_ver} → chosen params + perf summary

D. AOT Graph Compilation

Serialization: *.rtxgc (graph + schedule + kernel bundle manifest)

Compatibility: verify against {arch, driver, rustg_sha}; fallback to JIT if mismatch

Precapture CUDA/HIP graphs for hot regions; lazyinit remaining

E. CrossBackend Strategy

Feature flags per op; portability layer for epilogues

ROCm parity plan; Metal subset (mac dev runners)

  1. Operator & Kernel Targets (Phase 4) Attention family: fused QKV projection → attention core (Flashclass forward) → output proj (epilogue fusion)

MLP family: GEMM + bias + activation (GELU/SiLU) fused

Norms: LayerNorm/RMSNorm epilogues

Conv/FFT (pilot): 1D/2D FFT; smallkernel convs with autotuned tiles

Bench shapes: sequence 1k8k; hidden 4k16k; heads 3264; bf16/fp16 primary, fp32 reference.

  1. Benchmarks & Baselines Micro: synthesized vs. baseline kernels (latency, GB/s, occupancy)

Macro: LLM block forward (and training fwd+bwd where implemented); step time, tokens/sec, mem peak

Determinism: fixed seeds; parity to reference kernels; graph capture hash stability; kernel cache version pinning

  1. CI Gates (Phase 4) Perf Gate: ≥20% macro steptime win vs. Phase3 baseline; no weekly regression >5%

Cache Gate: kernel cache hitrate ≥80% on standard benches

Determinism Gate: parity thresholds hold; strict tests pass where enabled

Security Gate: supply chain scans, SBOM/sign; no unsigned kernel bundles

  1. Observability & Telemetry Nsight/rocprof traces with synthesizedkernel annotations and selected params

Metrics: synth_win_pct, cache_hit_pct, aot_load_ms, occ_pct, dram_gbps, l2_hit_pct

Dashboards: perSKU perf deltas; cache effectiveness; AOT load times

  1. Deliverables rtx-synth module: pattern library, template emitters, validators

Autotuning engine with NVMLaware constraints; persistent cache

AOT graph compiler/loader + compatibility checks

Synthesized kernels: attention fwd, fused MLP, norm epilogues; conv/FFT pilot

Bench suite & CI gates; metrics dashboards

Documentation: docs/phase4.md (synthesis, tuning, AOT); ADR updates (kernel cache, graph format)

  1. RACI — Phase 4 Agent Ownership Conductor (Orchestrator) — Accountable: phase delivery, dependency orchestration

IR Rewrite & Fusion Agent — Responsible: pattern detection & rewrite rules

Kernel Synthesizer Agent — Responsible: template emitters; compile; numeric parity; occupancy reports

AutoTuner Agent — Responsible: search strategies; profile DB; cache management

Rust Engineer — Responsible: runtime hooks for AOT load/verify; kernel cache I/O; error handling

Performance Engineer — Accountable: micro/macro benches; thresholds; dashboards

Security Engineer & Auditor — Accountable: provenance for kernel bundles; scan results; signing

DevOps Engineer — Responsible: CI matrices; artifact storage; runner provisioning

Governance & Provenance Agent — Responsible: SBOM/signature pipeline; manifest policies

Agent Organizer — Accountable: tool allowlists; routing; freeze on gate failure

  1. Risks & Mitigations Search explosion → bandit pruning; parameter templates; profile seeding

Numeric drift → robust reference kernels; tolerance checks; soak tests

Cache invalidation → version keys include driver + rustg_sha; fallback JIT path

Crossbackend gaps → feature flags; ROCm/Metal parity backlog; transparent fallsbacks

AOT mismatch → strict compatibility checks; informative downgrade path

  1. Timeline (suggested) Weeks 12: Hardware profile DB; microbench capture; perf dashboards

Weeks 34: Pattern library + template emitters; compile/validate baseline templates

Weeks 56: Autotuning engine; persistent cache; Nsight/rocprof wiring

Weeks 78: AOT compiler/loader; synthesized attention/MLP; CI gates; docs & ADRs; phasegate review

  1. Phase5 Handover Seeds Inference scheduler design (continuous batching, KV paging, SLA lanes)

Crossnode AOT caching & distribution for Stratoswarm deployments

Online autotuning: workloadaware live refinement under safety guardrails

— End of Phase 4 Plan —