[llvm] [AMDGPU] Warn if 'amdgpu-waves-per-eu' target occupancy was not met (PR #74055)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 1 01:25:44 PST 2023
https://github.com/Pierre-vh created https://github.com/llvm/llvm-project/pull/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
>From 825cdf977e57049546058fe091c6c27cb19b539c Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Fri, 1 Dec 2023 10:24:47 +0100
Subject: [PATCH] [AMDGPU] Warn if 'amdgpu-waves-per-eu' target occupancy was
not met
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
---
llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp | 11 +++++++++++
.../AMDGPU/min-waves-per-eu-not-respected.ll | 16 ++++++++++++++++
2 files changed, 27 insertions(+)
create mode 100644 llvm/test/CodeGen/AMDGPU/min-waves-per-eu-not-respected.ll
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" }
More information about the llvm-commits
mailing list