Skip to content

Commit 2fbf339

Browse files
committed
[AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (llvm#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 llvm#76954 as well. Change-Id: I0c99e616adddaae5e8ce4ad7283eabdbf64250c3
1 parent ba3b5fb commit 2fbf339

33 files changed

+1101
-207
lines changed

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 17 additions & 7 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

@@ -275,16 +276,25 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
275276
Builder.defineMacro("__R600__");
276277

277278
if (GPUKind != llvm::AMDGPU::GK_NONE) {
278-
StringRef CanonName = isAMDGCN(getTriple()) ?
279-
getArchNameAMDGCN(GPUKind) : getArchNameR600(GPUKind);
279+
280+
llvm::SmallString<16> CanonName =
281+
(isAMDGCN(getTriple()) ? getArchNameAMDGCN(GPUKind)
282+
: getArchNameR600(GPUKind));
283+
284+
// Sanitize the name of generic targets.
285+
// e.g. gfx10-1-generic -> gfx10_1_generic
286+
if (GPUKind >= llvm::AMDGPU::GK_AMDGCN_GENERIC_FIRST &&
287+
GPUKind <= llvm::AMDGPU::GK_AMDGCN_GENERIC_LAST) {
288+
std::replace(CanonName.begin(), CanonName.end(), '.', '_');
289+
std::replace(CanonName.begin(), CanonName.end(), '-', '_');
290+
}
291+
280292
Builder.defineMacro(Twine("__") + Twine(CanonName) + Twine("__"));
281-
// Emit macros for gfx family e.g. gfx906 -> __GFX9__, gfx1030 -> __GFX10___
282293
if (isAMDGCN(getTriple())) {
283-
assert(CanonName.starts_with("gfx") && "Invalid amdgcn canonical name");
284-
Builder.defineMacro(Twine("__") + Twine(CanonName.drop_back(2).upper()) +
294+
// Emit macros for gfx family e.g. gfx906 -> __GFX9__, gfx1030 -> __GFX10___
295+
StringRef CanonFamilyName = getArchFamilyNameAMDGCN(GPUKind);
296+
Builder.defineMacro(Twine("__") + Twine(CanonFamilyName.upper()) +
285297
Twine("__"));
286-
}
287-
if (isAMDGCN(getTriple())) {
288298
Builder.defineMacro("__amdgcn_processor__",
289299
Twine("\"") + Twine(CanonName) + Twine("\""));
290300
Builder.defineMacro("__amdgcn_target_id__",

clang/test/Driver/amdgpu-macros.cl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@
132132
// 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
133133
// 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
134134

135+
// 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
136+
// 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
137+
// 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
138+
// 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
139+
135140
// ARCH-GCN-DAG: #define FP_FAST_FMA 1
136141

137142
// 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
@@ -116,6 +116,11 @@
116116
// RUN: %clang -### -target amdgcn -mcpu=gfx1200 %s 2>&1 | FileCheck --check-prefix=GFX1200 %s
117117
// RUN: %clang -### -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck --check-prefix=GFX1201 %s
118118

119+
// RUN: %clang -### -target amdgcn -mcpu=gfx9-generic %s 2>&1 | FileCheck --check-prefix=GFX9_GENERIC %s
120+
// RUN: %clang -### -target amdgcn -mcpu=gfx10.1-generic %s 2>&1 | FileCheck --check-prefix=GFX10_1_GENERIC %s
121+
// RUN: %clang -### -target amdgcn -mcpu=gfx10.3-generic %s 2>&1 | FileCheck --check-prefix=GFX10_3_GENERIC %s
122+
// RUN: %clang -### -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck --check-prefix=GFX11_GENERIC %s
123+
119124
// GCNDEFAULT-NOT: -target-cpu
120125
// GFX600: "-target-cpu" "gfx600"
121126
// GFX601: "-target-cpu" "gfx601"
@@ -162,3 +167,8 @@
162167
// GFX1152: "-target-cpu" "gfx1152"
163168
// GFX1200: "-target-cpu" "gfx1200"
164169
// GFX1201: "-target-cpu" "gfx1201"
170+
171+
// GFX9_GENERIC: "-target-cpu" "gfx9-generic"
172+
// GFX10_1_GENERIC: "-target-cpu" "gfx10.1-generic"
173+
// GFX10_3_GENERIC: "-target-cpu" "gfx10.3-generic"
174+
// 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, gfx1152, 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, gfx1152, 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)