Skip to content

Commit ae04462

Browse files
arsenmpravinjagtap
authored andcommitted
AMDGPU: Increase the LDS size to support to 160 KB for gfx950 (llvm#116309)
1 parent 5f7837f commit ae04462

File tree

10 files changed

+173
-9
lines changed

10 files changed

+173
-9
lines changed

llvm/docs/AMDGPUUsage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5338,6 +5338,8 @@ The fields used by CP for code objects before V3 also match those specified in
53385338
roundup(lds-size / (64 * 4))
53395339
GFX7-GFX11
53405340
roundup(lds-size / (128 * 4))
5341+
GFX950
5342+
roundup(lds-size / (320 * 4))
53415343

53425344
24 1 bit ENABLE_EXCEPTION_IEEE_754_FP Wavefront starts execution
53435345
_INVALID_OPERATION with specified exceptions

llvm/lib/Target/AMDGPU/AMDGPU.td

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ def FeatureVolcanicIslands : GCNSubtargetFeatureGeneration<"VOLCANIC_ISLANDS",
11841184

11851185
def FeatureGFX9 : GCNSubtargetFeatureGeneration<"GFX9",
11861186
"gfx9",
1187-
[FeatureFP64, FeatureAddressableLocalMemorySize65536,
1187+
[FeatureFP64,
11881188
FeatureWavefrontSize64, FeatureFlatAddressSpace,
11891189
FeatureGCN3Encoding, FeatureCIInsts, Feature16BitInsts,
11901190
FeatureSMemRealTime, FeatureScalarStores, FeatureInv2PiInlineImm,
@@ -1348,6 +1348,7 @@ def FeatureISAVersion8_1_0 : FeatureSet<
13481348

13491349
def FeatureISAVersion9_0_Common : FeatureSet<
13501350
[FeatureGFX9,
1351+
FeatureAddressableLocalMemorySize65536,
13511352
FeatureLDSBankCount32,
13521353
FeatureImageInsts,
13531354
FeatureMadMacF32Insts]>;
@@ -1365,7 +1366,8 @@ def FeatureISAVersion9_Generic : FeatureSet<
13651366

13661367
def FeatureISAVersion9_0_MI_Common : FeatureSet<
13671368
!listconcat(FeatureISAVersion9_0_Common.Features,
1368-
[FeatureFmaMixInsts,
1369+
[FeatureAddressableLocalMemorySize65536,
1370+
FeatureFmaMixInsts,
13691371
FeatureDLInsts,
13701372
FeatureDot1Insts,
13711373
FeatureDot2Insts,
@@ -1481,15 +1483,17 @@ def FeatureISAVersion9_4_Common : FeatureSet<
14811483

14821484
def FeatureISAVersion9_5_Common : FeatureSet<
14831485
!listconcat(FeatureISAVersion9_4_Common.Features,
1484-
[FeatureFP8Insts,
1486+
[FeatureAddressableLocalMemorySize163840,
1487+
FeatureFP8Insts,
14851488
FeatureFP8ConversionInsts,
14861489
FeatureCvtFP8VOP1Bug,
1487-
FeatureGFX950Insts
1490+
FeatureGFX950Insts,
14881491
])>;
14891492

14901493
def FeatureISAVersion9_4_0 : FeatureSet<
14911494
!listconcat(FeatureISAVersion9_4_Common.Features,
14921495
[
1496+
FeatureAddressableLocalMemorySize65536,
14931497
FeatureForceStoreSC0SC1,
14941498
FeatureFP8Insts,
14951499
FeatureFP8ConversionInsts,
@@ -1500,6 +1504,7 @@ def FeatureISAVersion9_4_0 : FeatureSet<
15001504
def FeatureISAVersion9_4_1 : FeatureSet<
15011505
!listconcat(FeatureISAVersion9_4_Common.Features,
15021506
[
1507+
FeatureAddressableLocalMemorySize65536,
15031508
FeatureForceStoreSC0SC1,
15041509
FeatureFP8Insts,
15051510
FeatureFP8ConversionInsts,
@@ -1510,6 +1515,7 @@ def FeatureISAVersion9_4_1 : FeatureSet<
15101515
def FeatureISAVersion9_4_2 : FeatureSet<
15111516
!listconcat(FeatureISAVersion9_4_Common.Features,
15121517
[
1518+
FeatureAddressableLocalMemorySize65536,
15131519
FeatureFP8Insts,
15141520
FeatureFP8ConversionInsts,
15151521
FeatureCvtFP8VOP1Bug,
@@ -1518,7 +1524,8 @@ def FeatureISAVersion9_4_2 : FeatureSet<
15181524

15191525
def FeatureISAVersion9_4_Generic : FeatureSet<
15201526
!listconcat(FeatureISAVersion9_4_Common.Features,
1521-
[FeatureRequiresCOV6])>;
1527+
[FeatureAddressableLocalMemorySize65536,
1528+
FeatureRequiresCOV6])>;
15221529

15231530
def FeatureISAVersion9_5_0 : FeatureSet<FeatureISAVersion9_5_Common.Features>;
15241531

llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -989,12 +989,16 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
989989
ProgInfo.DX10Clamp = Mode.DX10Clamp;
990990

991991
unsigned LDSAlignShift;
992-
if (STM.getGeneration() < AMDGPUSubtarget::SEA_ISLANDS) {
993-
// LDS is allocated in 64 dword blocks.
994-
LDSAlignShift = 8;
995-
} else {
992+
if (STM.getFeatureBits().test(FeatureAddressableLocalMemorySize163840)) {
993+
// LDS is allocated in 320 dword blocks.
994+
LDSAlignShift = 11;
995+
} else if (STM.getFeatureBits().test(
996+
FeatureAddressableLocalMemorySize65536)) {
996997
// LDS is allocated in 128 dword blocks.
997998
LDSAlignShift = 9;
999+
} else {
1000+
// LDS is allocated in 64 dword blocks.
1001+
LDSAlignShift = 8;
9981002
}
9991003

10001004
ProgInfo.SGPRSpill = MFI->getNumSpilledSGPRs();

llvm/lib/Target/AMDGPU/AMDGPUFeatures.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class SubtargetFeatureAddressableLocalMemorySize <int Value> : SubtargetFeature<
2929

3030
def FeatureAddressableLocalMemorySize32768 : SubtargetFeatureAddressableLocalMemorySize<32768>;
3131
def FeatureAddressableLocalMemorySize65536 : SubtargetFeatureAddressableLocalMemorySize<65536>;
32+
def FeatureAddressableLocalMemorySize163840 : SubtargetFeatureAddressableLocalMemorySize<163840>;
3233

3334
class SubtargetFeatureWavefrontSize <int ValueLog2> : SubtargetFeature<
3435
"wavefrontsize"#!shl(1, ValueLog2),

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,8 @@ unsigned getAddressableLocalMemorySize(const MCSubtargetInfo *STI) {
934934
return 32768;
935935
if (STI->getFeatureBits().test(FeatureAddressableLocalMemorySize65536))
936936
return 65536;
937+
if (STI->getFeatureBits().test(FeatureAddressableLocalMemorySize163840))
938+
return 163840;
937939
return 0;
938940
}
939941

llvm/test/CodeGen/AMDGPU/extra-lds-size.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx1010 < %s | FileCheck -check-prefix=GFX10-MESA %s
33
; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx1100 < %s | FileCheck -check-prefix=GFX11-PAL %s
44
; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx1100 < %s | FileCheck -check-prefix=GFX11-MESA %s
5+
; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx950 < %s | FileCheck -check-prefix=GFX950-PAL %s
6+
; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx950 < %s | FileCheck -check-prefix=GFX950-MESA %s
57
; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx1200 < %s | FileCheck -check-prefix=GFX1200-PAL %s
68
; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx1200 < %s | FileCheck -check-prefix=GFX1200-MESA %s
79

@@ -17,6 +19,11 @@
1719
; GFX11-MESA: .long 45100
1820
; GFX11-MESA-NEXT: .long 1024
1921

22+
; GFX950-PAL: '0x2c0b (SPI_SHADER_PGM_RSRC2_PS)': 0x200
23+
24+
; GFX950-MESA: .long 45100
25+
; GFX950-MESA-NEXT: .long 512
26+
2027
; GFX1200-PAL: '0x2c0b (SPI_SHADER_PGM_RSRC2_PS)': 0x400
2128

2229
; GFX1200-MESA: .long 45100
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT160K %s
2+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx9-4-generic -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
3+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx9-generic -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
4+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
5+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx941 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
6+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
7+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
8+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx906 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
9+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
10+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
11+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90c -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
12+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
13+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1030 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
14+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
15+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1200 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
16+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx803 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
17+
; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
18+
; RUN: not llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx600 -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT32K %s
19+
20+
; gfx950 supports upto 160 KB LDS memory. The generic target does not.
21+
; This is a negative test to check when the LDS size exceeds the max usable limit.
22+
23+
; ERROR-LIMIT160K: error: <unknown>:0:0: local memory (163844) exceeds limit (163840) in function 'test_lds_limit'
24+
; ERROR-LIMIT64K: error: <unknown>:0:0: local memory (163844) exceeds limit (65536) in function 'test_lds_limit'
25+
; ERROR-LIMIT32K: error: <unknown>:0:0: local memory (163844) exceeds limit (32768) in function 'test_lds_limit'
26+
@dst = addrspace(3) global [40961 x i32] poison
27+
28+
define amdgpu_kernel void @test_lds_limit(i32 %val) {
29+
%gep = getelementptr [40961 x i32], ptr addrspace(3) @dst, i32 0, i32 100
30+
store i32 %val, ptr addrspace(3) %gep
31+
ret void
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
2+
; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx950 -verify-machineinstrs < %s | FileCheck -check-prefix=MESA %s
3+
4+
; gfx950 supports upto 160 KB configurable LDS memory.
5+
; This test checks the max and above the old i.e. 128 KiB size of LDS that can be allocated.
6+
7+
@lds.i32 = addrspace(3) global i32 poison
8+
@lds.array.size.131076 = addrspace(3) global [32768 x i32] poison
9+
@lds.array.size.163840 = addrspace(3) global [40959 x i32] poison
10+
11+
; GCN-LABEL: test_lds_array_size_131076:
12+
; GCN: .amdhsa_group_segment_fixed_size 131076
13+
; GCN: ; LDSByteSize: 131076 bytes/workgroup
14+
; MESA: granulated_lds_size = 65
15+
define amdgpu_kernel void @test_lds_array_size_131076() {
16+
%gep = getelementptr inbounds [32768 x i32], ptr addrspace(3) @lds.array.size.131076, i32 0, i32 20
17+
%val = load i32, ptr addrspace(3) %gep
18+
store i32 %val, ptr addrspace(3) @lds.i32
19+
ret void
20+
}
21+
22+
; GCN-LABEL: test_lds_array_size_163840:
23+
; GCN: .amdhsa_group_segment_fixed_size 163840
24+
; GCN: ; LDSByteSize: 163840 bytes/workgroup
25+
; MESA: granulated_lds_size = 80
26+
define amdgpu_kernel void @test_lds_array_size_163840() {
27+
%gep = getelementptr inbounds [40959 x i32], ptr addrspace(3) @lds.array.size.163840 , i32 0, i32 20
28+
%val = load i32, ptr addrspace(3) %gep
29+
store i32 %val, ptr addrspace(3) @lds.i32
30+
ret void
31+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx950 -verify-machineinstrs < %s | FileCheck -check-prefix=PAL %s
2+
3+
; GFX950supports upto 160 KB configurable LDS memory.
4+
; This test checks the min and max size of LDS that can be allocated.
5+
6+
; PAL: .shader_functions:
7+
; PAL: test_lds_array_i32:
8+
; PAL: .lds_size: 0x28000
9+
; PAL: test_lds_i32:
10+
; PAL: .lds_size: 0x4
11+
12+
13+
@lds.i32 = addrspace(3) global i32 poison
14+
@lds.array.i32 = addrspace(3) global [40959 x i32] poison
15+
16+
define amdgpu_gfx void @test_lds_i32(i32 %val) {
17+
store i32 %val, ptr addrspace(3) @lds.i32
18+
ret void
19+
}
20+
21+
define amdgpu_gfx void @test_lds_array_i32() {
22+
%gep = getelementptr inbounds [40959 x i32], ptr addrspace(3) @lds.array.i32, i32 0, i32 20
23+
%val = load i32, ptr addrspace(3) %gep
24+
store i32 %val, ptr addrspace(3) @lds.i32
25+
ret void
26+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
;; Test disassembly for gfx950 kernel descriptor.
2+
3+
; RUN: rm -rf %t && split-file %s %t && cd %t
4+
5+
;--- 1.s
6+
; RUN: llvm-mc --triple=amdgcn-amd-amdhsa -mattr=-xnack -filetype=obj -mcpu=gfx950 < 1.s > 1.o
7+
; RUN: llvm-objdump --disassemble-symbols=kernel.kd 1.o | tail -n +7 | tee 1-disasm.s | FileCheck 1.s
8+
; RUN: llvm-mc --triple=amdgcn-amd-amdhsa -mattr=-xnack -filetype=obj -mcpu=gfx950 < 1-disasm.s > 1-disasm.o
9+
; FIxMe: cmp 1.o 1-disasm.o
10+
; CHECK: .amdhsa_kernel kernel
11+
; CHECK-NEXT: .amdhsa_group_segment_fixed_size 163840
12+
; CHECK-NEXT: .amdhsa_private_segment_fixed_size 0
13+
; CHECK-NEXT: .amdhsa_kernarg_size 0
14+
; CHECK-NEXT: .amdhsa_accum_offset 4
15+
; CHECK-NEXT: .amdhsa_tg_split 0
16+
; CHECK-NEXT: .amdhsa_next_free_vgpr 8
17+
; CHECK-NEXT: .amdhsa_reserve_vcc 0
18+
; CHECK-NEXT: .amdhsa_reserve_xnack_mask 0
19+
; CHECK-NEXT: .amdhsa_next_free_sgpr 8
20+
; CHECK-NEXT: .amdhsa_float_round_mode_32 0
21+
; CHECK-NEXT: .amdhsa_float_round_mode_16_64 0
22+
; CHECK-NEXT: .amdhsa_float_denorm_mode_32 0
23+
; CHECK-NEXT: .amdhsa_float_denorm_mode_16_64 3
24+
; CHECK-NEXT: .amdhsa_dx10_clamp 1
25+
; CHECK-NEXT: .amdhsa_ieee_mode 1
26+
; CHECK-NEXT: .amdhsa_fp16_overflow 0
27+
; CHECK-NEXT: .amdhsa_enable_private_segment 0
28+
; CHECK-NEXT: .amdhsa_system_sgpr_workgroup_id_x 1
29+
; CHECK-NEXT: .amdhsa_system_sgpr_workgroup_id_y 0
30+
; CHECK-NEXT: .amdhsa_system_sgpr_workgroup_id_z 0
31+
; CHECK-NEXT: .amdhsa_system_sgpr_workgroup_info 0
32+
; CHECK-NEXT: .amdhsa_system_vgpr_workitem_id 0
33+
; CHECK-NEXT: .amdhsa_exception_fp_ieee_invalid_op 0
34+
; CHECK-NEXT: .amdhsa_exception_fp_denorm_src 0
35+
; CHECK-NEXT: .amdhsa_exception_fp_ieee_div_zero 0
36+
; CHECK-NEXT: .amdhsa_exception_fp_ieee_overflow 0
37+
; CHECK-NEXT: .amdhsa_exception_fp_ieee_underflow 0
38+
; CHECK-NEXT: .amdhsa_exception_fp_ieee_inexact 0
39+
; CHECK-NEXT: .amdhsa_exception_int_div_zero 0
40+
; CHECK-NEXT: .amdhsa_user_sgpr_dispatch_ptr 0
41+
; CHECK-NEXT: .amdhsa_user_sgpr_queue_ptr 0
42+
; CHECK-NEXT: .amdhsa_user_sgpr_kernarg_segment_ptr 0
43+
; CHECK-NEXT: .amdhsa_user_sgpr_dispatch_id 0
44+
; CHECK-NEXT: .amdhsa_user_sgpr_private_segment_size 0
45+
; CHECK-NEXT: .amdhsa_uses_dynamic_stack 0
46+
; CHECK-NEXT:.end_amdhsa_kernel
47+
.amdhsa_kernel kernel
48+
.amdhsa_group_segment_fixed_size 163840
49+
.amdhsa_next_free_vgpr 0
50+
.amdhsa_next_free_sgpr 0
51+
.amdhsa_accum_offset 4
52+
.end_amdhsa_kernel

0 commit comments

Comments
 (0)