arXiv(opens in a new tab)cs.DCSep 2026Cited by 2 papers on PaperVantage

Manuscript Offprint

arXiv:2609.11356

Taming Bitwise Behavior in GPU Kernels with Tensor Core: Black-Box Reconstruction, Compiler Enforcement, and Static Verification

Ziteng Yang, Nicholas J. Riasanovsky, Warren Deng, Vivek Sarkar

Abstract

Determinism and numerical reproducibility are increasingly required of the GPU kernels under machine learning systems, yet two deterministic implementations of one kernel differ bit for bit. The result is decided by the floating-point (FP) reduction order above all, and by partial-sum precision, multiply-add fusion and where the rounding falls: written by hand, left to the compiler by a block-level language like Triton, or owned by a closed library like cuBLAS or rocBLAS. The tile shape chosen for speed therefore chooses the arithmetic, and a request stops being batch invariant. Holding the order still costs performance, reported at up to 20%. Also, an autotuner searching hundreds of configurations cannot tell which of them agree bit for bit.

In this work we characterize what decides the bitwise behavior of GPU kernels, for reductions and General Matrix Multiply (GEMM). i) We give a descriptor that records the parameters fixing a GEMM's reduction order, such as where the K axis is cut in a split-K GEMM. On that basis we give the first black-box reconstruction of a closed source library's arithmetic towards bit-level correctness, on NVIDIA cuBLAS, and rebuild it as a bitwise equivalent GEMM family in Triton, a block-level GPU language. It matches cuBLAS bit for bit at a 100% rate on Blackwell and Hopper, and with the epilogue fused from realistic LLM shape, the performance matches or even exceed torch.compile. ii) Lowering to backend, we enforce balanced tree reduction in Triton's compiler, with a data-layout optimization that brings 19 of 27 kernels on GB300 and H100 within 10% of the free-order mode and 5 even exceed. iii) We build the first sound static equivalence checkers to decide bitwise equivalence between compiled GPU kernels, and the first to partition two vendors' instruction sets, NVIDIA PTX and AMD GCN with integration into Triton's autotuner as a static pruning predicate, so a search runs inside a single bitwise-equivalence class.

CCS Concepts: • Software and its engineering;

Nicholas J. Riasanovsky

Meta

Menlo Park, California, USA

njriasan@meta.com

Vivek Sarkar

Georgia Institute of Technology

Atlanta, Georgia, USA

vsarkar@gatech.edu

Keywords: bitwise reproducibility, numerical determinism, floating-point reduction order, compilers, compiler backends, code generation, program equivalence, static equivalence checking, black-box reconstruction, GPU kernels, GEMM, tensor compilers, Triton, autotuning, machine learning systems

1 Introduction

Numerical determinism is now an important need for the systems that train and serve large models: the same computation, the same bits, whenever and wherever it runs. Without determinism during numerical computation, a model may answer differently when asked the same question twice with the same weights and the same seed. A kernel is batch invariant when one request's output is the same whatever else shares its batch, and the kernels serving these models are not. Serving a request alongside others changes how many rows a kernel reduces at once, which changes the algorithm its partial sums are combined by, giving a different floating-point reduction order, while floating-point addition is not associative, so the bits move [24]. Measured across batch size, GPU count and GPU generation on one 7B model in bfloat16, the difference is worth up to nine percentage points of accuracy and generations that differ in length by thousands of tokens [63].

The same instability reaches training. Two runs of one configuration, differing only in effects this small, end at meaningfully different models, and a retrained model changes its mind about individual examples it used to get right [10, 51]. Reinforcement learning is worse than either, because it runs two engines at once: a rollout engine generates, a training engine scores, and when the two disagree about a token's log-probability the objective being optimized is no longer the one that was written down [48].

