[llvm] 61a8c98 - [AMDGPU] Fix maximum physical LDS reporting for gfx6 (#223185)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 14 19:46:13 PDT 2026
Author: Chinmay Deshpande
Date: 2026-09-14T19:46:08-07:00
New Revision: 61a8c98594dbce9e09f39614b89cb74e563bcbbc
URL: https://github.com/llvm/llvm-project/commit/61a8c98594dbce9e09f39614b89cb74e563bcbbc
DIFF: https://github.com/llvm/llvm-project/commit/61a8c98594dbce9e09f39614b89cb74e563bcbbc.diff
LOG: [AMDGPU] Fix maximum physical LDS reporting for gfx6 (#223185)
Reference:
https://docs.amd.com/api/khub/documents/VeItSxvoJNzy28rl~JwEAQ/content#page=77
> “The maximum LDS allocation size for a work-group is still 32 kB,
however each compute unit has a total of 64 kB of LDS.”
Reference:
https://docs.amd.com/api/khub/documents/J4foK5jvufN9rTHf_DlCPw/content#page=22
> “Each compute unit has a 64 kB of Local Data Share (LDS) memory
space…”
> “Each workgroup can allocate up to 32 kB of this space, and can read
and write any portion of the LDS space allocated to it.”
Added:
Modified:
llvm/include/llvm/TargetParser/AMDGPUTargetParser.h
llvm/lib/Target/AMDGPU/AMDGPU.td
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
llvm/lib/TargetParser/AMDGPUTargetParser.cpp
llvm/test/CodeGen/AMDGPU/default-flat-work-group-size-overrides-waves-per-eu.ll
llvm/test/CodeGen/AMDGPU/occupancy-levels.ll
llvm/unittests/TargetParser/TargetParserTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h b/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h
index 3c2037c90be51..4b0fa417c6b10 100644
--- a/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h
+++ b/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h
@@ -209,12 +209,13 @@ LLVM_ABI unsigned getAddressableNumVGPRs(Triple::SubArchType SubArch,
/// min(getMaxHWAddressableLocalMemorySize(), getLocalMemorySize())
///
/// The physical LDS block belongs to a WGP on gfx10/11/12 and to a CU
-/// otherwise. On gfx10/11/12, the block is twice the address limit, so a
-/// work-group cannot address the entire block in full-SIMD mode.
+/// otherwise. On gfx6 and gfx10/11/12, the block is twice the address limit, so
+/// a work-group cannot address the entire block in full-SIMD mode.
///
/// The mode columns below show local/addressable LDS, in KiB:
///
/// GPU address limit full-SIMD half-SIMD
+/// gfx600 32 64/32 n/a (always full-SIMD)
/// gfx900 64 64/64 n/a (always full-SIMD)
/// gfx1030 64 128/64 64/64
/// gfx1250 320 320/320 n/a (always full-SIMD)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index 30db12b565082..5eaa5df801690 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -270,9 +270,9 @@ defm LDSMisalignedBug : AMDGPUSubtargetFeature<"lds-misaligned-bug",
/*GenPredicate=*/0
>;
-// Set for gfx10/11/12 where a work-group can address only half of the physical
-// LDS block. So the physical block is twice the addressable size, for example
-// 128k physical and 64k addressable.
+// Set where a work-group can address only half of the physical LDS block:
+// gfx6 has 64 KiB physical and 32 KiB addressable, while gfx10/11/12 have
+// 128 KiB physical and 64 KiB addressable.
defm HalfAddressablePhysicalLocalMemory : AMDGPUSubtargetFeature<"half-addressable-physical-local-memory",
"A work-group can address only half of the physical LDS block",
/*GenPredicate=*/0
@@ -1619,7 +1619,8 @@ class GCNSubtargetFeatureGeneration <string Value,
def FeatureSouthernIslands : GCNSubtargetFeatureGeneration<"SOUTHERN_ISLANDS",
"southern-islands",
- [FeatureFP64, FeatureAddressableLocalMemorySize32768, FeatureMIMG_R128,
+ [FeatureFP64, FeatureAddressableLocalMemorySize32768,
+ FeatureHalfAddressablePhysicalLocalMemory, FeatureMIMG_R128,
FeatureWavefrontSize64, FeatureSupportsWave64, FeatureSMemTimeInst,
FeatureMadMacF32Insts,
FeatureDsSrc2Insts, FeatureLDSBankCount32, FeatureMovrel,
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
index 88e2d2f485262..58ca7e69cecf8 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
@@ -1130,8 +1130,9 @@ static unsigned getMaxHWAddressableLocalMemorySize(const MCSubtargetInfo &STI) {
// Total physical size of LDS on the block, in bytes. On targets with
// FeatureHalfAddressablePhysicalLocalMemory the physical block is twice the
-// addressable size (gfx10/11/12, 128k physical and 64k addressable). On other
-// targets it is equal to the addressable size.
+// addressable size (gfx6: 64 KiB physical and 32 KiB addressable;
+// gfx10/11/12: 128 KiB physical and 64 KiB addressable). On other targets it is
+// equal to the addressable size.
static unsigned getPhysicalLocalMemorySize(const MCSubtargetInfo &STI) {
unsigned Addressable = getMaxHWAddressableLocalMemorySize(STI);
if (STI.getFeatureBits().test(FeatureHalfAddressablePhysicalLocalMemory))
@@ -1140,7 +1141,7 @@ static unsigned getPhysicalLocalMemorySize(const MCSubtargetInfo &STI) {
}
// Sizes in use, by generation (addressable / physical block):
-// gfx6 : 32 KiB
+// gfx6 : 32 KiB addressable, 64 KiB physical block
// gfx7 / gfx8 / gfx9: 64 KiB
// gfx9.5 (gfx950) : 160 KiB
// gfx10 / 11 / 12 : 64 KiB addressable, 128 KiB physical block
diff --git a/llvm/lib/TargetParser/AMDGPUTargetParser.cpp b/llvm/lib/TargetParser/AMDGPUTargetParser.cpp
index c4f0d8deba089..fc027c48ca354 100644
--- a/llvm/lib/TargetParser/AMDGPUTargetParser.cpp
+++ b/llvm/lib/TargetParser/AMDGPUTargetParser.cpp
@@ -479,7 +479,7 @@ AMDGPU::getMaxHWAddressableLocalMemorySize(Triple::SubArchType SubArch) {
}
unsigned AMDGPU::getLocalMemorySize(GPUKind AK, bool FullSIMDMode) {
- // gfx10/11/12 address half of the physical block, e.g. 64 KiB of 128 KiB.
+ // gfx6 and gfx10/11/12 address half of the physical block.
unsigned Size = getMaxHWAddressableLocalMemorySize(AK);
if (getFeatureBitset(AK).test(FEAT_HALF_ADDRESSABLE_PHYSICAL_LOCAL_MEMORY))
Size *= 2;
diff --git a/llvm/test/CodeGen/AMDGPU/default-flat-work-group-size-overrides-waves-per-eu.ll b/llvm/test/CodeGen/AMDGPU/default-flat-work-group-size-overrides-waves-per-eu.ll
index dc05258ac5904..ef9901b1f379f 100644
--- a/llvm/test/CodeGen/AMDGPU/default-flat-work-group-size-overrides-waves-per-eu.ll
+++ b/llvm/test/CodeGen/AMDGPU/default-flat-work-group-size-overrides-waves-per-eu.ll
@@ -14,21 +14,21 @@
; CHECK-NOT: @explicit_default_workgroup_size.stack
; CHECK-LABEL: @no_flat_workgroup_size(
-; CHECK: alloca [5 x i32]
+; CHECK: alloca [9 x i32]
; CHECK: store i32 4, ptr addrspace(5) %arrayidx1, align 4
define amdgpu_kernel void @no_flat_workgroup_size(ptr addrspace(1) nocapture %out, ptr addrspace(1) nocapture %in) #0 {
entry:
- %stack = alloca [5 x i32], align 4, addrspace(5)
+ %stack = alloca [9 x i32], align 4, addrspace(5)
%0 = load i32, ptr addrspace(1) %in, align 4
- %arrayidx1 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 %0
+ %arrayidx1 = getelementptr inbounds [9 x i32], ptr addrspace(5) %stack, i32 0, i32 %0
store i32 4, ptr addrspace(5) %arrayidx1, align 4
%arrayidx2 = getelementptr inbounds i32, ptr addrspace(1) %in, i32 1
%1 = load i32, ptr addrspace(1) %arrayidx2, align 4
- %arrayidx3 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 %1
+ %arrayidx3 = getelementptr inbounds [9 x i32], ptr addrspace(5) %stack, i32 0, i32 %1
store i32 5, ptr addrspace(5) %arrayidx3, align 4
%2 = load i32, ptr addrspace(5) %stack, align 4
store i32 %2, ptr addrspace(1) %out, align 4
- %arrayidx12 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 1
+ %arrayidx12 = getelementptr inbounds [9 x i32], ptr addrspace(5) %stack, i32 0, i32 1
%3 = load i32, ptr addrspace(5) %arrayidx12
%arrayidx13 = getelementptr inbounds i32, ptr addrspace(1) %out, i32 1
store i32 %3, ptr addrspace(1) %arrayidx13
@@ -36,21 +36,21 @@ entry:
}
; CHECK-LABEL: @explicit_default_workgroup_size(
-; CHECK: alloca [5 x i32]
+; CHECK: alloca [9 x i32]
; CHECK: store i32 4, ptr addrspace(5) %arrayidx1, align 4
define amdgpu_kernel void @explicit_default_workgroup_size(ptr addrspace(1) nocapture %out, ptr addrspace(1) nocapture %in) #1 {
entry:
- %stack = alloca [5 x i32], align 4, addrspace(5)
+ %stack = alloca [9 x i32], align 4, addrspace(5)
%0 = load i32, ptr addrspace(1) %in, align 4
- %arrayidx1 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 %0
+ %arrayidx1 = getelementptr inbounds [9 x i32], ptr addrspace(5) %stack, i32 0, i32 %0
store i32 4, ptr addrspace(5) %arrayidx1, align 4
%arrayidx2 = getelementptr inbounds i32, ptr addrspace(1) %in, i32 1
%1 = load i32, ptr addrspace(1) %arrayidx2, align 4
- %arrayidx3 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 %1
+ %arrayidx3 = getelementptr inbounds [9 x i32], ptr addrspace(5) %stack, i32 0, i32 %1
store i32 5, ptr addrspace(5) %arrayidx3, align 4
%2 = load i32, ptr addrspace(5) %stack, align 4
store i32 %2, ptr addrspace(1) %out, align 4
- %arrayidx12 = getelementptr inbounds [5 x i32], ptr addrspace(5) %stack, i32 0, i32 1
+ %arrayidx12 = getelementptr inbounds [9 x i32], ptr addrspace(5) %stack, i32 0, i32 1
%3 = load i32, ptr addrspace(5) %arrayidx12
%arrayidx13 = getelementptr inbounds i32, ptr addrspace(1) %out, i32 1
store i32 %3, ptr addrspace(1) %arrayidx13
diff --git a/llvm/test/CodeGen/AMDGPU/occupancy-levels.ll b/llvm/test/CodeGen/AMDGPU/occupancy-levels.ll
index b7ee93228e7aa..3299f9d1ce2f6 100644
--- a/llvm/test/CodeGen/AMDGPU/occupancy-levels.ll
+++ b/llvm/test/CodeGen/AMDGPU/occupancy-levels.ll
@@ -656,7 +656,7 @@ define amdgpu_kernel void @used_lds_13112() {
}
; GCN-LABEL: {{^}}used_lds_8252_max_group_size_64:
-; GFX6: ; Occupancy: 1{{$}}
+; GFX6: ; Occupancy: 2{{$}}
; GFX7: ; Occupancy: 2{{$}}
; GFX8: ; Occupancy: 2{{$}}
; GFX9: ; Occupancy: 2{{$}}
@@ -680,7 +680,7 @@ define amdgpu_kernel void @used_lds_8252_max_group_size_64() #3 {
}
; GCN-LABEL: {{^}}used_lds_8252_max_group_size_96:
-; GFX6: ; Occupancy: 2{{$}}
+; GFX6: ; Occupancy: 4{{$}}
; GFX7: ; Occupancy: 4{{$}}
; GFX8: ; Occupancy: 4{{$}}
; GFX9: ; Occupancy: 4{{$}}
@@ -704,7 +704,7 @@ define amdgpu_kernel void @used_lds_8252_max_group_size_96() #4 {
}
; GCN-LABEL: {{^}}used_lds_8252_max_group_size_128:
-; GFX6: ; Occupancy: 2{{$}}
+; GFX6: ; Occupancy: 4{{$}}
; GFX7: ; Occupancy: 4{{$}}
; GFX8: ; Occupancy: 4{{$}}
; GFX9: ; Occupancy: 4{{$}}
@@ -727,7 +727,7 @@ define amdgpu_kernel void @used_lds_8252_max_group_size_128() #5 {
}
; GCN-LABEL: {{^}}used_lds_8252_max_group_size_192:
-; GFX6: ; Occupancy: 3{{$}}
+; GFX6: ; Occupancy: 6{{$}}
; GFX7: ; Occupancy: 6{{$}}
; GFX8: ; Occupancy: 6{{$}}
; GFX9: ; Occupancy: 6{{$}}
@@ -750,7 +750,7 @@ define amdgpu_kernel void @used_lds_8252_max_group_size_192() #6 {
}
; GCN-LABEL: {{^}}used_lds_8252_max_group_size_256:
-; GFX6: ; Occupancy: 3{{$}}
+; GFX6: ; Occupancy: 7{{$}}
; GFX7: ; Occupancy: 7{{$}}
; GFX8: ; Occupancy: 7{{$}}
; GFX9: ; Occupancy: 7{{$}}
@@ -771,7 +771,7 @@ define amdgpu_kernel void @used_lds_8252_max_group_size_256() #7 {
}
; GCN-LABEL: {{^}}used_lds_8252_max_group_size_512:
-; GFX6: ; Occupancy: 6{{$}}
+; GFX6: ; Occupancy: 10{{$}}
; GFX7: ; Occupancy: 10{{$}}
; GFX8: ; Occupancy: 10{{$}}
; GFX9: ; Occupancy: 10{{$}}
@@ -806,7 +806,7 @@ define amdgpu_kernel void @used_lds_8252_max_group_size_1024() #9 {
}
; GCN-LABEL: {{^}}used_lds_8252_max_group_size_32:
-; GFX6: ; Occupancy: 1{{$}}
+; GFX6: ; Occupancy: 2{{$}}
; GFX7: ; Occupancy: 2{{$}}
; GFX8: ; Occupancy: 2{{$}}
; GFX9: ; Occupancy: 2{{$}}
diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp b/llvm/unittests/TargetParser/TargetParserTest.cpp
index ad86abae775f5..3cf07ca5b0202 100644
--- a/llvm/unittests/TargetParser/TargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -2867,7 +2867,11 @@ TEST(TargetParserTest, testAMDGPUHalfAddressableLDSFeature) {
AMDGPU::FEAT_HALF_ADDRESSABLE_PHYSICAL_LOCAL_MEMORY);
};
- // Only gfx10/11/12 address half of the physical LDS block.
+ // Gfx6 and gfx10/11/12 address half of the physical LDS block.
+ EXPECT_TRUE(Has(AMDGPU::GK_GFX600));
+ EXPECT_TRUE(Has(AMDGPU::GK_GFX601));
+ EXPECT_TRUE(Has(AMDGPU::GK_GFX602));
+ EXPECT_FALSE(Has(AMDGPU::GK_GFX700));
EXPECT_FALSE(Has(AMDGPU::GK_GFX900));
EXPECT_TRUE(Has(AMDGPU::GK_GFX1030));
EXPECT_TRUE(Has(AMDGPU::GK_GFX1100));
@@ -3259,10 +3263,19 @@ TEST(TargetParserTest, testAMDGPUgetBufferResourceNumRecordsWidth) {
}
TEST(TargetParserTest, testAMDGPUgetLocalMemorySize) {
+ // gfx6 addresses 32 KiB of a 64 KiB block.
+ for (Triple::SubArchType SubArch :
+ {Triple::AMDGPUSubArch600, Triple::AMDGPUSubArch601,
+ Triple::AMDGPUSubArch602}) {
+ SCOPED_TRACE(AMDGPU::getArchNameFromSubArch(SubArch));
+ EXPECT_EQ(AMDGPU::getLocalMemorySize(SubArch, true), 65536u);
+ EXPECT_EQ(AMDGPU::getLocalMemorySize(SubArch, false), 32768u);
+ }
+
// Without a half-addressable physical block the total matches the
// addressable cap, and running on two SIMDs halves it.
- EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX600, true), 32768u);
- EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX600, false), 16384u);
+ EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX700, true), 65536u);
+ EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX700, false), 32768u);
EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX900, true), 65536u);
EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX950, true), 163840u);
@@ -3286,7 +3299,15 @@ TEST(TargetParserTest, testAMDGPUgetLocalMemorySize) {
TEST(TargetParserTest, testAMDGPUgetAddressableLocalMemorySize) {
// A work-group never allocates past the hardware cap, so the doubled
- // gfx10/11/12 block is capped back to the addressable size.
+ // gfx6 and gfx10/11/12 blocks are capped back to the addressable size.
+ for (Triple::SubArchType SubArch :
+ {Triple::AMDGPUSubArch600, Triple::AMDGPUSubArch601,
+ Triple::AMDGPUSubArch602}) {
+ SCOPED_TRACE(AMDGPU::getArchNameFromSubArch(SubArch));
+ EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(SubArch, true), 32768u);
+ EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(SubArch, false), 32768u);
+ }
+
EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX1030, true),
65536u);
EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX1030, false),
@@ -3295,10 +3316,10 @@ TEST(TargetParserTest, testAMDGPUgetAddressableLocalMemorySize) {
65536u);
// Without a doubled block the cap is only reached in full-SIMD mode.
- EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX600, true),
+ EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX700, true),
+ 65536u);
+ EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX700, false),
32768u);
- EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX600, false),
- 16384u);
EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX950, true),
163840u);
EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX1250, true),
More information about the llvm-commits
mailing list