Skip to content

Commit f93aa51

Browse files
authored
[AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (#76955)
These generic targets include multiple GPUs and will, in the future, provide a way to build once and run on multiple GPU, at the cost of less optimization opportunities. Note that this is just doing the compiler side of things, device libs an runtimes/loader/etc. don't know about these targets yet, so none of them actually work in practice right now. This is just the initial commit to make LLVM aware of them. This contains the documentation changes for both this change and #76954 as well.
1 parent b221b97 commit f93aa51

32 files changed

+1101
-202
lines changed

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/Basic/LangOptions.h"
1818
#include "clang/Basic/MacroBuilder.h"
1919
#include "clang/Basic/TargetBuiltins.h"
20+
#include "llvm/ADT/SmallString.h"
2021
using namespace clang;
2122
using namespace clang::targets;
2223

@@ -279,13 +280,25 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
279280
if (GPUKind == llvm::AMDGPU::GK_NONE && !IsHIPHost)
280281
return;
281282

282-
StringRef CanonName = isAMDGCN(getTriple()) ? getArchNameAMDGCN(GPUKind)
283-
: getArchNameR600(GPUKind);
283+
llvm::SmallString<16> CanonName =
284+
(isAMDGCN(getTriple()) ? getArchNameAMDGCN(GPUKind)
285+
: getArchNameR600(GPUKind));
286+
287+
// Sanitize the name of generic targets.
288+
// e.g. gfx10.1-generic -> gfx10_1_generic
289+
if (GPUKind >= llvm::AMDGPU::GK_AMDGCN_GENERIC_FIRST &&
290+
GPUKind <= llvm::AMDGPU::GK_AMDGCN_GENERIC_LAST) {
291+
std::replace(CanonName.begin(), CanonName.end(), '.', '_');
292+
std::replace(CanonName.begin(), CanonName.end(), '-', '_');
293+
}
294+
284295
Builder.defineMacro(Twine("__") + Twine(CanonName) + Twine("__"));
285296
// Emit macros for gfx family e.g. gfx906 -> __GFX9__, gfx1030 -> __GFX10___
286297
if (isAMDGCN(getTriple()) && !IsHIPHost) {
287-
assert(CanonName.starts_with("gfx") && "Invalid amdgcn canonical name");
288-
Builder.defineMacro(Twine("__") + Twine(CanonName.drop_back(2).upper()) +
298+
assert(StringRef(CanonName).starts_with("gfx") &&
299+
"Invalid amdgcn canonical name");
300+
StringRef CanonFamilyName = getArchFamilyNameAMDGCN(GPUKind);
301+
Builder.defineMacro(Twine("__") + Twine(CanonFamilyName.upper()) +
289302
Twine("__"));
290303
Builder.defineMacro("__amdgcn_processor__",
291304
Twine("\"") + Twine(CanonName) + Twine("\""));

clang/test/Driver/amdgpu-macros.cl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@
131131
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx1200 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1200 -DFAMILY=GFX12
132132
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1201 -DFAMILY=GFX12
133133

134+
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx9_generic -DFAMILY=GFX9
135+
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx10_1_generic -DFAMILY=GFX10
136+
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx10_3_generic -DFAMILY=GFX10
137+
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx11_generic -DFAMILY=GFX11
138+
134139
// ARCH-GCN-DAG: #define FP_FAST_FMA 1
135140

136141
// FAST_FMAF-DAG: #define FP_FAST_FMAF 1

clang/test/Driver/amdgpu-mcpu.cl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@
115115
// RUN: %clang -### -target amdgcn -mcpu=gfx1200 %s 2>&1 | FileCheck --check-prefix=GFX1200 %s
116116
// RUN: %clang -### -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck --check-prefix=GFX1201 %s
117117

118+
// RUN: %clang -### -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck --check-prefix=GFX9_GENERIC %s
119+
// RUN: %clang -### -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck --check-prefix=GFX10_1_GENERIC %s
120+
// RUN: %clang -### -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck --check-prefix=GFX10_3_GENERIC %s
121+
// RUN: %clang -### -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck --check-prefix=GFX11_GENERIC %s
122+
118123
// GCNDEFAULT-NOT: -target-cpu
119124
// GFX600: "-target-cpu" "gfx600"
120125
// GFX601: "-target-cpu" "gfx601"
@@ -160,3 +165,8 @@
160165
// GFX1151: "-target-cpu" "gfx1151"
161166
// GFX1200: "-target-cpu" "gfx1200"
162167
// GFX1201: "-target-cpu" "gfx1201"
168+
169+
// GFX9_GENERIC: "-target-cpu" "gfx9-generic"
170+
// GFX10_1_GENERIC: "-target-cpu" "gfx10.1-generic"
171+
// GFX10_3_GENERIC: "-target-cpu" "gfx10.3-generic"
172+
// GFX11_GENERIC: "-target-cpu" "gfx11-generic"

clang/test/Misc/target-invalid-cpu-note.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
// RUN: not %clang_cc1 -triple amdgcn--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AMDGCN
3939
// AMDGCN: error: unknown target CPU 'not-a-cpu'
40-
// AMDGCN-NEXT: note: valid target CPU values are: gfx600, tahiti, gfx601, pitcairn, verde, gfx602, hainan, oland, gfx700, kaveri, gfx701, hawaii, gfx702, gfx703, kabini, mullins, gfx704, bonaire, gfx705, gfx801, carrizo, gfx802, iceland, tonga, gfx803, fiji, polaris10, polaris11, gfx805, tongapro, gfx810, stoney, gfx900, gfx902, gfx904, gfx906, gfx908, gfx909, gfx90a, gfx90c, gfx940, gfx941, gfx942, gfx1010, gfx1011, gfx1012, gfx1013, gfx1030, gfx1031, gfx1032, gfx1033, gfx1034, gfx1035, gfx1036, gfx1100, gfx1101, gfx1102, gfx1103, gfx1150, gfx1151, gfx1200, gfx1201{{$}}
40+
// AMDGCN-NEXT: note: valid target CPU values are: gfx600, tahiti, gfx601, pitcairn, verde, gfx602, hainan, oland, gfx700, kaveri, gfx701, hawaii, gfx702, gfx703, kabini, mullins, gfx704, bonaire, gfx705, gfx801, carrizo, gfx802, iceland, tonga, gfx803, fiji, polaris10, polaris11, gfx805, tongapro, gfx810, stoney, gfx900, gfx902, gfx904, gfx906, gfx908, gfx909, gfx90a, gfx90c, gfx940, gfx941, gfx942, gfx1010, gfx1011, gfx1012, gfx1013, gfx1030, gfx1031, gfx1032, gfx1033, gfx1034, gfx1035, gfx1036, gfx1100, gfx1101, gfx1102, gfx1103, gfx1150, gfx1151, gfx1200, gfx1201, gfx9-generic, gfx10.1-generic, gfx10.3-generic, gfx11-generic{{$}}
4141

4242
// RUN: not %clang_cc1 -triple wasm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix WEBASM
4343
// WEBASM: error: unknown target CPU 'not-a-cpu'

0 commit comments

Comments
 (0)