Skip to content

Commit 5ad038a

Browse files
committed
[Clang][OpenMP][NVPTX] Replace libomptarget-nvptx-path with libomptarget-nvptx-bc-path
D94700 removed the static library so we no longer need to pass `-llibomptarget-nvptx` to `nvlink`. Since the bitcode library is the only device runtime for now, instead of emitting a warning when it is not found, an error should be raised. We also set a new option `libomptarget-nvptx-bc-path` to let user choose which bitcode library is being used. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D95161
1 parent e4847a7 commit 5ad038a

File tree

6 files changed

+52
-51
lines changed

6 files changed

+52
-51
lines changed

clang/docs/ClangCommandLineReference.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,9 +1143,9 @@ Set directory to include search path with prefix
11431143

11441144
Add directory to SYSTEM include search path, absolute paths are relative to -isysroot
11451145

1146-
.. option:: --libomptarget-nvptx-path=<arg>
1146+
.. option:: --libomptarget-nvptx-bc-path=<arg>
11471147

1148-
Path to libomptarget-nvptx libraries
1148+
Path to libomptarget-nvptx bitcode library
11491149

11501150
.. option:: --ptxas-path=<arg>
11511151

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ def err_drv_omp_host_target_not_supported : Error<
263263
"The target '%0' is not a supported OpenMP host target.">;
264264
def err_drv_expecting_fopenmp_with_fopenmp_targets : Error<
265265
"The option -fopenmp-targets must be used in conjunction with a -fopenmp option compatible with offloading, please use -fopenmp=libomp or -fopenmp=libiomp5.">;
266+
def err_drv_omp_offload_target_missingbcruntime : Error<
267+
"No library '%0' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.">;
268+
def err_drv_omp_offload_target_bcruntime_not_found : Error<"Bitcode library '%0' does not exist.">;
266269
def warn_drv_omp_offload_target_duplicate : Warning<
267270
"The OpenMP offloading target '%0' is similar to target '%1' already specified - will be ignored.">,
268271
InGroup<OpenMPTarget>;
269-
def warn_drv_omp_offload_target_missingbcruntime : Warning<
270-
"No library '%0' found in the default clang lib directory or in LIBRARY_PATH. Expect degraded performance due to no inlining of runtime functions on target devices.">,
271-
InGroup<OpenMPTarget>;
272272
def err_drv_unsupported_embed_bitcode
273273
: Error<"%0 is not supported with -fembed-bitcode">;
274274
def err_drv_bitcode_unsupported_on_toolchain : Error<

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,8 @@ def gpu_max_threads_per_block_EQ : Joined<["--"], "gpu-max-threads-per-block=">,
992992
def gpu_instrument_lib_EQ : Joined<["--"], "gpu-instrument-lib=">,
993993
HelpText<"Instrument device library for HIP, which is a LLVM bitcode containing "
994994
"__cyg_profile_func_enter and __cyg_profile_func_exit">;
995-
def libomptarget_nvptx_path_EQ : Joined<["--"], "libomptarget-nvptx-path=">, Group<i_Group>,
996-
HelpText<"Path to libomptarget-nvptx libraries">;
995+
def libomptarget_nvptx_bc_path_EQ : Joined<["--"], "libomptarget-nvptx-bc-path=">, Group<i_Group>,
996+
HelpText<"Path to libomptarget-nvptx bitcode library">;
997997
def dD : Flag<["-"], "dD">, Group<d_Group>, Flags<[CC1Option]>,
998998
HelpText<"Print macro definitions in -E mode in addition to normal output">;
999999
def dI : Flag<["-"], "dI">, Group<d_Group>, Flags<[CC1Option]>,

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,6 @@ void NVPTX::OpenMPLinker::ConstructJob(Compilation &C, const JobAction &JA,
600600
CmdArgs.push_back("-arch");
601601
CmdArgs.push_back(Args.MakeArgString(GPUArch));
602602

603-
// Assume that the directory specified with --libomptarget_nvptx_path
604-
// contains the static library libomptarget-nvptx.a.
605-
if (const Arg *A = Args.getLastArg(options::OPT_libomptarget_nvptx_path_EQ))
606-
CmdArgs.push_back(Args.MakeArgString(Twine("-L") + A->getValue()));
607-
608603
// Add paths specified in LIBRARY_PATH environment variable as -L options.
609604
addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
610605

@@ -614,9 +609,6 @@ void NVPTX::OpenMPLinker::ConstructJob(Compilation &C, const JobAction &JA,
614609
llvm::sys::path::append(DefaultLibPath, "lib" CLANG_LIBDIR_SUFFIX);
615610
CmdArgs.push_back(Args.MakeArgString(Twine("-L") + DefaultLibPath));
616611

617-
// Add linking against library implementing OpenMP calls on NVPTX target.
618-
CmdArgs.push_back("-lomptarget-nvptx");
619-
620612
for (const auto &II : Inputs) {
621613
if (II.getType() == types::TY_LLVM_IR ||
622614
II.getType() == types::TY_LTO_IR ||
@@ -761,9 +753,6 @@ void CudaToolChain::addClangTargetOptions(
761753

762754
if (DeviceOffloadingKind == Action::OFK_OpenMP) {
763755
SmallVector<StringRef, 8> LibraryPaths;
764-
if (const Arg *A = DriverArgs.getLastArg(options::OPT_libomptarget_nvptx_path_EQ))
765-
LibraryPaths.push_back(A->getValue());
766-
767756
// Add user defined library paths from LIBRARY_PATH.
768757
llvm::Optional<std::string> LibPath =
769758
llvm::sys::Process::GetEnv("LIBRARY_PATH");
@@ -781,22 +770,37 @@ void CudaToolChain::addClangTargetOptions(
781770
llvm::sys::path::append(DefaultLibPath, Twine("lib") + CLANG_LIBDIR_SUFFIX);
782771
LibraryPaths.emplace_back(DefaultLibPath.c_str());
783772

784-
std::string LibOmpTargetName =
785-
"libomptarget-nvptx-" + GpuArch.str() + ".bc";
786-
bool FoundBCLibrary = false;
787-
for (StringRef LibraryPath : LibraryPaths) {
788-
SmallString<128> LibOmpTargetFile(LibraryPath);
789-
llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
790-
if (llvm::sys::fs::exists(LibOmpTargetFile)) {
773+
// First check whether user specifies bc library
774+
if (const Arg *A =
775+
DriverArgs.getLastArg(options::OPT_libomptarget_nvptx_bc_path_EQ)) {
776+
std::string LibOmpTargetName(A->getValue());
777+
if (llvm::sys::fs::exists(LibOmpTargetName)) {
791778
CC1Args.push_back("-mlink-builtin-bitcode");
792-
CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
793-
FoundBCLibrary = true;
794-
break;
779+
CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetName));
780+
} else {
781+
getDriver().Diag(diag::err_drv_omp_offload_target_bcruntime_not_found)
782+
<< LibOmpTargetName;
783+
}
784+
} else {
785+
bool FoundBCLibrary = false;
786+
787+
std::string LibOmpTargetName =
788+
"libomptarget-nvptx-" + GpuArch.str() + ".bc";
789+
790+
for (StringRef LibraryPath : LibraryPaths) {
791+
SmallString<128> LibOmpTargetFile(LibraryPath);
792+
llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
793+
if (llvm::sys::fs::exists(LibOmpTargetFile)) {
794+
CC1Args.push_back("-mlink-builtin-bitcode");
795+
CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
796+
FoundBCLibrary = true;
797+
break;
798+
}
795799
}
800+
if (!FoundBCLibrary)
801+
getDriver().Diag(diag::err_drv_omp_offload_target_missingbcruntime)
802+
<< LibOmpTargetName;
796803
}
797-
if (!FoundBCLibrary)
798-
getDriver().Diag(diag::warn_drv_omp_offload_target_missingbcruntime)
799-
<< LibOmpTargetName;
800804
}
801805
}
802806

clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-test.bc

Whitespace-only changes.

clang/test/Driver/openmp-offload-gpu.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,6 @@
3434

3535
/// ###########################################################################
3636

37-
/// Check that -lomptarget-nvptx is passed to nvlink.
38-
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp \
39-
// RUN: -fopenmp-targets=nvptx64-nvidia-cuda %s 2>&1 \
40-
// RUN: | FileCheck -check-prefix=CHK-NVLINK %s
41-
/// Check that the value of --libomptarget-nvptx-path is forwarded to nvlink.
42-
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp \
43-
// RUN: --libomptarget-nvptx-path=/path/to/libomptarget/ \
44-
// RUN: -fopenmp-targets=nvptx64-nvidia-cuda %s 2>&1 \
45-
// RUN: | FileCheck -check-prefixes=CHK-NVLINK,CHK-LIBOMPTARGET-NVPTX-PATH %s
46-
47-
// CHK-NVLINK: nvlink
48-
// CHK-LIBOMPTARGET-NVPTX-PATH-SAME: "-L/path/to/libomptarget/"
49-
// CHK-NVLINK-SAME: "-lomptarget-nvptx"
50-
51-
/// ###########################################################################
52-
5337
/// Check cubin file generation and usage by nvlink
5438
// RUN: %clang -### -no-canonical-prefixes -target powerpc64le-unknown-linux-gnu -fopenmp=libomp \
5539
// RUN: -fopenmp-targets=nvptx64-nvidia-cuda -save-temps %s 2>&1 \
@@ -173,13 +157,15 @@
173157
// RUN: -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
174158
// RUN: -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
175159
// RUN: | FileCheck -check-prefix=CHK-BCLIB %s
176-
/// The user can override default detection using --libomptarget-nvptx-path=.
177-
// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda --libomptarget-nvptx-path=%S/Inputs/libomptarget \
160+
/// The user can override default detection using --libomptarget-nvptx-bc-path=.
161+
// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
162+
// RUN: --libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-test.bc \
178163
// RUN: -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
179164
// RUN: -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
180-
// RUN: | FileCheck -check-prefix=CHK-BCLIB %s
165+
// RUN: | FileCheck -check-prefix=CHK-BCLIB-USER %s
181166

182167
// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-sm_20.bc
168+
// CHK-BCLIB-USER: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
183169
// CHK-BCLIB-NOT: {{error:|warning:}}
184170

185171
/// ###########################################################################
@@ -191,7 +177,18 @@
191177
// RUN: -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
192178
// RUN: | FileCheck -check-prefix=CHK-BCLIB-WARN %s
193179

194-
// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Expect degraded performance due to no inlining of runtime functions on target devices.
180+
// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
181+
182+
/// ###########################################################################
183+
184+
/// Check that the error is thrown when the libomptarget bitcode library does not exist.
185+
// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
186+
// RUN: -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
187+
// RUN: --libomptarget-nvptx-bc-path=not-exist.bc \
188+
// RUN: -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
189+
// RUN: | FileCheck -check-prefix=CHK-BCLIB-ERROR %s
190+
191+
// CHK-BCLIB-ERROR: Bitcode library 'not-exist.bc' does not exist.
195192

196193
/// Check that debug info is emitted in dwarf-2
197194
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O1 --no-cuda-noopt-device-debug 2>&1 \

0 commit comments

Comments
 (0)