Skip to content

Commit 9016641

Browse files
committed
[AMDGPU] add macro __AMDGCN_CDNA_VERSION__
If a processor belongs to CDNA generation, pre-define macro `__AMDGCN_CDNA_VERSION__` as an integer. Fixes: ROCm#59
1 parent 5ae9ffb commit 9016641

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

clang/docs/AMDGPUSupport.rst

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Predefined Macros
4545
- Defined with the target ID as a string.
4646
* - ``__amdgcn_feature_<feature-name>__``
4747
- Defined for each supported target feature. The value is 1 if the feature is enabled and 0 if it is disabled. Allowed feature names are sramecc and xnack.
48+
* - ``__AMDGCN_CDNA_VERSION__``
49+
- Defined with the CDNA version as an integer if the processor belongs to the CDNA generation.
4850
* - ``__AMDGCN_CUMODE__``
4951
- Defined as 1 if the CU mode is enabled and 0 if the WGP mode is enabled.
5052
* - ``__AMDGCN_UNSAFE_FP_ATOMICS__``

clang/lib/Basic/Targets/AMDGPU.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
249249
for (auto F : {"image-insts", "gws"})
250250
ReadOnlyFeatures.insert(F);
251251
HalfArgsAndReturns = true;
252+
253+
switch (GPUKind) {
254+
case llvm::AMDGPU::GK_GFX908:
255+
CDNAVersion = 1;
256+
break;
257+
case llvm::AMDGPU::GK_GFX90A:
258+
CDNAVersion = 2;
259+
break;
260+
case llvm::AMDGPU::GK_GFX940:
261+
case llvm::AMDGPU::GK_GFX941:
262+
case llvm::AMDGPU::GK_GFX942:
263+
CDNAVersion = 3;
264+
break;
265+
default:
266+
CDNAVersion = 0;
267+
}
252268
}
253269

254270
void AMDGPUTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
@@ -299,6 +315,8 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
299315
StringRef CanonFamilyName = getArchFamilyNameAMDGCN(GPUKind);
300316
Builder.defineMacro(Twine("__") + Twine(CanonFamilyName.upper()) +
301317
Twine("__"));
318+
if (CDNAVersion)
319+
Builder.defineMacro("__AMDGCN_CDNA_VERSION__", Twine(CDNAVersion));
302320
Builder.defineMacro("__amdgcn_processor__",
303321
Twine("\"") + Twine(CanonName) + Twine("\""));
304322
Builder.defineMacro("__amdgcn_target_id__",

clang/lib/Basic/Targets/AMDGPU.h

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
5151
llvm::StringMap<bool> OffloadArchFeatures;
5252
std::string TargetID;
5353

54+
unsigned CDNAVersion = 0;
55+
5456
bool hasFP64() const {
5557
return getTriple().getArch() == llvm::Triple::amdgcn ||
5658
!!(GPUFeatures & llvm::AMDGPU::FEATURE_FP64);

clang/test/Driver/amdgpu-macros.cl

+6-5
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@
103103
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx902 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx902 -DFAMILY=GFX9
104104
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx904 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx904 -DFAMILY=GFX9
105105
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx906 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx906 -DFAMILY=GFX9
106-
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx908 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx908 -DFAMILY=GFX9
106+
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx908 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,CDNA,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx908 -DFAMILY=GFX9 -DCDNA=1
107107
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx908 -munsafe-fp-atomics %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,UNSAFEFPATOMIC %s -DWAVEFRONT_SIZE=64 -DCPU=gfx908 -DFAMILY=GFX9
108108
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx909 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx909 -DFAMILY=GFX9
109-
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx90a %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx90a -DFAMILY=GFX9
109+
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx90a %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,CDNA,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx90a -DFAMILY=GFX9 -DCDNA=2
110110
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx90c %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx90c -DFAMILY=GFX9
111-
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx940 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx940 -DFAMILY=GFX9
112-
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx941 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx941 -DFAMILY=GFX9
113-
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx942 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx942 -DFAMILY=GFX9
111+
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx940 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,CDNA,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx940 -DFAMILY=GFX9 -DCDNA=3
112+
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx941 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,CDNA,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx941 -DFAMILY=GFX9 -DCDNA=3
113+
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx942 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,CDNA,FAST_FMAF %s -DWAVEFRONT_SIZE=64 -DCPU=gfx942 -DFAMILY=GFX9 -DCDNA=3
114114
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx1010 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1010 -DFAMILY=GFX10
115115
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx1011 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1011 -DFAMILY=GFX10
116116
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx1012 %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1012 -DFAMILY=GFX10
@@ -150,6 +150,7 @@
150150
// ARCH-GCN-DAG: #define __[[CPU]]__ 1
151151
// ARCH-GCN-DAG: #define __[[FAMILY]]__ 1
152152
// ARCH-GCN-DAG: #define __amdgcn_processor__ "[[CPU]]"
153+
// CDNA-DAG: #define __AMDGCN_CDNA_VERSION__ [[CDNA]]
153154
// ARCH-GCN-DAG: #define __AMDGCN_WAVEFRONT_SIZE [[WAVEFRONT_SIZE]]
154155
// UNSAFEFPATOMIC-DAG: #define __AMDGCN_UNSAFE_FP_ATOMICS__ 1
155156

0 commit comments

Comments
 (0)