Skip to content
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

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

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

Pierre-vh
Copy link
Contributor

This should make it a bit harder to miss this type of issue. The warning only shows if amdgpu-waves-per-eu is used.

See SWDEV-434482

This should make it a bit harder to miss this type of issue.
The warning only shows if amdgpu-waves-per-eu is used.

See SWDEV-434482
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 1, 2023

@llvm/pr-subscribers-backend-amdgpu

Author: Pierre van Houtryve (Pierre-vh)

Changes

This should make it a bit harder to miss this type of issue. The warning only shows if amdgpu-waves-per-eu is used.

See SWDEV-434482


Full diff: https://github.com/llvm/llvm-project/pull/74055.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp (+11)
  • (added) llvm/test/CodeGen/AMDGPU/min-waves-per-eu-not-respected.ll (+16)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index eb30f31af6d6b68..4bf1f1357b694ee 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -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) {
+    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) {
diff --git a/llvm/test/CodeGen/AMDGPU/min-waves-per-eu-not-respected.ll b/llvm/test/CodeGen/AMDGPU/min-waves-per-eu-not-respected.ll
new file mode 100644
index 000000000000000..50de3541e05b4d6
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/min-waves-per-eu-not-respected.ll
@@ -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" }

Copy link
Collaborator

@nhaehnle nhaehnle left a comment

Choose a reason for hiding this comment

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

Seems fine to me from a graphics perspective.

@@ -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

@Pierre-vh Pierre-vh merged commit ecd2f56 into llvm:main Dec 6, 2023
4 checks passed
@Pierre-vh Pierre-vh deleted the diag-waves-per-eu branch December 6, 2023 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants