mirror of
https://github.com/luxfi/pvm.git
synced 2026-10-30 15:20:39 +00:00
Ship the GPU-native PlatformVM transition substrate. Four kernels in
canonical order produce byte-identical roots across CPU, Metal, and
CUDA backends:
- pvm_validator_set_apply Add/Remove/UpdateWeight/Jail/Unjail/RotateKeys
- pvm_stake_transition Bond/Unbond/Delegate/Redelegate/Reward/Commission
- pvm_slashing_transition Equivocation tombstones; downtime+vote jail
- pvm_epoch_transition Promotion + auto-unjail + 4-root composition
Per-kernel sources mirror byte-for-byte between .metal and .cu so the
keccak-folded roots agree across backends. Drivers:
- pvm_gpu_engine.mm Apple Metal: AOT metallib + PSO-per-kernel
- pvm_gpu_engine_cuda.cpp CUDA: <<<1,1>>> launchers + cudaMemcpy
- pvm_engine_stub.cpp CPU-only fallback (returns nullptr)
Tests:
- pvm-gpu-engine-test 6/6 (Apple M1 Max) — Metal vs CPU byte match
for full round (100v / 1000s / 5ev), jailed
exclusion, redelegate atomicity, empty round
determinism, reward saturation
- pvm-determinism-test 6/6 — CPU<->GPU byte-identical roots; two
engines bytewise identical across runs
Two real bugs found and fixed during bring-up:
1. rotl64 invoked with n=0 (kKeccakRot[0] is 0) is undefined behavior:
`x >> (64 - 0)` is a 64-wide shift on a 64-bit value. clang -O2 on
Apple Silicon exploited the UB and produced garbage keccak output.
Fix: mask shift counts (`(n & 63)`, `((64 - n) & 63)`). Applied
identically in CPU, Metal, and CUDA so all backends agree.
2. Metal PSO compile of pvm_stake_transition crashed Apple's optimizer
pipeline (XPC_ERROR_CONNECTION_INTERRUPTED after retries). Repro:
-Os/-O2 fails, -O0 always succeeds. The kernels are 1x1 single-thread
dispatches; we lose nothing by skipping the optimizer. Build with
`metal -O0`.
CMakeLists bumped to 0.53.0. Adds Metal AOT metallib build, CUDA target,
and the two new test executables. .metallib lookup now checks the
executable's directory first so the engine works from any CWD.
.gitignore added to keep build/ out of future commits.