Repository navigation
CUDA: cheaper Goldilocks arithmetic, no third squeeze on the GPU, arch-targeted NVRTC - #100
Conversation
…h-targeted NVRTC Kernel: - reduce128 is a 6-instruction fold that leaves the final borrow and the two 32-bit wraps uncorrected. Each slips with probability about 2^-33 per multiply and shifts the value by +-EPS mod p; a slipped hash is wrong for that nonce only, and the host re-verifies every candidate on the CPU. - gf64_add folds the 2^64 carry once with a mad pair instead of two passes. - Internal rounds add the unreduced 96-bit row sum straight into the 128-bit diagonal product instead of reducing it first. - mining_main compares the first 256 output bits only and reports any prefix <= target as a candidate; the third squeeze is gone from the GPU. - Only the upper eight target words are loaded. Host: - A rejected candidate (prefix equal, or an arithmetic slip that happened to land below the target) resumes the search after that nonce instead of marking the device lost. - NVRTC targets the device's compute capability (cached per capability) and falls back to generic PTX with a warning. Registers, local, shared, and constant bytes of mining_main are logged per device; spills log a warning. Tests: - Bit-exact Rust models of reduce128 and gf64_add; a host-only test proves the model equals value mod p plus the predicted slip term on every input and slips on none of 4096 random inputs; a GPU test checks the kernel against the models bit for bit.
Blocking findings
Local non-GPU validation passed: Verdict: request changes. |
|
Measured on a Vast RTX 4090 (driver 580.159.03, 350 W cap, NVRTC 12.8), release binaries, GPU only, three alternating 30 s runs each:
+22 to +23 percent. All eight |
…ch contract Review: - NVRTC now compiles PTX for compute_XY through the PTX API, choosing the newest architecture NVRTC reports as supported that the device can run. Any compile error fails initialization; there is no silent fallback. Loading NVRTC's cubin instead measured equal to the driver JIT on a 4090, so the PTX route stays. - The approximate reduction is an explicit engine contract (doc comment on CudaEngine): about one nonce in three million is hashed wrong, a wrong candidate is rejected and skipped, a wrong miss is lost. A host test runs the bit-exact reducer model over four million random 64x64-bit products and requires zero slips. Kernel keeps from same-host kernel-only A/B on an RTX 4090: - specialized squaring, three partial products (+3%); - zero-row round-constant tables, no per-round selects (+1%, last spill gone); - 96-bit lane reduce through the 6-op fold (+1.3%). Release-binary A/B against v4.1.1, three alternating 30 s runs, GPU tests passing on both cards: RTX 4090 624-629 -> 816-820 MH/s (+30.5%), RTX 3080 Ti 289 -> 380 MH/s (+31.4%). Record in docs/benchmarks.
|
Review points, addressed in the latest commits: P1, sm_ through the PTX API.* Valid in spirit, and now fixed the way NVIDIA documents it: P1, false negatives. Correct that CPU verification only catches false positives. This is now an explicit engine contract in the P3, no real-GPU validation. Now done on an RTX 4090 and an RTX 3080 Ti: all nine |
…rejected candidate MinerEngine::search_range documents that Exhausted means every nonce was evaluated and that a non-bit-exact engine must state its miss probability; hash_nonces is documented as a kernel self-test. A GPU test sets the target equal to a golden hash so the golden nonce is a prefix-equal candidate that CPU verification rejects, and asserts the search resumes and finds a CPU-verified solution afterwards with the expected hash count. Ten engine-cuda GPU tests pass on an RTX 3070 (sm_86, driver 580.173.02).
|
Re-review requested at 9bba7ae. The review at b953137 predates the fixes; each blocking finding maps to the head as follows. 1. sm_ through the PTX API.* 2. Approximate arithmetic can miss valid solutions. Made an explicit contract rather than removed, because exactness costs the whole gain: the 3. Real-GPU validation. Ten |
|
Re-reviewed at The previous blockers are addressed:
I also checked the specialized squaring carry construction, zero-row round-constant indexing, 96-bit lane reduction, architecture selection, benchmark JSON validity, and the full diff. One non-blocking interpretation note: observing zero slips in 4M random products does not empirically validate a ~2^-33 event rate because the expected number of observations is far below one. The edge/model-invariant tests provide the useful correctness evidence here; the probability remains an analytical claim. Verdict: APPROVE. No blocking findings. |
|
Re-reviewed at The earlier NVRTC, contract-documentation, GPU-validation, and benchmark concerns are addressed. The Blocking finding
The new Validation: the full delta and line-level control flow were reviewed, Verdict: REQUEST CHANGES. |
… exact The claim was a first-come atomicExch, so an arbitrary candidate thread won while other candidate threads returned early, and resuming after a rejected winner could skip lower nonces those threads never evaluated. The kernel now publishes the minimum candidate index with atomicMin (slot initialized to u32::MAX), and every candidate thread stops there. Everything below the published index has been fully evaluated, so resuming right after a rejected candidate covers every nonce exactly once, and a found batch reports the lowest valid nonce deterministically. The resume test now computes the lowest valid nonce on the CPU and requires the engine to return exactly that after rejecting the golden nonce; the old claim fails it nondeterministically. Ten GPU tests pass three times in a row on an RTX 4070 (sm_89).
|
Fixed in d222e80. You were right: the first-come The kernel now publishes the minimum candidate index with The continuation test now computes the lowest valid nonce on the CPU and requires the engine to return exactly that after rejecting the golden nonce ( |
|
Re-reviewed at The previous lowest-candidate blocker is addressed. The benchmark conditions also satisfy the requested steady-state check. The release CLI sets difficulty to Blocking findings
Validation: Verdict: REQUEST CHANGES. |
The claim flag was a plain store from every candidate thread, a write/write race under the CUDA memory model. The record is now two atomically updated words: the lowest candidate index (u32::MAX when none) and the number of nonces that candidate threads left unevaluated. A found batch reports dispatched minus unevaluated, which is exactly what was hashed, instead of the whole dispatched rectangle; a rejected candidate still counts the nonces below it. The contract doc states this, and the found-batch test now expects one evaluated nonce per thread at difficulty 1 rather than the full batch.
|
Both findings addressed in 892e748 (GPU validation of this head is running now; will post results). P1, racy flag store. The flag is gone. The result record is now two words that are only ever updated atomically: P2, |
…s work With a 4M batch and 4 nonces per thread only 1,000,000 of the 1,048,576 threads reach a nonce; the rest exit before evaluating anything, so the exact evaluated count is batch_size.div_ceil(nonces_per_thread).
|
GPU validation of the race-free record and exact accounting: all ten d3d353e only changes that test's expected value: with a 4M batch and 4 nonces per thread, 1,000,000 threads have work and each evaluates exactly one nonce, while the remaining 48,576 threads exit before their first index, so the exact count is |
|
Re-reviewed at The two findings from the previous review are substantially addressed:
Blocking finding
Validation: Verdict: REQUEST CHANGES. |
A launch whose lowest candidate is rejected by CPU verification still executed every nonce its threads reached; only the resume point is the rejected index plus one. Report dispatched minus unevaluated for that launch as well, so worker rates and GPU metrics reflect the work done. The nonces above the rejected candidate are hashed again after the resume and count again. The resume test now expects 33 + 32 hashes.
|
Fixed in d0a02fb. A rejected launch now reports |
|
GPU confirmation for d0a02fb: all ten |
|
Re-reviewed at The remaining rejected-launch accounting blocker is fixed. The earlier fixes remain sound:
The performance evidence still uses the requested realistic, effectively infinite-difficulty conditions: the release benchmark CLI sets difficulty to Validation: Verdict: APPROVE. No blocking findings. |
Summary
Second round of CUDA engine work, following #97. The kernel is issue-bound, so this reduces instructions per hash, mostly in the Goldilocks field arithmetic.
Kernel
reduce128is a 6-instruction fold of the 128-bit product. It leaves the final borrow and two 32-bit wraps uncorrected. Each slips with probability about 2^-33 per multiply and shifts the value by ±EPS mod p. See the engine contract below.gf64_addfolds the 2^64 carry once with amadpair.gf64_sqruses three partial products instead of four.mining_maincompares only the first 256 output bits and reports any prefix ≤ target as a candidate. The third squeeze, a full extra inlined permutation, is gone from the GPU. Only the upper eight target words are loaded.atomicMin, initialized tou32::MAX); every candidate thread stops there. Everything below the published index has been fully evaluated, so resuming after a rejected candidate is exact and a found batch returns the lowest valid nonce deterministically.Host
compute_XY, picking the newest architecture NVRTC reports as supported that the device can run, cached per capability. Any compile error fails initialization. Registers, local, shared, and constant bytes ofmining_mainare logged per device; a spill logs a warning.Engine contract (documented on
CudaEngineand onMinerEngine::search_range)The GPU hashes about one nonce in three million wrong. A wrong hash below the target is rejected by CPU verification and skipped. A wrong hash for a nonce that is actually valid is missed and the range reports
Exhausted, which the trait now documents as "no solution found", never a proof.hash_countcounts every evaluated nonce. Expected loss is about 3e-7 of solutions; the shortcut buys the throughput below.hash_noncesis a kernel self-test under the same contract, not a verifier.Measurements
Release v4.1.1 Linux binary vs this branch, GPU only, default 32M batch, three alternating 30 s runs each, after the
engine-cudaGPU tests passed on each card. Record:docs/benchmarks/2026-09-10-vast-pr100.json.mining_main: 64 registers, 0 B local memory on both. v4.1.1 had 16 B local.Kernel-only A/B on the 4090 also rejected: geometry sweep (flat across 20 grid/nonce combinations), launch bounds 3 or 2 blocks per SM (0 / −1%), internal-round unroll (noise),
__byte_perm(0), ALU-only EPS fold (−13%),mad-with-1 lane adds (−6%, ptxas rewrites them), NVRTC cubin instead of driver JIT (equal), two nonces per thread interleaved (−6.5% on both cards).Tests
reduction_models_deviate_only_on_carry_wrapsandreduction_slips_are_absent_in_millions_of_random_products(host, run in CI): bit-exact Rust models of the kernel'sreduce128andgf64_add; the model equalsvalue mod pplus exactly the predicted slip term on every input, and slips on none of 4M random 64×64-bit products.cuda_field_arithmetic_matches_models_bit_exactly(GPU): kernel output equals the model bit for bit.cuda_search_resumes_after_rejected_candidate_and_returns_lowest_solution(GPU): plants a prefix-equal candidate that CPU verification rejects among many racing real solutions and requires the engine to return exactly the lowest valid nonce with the expected hash count.hash-1/hash/hash+1), nonce carries, CPU-verified solution, and found-batch accounting: unchanged. All ten GPU tests pass on an RTX 4090, RTX 3080 Ti, RTX 3070, and RTX 4070.