From 12877b6224097c3a2e1aa2e00b9ef1fa8df1d4dd Mon Sep 17 00:00:00 2001 From: xrip Date: Mon, 7 Sep 2026 09:25:56 +0000 Subject: [PATCH] cuda : select SM75 prefill cuBLAS path; document optional 25% build gain Default build: this narrow automatic dispatch gives about 9-10% prefill gain in the tested 9B models. No extra build or launch flag is required. For the larger measured 24-25% long-prompt gain, configure with -DGGML_CUDA_FORCE_CUBLAS=ON and rebuild. This is an existing CMake option, not a runtime environment variable or a new feature in this commit. With it enabled, Ornith-1.0-9B UD-Q4_K_XL gained 25.24% prefill and Qwen3.5-9B UD-Q4_K_XL gained 24.26% on 16384-token server requests, with TG near 66 t/s. These results are specific to one CMP50HX 10 GiB, the tested models and batch settings; they are not a universal 25% gain or a full-model 27B measurement. Global cuBLAS is not enabled by default: the tested N256 matrix operations lost 12.83-28.20%. That is an operation-level result, not a measured short-request server regression. Other shapes, workloads and peak memory still need validation before broadening the default dispatch. Select the existing FP16 cuBLAS path for contiguous, device-backed Q4_K and IQ4_XS FFN weights at batches of 1024 through 2048 tokens on SM75. Limit the rule to 4096x12288 and 5120x17408 matrices in either orientation to bound the FP16 weight workspace and avoid unmeasured shapes. Keep MMVQ decode, smaller batches, batched matrices, host-backed weights, MoE dispatch, other quant types and other architectures unchanged. Honor GGML_CUDA_FORCE_MMQ. No new kernel or quantization format is added. Validation on one CMP50HX 10 GiB: - 52 existing and 24 added numerical matrix cases passed. - Three paired timing runs: selected shapes gained 12.4-43.9%; small-batch controls ranged from -0.14% to +1.32%. - Real 16384-token requests, three measured runs after warmup, no cached prompt tokens: Ornith 9B UD-Q4_K_XL gained 9.77% prefill and Qwen3.5 9B UD-Q4_K_XL gained 9.14% against the final baseline repeat. TG stayed within 0.2% of that baseline. Compute Sanitizer remains unavailable on this device; numerical checks are not a substitute for sanitizer coverage. --- ggml/src/ggml-cuda/ggml-cuda.cu | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu index 28fd850d8..d298ba103 100644 --- a/ggml/src/ggml-cuda/ggml-cuda.cu +++ b/ggml/src/ggml-cuda/ggml-cuda.cu @@ -1929,6 +1929,19 @@ static void ggml_cuda_mul_mat(ggml_backend_cuda_context & ctx, const ggml_tensor ggml_cuda_mul_mat_vec_q(ctx, src0, src1, nullptr, dst); return; } +#ifndef GGML_CUDA_FORCE_MMQ + // Bound FP16 weight workspace and keep small batches on MMQ. + const bool sm75_ffn = (ne00 == 4096 && ne01 == 12288) || (ne00 == 12288 && ne01 == 4096) + || (ne00 == 5120 && ne01 == 17408) || (ne00 == 17408 && ne01 == 5120); + if (cc == GGML_CUDA_CC_TURING && sm75_ffn && ne11 >= 1024 && ne11 <= 2048 + && (src0->type == GGML_TYPE_Q4_K || src0->type == GGML_TYPE_IQ4_XS) + && ne02 == 1 && ne03 == 1 && ne12 == 1 && ne13 == 1 + && ggml_is_contiguous(src0) && ggml_is_contiguous(src1) + && !ggml_backend_buffer_is_host(src0->buffer)) { + ggml_cuda_mul_mat_cublas(ctx, src0, src1, dst); + return; + } +#endif if (ggml_cuda_should_use_mmq(src0->type, cc, ne11, /*n_experts =*/ 0)) { ggml_cuda_mul_mat_q(ctx, src0, src1, nullptr, dst); return;