Repository navigation
musa: define __CUDA_ARCH__ and fix the q8_0 dequantization kernel - #29508
Conversation
00c9d56 to
978cbb4
Compare
|
The |
978cbb4 to
9588757
Compare
JohannesGaessler
left a comment
There was a problem hiding this comment.
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. |
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.
cf51c4f to
bf76859
Compare
|
@JohannesGaessler Please see: #29683 |
|
The |
Yes, last time the CI was green. |
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)
Overview
Aligns
__CUDA_ARCH__on MUSA with the HIP approach, as discussed in #29292 (comment).__CUDA_ARCH__is defined invendors/hip.h, but it was never defined for MUSA, so every architecture test in the sharedggml-cudasources evaluated to 0 and the kernels behind them were compiled with an empty body and still launched.vendors/musa.h— define__CUDA_ARCH__asGGML_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 withdefined(__CUDA_ARCH__) || defined(__MUSA_ARCH__), which is also how nvcc behavesconvert.cuh—dequantize_block_q8_0_f16is guarded by__CUDA_ARCH__ >= GGML_CUDA_CC_PASCAL, so it had an empty body and everyq8_0dequantization produced garbagecommon.cuh,mmvq.cu— drop the now-redundantdefined(__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 ofNO_DEVICE_CODEis keptNVIDIA 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:test-backend-opsMUL_MAT_IDand 18xMUL_MAT, alltype_a=q8_0,NaNor above tolerance-o MUL_MAT_IDalone: 899/929 on master, 929/929 here. The failing case is the one that reachesbatched_mul_mat_traits<GGML_TYPE_F16>::convertfor quantizedsrc0. The CUB based ops (ARGSORT,TOP_K,SUM,CUMSUM,MEAN,SSM_SCAN) are 682/682, and the same tree builds forMUSA_ARCHITECTURES=21;22;31(only31was run on hardware). Model smokes (Qwen3-0.6B-Q4_K_M with-fa on -ctk q8_0 -ctv q8_0) andllama-benchare unchanged to within noise.The
cuda,hip,musa,gpu-cudaandgpu-rocmchecks pass.Additional information
Requirements