llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-amdgpu Author: Yaxun (Sam) Liu (yxsamliu) <details> <summary>Changes</summary> LLVM #<!-- -->196505 removed the 16-byte array alignment rule that AMDGPU inherited from the x86-64 MSVC host. In a gfx1100 WMMA example, an LDS array dropped from 16-byte to 2-byte alignment. A read changed from four `ds_load_2addr_b32` instructions to two `ds_load_b128` instructions. The vLLM W4A16 prefill GEMM took 6.10 ms on Windows and 1.57 ms with explicit 4-byte alignment using the same compiler. Restore the old device alignment rule. It aligns the array's starting address after struct layout and array element spacing are determined. https://github.com/llvm/llvm-project/pull/196505 https://github.com/ROCm/TheRock/issues/10272#issuecomment-7236349933 AI assisted. --- Full diff: https://github.com/llvm/llvm-project/pull/246922.diff 2 Files Affected: - (modified) clang/lib/Basic/Targets/AMDGPU.cpp (+10) - (added) clang/test/CodeGenHIP/amdgpu-shared-array-alignment.hip (+21) ``````````diff diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp index c3e6f8bbcafa8a..53dafb1c6620e6 100644 --- a/clang/lib/Basic/Targets/AMDGPU.cpp +++ b/clang/lib/Basic/Targets/AMDGPU.cpp @@ -355,6 +355,16 @@ void AMDGPUTargetInfo::setAuxTarget(const TargetInfo *Aux) { Float128Format = SaveFloat128Format; LongDoubleWidth = SaveLongDoubleWidth; LongDoubleAlign = SaveLongDoubleAlign; + + // Keep the AMDGCN large-array alignment used before the x86-64 MSVC + // target switched to its own minimum global alignment rules. + const llvm::Triple &AuxTriple = Aux->getTriple(); + if (getTriple().isAMDGCN() && AuxTriple.getArch() == llvm::Triple::x86_64 && + AuxTriple.isWindowsMSVCEnvironment()) { + LargeArrayMinWidth = 128; + LargeArrayAlign = 128; + } + // For certain builtin types support on the host target, claim they are // support to pass the compilation of the host code during the device-side // compilation. diff --git a/clang/test/CodeGenHIP/amdgpu-shared-array-alignment.hip b/clang/test/CodeGenHIP/amdgpu-shared-array-alignment.hip new file mode 100644 index 00000000000000..b945d3a91700e4 --- /dev/null +++ b/clang/test/CodeGenHIP/amdgpu-shared-array-alignment.hip @@ -0,0 +1,21 @@ +// NOTE: Do not autogenerate. Check only the alignment of the LDS arrays. +// REQUIRES: amdgpu-registered-target +// RUN: %clang_cc1 -triple amdgpu11.00-amd-amdhsa -aux-triple x86_64-pc-windows-msvc \ +// RUN: -fcuda-is-device -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple amdgpu11.00-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \ +// RUN: -fcuda-is-device -emit-llvm -o - %s | FileCheck %s + +// CHECK-DAG: @{{.*}}small = internal addrspace(3) global [7 x half] undef, align 2{{$}} +// CHECK-DAG: @{{.*}}large = internal addrspace(3) global [8 x half] undef, align 16{{$}} +// CHECK-DAG: @{{.*}}explicit_align = internal addrspace(3) global [8 x half] undef, align 4{{$}} + +__attribute__((device)) void use(_Float16 *); + +__attribute__((global)) void kernel() { + __attribute__((shared)) _Float16 small[7]; + __attribute__((shared)) _Float16 large[8]; + __attribute__((shared, aligned(4))) _Float16 explicit_align[8]; + use(small); + use(large); + use(explicit_align); +} `````````` </details> https://github.com/llvm/llvm-project/pull/246922 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
