Skip to content

Commit 36d4778

Browse files
[ASan] Skip explicit check of 'xnack' feature for gfx1250 && gfx1251. (#166754)
Xnack processing is essential and performed at the frontend to enable ASan instrumentation for AMDGPU device code. Certain AMDGPU subtargets like gfx1250 && gfx1251 don't have to enable 'xnack+' explictly in '--offload-arch=' for device ASan instrumentation.
1 parent 55436ae commit 36d4778

File tree

8 files changed

+43
-6
lines changed

8 files changed

+43
-6
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/Support/Process.h"
2323
#include "llvm/Support/VirtualFileSystem.h"
2424
#include "llvm/TargetParser/Host.h"
25+
#include "llvm/TargetParser/TargetParser.h"
2526
#include <optional>
2627
#include <system_error>
2728

@@ -1095,9 +1096,21 @@ bool AMDGPUToolChain::shouldSkipSanitizeOption(
10951096
if (K != SanitizerKind::Address)
10961097
return true;
10971098

1099+
// Check 'xnack+' availability by default
1100+
llvm::StringRef Processor =
1101+
getProcessorFromTargetID(TC.getTriple(), TargetID);
1102+
auto ProcKind = TC.getTriple().isAMDGCN()
1103+
? llvm::AMDGPU::parseArchAMDGCN(Processor)
1104+
: llvm::AMDGPU::parseArchR600(Processor);
1105+
auto Features = TC.getTriple().isAMDGCN()
1106+
? llvm::AMDGPU::getArchAttrAMDGCN(ProcKind)
1107+
: llvm::AMDGPU::getArchAttrR600(ProcKind);
1108+
if (Features & llvm::AMDGPU::FEATURE_XNACK_ALWAYS)
1109+
return false;
1110+
1111+
// Look for the xnack feature in TargetID
10981112
llvm::StringMap<bool> FeatureMap;
10991113
auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
1100-
11011114
assert(OptionalGpuArch && "Invalid Target ID");
11021115
(void)OptionalGpuArch;
11031116
auto Loc = FeatureMap.find("xnack");

clang/test/Driver/Inputs/rocm/amdgcn/bitcode/oclc_isa_version_1250.bc

Whitespace-only changes.

clang/test/Driver/Inputs/rocm/amdgcn/bitcode/oclc_isa_version_1251.bc

Whitespace-only changes.

clang/test/Driver/amdgpu-openmp-sanitize-options.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack+ -fsanitize=address --rocm-path=%S/Inputs/rocm %s 2>&1 \
2323
// RUN: | FileCheck -check-prefixes=HOSTSAN,GPUSAN,SAN %s
2424

25-
// ASan enabled for multiple amdgpu-arch [gfx908:xnack+,gfx900:xnack+]
25+
// GPU ASan enabled for multiple amdgpu-arch [gfx908:xnack+,gfx900:xnack+]
2626
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack+ --offload-arch=gfx900:xnack+ -fsanitize=address -fgpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
2727
// RUN: | FileCheck -check-prefixes=HOSTSAN,GPUSAN,SAN %s
2828

29+
// GPU ASan enabled for amdgpu-arch [gfx1250,gfx1251]
30+
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx1250,gfx1251 -fsanitize=address -fgpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
31+
// RUN: | FileCheck -check-prefixes=HOSTSAN,GPUSAN,SAN %s
32+
2933
// GPU ASan Disabled Test Cases
3034

3135
// GPU ASan disabled through '-fsanitize=address' without '-fgpu-sanitize' flag for amdgpu-arch [gfx908]
@@ -56,9 +60,9 @@
5660

5761
// HOSTSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "--offload-targets=amdgcn-amd-amdhsa".* "-x" "c".*}}
5862

59-
// GPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu".* "-emit-llvm-bc".* "-mlink-bitcode-file" "[^"]*asanrtl.bc".* "-mlink-bitcode-file" "[^"]*ockl.bc".* "-target-cpu" "(gfx908|gfx900)".* "-fopenmp".* "-fsanitize=address".* "-x" "c".*}}
63+
// GPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu".* "-emit-llvm-bc".* "-mlink-bitcode-file" "[^"]*asanrtl.bc".* "-mlink-bitcode-file" "[^"]*ockl.bc".* "-target-cpu" "(gfx908|gfx900|gfx1250|gfx1251)".* "-fopenmp".* "-fsanitize=address".* "-x" "c".*}}
6064
// NOGPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu".* "-emit-llvm-bc".* "-target-cpu" "(gfx908|gfx900)".* "-fopenmp".* "-x" "c".*}}
6165

62-
// SAN: {{"[^"]*llvm-offload-binary[^"]*" "-o".* "--image=file=.*.bc,triple=amdgcn-amd-amdhsa,arch=gfx908(:xnack\-|:xnack\+)?,kind=openmp(,feature=(\-xnack|\+xnack))?"}}
66+
// SAN: {{"[^"]*llvm-offload-binary[^"]*" "-o".* "--image=file=.*.bc,triple=amdgcn-amd-amdhsa,arch=(gfx908|gfx1250|gfx1251)(:xnack\-|:xnack\+)?,kind=openmp(,feature=(\-xnack|\+xnack))?"}}
6367
// SAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "--offload-targets=amdgcn-amd-amdhsa".* "-x" "ir".*}}
6468
// SAN: {{"[^"]*clang-linker-wrapper[^"]*".* "--host-triple=x86_64-unknown-linux-gnu".* "--linker-path=[^"]*".* "--whole-archive" "[^"]*(libclang_rt.asan_static.a|libclang_rt.asan_static-x86_64.a)".* "--whole-archive" "[^"]*(libclang_rt.asan.a|libclang_rt.asan-x86_64.a)".*}}

clang/test/Driver/hip-sanitize-options.hip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
// RUN: -nogpuinc --rocm-path=%S/Inputs/rocm \
44
// RUN: %s 2>&1 | FileCheck -check-prefixes=NORDC %s
55

6+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu --offload-arch=gfx1250,gfx1251 \
7+
// RUN: -fsanitize=address \
8+
// RUN: -nogpuinc --rocm-path=%S/Inputs/rocm \
9+
// RUN: %s 2>&1 | FileCheck -check-prefixes=NORDC %s
10+
611
// RUN: %clang -### --target=x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack+ \
712
// RUN: -fsanitize=address -fno-gpu-sanitize \
813
// RUN: -nogpuinc --rocm-path=%S/Inputs/rocm \

clang/test/Driver/rocm-device-libs.cl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@
138138
// RUN: %s \
139139
// RUN: 2>&1 | FileCheck --check-prefixes=ASAN,COMMON %s
140140

141+
// RUN: %clang -### -target amdgcn-amd-amdhsa \
142+
// RUN: -x cl -mcpu=gfx1250 -fsanitize=address \
143+
// RUN: --rocm-path=%S/Inputs/rocm \
144+
// RUN: %s \
145+
// RUN: 2>&1 | FileCheck --check-prefixes=ASAN,COMMON %s
146+
147+
// RUN: %clang -### -target amdgcn-amd-amdhsa \
148+
// RUN: -x cl -mcpu=gfx1251 -fsanitize=address \
149+
// RUN: --rocm-path=%S/Inputs/rocm \
150+
// RUN: %s \
151+
// RUN: 2>&1 | FileCheck --check-prefixes=ASAN,COMMON %s
152+
141153
// RUN: %clang -### -target amdgcn-amd-amdhsa \
142154
// RUN: -x cl -mcpu=gfx908:xnack+ \
143155
// RUN: --rocm-path=%S/Inputs/rocm \

llvm/include/llvm/TargetParser/TargetParser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ enum ArchFeatureKind : uint32_t {
161161

162162
// WGP mode is supported.
163163
FEATURE_WGP = 1 << 9,
164+
165+
// Xnack is available by default
166+
FEATURE_XNACK_ALWAYS = 1 << 10
164167
};
165168

166169
enum FeatureError : uint32_t {

llvm/lib/TargetParser/TargetParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ constexpr GPUInfo AMDGCNGPUs[] = {
174174
{{"gfx1153"}, {"gfx1153"}, GK_GFX1153, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
175175
{{"gfx1200"}, {"gfx1200"}, GK_GFX1200, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
176176
{{"gfx1201"}, {"gfx1201"}, GK_GFX1201, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
177-
{{"gfx1250"}, {"gfx1250"}, GK_GFX1250, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
178-
{{"gfx1251"}, {"gfx1251"}, GK_GFX1251, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
177+
{{"gfx1250"}, {"gfx1250"}, GK_GFX1250, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK_ALWAYS},
178+
{{"gfx1251"}, {"gfx1251"}, GK_GFX1251, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK_ALWAYS},
179179

180180
{{"gfx9-generic"}, {"gfx9-generic"}, GK_GFX9_GENERIC, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
181181
{{"gfx10-1-generic"}, {"gfx10-1-generic"}, GK_GFX10_1_GENERIC, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},

0 commit comments

Comments
 (0)