perf: fused-PTX field arithmetic, +54..66% on every card #23
Reference in New Issue
Block a user
Delete Branch "perf/fused-field-ptx"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes the bulk of the gap to the closed-source qpow-cuda kernel (quantus/miner#3).
Why they were 2x faster. Same 1472 multiplies per hash; their PTX (the fatbin ships compute_120 PTX) shows every field operation as one self-contained inline-PTX block. The 128-bit product is reduced with
mad.lo.cc.u32/madc.hi.cc.u32, which ptxas emits as one IMAD.WIDE with a carry-out predicate, plus three ALU ops folding the 2^96 = -1 term. The internal layer's row sum rides in themad.wide.u32partial products for free. Accumulators are 32-bit limb chains (IADD, IADD.X, merged IADD3.X carries). Ours paid a ~14-op compare-and-select reduction, a 64-bit add-with-carry per diagonal element, and five instructions per accumulator add on sm_120.What this does. Ports those primitives behind
LAIR_FUSED_MUL(default 1):gf_mul,gf_sqr(three-product squaring),gf_mul_addwith the addend folded into the partial products,acc_add/acc_add2as limb chains, a four-opacc_reduce; the round constant joins the unreduced sum in the internal layer.LAIR_EXACT_REDUCE(default 0): with 0 the reduction drops its final borrow as their kernel does. That is wrong only when the product's bits 64..95 are zero and its low 64 bits are below its top 32 bits, about 2^-64 per multiply (emulated against a reference multiply: 0/3M random mismatches, and the constructed 2^48*2^48 fails as predicted; the other apparent hazard, hh+carry wrapping 32 bits, is impossible). Exactness measured at -15%, so it is off.Measured, three interleaved rounds, parity 40/40 against the CPU on each host:
Static sm_120 31,280 -> 20,888 instructions, sm_86/89 39,208 -> 22,576, no spills, 110 registers on sm_120. ncu: 22,913 instructions per nonce against their 22,233; the residual 8% per 5090 is cycles (2.08 vs 1.87 SM-cycles/nonce, more dispatch stalls), not instructions or instruction cache.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ue5ZZm1Hiv5zPnucykKKuF
quantus-bench
3763996ae6on benjy.hanzalova.internaltotal median: 708.79 MH/s (batch 1000000, 5 x 30s, engine gpu-cuda)
--- resume miner ---
active