feat(gpu): name the algebraic hashes on the device dispatch, loudly - #957
Merged
Conversation
The three algebraic StarkHash configurations (RpoStarkHash, RpxStarkHash, PoseidonStarkHash) become expressible under `cuda`. AlgebraicBatchBackend and AlgebraicPairBackend implement DeviceTreeBackend with the tag's own CommitmentHash as the dispatch key; the tag carries that constant once (AlgebraicHasher::COMMITMENT_HASH) and the StarkHash impl reads it, so the configuration's name and its device key cannot be edited apart. The `#[cfg(not(feature = "cuda"))]` fork around the configurations, their inhabitation check and their tag test goes away. math_cuda::DeviceHash gains Rpo256 / Rpx256 / Poseidon twins. No kernels exist for them yet, so every device dispatch site — five `match hash` sites in lde.rs, two in fri.rs, the two comp-poly tree builders in gpu_lde.rs — carries a third arm that aborts with `unimplemented!` naming the hash and the site. Never a byte-hash fallback: a tree labelled RPO is built by RPO kernels or not built at all (HASH-PINNING.md). The gpu_lde bridge becomes a total const map in both directions plus a compile-time round-trip assertion, so a CommitmentHash variant without a DeviceHash twin, or a cross-paired arm, fails to compile at the bridge with a message naming the gap. config.rs's device tie-in moves from a never-called closure to a const block so its value comparison actually evaluates; algebraic_commit.rs carries the same check for its three configurations. Both assertions were verified to fail the build when deliberately broken. Gates (stub cubins): clippy -D warnings -A clippy::op_ref on math-cuda, stark/cuda and lambda-vm-prover/cuda with --lib --tests; cargo check on the non-cuda prover with --lib --tests; cargo fmt --check. The prover/cuda --tests pass is green modulo prover/tests/cuda_path_integration.rs:120, a pre-existing non-exhaustive match over CommitmentHash that this change does not own.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
StarkHashconfigurations (RpoStarkHash,RpxStarkHash,PoseidonStarkHash) now compile undercuda.AlgebraicBatchBackendandAlgebraicPairBackendimplementDeviceTreeBackend, keyed by the newAlgebraicHasher::COMMITMENT_HASH; theStarkHashimpl reads that same constant, so a configuration's name and its device key cannot be edited apart. Thecfg(not(feature = "cuda"))fork around the configurations, their inhabitation check and their tag test is gone.math_cuda::DeviceHashgainsRpo256/Rpx256/Poseidontwins. No kernels exist for them yet, so every device dispatch site carries a third arm,unimplemented!("{hash:?} device commit not yet ported (<site>)"). Never a byte-hash fallback: a tree labelled RPO is built by RPO kernels or not built at all (HASH-PINNING.md).gpu_lde.rsbridge:device_hash_for/commitment_hash_forare totalconst fns in both directions, plus a const round-trip assertion. ACommitmentHashvariant without aDeviceHashtwin, or a cross-paired arm, fails to compile at the bridge with a message naming the gap. Verified by breaking it:Rpx256 => DeviceHash::Rpo256fails with E0080 at the assertion.config.rs: the device tie-in was a never-called closure, so its value comparison never ran. It is now a const block that evaluates (verified to fail when broken).algebraic_commit.rscarries the same check for its three configurations.hash_pin.rs(doc only): a "cuda on an algebraic pin" section. Such a build compiles and aborts at its first device commit; neither acompile_error!nor a fallback belongs there.Loud-arm sites (lane K's phase-2 checklist)
crypto/math-cuda/src/lde.rsbuild_inner_tree_levels_forcrypto/math-cuda/src/lde.rscoset_lde_row_major_innercrypto/math-cuda/src/lde.rscoset_lde_row_major_split_treescrypto/math-cuda/src/lde.rscoset_lde_batch_base_into_with_merkle_tree_innercrypto/math-cuda/src/lde.rsevaluate_poly_coset_batch_ext3_into_innercrypto/math-cuda/src/fri.rsFriCommitState::fold_and_commit_layercrypto/math-cuda/src/fri.rsFriCommitState::fold_and_commit_layercrypto/stark/src/gpu_lde.rstry_build_comp_poly_tree_gpucrypto/stark/src/gpu_lde.rstry_build_comp_poly_tree_gpu_from_devPorting a family means replacing these nine arms with launches. Every
matchonDeviceHashis exhaustive, so a new dispatch site cannot omit the arm.Evidence
Box A, at 3e2a0cc (this branch sits on
per-table-gpu@ fc9f1e1, after #956; the tip a42554c (#953) touches no file this PR touches):make lint:D2_LINT exit=0math-cudaparity:blake3_fused_parity ok. 3 passed,merkle_root_parity ok. 3 passed,comp_poly_tree ok. 4 passed,one_lde_buffer ok. 3 passed; 1 ignoredmake test-cuda-integration:ok. 7 passed ... 13.41smake test-cuda-d1:ok. 1 passed ... 2.62sLaptop, stub cubins:
cargo clippy -D warnings -A clippy::op_refonmath-cuda,stark --features cudaandlambda-vm-prover --features cuda(--lib --tests) green;cargo check -p lambda-vm-prover --lib --tests(non-cuda) green;cargo fmt --checkclean.Behaviour to know
Under
cudaan algebraic pin now compiles and aborts, naming the hash and the site, at the first device commit of any table at or above the GPU LDE threshold. Proving a block under an algebraic pin on GPU requires the kernels, not a fallback. No proof-format change:CommitmentHashvariants and order and the 32-byte node are untouched, and the byte-hash device paths are unchanged (parity above).Follow-ups recorded by the coordinator: F2 (the
lfm/mod.rsnot(cuda)test-module gates), step 6c (hash-rpo'scompile_error!and the HASH-PINNING §CUDA rewrite).