Skip to content

Commit 7282975

Browse files
authored
[Libomptarget] Explicitly pass the OpenMP device libraries to tests (#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: #68220 Fixes #68141
1 parent 2d4d8c8 commit 7282975

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

openmp/libomptarget/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ if("libc" IN_LIST LLVM_ENABLE_RUNTIMES AND (LIBC_GPU_BUILD OR
9595
LIBC_GPU_ARCHITECTURES))
9696
set(LIBC_GPU_SUPPORT TRUE)
9797
endif()
98+
99+
# Find the path of the GPU libc static library.
100+
find_library(GPU_LIBC_PATH NAMES cgpu
101+
PATHS ${LIBOMPTARGET_LLVM_LIBRARY_DIR} NO_DEFAULT_PATH)
102+
if((NOT GPU_LIBC_PATH) OR (NOT LIBC_GPU_SUPPORT))
103+
set(GPU_LIBC_PATH "")
104+
endif()
105+
106+
set(LIBOMPTARGET_GPU_LIBC_PATH ${GPU_LIBC_PATH} CACHE STRING
107+
"Location of the 'libcgpu.a' library ")
98108
set(LIBOMPTARGET_GPU_LIBC_SUPPORT ${LIBC_GPU_SUPPORT} CACHE BOOL
99109
"Libomptarget support for the GPU libc")
100110
pythonize_bool(LIBOMPTARGET_GPU_LIBC_SUPPORT)

openmp/libomptarget/test/lit.cfg

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ elif config.operating_system == 'Darwin':
128128
config.test_flags += " -Wl,-rpath," + config.library_dir
129129
config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory
130130
else: # Unices
131+
config.test_flags += " -nogpulib"
131132
config.test_flags += " -Wl,-rpath," + config.library_dir
132133
config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory
133134
config.test_flags += " -Wl,-rpath," + config.llvm_lib_directory
@@ -151,6 +152,10 @@ def remove_suffix_if_present(name):
151152
else:
152153
return name
153154

155+
def add_libraries(source):
156+
return source + " " + config.libomptarget_libc_path + " " + \
157+
config.library_dir + "/libomptarget.devicertl.a"
158+
154159
# substitutions
155160
# - for targets that exist in the system create the actual command.
156161
# - 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:
229234
"%libomptarget-run-" + libomptarget_target))
230235
config.substitutions.append(("%libomptarget-compilexx-" + \
231236
libomptarget_target, \
232-
"%clangxx-" + libomptarget_target + " %s -o %t" + \
233-
(" -lcgpu" if config.libomptarget_has_libc else "")))
237+
"%clangxx-" + libomptarget_target + add_libraries(" %s -o %t")))
234238
config.substitutions.append(("%libomptarget-compile-" + \
235239
libomptarget_target, \
236-
"%clang-" + libomptarget_target + " %s -o %t" +
237-
(" -lcgpu" if config.libomptarget_has_libc else "")))
240+
"%clang-" + libomptarget_target + add_libraries(" %s -o %t")))
238241
config.substitutions.append(("%libomptarget-compile-fortran-" + \
239242
libomptarget_target, \
240243
"%flang-" + libomptarget_target + " %s -o %t"))
@@ -256,12 +259,10 @@ for libomptarget_target in config.libomptarget_all_targets:
256259
"%libomptarget-run-" + libomptarget_target))
257260
config.substitutions.append(("%libomptarget-compileoptxx-" + \
258261
libomptarget_target, \
259-
"%clangxx-" + libomptarget_target + " -O3 %s -o %t" +
260-
(" -lcgpu" if config.libomptarget_has_libc else "")))
262+
"%clangxx-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))
261263
config.substitutions.append(("%libomptarget-compileopt-" + \
262264
libomptarget_target, \
263-
"%clang-" + libomptarget_target + " -O3 %s -o %t" +
264-
(" -lcgpu" if config.libomptarget_has_libc else "")))
265+
"%clang-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))
265266
config.substitutions.append(("%libomptarget-run-" + \
266267
libomptarget_target, \
267268
"%t"))

openmp/libomptarget/test/lit.site.cfg.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ config.libomptarget_not = "@OPENMP_NOT_EXECUTABLE@"
2323
config.libomptarget_debug = @LIBOMPTARGET_DEBUG@
2424
config.has_libomptarget_ompt = @LIBOMPTARGET_OMPT_SUPPORT@
2525
config.libomptarget_has_libc = @LIBOMPTARGET_GPU_LIBC_SUPPORT@
26+
config.libomptarget_libc_path = "@LIBOMPTARGET_GPU_LIBC_PATH@"
2627

2728
# Let the main config do the real work.
2829
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")

0 commit comments

Comments
 (0)