Skip to content

Rocm performance improvement - #1293

Open
lightvector wants to merge 1 commit into
masterfrom
rocmopt
Open

lightvector wants to merge 1 commit into
masterfrom
rocmopt

Conversation

@lightvector

Copy link
Copy Markdown
Owner

This PR does a bunch of performance optimizations for rocm.

#1269 added the dot2 attention kernels and enabled them by default only on RDNA2. But they're also better in a lot of other cases too.

Notable Changes

  • Use dot2 attention by default on RDNA and gfx94x (rocmUseDot2Attention = auto).
    • For head dim 32 (all current official transformers), now we prefer dot2 over CK's fused
      attention on RDNA (gfx10/11/12) and gfx94x.
    • On every arch, dot2 is the fallback whenever CK's fused attention does not run, for example
      when the installed CK is incompatible with the vendored kernels, as on stock ROCm 7.0.
  • Use HIP graphs for FP16 forward passes.
    • Reuses the CUDA backend's per-batch-size graph cache.
    • rocmUseGraphs = false disables graphs.
  • Combine QKV into one gemm for dot2, not only with the CK GEMM kernels. Gains 0-3% on MI300X and is neutral elsewhere.
  • CUDA's vectorized learnable-RoPE kernel is now shared with ROCm.
  • Optimized dot2 launch configuration for 64-wide waves (CDNA): one query row per lane, with 8 or 4 key
    splits depending on launch size.

Performance

(benchmarknn, FP16, 19x19, one server thread), relative to master with #1269
merged, for batch sizes 1 / 8 / 32 / 64:

tf3-b11c768

GPU batch 1 batch 8 batch 32 batch 64
RX 7900 XTX (gfx1100) 215 → 241 710 → 822 918 → 1050 934 → 1081
Radeon 8060S (gfx1151) 170 → 182 395 → 441 363 → 376 336 → 356
RX 9060 XT (gfx1200) 204 → 220 425 → 519 441 → 499 435 → 489
Radeon AI PRO R9700 (gfx1201) * 139 → 296 675 → 836 790 → 942 770 → 884
MI300X (gfx942), ROCm 7.0.2 ** 87 → 285 566 → 1244 1392 → 2207 1533 → 2513
Radeon Pro W6800 (gfx1030) 174 → 175 345 → 345 376 → 376 383 → 383

tf3-b10c512

GPU batch 1 batch 8 batch 32 batch 64
RX 7900 XTX (gfx1100) 332 → 379 1264 → 1514 1787 → 2078 1787 → 2137
Radeon 8060S (gfx1151) 239 → 261 720 → 823 658 → 730 521 → 557
RX 9060 XT (gfx1200) 265 → 297 774 → 960 822 → 951 792 → 893
Radeon AI PRO R9700 (gfx1201) * 155 → 361 1040 → 1291 1347 → 1627 1351 → 1625
MI300X (gfx942), ROCm 7.0.2 ** 98 → 329 670 → 1665 1908 → 3326 2771 → 4482
Radeon Pro W6800 (gfx1030) 282 → 285 679 → 681 800 → 801 831 → 831

* Machine has old Xeon E5 v2 host and is launch-bound at small batch sizes. Most of its
batch-1 gain is from HIP graphs (2.1-2.8x at batch 1, 1.2-2.1x at batch 4). On hosts with fast
CPUs, graphs were neutral.

** Without a compatible CK, master runs MI300X attention on the plain kernel. With a compatible CK
(TheRock 7.13), dot2 was still 1.12-1.44x faster end to end than CK's fused attention, at batch sizes
1 to 256.

Other notes:

  • Convnets (b28c512nbt, b18c384nbt) are unchanged except on the launch-bound host, where graphs give
    2.6x at batch 1.
  • RDNA2 is unchanged, since it already used dot2.
  • The two smallest changes (head dim 64 staying on CK, and the 4-split tier for large launches on
    wave64) were measured separately:
    • Head-dim-64 nets on RDNA3/4 run at the same speed as master (0.97-1.02x).
    • The 4-split tier is 1.5-2.3% faster on MI300X at batch sizes 32-256.

Tested with testgpuerror and testbackendreference** on all the gpus above on multiple models on multiple configurations.

This branch has not been deployed

No deployments
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