Skip to content

Fix core dump issue for binary built for old GPUs (cm<89) - #231

Open
jasonchen31 wants to merge 2 commits into
0xShug0:devfrom
jasonchen31:dev
Open

Fix core dump issue for binary built for old GPUs (cm<89)#231
jasonchen31 wants to merge 2 commits into
0xShug0:devfrom
jasonchen31:dev

Conversation

@jasonchen31

@jasonchen31 jasonchen31 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Fixing #227

PR: Gate SageAttention2 for pre-sm_89 CUDA builds and expose --cuda-arch in the Linux build script

Problem

Two bugs broke CUDA builds targeting old GPUs (compute capability 6.1, e.g. Pascal GTX 10xx):

  1. SageAttention2 is unconditionally compiled and can't build for old GPUs.
    The vendored ggml CUDA backend globs sage-attn2.cu into every build. Its
    headers include <cuda/barrier> / <cuda/pipeline> unconditionally, which
    CUDA hard-errors on sub-sm_70 targets:

    #error "CUDA synchronization primitives are only supported for sm_70 and up."
    
  2. scripts/build_linux.sh --backend cuda never sets the target GPU architecture.
    It silently inherits CMAKE_CUDA_ARCHITECTURES=native (the build machine's
    GPU). Building on any modern GPU produced a single-arch image with no sm_61
    code, and left the Sage gate "ON" (arch >= 89), so kernels with SM89+
    instructions were packaged into a binary that core-dumped when run on a 6.1 GPU.

A direct cmake -S . -B build -DENGINE_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=61
worked because it pins the arch (and 61 < 89 disables Sage at compile time).

Changes

external/ggml/src/ggml-cuda/CMakeLists.txt (build gate)

Add a fail-closed build-time gate for SageAttention2:

  • Default ON, but turned OFF if any CMAKE_CUDA_ARCHITECTURES entry
    parses to < 89 (or is unparseable, e.g. native).
  • When OFF, sage-attn2.cu is removed from the source list and a
    GGML_CUDA_SAGE_ATTN2_ENABLED compile definition is not added; a
    message(STATUS ...) reports CUDA SageAttention2 disabled.

external/ggml/src/ggml-cuda/sage-attn2.cuh (stub definitions)

Because ggml-cuda.cu unconditionally references the four Sage entry points
(ggml_cuda_sage_attn2, _i8, _supported, _i8_supported), the header now:

  • keeps the real declarations when GGML_CUDA_SAGE_ATTN2_ENABLED is defined
    (arch >= 89), and
  • provides static inline stubs when it is not: supported() returns false
    (op never attached to a graph) and the compute entry points GGML_ABORT.
    Since ggml-cuda.cu already includes this header, no dispatcher edits are
    needed.

scripts/build_linux.sh (target architecture control)

  • New --cuda-arch <spec> flag that forwards -DCMAKE_CUDA_ARCHITECTURES=<spec>
    (with -UCMAKE_CUDA_ARCHITECTURES to avoid the sticky cache entry, mirroring
    the existing HIP --gpu-targets handling).
  • Status output prints the effective CUDA architectures (or
    <auto: machine-native ...> when unset).

Docs

  • docs/build/linux.md: document --cuda-arch, including the
    old-GPU example and the equivalence with the working direct CMake invocation.
    Noted that ENGINE_ENABLE_NATIVE_CPU=OFF is not required, since
    GGML_NATIVE affects CUDA arch only as a fallback when
    CMAKE_CUDA_ARCHITECTURES is undefined.

Why this is safe for correctness

  • Disabling Sage does not leave MiniMax-H3 (the only Sage consumer) without
    an attention path: src/community_models/minimax_h3/dit_denoiser.cpp already
    falls back to ggml_flash_attn_ext when the Sage op is unsupported.
  • Flash attention has a real Pascal (cc 610) kernel path
    (BEST_FATTN_KERNEL_TILE in external/ggml/src/ggml-cuda/fattn.cu), which is
    compiled into the sm_61 build.
  • Sage physically cannot run below SM89 anyway; the runtime supported()
    guard already returns false for cc < 890, so a 6.1 GPU would have used flash
    attention regardless. The real fix is compiling the whole backend for sm_61.

Usage

# Old GPU (compute capability 6.1)
./scripts/build_linux.sh --backend cuda --cuda-arch 61 --target audiocpp_cli --target audiocpp_server

Validation status

  • git diff for CMakeLists.txt is a pure additive change (22 insertions /
    0 deletions); CRLF line endings of the vendored file are preserved.
  • Verified locally via a cmake -P-equivalent simulation that the gate resolves
    correctly: 61/52/mixed-low/native -> Sage OFF; 89-real/120a-real -> ON.

@jasonchen31
jasonchen31 marked this pull request as draft August 13, 2026 20:56
@jasonchen31

Copy link
Copy Markdown
Contributor Author

I compiled again while fixing the SensVoice ASR Webui missing issue, Sage Attention was somehow included and the build failed again. Still working on it.

@jasonchen31

Copy link
Copy Markdown
Contributor Author

It should be fixed this time. clean build success, and GPU inference correctly.

@jasonchen31
jasonchen31 marked this pull request as ready for review August 13, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant