From 02c8092acf76be0754bf9e3920808eac0fa1b56f Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 29 Sep 2026 12:06:58 +0200 Subject: [PATCH] D-1: the prompt attention's shared-memory opt-in per device (a layer split with fp16 KV failed on the second card) The opt-in was set once per process, but it is a per-device setting. The int8 kernel fits the default 48 KB; the fp16 one (KV of contexts up to 8K) needs 54 KB, so on the second card of a split its launch failed. --- src/kernels/cuda/qsa_prompt_attn.cu | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/kernels/cuda/qsa_prompt_attn.cu b/src/kernels/cuda/qsa_prompt_attn.cu index 7f65a377..b6036824 100644 --- a/src/kernels/cuda/qsa_prompt_attn.cu +++ b/src/kernels/cuda/qsa_prompt_attn.cu @@ -572,15 +572,18 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_i8_kernel(const float* __ bool launch_i8(const float* q, const QsaAttnPools& pools, const int32_t* ids, const int32_t* steps, int64_t cap, const QsaShapes& s, float* attn, int64_t n_q, cudaStream_t st) { - static bool attr = false; + static bool attr[64] = {}; // the shared-memory opt-in is per device (a layer split runs this on several) + int dev = 0; + cudaGetDevice(&dev); const int bytes = (int) sizeof(Smem2); - if (!attr) { + if (dev < 0 || dev >= 64) return false; + if (!attr[dev]) { if (cudaFuncSetAttribute(prompt_attn_i8_kernel, cudaFuncAttributeMaxDynamicSharedMemorySize, bytes) != cudaSuccess) { cudaGetLastError(); return false; } - attr = true; + attr[dev] = true; } const float scale_log2 = 1.4426950408889634f / sqrtf((float) HD); for (int64_t q0 = 0; q0 < n_q; q0 += 65535) { @@ -600,15 +603,18 @@ bool launch_i8(const float* q, const QsaAttnPools& pools, const int32_t* ids, co template bool launch(const float* q, const QsaAttnPools& pools, const int32_t* ids, const int32_t* steps, int64_t cap, const QsaShapes& s, float* attn, int64_t n_q, cudaStream_t st) { - static bool attr = false; + static bool attr[64] = {}; // per device, as above + int dev = 0; + cudaGetDevice(&dev); const int bytes = (int) sizeof(Smem); - if (!attr) { + if (dev < 0 || dev >= 64) return false; + if (!attr[dev]) { if (cudaFuncSetAttribute(prompt_attn_kernel, cudaFuncAttributeMaxDynamicSharedMemorySize, bytes) != cudaSuccess) { cudaGetLastError(); return false; } - attr = true; + attr[dev] = true; } const float scale_log2 = 1.4426950408889634f / sqrtf((float) HD); for (int64_t q0 = 0; q0 < n_q; q0 += 65535) {