[HIP] Add offload PGO tiled matmul E2E test#366
Open
Conversation
Add a tiled matrix multiply kernel that demonstrates the offload PGO workflow on AMDGPU. The kernel uses a large per-thread sub-tile (configurable via -DTH_M and -DTH_N) with LDS-based cooperative tile loading, creating natural register pressure that exceeds the VGPR budget and causes spills. Boundary tile handling creates biased branches that PGO can optimize by guiding the register allocator to reduce spills on the hot path. Sub-tile sizes are tunable per architecture to induce spills on GPUs with different register file sizes. Two tests are registered: - pgo-tiled-matmul: correctness test (compile + run + verify) - pgo-tiled-matmul-pipeline: full PGO pipeline test (baseline -> instrument -> collect -> merge -> PGO build -> compare) The pipeline test verifies that the full -fprofile-generate / -fprofile-use workflow completes successfully and reports the performance difference for information.
jmmartinez
reviewed
Mar 10, 2026
| size_t elems_B = (size_t)groups * K * N; | ||
| size_t elems_C = (size_t)groups * M * N; | ||
|
|
||
| float *h_A = (float*)malloc(elems_A * sizeof(float)); |
Contributor
There was a problem hiding this comment.
Nitpick: Does it make sense to restrict ourselves to C apis instead of using std::vector and let it handle the memory on its own?
|
|
||
| CLANG="@CMAKE_CXX_COMPILER@" | ||
| CLANG_DIR=$(dirname "$CLANG") | ||
| LLVM_PROFDATA="$CLANG_DIR/llvm-profdata" |
Contributor
There was a problem hiding this comment.
I don't think it changes much, but we could use clang --print-prog-name=<prog>:
Suggested change
| LLVM_PROFDATA="$CLANG_DIR/llvm-profdata" | |
| LLVM_PROFDATA="$("$CLANG" --print-prog-name=llvm-profdata)" |
jmmartinez
reviewed
Mar 10, 2026
Contributor
jmmartinez
left a comment
There was a problem hiding this comment.
Looks good to me but I'll JP have the final word.
jplehr
reviewed
Mar 11, 2026
Contributor
jplehr
left a comment
There was a problem hiding this comment.
LG
Just comments about the GPU arch of the bots.
Reporting the actual PGO speed-up just for information purpose is good.
| // Sub-tile dimensions are configurable via -D flags to tune register | ||
| // pressure per GPU architecture: | ||
| // gfx1100 (256 VGPRs): default TH_M=16, TH_N=16 → 256 accumulators → spills | ||
| // gfx950 (512 VGPRs): -DTH_M=20 -DTH_N=16 → 320 accumulators → spills |
Contributor
There was a problem hiding this comment.
Given that the bot executes on gfx90a should we have a config here for that arch?
| BENCH_RUNS=5 | ||
|
|
||
| # Detect GPU architecture and set sub-tile size to induce register spills. | ||
| # gfx950 has 512 VGPRs (vs 256 on gfx1100), so needs larger sub-tiles. |
Contributor
There was a problem hiding this comment.
Bots run on gfx90a, does this need adjustment?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[HIP] Add offload PGO tiled matmul E2E test
Add a tiled matrix multiply kernel that demonstrates the offload PGO
workflow on AMDGPU. The kernel uses a large per-thread sub-tile
(configurable via -DTH_M and -DTH_N) with LDS-based cooperative tile
loading, creating natural register pressure that exceeds the VGPR
budget and causes spills. Boundary tile handling creates biased
branches that PGO can optimize by guiding the register allocator to
reduce spills on the hot path.
Sub-tile sizes are tunable per architecture to induce spills on GPUs
with different register file sizes.
Two tests are registered:
(baseline -> instrument -> collect -> merge -> PGO build -> compare)
The pipeline test verifies that the full -fprofile-generate /
-fprofile-use workflow completes successfully and reports the
performance difference for information.