Skip to content

Commit dde003b

Browse files
sstamenkclaude
andauthored
fix(rocm): avoid SIMT workgroup-count resonance (#2012)
* fix(rocm): avoid SIMT workgroup-count resonance Add one bounds-checked workgroup when a large HIP SIMT grid is an exact multiple of 256, avoiding scheduler underutilization observed on RDNA3 and RDNA4.\n\nCo-Authored-By: Claude <noreply@anthropic.com> * refactor(rocm): add explicit RDNA and CDNA macros Co-Authored-By: Claude <noreply@anthropic.com> * refactor(rocm): detect RDNA2 architectures Co-Authored-By: Claude <noreply@anthropic.com> * fix(rocm): exclude RDNA2 from dot2 path Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f2233a6 commit dde003b

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

csrc/common.cuh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@
44

55
#include "compat.cuh"
66

7+
// AMD GPU architecture detection. Use explicit device macros rather than the
8+
// broad __GFX9__/__GFX11__/__GFX12__ macros, which span distinct architectures.
9+
#define IS_RDNA2 \
10+
(defined(__gfx1030__) || defined(__gfx1031__) || defined(__gfx1032__) || defined(__gfx1033__) || \
11+
defined(__gfx1034__) || defined(__gfx1035__) || defined(__gfx1036__))
12+
#define IS_RDNA3 (defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || defined(__gfx1103__))
13+
#define IS_RDNA3_5 (defined(__gfx1150__) || defined(__gfx1151__) || defined(__gfx1152__) || defined(__gfx1153__))
14+
#define IS_RDNA4 (defined(__gfx1200__) || defined(__gfx1201__))
15+
#define IS_RDNA (IS_RDNA2 || IS_RDNA3 || IS_RDNA3_5 || IS_RDNA4)
16+
17+
#define IS_CDNA1 (defined(__gfx908__))
18+
#define IS_CDNA2 (defined(__gfx90a__))
19+
#define IS_CDNA3 (defined(__gfx942__))
20+
#define IS_CDNA4 (defined(__gfx950__))
21+
#define IS_CDNA (IS_CDNA1 || IS_CDNA2 || IS_CDNA3 || IS_CDNA4)
22+
723
// Warp size
824

925
#if BNB_HIP
10-
#if defined(__GFX9__)
26+
#if IS_CDNA
1127
#define BNB_WARP_SIZE 64 // CDNA
1228
#else
1329
#define BNB_WARP_SIZE 32 // RDNA

csrc/gemm_4bit_simt.cu

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
#include <cstdint>
55
#include <type_traits>
66

7+
#include "common.cuh"
78
#include "gemm_4bit_common.cuh"
89
#include "gemm_4bit_simt.cuh"
910

10-
#if defined(__GFX9__)
11+
#if IS_CDNA
1112
// gfx9/CDNA tuning:
1213
// - use fmaf for fp32 accumulation
1314
// - accumulate fp16/bf16 pairs in fp32 via fused multiply-add
@@ -26,9 +27,9 @@
2627
#define BNB_SIMT_FP16_PACKED_ACCUM 0
2728
#endif
2829

29-
// RDNA3/RDNA4 tuning:
30+
// RDNA3/RDNA3.5/RDNA4 tuning:
3031
// - use native packed bf16/fp16 dot2 instructions with fp32 accumulation
31-
#if defined(__GFX11__) || defined(__GFX12__)
32+
#if IS_RDNA3 || IS_RDNA3_5 || IS_RDNA4
3233
#define BNB_HIP_BF16_VDOT2 1
3334
#define BNB_HIP_FP16_DOT2 1
3435
#else
@@ -490,7 +491,14 @@ void launch_gemm_4bit_simt(
490491
bnb_stream_t stream // CUDA/HIP stream
491492
// clang-format on
492493
) {
493-
const int n_blocks = (N + WARPS_PER_BLOCK - 1) / WARPS_PER_BLOCK;
494+
int n_blocks = (N + WARPS_PER_BLOCK - 1) / WARPS_PER_BLOCK;
495+
#if BNB_HIP
496+
// Large HIP SIMT dispatches can underutilize the GPU when the workgroup
497+
// count is an exact multiple of 256. One additional bounds-checked block
498+
// breaks the scheduler resonance without changing useful work.
499+
if (n_blocks >= 512 && n_blocks % 256 == 0)
500+
n_blocks++;
501+
#endif
494502

495503
// M=1..8: M_BLOCK == M, so the inner m-loop fully unrolls at compile time.
496504
// M>8: M_BLOCK=8, ceil(M/8) grid rows.

0 commit comments

Comments
 (0)