From 638ab2dd5e4923159cdec98c0bf32e32b62425ab Mon Sep 17 00:00:00 2001 From: eadra Date: Tue, 6 Oct 2026 13:24:44 +0200 Subject: [PATCH] tests: prefill_mmq_kquant_test waits for its uploads before the kernels The inputs and the NaN sentinel go up with cudaMemcpy / cudaMemset on the legacy stream, and the kernels run on a cudaStreamNonBlocking stream, which does not wait for it: a pageable copy or the memset can land after the kernels started. On an RTX 4090 (sm_89, 128 SMs) that failed the screen ("unwritten or non-finite output") in 3 of 3 runs, in a different product each time; with the sync before the kernels, 5 of 5 runs passed. The same fix as the fused tests' (prefill_fused_moe_test.cpp, prefill_fused_iq_test.cpp). (PR #532) --- tests/cuda/prefill_mmq_kquant_test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/cuda/prefill_mmq_kquant_test.cpp b/tests/cuda/prefill_mmq_kquant_test.cpp index 38e0a41e..aa54ad47 100644 --- a/tests/cuda/prefill_mmq_kquant_test.cpp +++ b/tests/cuda/prefill_mmq_kquant_test.cpp @@ -95,6 +95,9 @@ void product(mmq::Context& ctx, cudaStream_t s, const char* name, ggml_type t, i ck(cudaMemcpy(db.p, bounds.data(), bounds.size() * 4, cudaMemcpyHostToDevice), "bounds"); ck(cudaMemcpy(dw.p, w.data(), w.size(), cudaMemcpyHostToDevice), "w"); ck(cudaMemset(dy.p, 0xff, (size_t) rows * (size_t) out_rows * 4), "sentinel"); + // the copies and the sentinel above run on the legacy stream, which a non-blocking stream does not wait for: a + // pageable cudaMemcpy/cudaMemset can still be in flight when the kernels start (a 128-SM 4090 caught it) + ck(cudaDeviceSynchronize(), "inputs"); mmq::quantize((const float*) dx.p, (const int32_t*) dsrc.p, dxq.p, (int) t, cols, cols, rows, s); mmq::Product p; p.w = dw.p; p.type = (int) t; p.w_rows = out_rows; p.w_cols = cols; p.expert_bytes = eb; p.n = n;