Floating-point accumulation order dominates [50]. The precision the partial sums are held at, whether a multiply and an add were contracted into one instruction (FMA fusion), and where the rounding to the output type falls all move the result as well. At different infrastructure stack levels, such problems are addressed with heavy effort: i) Compute in higher precision. A fixed-point accumulator of 2098 bits for a sum, 4288 for a dot product, holds every fp64 magnitude, so every addition is exact and one rounding closes it [2, 15, 19]. The Ozaki scheme reaches matrix multiplication the other way, splitting each input into int8 pieces a GPU's integer matrix unit multiplies exactly and accumulates in int32 [56]. Both cost several times the work. ii) Set library mode. To give callers the property without asking them to change an algorithm, production libraries attach conditions to it. Intel's oneMKL returns bit-identical results run to run only while the executable, the instruction-set code path and the thread count all stay fixed, and warns that pinning the code path can more than halve its speed; PyTorch's deterministic mode substitutes deterministic operators, raises an error where none exists, and scopes its guarantee to one release on one platform [26, 47]. The price is the conditions themselves, which the caller must hold. iii) Rewrite the GPU kernels. Nondeterministic LLM inference has been traced to kernels whose reduction order moves with batch size, and rewriting them to fix the order costs about 20% of matrix-multiply throughput against cuBLAS [24]; RepDL enforces correct rounding and order invariance to keep training and inference bit-identical across machines [60]; LayerCast holds weights in sixteen bits while performing every computation in fp32, paying in bandwidth rather than in kernel structure [63]. DeepSeek-V4 [18] makes a frontier training stack bitwise batch-invariant and deterministic end to end. a) cuBLAS picks its kernel from the problem dimensions behind a closed cost model, so the arithmetic moves with the batch; a matrix-multiply library of their own replaces it, and split-K, taken only at small batch sizes and so batch-dependent in the same way, is dropped wherever a kernel can do without it. b) Atomic adds land in thread arrival order, so the backward pass gives each streaming multiprocessor its own buffer and sums those in a fixed order. c) Its compiler turns fast-math off by default, aligns its lowering with the reference CUDA toolchain so no transformation moves a bit, and calls an SMT solver for the integer facts its layout inference rests on. Their matrix multiplication is reported to match or surpass standard split-K in most major scenarios. But none of them reproduces the discipline a closed library follows. iv) Align two engines. A reinforcement-learning rollout engine and training engine that disagree on a token's log-probability shift the objective being optimized; one answer moves the whole pipeline from bf16 to fp16, trading dynamic range for the rounding headroom that keeps the two consistent [48].

Holding the bits still is a challenge at different layers:

In the training algorithm, a policy update weighs each token by the ratio of two probabilities, so when the engine that generated it and the engine that scores it disagree the ratio is taken between two different models rather than between two policies of one [48]. In the ML system infrastructure, a stack is assembled from independently built parts, and one that accumulates differently breaks the agreement for all of them. Below the kernel, the vendor's assembler may reassociate an accumulation it judges safe to move, and where no machine code was shipped the driver assembles at load time, so a driver update can change bit-level semantics the program did not.

In the GPU kernel (scope of this work). Various obstacles exist to reaching numerical consistency: i) A vendor library will not fully disclose what arithmetic it performed, so a kernel written elsewhere has difficulty matching it. ii) Restricting the computation order reduces the flexibility of optimization towards parallelism. PyTorch's deterministic mode stops tuning a reduction kernel's configurations, and when its full search is enabled it takes the vendor's matrix multiply instead of a generated one [47]. Where agreement cannot be established, speed is what gets given up. iii) One source compiled twice by one compiler under different parameters may or may not agree, and an autotuner [13, 64] searching hundreds of configurations for speed has no way to do equivalence partition.

This paper makes four contributions.

A mechanistic account of bitwise behavior. We show that FP reduction order is the dominant factor that decides the numeric bits. We give a theoretical characterization of the factors deciding the FP reduction order of reduction kernels and General Matrix Multiply (GEMM) kernels. We give a formal descriptor for GEMM kernels, GEMMDesc, that describes the full bitwise behavior of the most commonly used GEMM variants. It records the parameters that decide the reduction order, for example where to cut the K axis in a split-K GEMM, and holds nothing that is only a speed knob. Two machines handed the same descriptor owe each other the same bits.

The first Triton GEMM family that is bit-identical to a closed-source vendor library. NVIDIA’s cuBLAS [42] is a black-box GPU kernel library that only provides incomplete computation information that decides the FP computation order. We applied the mechanism above, conducted a set of offline experiments (runtime profiling, numerical inference, and others), and give the first black-box reconstruction of such a library towards bit-level correctness: a Triton GEMM family over fp16, bf16 and fp8 e4m3 that reaches 100% bit-matches with cuBLAS GEMM on GB300, GB200 and H100. As an extra bonus, we discovered a logical bug in cuBLAS GEMM during that offline work (Appendix D). 1^{1}

First Balanced Tree reduction in and layout optimization in Triton compiler We implement compiler enforcement for balanced tree reduction (“inner tree” mode) in the compiler backend of Triton [54] (none before), the block-level GPU

1^{1}The 100% rate excludes this bug.

kernel language. We analyze and implement the data-layout optimization opportunity that the enforcement opens, bringing 19 of 27 kernels across GB300 and H100 within 10% of the free-order mode, and even past it on five of the ten on H100.

The first Static & sound equivalence checkers for compiled Triton kernels and integration in autotuner. We implemented the first static checker that decides the bitwise equivalence of two NVIDIA PTX kernel assembly, sound by construction, and the first symmetric one for a second vendor's instruction set, AMD GCN. It acts both as a static equivalence partitioner during the autotuning stage of a GPU kernel and as a verification of the mechanism we claim. We incorporate it into Triton's autotuner and achieved static pruning before the actual pruning happens for the first time. The checker is validated to be robustly sound across a large kernel suite, including fused kernels generated by PyTorch Inductor [8] and Flash Attention kernels [17]. It recovers the exact partition on the GEMM family and on Inductor's fused kernels, and comes within a factor 2.5 on reductions and normalizations.

References (30)