gtbercea updated this revision to Diff 133919. gtbercea added a comment. Add regression tests.
Repository: rC Clang https://reviews.llvm.org/D43197 Files: include/clang/Basic/DiagnosticDriverKinds.td lib/Driver/ToolChains/Cuda.cpp test/Driver/openmp-offload-gpu.c Index: test/Driver/openmp-offload-gpu.c =================================================================== --- test/Driver/openmp-offload-gpu.c +++ test/Driver/openmp-offload-gpu.c @@ -142,3 +142,24 @@ // RUN: | FileCheck -check-prefix=CHK-NOLIBDEVICE %s // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60 + +/// ########################################################################### + +/// Check that the runtime bitcode library is part of the compile line. Create a bogus +/// bitcode library that will be found via the LIBRARY_PATH. +// RUN: touch /tmp/libomptarget-nvptx-sm_60.bc +// RUN: LIBRARY_PATH=/tmp %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \ +// RUN: -Xopenmp-target -march=sm_60 -fopenmp-relocatable-target -save-temps \ +// RUN: -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB %s + +// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-cuda-bitcode{{.*}}libomptarget-nvptx-sm_60.bc + +/// ########################################################################### + +/// Check that the warning is thrown when the libomptarget bitcode library is not found. +/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should never exist. +// RUN: LIBRARY_PATH= %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \ +// RUN: -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps \ +// RUN: -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB-WARN %s + +// CHK-BCLIB-WARN: Expect degraded performance on the target device due to missing 'libomptarget-nvptx-sm_20.bc' in LIBRARY_PATH. Index: lib/Driver/ToolChains/Cuda.cpp =================================================================== --- lib/Driver/ToolChains/Cuda.cpp +++ lib/Driver/ToolChains/Cuda.cpp @@ -529,6 +529,36 @@ CC1Args.push_back("-target-feature"); CC1Args.push_back("+ptx42"); } + + if (DeviceOffloadingKind == Action::OFK_OpenMP) { + SmallVector<std::string, 8> LibraryPaths; + if (char *env = ::getenv("LIBRARY_PATH")) { + StringRef CompilerPath = env; + while (!CompilerPath.empty()) { + std::pair<StringRef, StringRef> Split = + CompilerPath.split(llvm::sys::EnvPathSeparator); + LibraryPaths.push_back(Split.first); + CompilerPath = Split.second; + } + } + + std::string LibOmpTargetName = + "libomptarget-nvptx-" + GpuArch.str() + ".bc"; + bool FoundBCLibrary = false; + for (std::string LibraryPath : LibraryPaths) { + SmallString<128> LibOmpTargetFile(LibraryPath); + llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName); + if (llvm::sys::fs::exists(LibOmpTargetFile)) { + CC1Args.push_back("-mlink-cuda-bitcode"); + CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile)); + FoundBCLibrary = true; + break; + } + } + if (!FoundBCLibrary) + getDriver().Diag(diag::remark_drv_omp_offload_target_missingbcruntime) + << LibOmpTargetName; + } } void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs, Index: include/clang/Basic/DiagnosticDriverKinds.td =================================================================== --- include/clang/Basic/DiagnosticDriverKinds.td +++ include/clang/Basic/DiagnosticDriverKinds.td @@ -196,6 +196,9 @@ def warn_drv_omp_offload_target_duplicate : Warning< "The OpenMP offloading target '%0' is similar to target '%1' already specified - will be ignored.">, InGroup<OpenMPTarget>; +def remark_drv_omp_offload_target_missingbcruntime : Warning< + "Expect degraded performance on the target device due to missing '%0' in LIBRARY_PATH.">, + InGroup<OpenMPTarget>; def err_drv_bitcode_unsupported_on_toolchain : Error< "-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
Index: test/Driver/openmp-offload-gpu.c =================================================================== --- test/Driver/openmp-offload-gpu.c +++ test/Driver/openmp-offload-gpu.c @@ -142,3 +142,24 @@ // RUN: | FileCheck -check-prefix=CHK-NOLIBDEVICE %s // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60 + +/// ########################################################################### + +/// Check that the runtime bitcode library is part of the compile line. Create a bogus +/// bitcode library that will be found via the LIBRARY_PATH. +// RUN: touch /tmp/libomptarget-nvptx-sm_60.bc +// RUN: LIBRARY_PATH=/tmp %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \ +// RUN: -Xopenmp-target -march=sm_60 -fopenmp-relocatable-target -save-temps \ +// RUN: -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB %s + +// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-cuda-bitcode{{.*}}libomptarget-nvptx-sm_60.bc + +/// ########################################################################### + +/// Check that the warning is thrown when the libomptarget bitcode library is not found. +/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should never exist. +// RUN: LIBRARY_PATH= %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \ +// RUN: -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps \ +// RUN: -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB-WARN %s + +// CHK-BCLIB-WARN: Expect degraded performance on the target device due to missing 'libomptarget-nvptx-sm_20.bc' in LIBRARY_PATH. Index: lib/Driver/ToolChains/Cuda.cpp =================================================================== --- lib/Driver/ToolChains/Cuda.cpp +++ lib/Driver/ToolChains/Cuda.cpp @@ -529,6 +529,36 @@ CC1Args.push_back("-target-feature"); CC1Args.push_back("+ptx42"); } + + if (DeviceOffloadingKind == Action::OFK_OpenMP) { + SmallVector<std::string, 8> LibraryPaths; + if (char *env = ::getenv("LIBRARY_PATH")) { + StringRef CompilerPath = env; + while (!CompilerPath.empty()) { + std::pair<StringRef, StringRef> Split = + CompilerPath.split(llvm::sys::EnvPathSeparator); + LibraryPaths.push_back(Split.first); + CompilerPath = Split.second; + } + } + + std::string LibOmpTargetName = + "libomptarget-nvptx-" + GpuArch.str() + ".bc"; + bool FoundBCLibrary = false; + for (std::string LibraryPath : LibraryPaths) { + SmallString<128> LibOmpTargetFile(LibraryPath); + llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName); + if (llvm::sys::fs::exists(LibOmpTargetFile)) { + CC1Args.push_back("-mlink-cuda-bitcode"); + CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile)); + FoundBCLibrary = true; + break; + } + } + if (!FoundBCLibrary) + getDriver().Diag(diag::remark_drv_omp_offload_target_missingbcruntime) + << LibOmpTargetName; + } } void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs, Index: include/clang/Basic/DiagnosticDriverKinds.td =================================================================== --- include/clang/Basic/DiagnosticDriverKinds.td +++ include/clang/Basic/DiagnosticDriverKinds.td @@ -196,6 +196,9 @@ def warn_drv_omp_offload_target_duplicate : Warning< "The OpenMP offloading target '%0' is similar to target '%1' already specified - will be ignored.">, InGroup<OpenMPTarget>; +def remark_drv_omp_offload_target_missingbcruntime : Warning< + "Expect degraded performance on the target device due to missing '%0' in LIBRARY_PATH.">, + InGroup<OpenMPTarget>; def err_drv_bitcode_unsupported_on_toolchain : Error< "-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits