Skip to content

musa: define __CUDA_ARCH__ and fix the q8_0 dequantization kernel - #29508

Merged
CISC merged 1 commit into
ggml-org:masterfrom
yeahdongcn:xd/musa-cuda-arch
Sep 30, 2026
Merged

CISC merged 1 commit into
ggml-org:masterfrom
yeahdongcn:xd/musa-cuda-arch

Conversation

@yeahdongcn

@yeahdongcn yeahdongcn commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Aligns __CUDA_ARCH__ on MUSA with the HIP approach, as discussed in #29292 (comment). __CUDA_ARCH__ is defined in vendors/hip.h, but it was never defined for MUSA, so every architecture test in the shared ggml-cuda sources evaluated to 0 and the kernels behind them were compiled with an empty body and still launched.

  • vendors/musa.h — define __CUDA_ARCH__ as GGML_CUDA_CC_RUBIN (1300), the way HIP does, and exclude the NVIDIA-only features that this value would otherwise enable: TURING_MMA_AVAILABLE, AMPERE_MMA_AVAILABLE, CP_ASYNC_AVAILABLE, __reduce_add_sync, the Ampere/Pascal-DP4A MMQ and MMVQ configurations and __bfloat1622float2. The definition is scoped to the device pass (#ifdef __MUSA_ARCH__), because CUB tells host from device code with defined(__CUDA_ARCH__) || defined(__MUSA_ARCH__), which is also how nvcc behaves
  • convert.cuh — dequantize_block_q8_0_f16 is guarded by __CUDA_ARCH__ >= GGML_CUDA_CC_PASCAL, so it had an empty body and every q8_0 dequantization produced garbage
  • common.cuh, mmvq.cu — drop the now-redundant defined(__CUDA_ARCH__) tests in the architecture comparisons; an undefined __CUDA_ARCH__ is already 0 in #if, which is what those sites relied on. The #ifdef __CUDA_ARCH__ that selects between the device and the empty host body of NO_DEVICE_CODE is kept

NVIDIA and HIP builds are unaffected: defined(__MUSA_ARCH__) is false there and the added !defined(GGML_USE_MUSA) conditions are no-ops. The host pass is unchanged as well.

Testing Done

Measured on one MTT S5000 (MUSA architecture 31, MUSA SDK 5.2.0, driver 5.2.0-server), built with -DGGML_MUSA=ON -DGGML_BACKEND_DL=ON -DLLAMA_BUILD_TESTS=ON:

build test-backend-ops
master 12458/12507 — 49 failures: 31x MUL_MAT_ID and 18x MUL_MAT, all type_a=q8_0, NaN or above tolerance
this PR 12507/12507

-o MUL_MAT_ID alone: 899/929 on master, 929/929 here. The failing case is the one that reaches batched_mul_mat_traits<GGML_TYPE_F16>::convert for quantized src0. The CUB based ops (ARGSORT, TOP_K, SUM, CUMSUM, MEAN, SSM_SCAN) are 682/682, and the same tree builds for MUSA_ARCHITECTURES=21;22;31 (only 31 was run on hardware). Model smokes (Qwen3-0.6B-Q4_K_M with -fa on -ctk q8_0 -ctv q8_0) and llama-bench are unchanged to within noise.

The cuda, hip, musa, gpu-cuda and gpu-rocm checks pass.

Additional information

Requirements

@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Sep 27, 2026
@yeahdongcn
yeahdongcn force-pushed the xd/musa-cuda-arch branch 3 times, most recently from 00c9d56 to 978cbb4 Compare September 27, 2026 04:16
@yeahdongcn yeahdongcn changed the title musa: define __CUDA_ARCH__ for device passes musa: define __CUDA_ARCH__ and fix the q8_0 and iq4_nl dequantization kernels Sep 27, 2026
@yeahdongcn
yeahdongcn marked this pull request as ready for review September 27, 2026 04:22
@yeahdongcn
yeahdongcn requested a review from a team as a code owner September 27, 2026 04:22
@yeahdongcn

Copy link
Copy Markdown
Collaborator Author

The gpu-cuda/gpu-rocm failures look like the pre-existing master breakage tracked in #29484

Comment thread ggml/src/ggml-cuda/mmvq.cu Resolved
@yeahdongcn yeahdongcn closed this Sep 27, 2026
@yeahdongcn yeahdongcn reopened this Sep 27, 2026
@yeahdongcn
yeahdongcn marked this pull request as draft September 27, 2026 09:44
@yeahdongcn
yeahdongcn marked this pull request as ready for review September 27, 2026 10:48

@JohannesGaessler JohannesGaessler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the changes to convert.cu are correct; if they are they indicate a bug not just for MUSA but for CUDA and HIP as well. Please put these changes into a separate PR to make bookkeeping on our end easier.

@yeahdongcn

Copy link
Copy Markdown
Collaborator Author

I'm not sure the changes to convert.cu are correct; if they are they indicate a bug not just for MUSA but for CUDA and HIP as well. Please put these changes into a separate PR to make bookkeeping on our end easier.

Thanks for the review. Indeed, this PR fixes two separate issues. I can split it into two PRs.

@yeahdongcn yeahdongcn changed the title musa: define __CUDA_ARCH__ and fix the q8_0 and iq4_nl dequantization kernels musa: define __CUDA_ARCH__ and fix the q8_0 dequantization kernel Sep 30, 2026
The MUSA vendor header never defined __CUDA_ARCH__, so every architecture
test in the shared ggml-cuda sources evaluated to 0.  Kernel bodies gated on
the architecture therefore compiled to nothing, for example the q8_0 -> f16
dequantization kernel in convert.cu, whose NO_DEVICE_CODE fallback expands to
an empty body in host code.

Report the newest architecture like the HIP backend does and exclude the
NVIDIA-only features explicitly, as they are not usable on MUSA.  Define it
for device passes only: CUB uses defined(__CUDA_ARCH__) to detect device
compilation, which is also how nvcc behaves.

Drop the now-redundant defined(__CUDA_ARCH__) checks in the architecture
comparisons: __CUDA_ARCH__ is undefined in host passes for CUDA and MUSA, and
HIP defines it for every pass, so both forms select the same branch.
@yeahdongcn

Copy link
Copy Markdown
Collaborator Author

@JohannesGaessler Please see: #29683

@JohannesGaessler

Copy link
Copy Markdown
Contributor

The hip-quality-check failure seems to be unrelated.

@JohannesGaessler JohannesGaessler added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Sep 30, 2026
@yeahdongcn

Copy link
Copy Markdown
Collaborator Author

The hip-quality-check failure seems to be unrelated.

Yes, last time the CI was green.

@CISC
CISC merged commit 272aad8 into ggml-org:master Sep 30, 2026
17 of 20 checks passed
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 7, 2026
The MUSA vendor header never defined __CUDA_ARCH__, so every architecture
test in the shared ggml-cuda sources evaluated to 0.  Kernel bodies gated on
the architecture therefore compiled to nothing, for example the q8_0 -> f16
dequantization kernel in convert.cu, whose NO_DEVICE_CODE fallback expands to
an empty body in host code.

Report the newest architecture like the HIP backend does and exclude the
NVIDIA-only features explicitly, as they are not usable on MUSA.  Define it
for device passes only: CUB uses defined(__CUDA_ARCH__) to detect device
compilation, which is also how nvcc behaves.

Drop the now-redundant defined(__CUDA_ARCH__) checks in the architecture
comparisons: __CUDA_ARCH__ is undefined in host passes for CUDA and MUSA, and
HIP defines it for every pass, so both forms select the same branch.

(cherry picked from commit 272aad8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants