Skip to content

[AMDGPU] Warn if 'amdgpu-waves-per-eu' target occupancy was not met #74055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,17 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
ProgInfo.Occupancy = STM.computeOccupancy(MF.getFunction(), ProgInfo.LDSSize,
ProgInfo.NumSGPRsForWavesPerEU,
ProgInfo.NumVGPRsForWavesPerEU);
const auto [MinWEU, MaxWEU] =
AMDGPU::getIntegerPairAttribute(F, "amdgpu-waves-per-eu", {0, 0}, true);
if (ProgInfo.Occupancy < MinWEU) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check how many times this fires in the test suite? I know we routinely clamp the lower bound (but also don't actually do anything with it)

Also, isn't there already a wrapped query for the attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It triggers 10 times in the test suite

[build] Failed Tests (10):
[build]   LLVM :: CodeGen/AMDGPU/attr-amdgpu-waves-per-eu.ll
[build]   LLVM :: CodeGen/AMDGPU/copy-vgpr-clobber-spill-vgpr.mir
[build]   LLVM :: CodeGen/AMDGPU/inline-asm-reserved-regs.ll
[build]   LLVM :: CodeGen/AMDGPU/mfma-cd-select.ll
[build]   LLVM :: CodeGen/AMDGPU/min-waves-per-eu-not-respected.ll
[build]   LLVM :: CodeGen/AMDGPU/occupancy-levels.ll
[build]   LLVM :: CodeGen/AMDGPU/scc-clobbered-sgpr-to-vmem-spill.ll
[build]   LLVM :: CodeGen/AMDGPU/sgpr-spill-incorrect-fi-bookkeeping-bug.ll
[build]   LLVM :: CodeGen/AMDGPU/sgpr-spill-no-vgprs.ll
[build]   LLVM :: CodeGen/AMDGPU/spill-scavenge-offset.ll
[build] 

The wrapped query does a bit of extra work other than getting the attribute. It'll return a default if the attribute isn't present, but here we just want to trigger the warning if the attribute is there so I think it's better to get it manually

DiagnosticInfoOptimizationFailure Diag(
F, F.getSubprogram(),
"failed to meet occupancy target given by 'amdgpu-waves-per-eu' in "
"'" +
F.getName() + "': desired occupancy was " + Twine(MinWEU) +
", final occupancy is " + Twine(ProgInfo.Occupancy));
F.getContext().diagnose(Diag);
}
}

static unsigned getRsrcReg(CallingConv::ID CallConv) {
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/CodeGen/AMDGPU/min-waves-per-eu-not-respected.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; RUN: llc -march=amdgcn -mcpu=gfx900 -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=WARN %s

; 1024 flat work group size across 2560 possible threads -> occupancy should be 8 max.
; WARN: warning: <unknown>:0:0: failed to meet occupancy target given by 'amdgpu-waves-per-eu' in 'occupancy_8_target_9': desired occupancy was 9, final occupancy is 8
define amdgpu_kernel void @occupancy_8_target_9() #0 {
ret void
}

; Impossible occupancy target
; WARN: warning: <unknown>:0:0: failed to meet occupancy target given by 'amdgpu-waves-per-eu' in 'impossible_occupancy': desired occupancy was 11, final occupancy is 10
define amdgpu_kernel void @impossible_occupancy() #1 {
ret void
}

attributes #0 = { "amdgpu-flat-work-group-size"="1,1024" "amdgpu-waves-per-eu"="9" }
attributes #1 = { "amdgpu-flat-work-group-size"="1,256" "amdgpu-waves-per-eu"="11" }