From 9e19948ff988043ddff2369668f20951d6c084aa Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 11 Nov 2026 07:09:47 +0100 Subject: [PATCH] split: the golden dot test draws its q8_1 scale and sum in a fixed order (same inputs under g++ and clang) The split tools built each q8_1 block's ds with two random draws as the two arguments of one call: b.ds = make_half2(__float2half((float) (rng() % 1000) / 500.0f), __float2half((float) ((int) (rng() % 200) - 100))); C++ leaves the order of those arguments unspecified: g++ (the host compiler under nvcc) drew s first, clang (HIP) d first, so a HIP build of split_qdot_golden saw other inputs than the ones qdot_golden.txt was written from (all 176 groups "inputs differ"). Every other input byte, the struct sizes and host __float2half (checked against a round-to-nearest-even reference over all 2^32 floats) were equal in both builds. Now s is drawn first, then d, into named locals - g++'s order, so qdot_golden.txt and the CUDA inputs are unchanged: - src/split/tools/qdot_golden.cuh:83 (make_inputs, the generator of the golden file and of the check) - src/split/tools/qdot_test.cu:100 (the oracle test's own copy of the draws) - src/split/tools/iqdot_test.cu:63 (the same draws) Test code only; no engine source changes. Checks: - RTX PRO 5000 (sm_120): split_qdot_test --write-golden output byte-identical to the committed qdot_golden.txt; 0 of 704,512 dots differ from ggml; --regen-golden equal; split_qdot_golden 0 of 176 groups differ. - RTX A4000 (sm_86): the same four results. - AMD Radeon AI PRO R9700 (gfx1201, HIP build of split_qdot_golden): 0 of 176 groups differ from the unchanged file's cuda lines, so the HIP dots equal the CUDA dots bit for bit and the file needs no hip line; with one Q8_0 dot's arithmetic changed (d8_0*d8_1*sumi -> d8_0*(d8_1*sumi)) the check fails (rc 1, Q8_0 groups differ, Q4_0 / Q5_1 still equal). - Not run: the Windows MSVC build of these files (owed). --- src/split/tools/iqdot_test.cu | 5 ++++- src/split/tools/qdot_golden.cuh | 6 +++++- src/split/tools/qdot_test.cu | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/split/tools/iqdot_test.cu b/src/split/tools/iqdot_test.cu index 47b08ecae3..25ecf6259c 100644 --- a/src/split/tools/iqdot_test.cu +++ b/src/split/tools/iqdot_test.cu @@ -60,7 +60,10 @@ bool run(const char* name, int nblocks, unsigned seed) { std::vector y((size_t) nblocks * 8); for (auto& b : y) { for (int i = 0; i < 32; ++i) b.qs[i] = (int8_t) (int) (rng() % 255 - 127); - b.ds = make_half2(__float2half((float) (rng() % 1000) / 500.0f), __float2half((float) ((int) (rng() % 200) - 100))); + // s drawn first, then d (as qdot_golden.cuh make_inputs: a fixed order on every compiler) + const float s = (float) ((int) (rng() % 200) - 100); + const float d = (float) (rng() % 1000) / 500.0f; + b.ds = make_half2(__float2half(d), __float2half(s)); } char* dw; block_q8_1* dy; diff --git a/src/split/tools/qdot_golden.cuh b/src/split/tools/qdot_golden.cuh index 461b23a5a0..87b46e25bd 100644 --- a/src/split/tools/qdot_golden.cuh +++ b/src/split/tools/qdot_golden.cuh @@ -80,7 +80,11 @@ inline Inputs make_inputs(int B, const std::vector& h16, int nblocks, int q in.y = std::vector((size_t) nblocks * (qk / QK8_1)); // (constructed at its size: block_q8_1 has no copy constructor, so no resize) for (auto& b : in.y) { for (int i = 0; i < 32; ++i) b.qs[i] = (int8_t) (int) (rng() % 255 - 127); - b.ds = make_half2(__float2half((float) (rng() % 1000) / 500.0f), __float2half((float) ((int) (rng() % 200) - 100))); + // s drawn first, then d, in named locals: as two arguments of one call their order was unspecified (g++ under nvcc drew s first, + // clang under HIP d first); this is g++'s order, so qdot_golden.txt is unchanged + const float s = (float) ((int) (rng() % 200) - 100); + const float d = (float) (rng() % 1000) / 500.0f; + b.ds = make_half2(__float2half(d), __float2half(s)); } return in; } diff --git a/src/split/tools/qdot_test.cu b/src/split/tools/qdot_test.cu index 0d303fe97c..e4cfcb2b20 100644 --- a/src/split/tools/qdot_test.cu +++ b/src/split/tools/qdot_test.cu @@ -97,7 +97,10 @@ bool run(const char* name, int B, std::vector h16, int nblocks, unsigned se std::vector y((size_t) nblocks * (qk / QK8_1)); for (auto& b : y) { for (int i = 0; i < 32; ++i) b.qs[i] = (int8_t) (int) (rng() % 255 - 127); - b.ds = make_half2(__float2half((float) (rng() % 1000) / 500.0f), __float2half((float) ((int) (rng() % 200) - 100))); + // s drawn first, then d (qdot_golden.cuh make_inputs: the same draws, a fixed order on every compiler) + const float s = (float) ((int) (rng() % 200) - 100); + const float d = (float) (rng() % 1000) / 500.0f; + b.ds = make_half2(__float2half(d), __float2half(s)); } char* dw; block_q8_1* dy;