[clang] 4ea3650 - HIP: Link correct denormal mode library
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 1 09:36:42 PDT 2020
Author: Matt Arsenault
Date: 2020-04-01T12:36:22-04:00
New Revision: 4ea3650c212ae471657d3a253cd424ce9d1316ac
URL: https://github.com/llvm/llvm-project/commit/4ea3650c212ae471657d3a253cd424ce9d1316ac
DIFF: https://github.com/llvm/llvm-project/commit/4ea3650c212ae471657d3a253cd424ce9d1316ac.diff
LOG: HIP: Link correct denormal mode library
This wasn't respecting the flush mode based on the default, and also
wasn't correctly handling the explicit
-fno-cuda-flush-denormals-to-zero overriding the mode.
Added:
Modified:
clang/lib/Driver/ToolChains/HIP.cpp
clang/test/Driver/hip-device-libs.hip
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/HIP.cpp b/clang/lib/Driver/ToolChains/HIP.cpp
index d21b3f5f0b19..e4ace81dbac7 100644
--- a/clang/lib/Driver/ToolChains/HIP.cpp
+++ b/clang/lib/Driver/ToolChains/HIP.cpp
@@ -285,6 +285,7 @@ void HIPToolChain::addClangTargetOptions(
(void) GpuArch;
assert(DeviceOffloadingKind == Action::OFK_HIP &&
"Only HIP offloading kinds are supported for GPUs.");
+ auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
CC1Args.push_back("-target-cpu");
CC1Args.push_back(DriverArgs.MakeArgStringRef(GpuArch));
@@ -345,11 +346,14 @@ void HIPToolChain::addClangTargetOptions(
std::string GFXVersion = GpuArch.drop_front(3).str();
std::string ISAVerBC = "oclc_isa_version_" + GFXVersion + ".amdgcn.bc";
- llvm::StringRef FlushDenormalControlBC;
- if (DriverArgs.hasArg(options::OPT_fcuda_flush_denormals_to_zero))
- FlushDenormalControlBC = "oclc_daz_opt_on.amdgcn.bc";
- else
- FlushDenormalControlBC = "oclc_daz_opt_off.amdgcn.bc";
+ bool FTZDAZ = DriverArgs.hasFlag(
+ options::OPT_fcuda_flush_denormals_to_zero,
+ options::OPT_fno_cuda_flush_denormals_to_zero,
+ getDefaultDenormsAreZeroForTarget(Kind));
+
+ std::string FlushDenormalControlBC = FTZDAZ ?
+ "oclc_daz_opt_on.amdgcn.bc" :
+ "oclc_daz_opt_off.amdgcn.bc";
llvm::StringRef WaveFrontSizeBC;
if (stoi(GFXVersion) < 1000)
@@ -359,7 +363,7 @@ void HIPToolChain::addClangTargetOptions(
BCLibs.append({"hip.amdgcn.bc", "ocml.amdgcn.bc", "ockl.amdgcn.bc",
"oclc_finite_only_off.amdgcn.bc",
- std::string(FlushDenormalControlBC),
+ FlushDenormalControlBC,
"oclc_correctly_rounded_sqrt_on.amdgcn.bc",
"oclc_unsafe_math_off.amdgcn.bc", ISAVerBC,
std::string(WaveFrontSizeBC)});
diff --git a/clang/test/Driver/hip-device-libs.hip b/clang/test/Driver/hip-device-libs.hip
index b79cb70cbe68..cb1747c2d798 100644
--- a/clang/test/Driver/hip-device-libs.hip
+++ b/clang/test/Driver/hip-device-libs.hip
@@ -2,23 +2,94 @@
// REQUIRES: x86-registered-target
// REQUIRES: amdgpu-registered-target
-// Test flush-denormals-to-zero enabled uses oclc_daz_opt_on
+// Test if oclc_daz_opt_on or if oclc_daz_opt_off is linked depending on
+// expected denormal mode.
+// Test subtarget with flushing on by default.
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx803 \
+// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
+
+
+// Test subtarget with flushing off by ddefault.
// RUN: %clang -### -target x86_64-linux-gnu \
// RUN: --cuda-gpu-arch=gfx900 \
// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
+
+
+// Test explicit flag, opposite of target default.
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx900 \
// RUN: -fcuda-flush-denormals-to-zero \
+// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
-// Test flush-denormals-to-zero disabled uses oclc_daz_opt_off
+// Test explicit flag, opposite of target default.
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx803 \
+// RUN: -fno-cuda-flush-denormals-to-zero \
+// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
+
+
+// Test explicit flag, same as target default.
// RUN: %clang -### -target x86_64-linux-gnu \
// RUN: --cuda-gpu-arch=gfx900 \
+// RUN: -fno-cuda-flush-denormals-to-zero \
// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
+
+// Test explicit flag, same as target default.
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx803 \
+// RUN: -fcuda-flush-denormals-to-zero \
+// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
+
+
+// Test last flag wins, not flushing
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx803 \
+// RUN: -fcuda-flush-denormals-to-zero -fno-cuda-flush-denormals-to-zero \
+// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
+
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx900 \
+// RUN: -fcuda-flush-denormals-to-zero -fno-cuda-flush-denormals-to-zero \
+// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
+
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx900 \
+// RUN: -fno-cuda-flush-denormals-to-zero -fcuda-flush-denormals-to-zero \
+// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
+
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx803 \
+// RUN: -fno-cuda-flush-denormals-to-zero -fcuda-flush-denormals-to-zero \
+// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
+
+
// Test environment variable HIP_DEVICE_LIB_PATH
// RUN: env HIP_DEVICE_LIB_PATH=%S/Inputs/hip_dev_lib \
@@ -33,4 +104,3 @@
// COM-SAME: "-mlink-builtin-bitcode" "{{.*}}ockl.amdgcn.bc"
// FLUSHD-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_daz_opt_on.amdgcn.bc"
// NOFLUSHD-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_daz_opt_off.amdgcn.bc"
-
More information about the cfe-commits
mailing list