diff --git a/src/vulkan/shaders/attn_prefill.glsl b/src/vulkan/shaders/attn_prefill.glsl index d1c6a9f5..41724649 100644 --- a/src/vulkan/shaders/attn_prefill.glsl +++ b/src/vulkan/shaders/attn_prefill.glsl @@ -22,7 +22,10 @@ shared float ss[4 * 16 * BK]; // scores of each subgroup; at the start the shared float16_t ps[4 * 16 * PP]; // softmax weights of each subgroup shared float rs[4 * 16]; // per row: the rescale factor, at the end the sum l shared float rm[4 * 16]; // per row: the final max -shared float16_t tq_q[4][16][256]; // Q staging, reused for the inverse WHT output (warp, row, dim) +const uint TQ_Q_W = (TQ_K || TQ_V) ? 4u : 1u; +const uint TQ_Q_R = (TQ_K || TQ_V) ? 16u : 1u; +const uint TQ_Q_D = (TQ_K || TQ_V) ? HD : 1u; +shared float16_t tq_q[TQ_Q_W][TQ_Q_R][TQ_Q_D]; // Q staging, reused for the inverse WHT output (warp, row, dim) float tq_kget(uint row, uint col) { uvec4 u = kvs[row * PQ + col / 8u]; return unpackFloat2x16(u[(col % 8u) / 2u])[col % 2u]; diff --git a/src/vulkan/shaders/tq.glsl b/src/vulkan/shaders/tq.glsl index d292aeb7..ae8ab110 100644 --- a/src/vulkan/shaders/tq.glsl +++ b/src/vulkan/shaders/tq.glsl @@ -95,7 +95,7 @@ float tq_c2(int q) { bool p = q >= 2; float m = p ? 0.133462 : 0.039994; return int tq_nearest(uint bits, float v) { return bits == 3u ? tq_q3(v) : bits == 2u ? tq_q2(v) : tq_q4(v); } float tq_centroid(uint bits, int q) { return bits == 3u ? tq_c3(q) : bits == 2u ? tq_c2(q) : tq_c4(q); } -shared float tq_red[256]; +shared float tq_red[(TQ_K || TQ_V) ? 256u : 1u]; // Per-128-group sum, in the same butterfly order as CUDA tq_group_sum. `slot` must be unique per (row, group) // within the workgroup; every invocation of that group calls this with the same slot. float tq_group_reduce(float cs, uint slot) { diff --git a/src/vulkan/spv/attn_prefill_128.spv b/src/vulkan/spv/attn_prefill_128.spv index 36213fb8..a61279f3 100644 Binary files a/src/vulkan/spv/attn_prefill_128.spv and b/src/vulkan/spv/attn_prefill_128.spv differ diff --git a/src/vulkan/spv/attn_prefill_256.spv b/src/vulkan/spv/attn_prefill_256.spv index 9c695fcc..b4f8b2a9 100644 Binary files a/src/vulkan/spv/attn_prefill_256.spv and b/src/vulkan/spv/attn_prefill_256.spv differ diff --git a/src/vulkan/spv/attn_prefill_64.spv b/src/vulkan/spv/attn_prefill_64.spv index 7a73af81..3ebfc09a 100644 Binary files a/src/vulkan/spv/attn_prefill_64.spv and b/src/vulkan/spv/attn_prefill_64.spv differ diff --git a/src/vulkan/spv/ink_clip.spv b/src/vulkan/spv/ink_clip.spv index ed4b35ad..854c8c86 100644 Binary files a/src/vulkan/spv/ink_clip.spv and b/src/vulkan/spv/ink_clip.spv differ diff --git a/src/vulkan/spv/kv_store.spv b/src/vulkan/spv/kv_store.spv index a9a16c99..daf0de50 100644 Binary files a/src/vulkan/spv/kv_store.spv and b/src/vulkan/spv/kv_store.spv differ diff --git a/src/vulkan/spv/rms_norm.spv b/src/vulkan/spv/rms_norm.spv index 906ba2c3..91dcc4fe 100644 Binary files a/src/vulkan/spv/rms_norm.spv and b/src/vulkan/spv/rms_norm.spv differ diff --git a/src/vulkan/spv_smem.rs b/src/vulkan/spv_smem.rs index 79e1fcee..bffaa99f 100644 --- a/src/vulkan/spv_smem.rs +++ b/src/vulkan/spv_smem.rs @@ -370,4 +370,14 @@ mod tests { assert!(worst_v100.0 <= 49152, "{} needs {} bytes of Workgroup memory with cooperative matrices off", worst_v100.1, worst_v100.0); } + + #[test] + fn attn_prefill_non_turbo_fits_48kb() { + for kernel in ["attn_prefill_64", "attn_prefill_128", "attn_prefill_256"] { + for mode in 0..=3u32 { + let bytes = shared_bytes_split(kernel, &[], mode, mode).unwrap(); + assert!(bytes <= 49152, "{kernel} with kv_mode={mode} needs {bytes} bytes (> 49152)"); + } + } + } }