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

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 01:46:50 PST 2023


Author: Pierre van Houtryve
Date: 2023-12-06T10:46:46+01:00
New Revision: ecd2f56a80ed2c0ccba990a8d46ed73c994bb5c4

URL: https://github.com/llvm/llvm-project/commit/ecd2f56a80ed2c0ccba990a8d46ed73c994bb5c4
DIFF: https://github.com/llvm/llvm-project/commit/ecd2f56a80ed2c0ccba990a8d46ed73c994bb5c4.diff

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

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

Added: 
    llvm/test/CodeGen/AMDGPU/min-waves-per-eu-not-respected.ll

Modified: 
    llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index eb30f31af6d6b..4bf1f1357b694 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 0000000000000..50de3541e05b4
--- /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" }


        


More information about the llvm-commits mailing list