Skip to content

cuda: gate D=512 VEC flash attention decode kernel body to HIP only - #378

Closed
Fenix46 wants to merge 1 commit into
TheTom:feature/turboquant-kv-cachefrom
Fenix46:fix/cuda-fattn-vec-d512-hip-only
Closed

Fenix46 wants to merge 1 commit into
TheTom:feature/turboquant-kv-cachefrom
Fenix46:fix/cuda-fattn-vec-d512-hip-only

Conversation

@Fenix46

@Fenix46 Fenix46 commented Sep 20, 2026

Copy link
Copy Markdown

Summary

The D=512 VEC flash-attention decode path (added for HIP/RDNA4) is only ever dispatched under GGML_USE_HIP in ggml_cuda_get_best_fattn_kernel, but the kernel body and its instantiations were left unguarded, so plain CUDA builds still compiled them.

For K=q8_0 combined with V=turbo2_0/turbo3_0/turbo4_0, the scaled V_cols_per_iter (nthreads_V / 8) at D=512 pushes the shared KQ buffer past 64KB. ptxas rejects this on Turing (sm_75) with uses too much shared data, which fails any plain-CUDA build that reaches these template instances, including GGML_CUDA_ARCHITECTURES=75.

Since ggml_cuda_get_best_fattn_kernel never routes D=512 decode to this path outside HIP, compiling it on CUDA has no runtime benefit, only a build-time cost.

Fix

  • Gate the kernel body in ggml_cuda_flash_attn_ext_vec_case_d512 (fattn-vec.cuh) behind GGML_USE_HIP; on non-HIP builds it aborts, matching the fact that the dispatcher never reaches it there.
  • Gate the corresponding dispatch call sites in ggml_cuda_flash_attn_ext_vec (fattn.cu) behind the same GGML_USE_HIP guard.
  • The template declarations (DECL_FATTN_VEC_CASE_D512 and its extern uses) are left unconditional, so none of the six per-type .cu instance files under template-instances/ needed to change.

D=512 VEC decode was added for HIP/RDNA4 (bef3727), dispatched only
under GGML_USE_HIP in ggml_cuda_get_best_fattn_kernel. The kernel body
and its instantiations were left unguarded, so plain CUDA builds still
compiled them. For K=q8_0 with turbo{2,3,4} V, the scaled V_cols_per_iter
(nthreads_V/8) at D=512 pushes the shared KQ buffer past 64KB, which
ptxas rejects on Turing (sm_75) with 'uses too much shared data'.

Since ggml_cuda_get_best_fattn_kernel never routes D=512 decode to this
path outside HIP, the CUDA-side instantiation had no runtime benefit.
Gate the kernel body in ggml_cuda_flash_attn_ext_vec_case_d512 (aborts
on non-HIP builds, matching the unreachable path) and the dispatch call
sites in ggml_cuda_flash_attn_ext_vec behind GGML_USE_HIP; keep the
template declarations unconditional so the .cu instance files and the
extern declarations don't need touching.
@TheTom

TheTom commented Sep 23, 2026

Copy link
Copy Markdown
Owner

Thanks for this. #372 fixed the same break a day earlier and removes the D=512 instances from non-HIP builds entirely instead of keeping an aborting stub, so I merged that one and I'm closing this as a duplicate.

For the record, since the comment here says 64 KB: ptxas reports a 0xc000 (48 KiB) static shared cap for both sm_75 and sm_89 with nvcc 13.0, and sm_121 accepts the 65,792-byte kernel, which is why a GB10 build never saw the error. Hosted CI builds sm_89 with nvcc 12.6, which also accepts it, so the break only shows up on CUDA 13 toolchains for pre-Blackwell cards.

Your Vulkan PR (#373) is in review separately.

@TheTom TheTom closed this Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants