[Openmp-commits] [openmp] [Libomptarget] Explicitly pass the OpenMP device libraries to tests (PR #68225)

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Wed Oct 4 07:40:33 PDT 2023


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/68225

Summary:
We have tests that depend on two static libraries
`libomptarget.devicertl.a` and `libcgpu.a`. These are currently
implicitly picked up and searched through the standard path. This patch
changes that to pass `-nogpulib` to disable implicit runtime path
searches. We then explicitly passed the built libraries to the
compilations so that we know exactly which libraries are being used.

Depends on: https://github.com/llvm/llvm-project/pull/68220


>From 5e8393f60cf45949fd5aa3a807195fbc841560d2 Mon Sep 17 00:00:00 2001
From: Joseph Huber <jhuber6 at vols.utk.edu>
Date: Tue, 3 Oct 2023 14:05:27 -0500
Subject: [PATCH] [Libomptarget] Explicitly pass the OpenMP device libraries to
 tests

Summary:
We have tests that depend on two static libraries
`libomptarget.devicertl.a` and `libcgpu.a`. These are currently
implicitly picked up and searched through the standard path. This patch
changes that to pass `-nogpulib` to disable implicit runtime path
searches. We then explicitly passed the built libraries to the
compilations so that we know exactly which libraries are being used.

Depends on: https://github.com/llvm/llvm-project/pull/68220
---
 openmp/libomptarget/CMakeLists.txt       | 10 ++++++++++
 openmp/libomptarget/test/lit.cfg         | 17 +++++++++--------
 openmp/libomptarget/test/lit.site.cfg.in |  1 +
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/openmp/libomptarget/CMakeLists.txt b/openmp/libomptarget/CMakeLists.txt
index 844107b3dade594..0414b1d911523ad 100644
--- a/openmp/libomptarget/CMakeLists.txt
+++ b/openmp/libomptarget/CMakeLists.txt
@@ -95,6 +95,16 @@ if("libc" IN_LIST LLVM_ENABLE_RUNTIMES AND (LIBC_GPU_BUILD OR
                                             LIBC_GPU_ARCHITECTURES))
   set(LIBC_GPU_SUPPORT TRUE)
 endif()
+
+# Find the path of the GPU libc static library.
+find_library(GPU_LIBC_PATH NAMES cgpu
+             PATHS ${LIBOMPTARGET_LLVM_LIBRARY_DIR} NO_DEFAULT_PATH)
+if((NOT GPU_LIBC_PATH) OR (NOT LIBC_GPU_SUPPORT))
+  set(GPU_LIBC_PATH "")
+endif()
+
+set(LIBOMPTARGET_GPU_LIBC_PATH  ${GPU_LIBC_PATH} CACHE STRING
+    "Location of the 'libcgpu.a' library ")
 set(LIBOMPTARGET_GPU_LIBC_SUPPORT ${LIBC_GPU_SUPPORT} CACHE BOOL
     "Libomptarget support for the GPU libc")
 pythonize_bool(LIBOMPTARGET_GPU_LIBC_SUPPORT)
diff --git a/openmp/libomptarget/test/lit.cfg b/openmp/libomptarget/test/lit.cfg
index a53d4e32436de12..323a5b58a2652e4 100644
--- a/openmp/libomptarget/test/lit.cfg
+++ b/openmp/libomptarget/test/lit.cfg
@@ -128,6 +128,7 @@ elif config.operating_system == 'Darwin':
     config.test_flags += " -Wl,-rpath," + config.library_dir
     config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory
 else: # Unices
+    config.test_flags += " -nogpulib"
     config.test_flags += " -Wl,-rpath," + config.library_dir
     config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory
     config.test_flags += " -Wl,-rpath," + config.llvm_lib_directory
@@ -151,6 +152,10 @@ def remove_suffix_if_present(name):
     else:
         return name
 
+def add_libraries(source):
+    return source + " " + config.libomptarget_libc_path + " " + \
+           config.library_dir + "/libomptarget.devicertl.a"
+
 # substitutions
 # - for targets that exist in the system create the actual command.
 # - for valid targets that do not exist in the system, return false, so that the
@@ -229,12 +234,10 @@ for libomptarget_target in config.libomptarget_all_targets:
             "%libomptarget-run-" + libomptarget_target))
         config.substitutions.append(("%libomptarget-compilexx-" + \
             libomptarget_target, \
-            "%clangxx-" + libomptarget_target + " %s -o %t" + \
-            (" -lcgpu" if config.libomptarget_has_libc else "")))
+            "%clangxx-" + libomptarget_target + add_libraries(" %s -o %t")))
         config.substitutions.append(("%libomptarget-compile-" + \
             libomptarget_target, \
-            "%clang-" + libomptarget_target + " %s -o %t" +
-            (" -lcgpu" if config.libomptarget_has_libc else "")))
+            "%clang-" + libomptarget_target + add_libraries(" %s -o %t")))
         config.substitutions.append(("%libomptarget-compile-fortran-" + \
             libomptarget_target, \
             "%flang-" + libomptarget_target + " %s -o %t"))
@@ -256,12 +259,10 @@ for libomptarget_target in config.libomptarget_all_targets:
             "%libomptarget-run-" + libomptarget_target))
         config.substitutions.append(("%libomptarget-compileoptxx-" + \
             libomptarget_target, \
-            "%clangxx-" + libomptarget_target + " -O3 %s -o %t" +
-            (" -lcgpu" if config.libomptarget_has_libc else "")))
+            "%clangxx-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))
         config.substitutions.append(("%libomptarget-compileopt-" + \
             libomptarget_target, \
-            "%clang-" + libomptarget_target + " -O3 %s -o %t" +
-            (" -lcgpu" if config.libomptarget_has_libc else "")))
+            "%clang-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))
         config.substitutions.append(("%libomptarget-run-" + \
             libomptarget_target, \
             "%t"))
diff --git a/openmp/libomptarget/test/lit.site.cfg.in b/openmp/libomptarget/test/lit.site.cfg.in
index 9ee60d6082b77e2..3d345d3012ec3ab 100644
--- a/openmp/libomptarget/test/lit.site.cfg.in
+++ b/openmp/libomptarget/test/lit.site.cfg.in
@@ -23,6 +23,7 @@ config.libomptarget_not = "@OPENMP_NOT_EXECUTABLE@"
 config.libomptarget_debug = @LIBOMPTARGET_DEBUG@
 config.has_libomptarget_ompt = @LIBOMPTARGET_OMPT_SUPPORT@
 config.libomptarget_has_libc = @LIBOMPTARGET_GPU_LIBC_SUPPORT@
+config.libomptarget_libc_path = "@LIBOMPTARGET_GPU_LIBC_PATH@"
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")



More information about the Openmp-commits mailing list