From 9ae6dbd2ce81db8810a8a872296fec44884f0f53 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 3 Oct 2026 01:57:12 +0200 Subject: [PATCH] #542: MMQ's device facts from cudaDeviceGetAttribute; warn when libcudart is older than the headers A CUDA 13 build that linked the system's CUDA 12 libcudart.so (a kit with a dangling libcudart.so symlink) read cudaDeviceProp shifted: sharedMemPerBlockOptin came back as 1, #420's fits() then refused MMQ for every i-quant and the prompts ran ~4x slower, with a log line printing "1 bytes of shared memory per block". - ggml_cuda_info() (CUDA) reads cc, smpbo, smpb, nsm, warp size, integrated and cooperative launch with cudaDeviceGetAttribute, which is ABI-stable. A matched build reads the same values: the same MMQ choices, the same output. - The engine warns at start when the loaded CUDA runtime's major version differs from the headers' it was compiled with, and says to rebuild against one toolkit (-DCUDAToolkit_ROOT). HIP is unchanged. --- src/prefill/ggml_cuda_host.cu | 27 ++++++++++++++++++++------- src/program/generate.cpp | 10 ++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/prefill/ggml_cuda_host.cu b/src/prefill/ggml_cuda_host.cu index c8f8284b..1245c2b0 100644 --- a/src/prefill/ggml_cuda_host.cu +++ b/src/prefill/ggml_cuda_host.cu @@ -80,17 +80,30 @@ const ggml_cuda_device_info & ggml_cuda_info() { d.smpbo = prop.sharedMemPerBlock; d.integrated = false; d.supports_cooperative_launch = false; -#else - d.cc = 100 * strata::cc_major_of(prop.major) + 10 * strata::cc_minor_of(prop.minor); // STRATA_EMULATE_CC - d.smpbo = strata::smem_optin_of((int) prop.sharedMemPerBlockOptin); - d.integrated = prop.integrated != 0; - d.supports_cooperative_launch = prop.cooperativeLaunch != 0; -#endif d.nsm = prop.multiProcessorCount; d.smpb = prop.sharedMemPerBlock; + d.warp_size = prop.warpSize; +#else + // #542: the fields MMQ's choices read come from cudaDeviceGetAttribute, which is ABI-stable: a + // cudaDeviceProp filled by an older libcudart than the headers (a CUDA 13 build that links a CUDA 12 + // libcudart.so) is shifted - sharedMemPerBlockOptin read 1 there, and every i-quant lost MMQ (#420's + // fits()). In a matched build both give the same values. + auto attr = [id](cudaDeviceAttr a) { + int v = 0; + CUDA_CHECK(cudaDeviceGetAttribute(&v, a, id)); + return v; + }; + d.cc = 100 * strata::cc_major_of(attr(cudaDevAttrComputeCapabilityMajor)) + + 10 * strata::cc_minor_of(attr(cudaDevAttrComputeCapabilityMinor)); // STRATA_EMULATE_CC + d.smpbo = strata::smem_optin_of(attr(cudaDevAttrMaxSharedMemoryPerBlockOptin)); + d.integrated = attr(cudaDevAttrIntegrated) != 0; + d.supports_cooperative_launch = attr(cudaDevAttrCooperativeLaunch) != 0; + d.nsm = attr(cudaDevAttrMultiProcessorCount); + d.smpb = (size_t) attr(cudaDevAttrMaxSharedMemoryPerBlock); + d.warp_size = attr(cudaDevAttrWarpSize); +#endif d.vmm = false; d.total_vram = prop.totalGlobalMem; - d.warp_size = prop.warpSize; d.physical_device = id; d.physical_share_count = 1; d.virtual_index = 0; diff --git a/src/program/generate.cpp b/src/program/generate.cpp index a7de0614..6088b323 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -2703,6 +2703,16 @@ int main(int argc, char** argv) { std::fprintf(stderr, "strata generate: GPU %d: %s, compute capability %d.%d%s\n", dev, name, strata::cc_major_of(p.major), strata::cc_minor_of(p.minor), strata::emulated_cc() ? " (STRATA_EMULATE_CC: a test mode, the card is emulated)" : ""); + { // #542: a build whose libcudart is older than its headers (a CUDA 13 kit with a dangling libcudart.so that + // CMake resolved to the system's CUDA 12 one) reads cudaDeviceProp shifted - silently, and slowly + int rt = 0; + if (cudaRuntimeGetVersion(&rt) == cudaSuccess && rt / 1000 != CUDART_VERSION / 1000) + std::fprintf(stderr, "strata generate: WARNING: this engine was compiled with CUDA %d.%d headers but " + "loaded a CUDA %d.%d runtime (libcudart): GPU properties can read wrong and some " + "kernels go unused. Rebuild it against one toolkit (cmake -DCUDAToolkit_ROOT=, with its libcudart.so present) (#542)\n", + CUDART_VERSION / 1000, CUDART_VERSION % 1000 / 10, rt / 1000, rt % 1000 / 10); + } #endif const std::string e = strata::core::device_code_error(); if (!e.empty()) {