Skip to content

Support launch bounds on the GCN target - #918

Open
gbaraldi wants to merge 1 commit into
JuliaGPU:mainfrom
gbaraldi:gcn-launch-bounds
Open

Support launch bounds on the GCN target#918
gbaraldi wants to merge 1 commit into
JuliaGPU:mainfrom
gbaraldi:gcn-launch-bounds

Conversation

@gbaraldi

Copy link
Copy Markdown
Member

The GCN target compiles every kernel with the backend's default amdgpu-flat-work-group-size of 1,1024, so the register allocator always budgets for 1024-item workgroups: on gfx942 that is a 128-VGPR cap, and register-heavy kernels spill even when they will only ever be launched with smaller workgroups. HIP C++ exposes this via __launch_bounds__; the PTX target already exposes it as minthreads/maxthreads.

This adds the same two fields to GCNCompilerTarget, emitted as amdgpu-flat-work-group-size on kernels. LLVM derives the minimum waves/EU from the attribute's maximum (AMDGPUSubtarget::getEffectiveWavesPerEU), which sets the VGPR budget (GCNSubtarget::getBaseMaxNumVGPRs).

Measured on MI300A (gfx942, ROCm 7.2.4, Julia 1.12) with a register-tiled FP32 GEMM from AMDGPU.jl (16×16 workgroup, 8×8 accumulator microtile per thread, 4096³):

default (1,1024) maxthreads=256
VGPRs 64 arch + 64 accum (at the 128 cap) 136, no accum
scratch 120 B, 29 spill/29 reload 0
occupancy 4 3
runtime 8.61 ms, 15.96 TFLOPS 4.89 ms, 28.11 TFLOPS

A companion AMDGPU.jl PR plumbs this through @roc maxthreads= and sets it automatically for KernelAbstractions kernels with static workgroup sizes, mirroring CUDA.jl. As a bonus the bound lands in the code object's .max_flat_workgroup_size, so HIP itself rejects out-of-bounds launches that were previously silent UB.

🤖 Generated with Claude Code

minthreads/maxthreads on GCNCompilerTarget emit amdgpu-flat-work-group-sizes,
mirroring the PTX target's fields. Without the attribute the backend budgets
registers for 1024-item workgroups.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants