forked from OSchip/llvm-project
[HIP] Check compatibility of -fgpu-sanitize with offload arch
-fgpu-sanitize is incompatible with offload arch containing xnack-. This patch checks that. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D102975
This commit is contained in:
parent
6f4794feb6
commit
6d2c095020
|
@ -707,16 +707,26 @@ AMDGPUToolChain::getGPUArch(const llvm::opt::ArgList &DriverArgs) const {
|
|||
getTriple(), DriverArgs.getLastArgValue(options::OPT_mcpu_EQ));
|
||||
}
|
||||
|
||||
void AMDGPUToolChain::checkTargetID(
|
||||
const llvm::opt::ArgList &DriverArgs) const {
|
||||
AMDGPUToolChain::ParsedTargetIDType
|
||||
AMDGPUToolChain::getParsedTargetID(const llvm::opt::ArgList &DriverArgs) const {
|
||||
StringRef TargetID = DriverArgs.getLastArgValue(options::OPT_mcpu_EQ);
|
||||
if (TargetID.empty())
|
||||
return;
|
||||
return {None, None, None};
|
||||
|
||||
llvm::StringMap<bool> FeatureMap;
|
||||
auto OptionalGpuArch = parseTargetID(getTriple(), TargetID, &FeatureMap);
|
||||
if (!OptionalGpuArch) {
|
||||
getDriver().Diag(clang::diag::err_drv_bad_target_id) << TargetID;
|
||||
if (!OptionalGpuArch)
|
||||
return {TargetID.str(), None, None};
|
||||
|
||||
return {TargetID.str(), OptionalGpuArch.getValue().str(), FeatureMap};
|
||||
}
|
||||
|
||||
void AMDGPUToolChain::checkTargetID(
|
||||
const llvm::opt::ArgList &DriverArgs) const {
|
||||
auto PTID = getParsedTargetID(DriverArgs);
|
||||
if (PTID.OptionalTargetID && !PTID.OptionalGPUArch) {
|
||||
getDriver().Diag(clang::diag::err_drv_bad_target_id)
|
||||
<< PTID.OptionalTargetID.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,19 @@ public:
|
|||
|
||||
protected:
|
||||
/// Check and diagnose invalid target ID specified by -mcpu.
|
||||
void checkTargetID(const llvm::opt::ArgList &DriverArgs) const;
|
||||
virtual void checkTargetID(const llvm::opt::ArgList &DriverArgs) const;
|
||||
|
||||
/// The struct type returned by getParsedTargetID.
|
||||
struct ParsedTargetIDType {
|
||||
Optional<std::string> OptionalTargetID;
|
||||
Optional<std::string> OptionalGPUArch;
|
||||
Optional<llvm::StringMap<bool>> OptionalFeatures;
|
||||
};
|
||||
|
||||
/// Get target ID, GPU arch, and target ID features if the target ID is
|
||||
/// specified and valid.
|
||||
ParsedTargetIDType
|
||||
getParsedTargetID(const llvm::opt::ArgList &DriverArgs) const;
|
||||
|
||||
/// Get GPU arch from -mcpu without checking.
|
||||
StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const;
|
||||
|
|
|
@ -459,3 +459,28 @@ HIPToolChain::getHIPDeviceLibs(const llvm::opt::ArgList &DriverArgs) const {
|
|||
|
||||
return BCLibs;
|
||||
}
|
||||
|
||||
void HIPToolChain::checkTargetID(const llvm::opt::ArgList &DriverArgs) const {
|
||||
auto PTID = getParsedTargetID(DriverArgs);
|
||||
if (PTID.OptionalTargetID && !PTID.OptionalGPUArch) {
|
||||
getDriver().Diag(clang::diag::err_drv_bad_target_id)
|
||||
<< PTID.OptionalTargetID.getValue();
|
||||
return;
|
||||
}
|
||||
|
||||
assert(PTID.OptionalFeatures && "Invalid return from getParsedTargetID");
|
||||
auto &FeatureMap = PTID.OptionalFeatures.getValue();
|
||||
// Sanitizer is not supported with xnack-.
|
||||
if (DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
|
||||
options::OPT_fno_gpu_sanitize, false)) {
|
||||
auto Loc = FeatureMap.find("xnack");
|
||||
if (Loc != FeatureMap.end() && !Loc->second) {
|
||||
auto &Diags = getDriver().getDiags();
|
||||
auto DiagID = Diags.getCustomDiagID(
|
||||
DiagnosticsEngine::Error,
|
||||
"'-fgpu-sanitize' is not compatible with offload arch '%0'. "
|
||||
"Use an offload arch without 'xnack-' instead");
|
||||
Diags.Report(DiagID) << PTID.OptionalTargetID.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ public:
|
|||
unsigned GetDefaultDwarfVersion() const override { return 4; }
|
||||
|
||||
const ToolChain &HostTC;
|
||||
void checkTargetID(const llvm::opt::ArgList &DriverArgs) const override;
|
||||
|
||||
protected:
|
||||
Tool *buildLinker() const override;
|
||||
|
|
|
@ -25,6 +25,11 @@
|
|||
// RUN: -nogpuinc --rocm-path=%S/Inputs/rocm-invalid \
|
||||
// RUN: %s 2>&1 | FileCheck -check-prefixes=FAIL %s
|
||||
|
||||
// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack- \
|
||||
// RUN: -fsanitize=address -fgpu-sanitize \
|
||||
// RUN: -nogpuinc --rocm-path=%S/Inputs/rocm \
|
||||
// RUN: %s 2>&1 | FileCheck -check-prefix=XNACK %s
|
||||
|
||||
// CHECK-NOT: {{"[^"]*clang[^"]*".* "-fcuda-is-device".* "-fsanitize=address"}}
|
||||
// CHECK-NOT: {{"[^"]*lld(\.exe){0,1}".* ".*hip.bc"}}
|
||||
// CHECK: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* "-fsanitize=address"}}
|
||||
|
@ -38,3 +43,5 @@
|
|||
// RDC: {{"[^"]*lld(\.exe){0,1}".*}} "[[OUT]]" {{".*asanrtl.bc" ".*hip.bc"}}
|
||||
|
||||
// FAIL: AMDGPU address sanitizer runtime library (asanrtl) is not found. Please install ROCm device library which supports address sanitizer
|
||||
|
||||
// XNACK: error: '-fgpu-sanitize' is not compatible with offload arch 'gfx900:xnack-'. Use an offload arch without 'xnack-' instead
|
||||
|
|
Loading…
Reference in New Issue