[llvm-branch-commits] [llvm] [19.x] Backport standalone build fixes for offload (PR #118643)

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 17 01:09:05 PST 2024


=?utf-8?q?Michał_Górny?= <mgorny at gentoo.org>,
=?utf-8?q?Michał_Górny?= <mgorny at gentoo.org>,
=?utf-8?q?Michał_Górny?= <mgorny at gentoo.org>,
=?utf-8?q?Michał_Górny?= <mgorny at gentoo.org>,
=?utf-8?q?Michał_Górny?= <mgorny at gentoo.org>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/118643 at github.com>


https://github.com/tru updated https://github.com/llvm/llvm-project/pull/118643

>From be6e2e72cb51f95c852e6d6567c8b2d066dfd19e Mon Sep 17 00:00:00 2001
From: estewart08 <ethan.stewart at amd.com>
Date: Mon, 19 Aug 2024 17:59:21 -0500
Subject: [PATCH 1/6] [offload] - Fix issue with standalone debug offload build
 (#104647)

Error: CommandLine Error: Option 'attributor-manifest-internal'
registered more than once

During the standalone debug build of offload the above error is seen at
app runtime when using a prebuilt llvm with LLVM_LINK_LLVM_DYLIB=ON.
This is caused by linking both libLLVM.so and various archives that are
found via llvm_map_components_to_libnames for jit support.
---
 offload/plugins-nextgen/common/CMakeLists.txt | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/offload/plugins-nextgen/common/CMakeLists.txt b/offload/plugins-nextgen/common/CMakeLists.txt
index 284f98875170cd..aea20c6ec31435 100644
--- a/offload/plugins-nextgen/common/CMakeLists.txt
+++ b/offload/plugins-nextgen/common/CMakeLists.txt
@@ -11,13 +11,15 @@ add_dependencies(PluginCommon intrinsics_gen)
 
 # Only enable JIT for those targets that LLVM can support.
 set(supported_jit_targets AMDGPU NVPTX)
-foreach(target IN LISTS supported_jit_targets)
-  if("${target}" IN_LIST LLVM_TARGETS_TO_BUILD)
-	  target_compile_definitions(PluginCommon PRIVATE "LIBOMPTARGET_JIT_${target}")
-    llvm_map_components_to_libnames(llvm_libs ${target})
-    target_link_libraries(PluginCommon PRIVATE ${llvm_libs})
-  endif()
-endforeach()
+if (NOT LLVM_LINK_LLVM_DYLIB)
+  foreach(target IN LISTS supported_jit_targets)
+    if("${target}" IN_LIST LLVM_TARGETS_TO_BUILD)
+      target_compile_definitions(PluginCommon PRIVATE "LIBOMPTARGET_JIT_${target}")
+      llvm_map_components_to_libnames(llvm_libs ${target})
+      target_link_libraries(PluginCommon PRIVATE ${llvm_libs})
+    endif()
+  endforeach()
+endif()
 
 # Include the RPC server from the `libc` project if availible.
 if(TARGET llvmlibc_rpc_server AND ${LIBOMPTARGET_GPU_LIBC_SUPPORT})

>From e3b2d0149ffadef53fe8165f55e648466c025416 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sat, 30 Nov 2024 12:32:57 +0100
Subject: [PATCH 2/6] [offload] Include CheckCXXCompilerFlag in CMake

Include CheckCXXCompilerFlag before it is used in the top-level CMake
file.  This fixes standalone builds, but it is also cleaner than
assuming that some previous CMake file will include it for us.
---
 offload/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index 4cd97a6a5ff63d..3ba892c76c8b8e 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -127,6 +127,7 @@ include(LibomptargetGetDependencies)
 # Set up testing infrastructure.
 include(OpenMPTesting)
 
+include(CheckCXXCompilerFlag)
 check_cxx_compiler_flag(-Werror=global-constructors OFFLOAD_HAVE_WERROR_CTOR)
 
 # LLVM source tree is required at build time for libomptarget

>From 5ce79b5045ae2e362fbd7b28351b10634d05b0f5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sat, 30 Nov 2024 15:32:39 +0100
Subject: [PATCH 3/6] [offload] [test] Add "omp" test dependency only when
 present

Add the `omp` target dependency to tests only when the respective target
is present, i.e. when not building standalone against system libomp.
---
 offload/test/CMakeLists.txt | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/offload/test/CMakeLists.txt b/offload/test/CMakeLists.txt
index 3ac5d7907e2cc2..c90ed26389faf6 100644
--- a/offload/test/CMakeLists.txt
+++ b/offload/test/CMakeLists.txt
@@ -22,6 +22,11 @@ if(CUDAToolkit_FOUND)
   get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
 endif()
 
+set(OMP_DEPEND)
+if(TARGET omp)
+  set(OMP_DEPEND omp)
+endif()
+
 string(REGEX MATCHALL "([^\ ]+\ |[^\ ]+$)" SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}")
 foreach(CURRENT_TARGET IN LISTS SYSTEM_TARGETS)
   string(STRIP "${CURRENT_TARGET}" CURRENT_TARGET)
@@ -29,7 +34,7 @@ foreach(CURRENT_TARGET IN LISTS SYSTEM_TARGETS)
   add_offload_testsuite(check-libomptarget-${CURRENT_TARGET}
     "Running libomptarget tests"
     ${CMAKE_CURRENT_BINARY_DIR}/${CURRENT_TARGET}
-    DEPENDS omptarget omp ${LIBOMPTARGET_TESTED_PLUGINS}
+    DEPENDS omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
     ARGS ${LIBOMPTARGET_LIT_ARG_LIST})
   list(APPEND LIBOMPTARGET_LIT_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CURRENT_TARGET})
 
@@ -43,12 +48,12 @@ add_offload_testsuite(check-libomptarget
   "Running libomptarget tests"
   ${LIBOMPTARGET_LIT_TESTSUITES}
   EXCLUDE_FROM_CHECK_ALL
-  DEPENDS omptarget omp ${LIBOMPTARGET_TESTED_PLUGINS}
+  DEPENDS omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
   ARGS ${LIBOMPTARGET_LIT_ARG_LIST})
 
 add_offload_testsuite(check-offload
   "Running libomptarget tests"
   ${LIBOMPTARGET_LIT_TESTSUITES}
   EXCLUDE_FROM_CHECK_ALL
-  DEPENDS omptarget omp ${LIBOMPTARGET_TESTED_PLUGINS}
+  DEPENDS omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
   ARGS ${LIBOMPTARGET_LIT_ARG_LIST})

>From 909104bb5a0540a3bffaa4a816efc1c54be81969 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sat, 30 Nov 2024 15:39:53 +0100
Subject: [PATCH 4/6] [offload] Define OPENMP_TEST*_FLAGS in standalone builds

Copy the `OPENMP_TEST_FLAGS` and `OPENMP_TEST_OPENMP_FLAGS` from openmp
for standalone builds, as required by the lit configs.
---
 offload/CMakeLists.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index 3ba892c76c8b8e..752434c6a28e1d 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -283,6 +283,11 @@ if(OPENMP_STANDALONE_BUILD)
       ${LLVM_LIBRARY_DIRS}
     REQUIRED
   )
+
+  set(OPENMP_TEST_FLAGS "" CACHE STRING
+    "Extra compiler flags to send to the test compiler.")
+  set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
+    "OpenMP compiler flag to use for testing OpenMP runtime libraries.")
 endif()
 
 macro(pythonize_bool var)

>From b70bf59262cbae12728bd866506debff5c89eb4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sat, 30 Nov 2024 15:44:37 +0100
Subject: [PATCH 5/6] [offload] Define LIBOMPTARGET_OPENMP_*_FOLDER in
 standalone builds

Define `LIBOMPTARGET_OPENMP_HEADER_FOLDER`
and `LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER` needed for testing
in standalone builds.
---
 offload/CMakeLists.txt | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index 752434c6a28e1d..959d6260bc7490 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -284,10 +284,25 @@ if(OPENMP_STANDALONE_BUILD)
     REQUIRED
   )
 
+  find_path (
+    LIBOMP_INCLUDE_DIR
+    NAMES
+      omp.h
+    HINTS
+    ${COMPILER_RESOURCE_DIR}/include
+    ${CMAKE_INSTALL_PREFIX}/include
+  )
+
+  get_filename_component(LIBOMP_LIBRARY_DIR ${LIBOMP_STANDALONE} DIRECTORY)
+
   set(OPENMP_TEST_FLAGS "" CACHE STRING
     "Extra compiler flags to send to the test compiler.")
   set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
     "OpenMP compiler flag to use for testing OpenMP runtime libraries.")
+  set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMP_INCLUDE_DIR}" CACHE STRING
+    "Path to folder containing omp.h")
+  set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR}" CACHE STRING
+    "Path to folder containing libomp.so, and libLLVMSupport.so with profiling enabled")
 endif()
 
 macro(pythonize_bool var)

>From 2384a062fc1cc9d115c537f0cfe36ae6028e7bfd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sun, 1 Dec 2024 16:26:46 +0100
Subject: [PATCH 6/6] [cmake] Use DetectTestCompiler from openmp directory

Fix the DetectTestCompiler project use to reference the openmp source
tree, since the respective files were not copied to offload, and there
is no point in duplicating them.

Fixes #90333
---
 offload/cmake/OpenMPTesting.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/offload/cmake/OpenMPTesting.cmake b/offload/cmake/OpenMPTesting.cmake
index 11eafeb764260f..3e04a3423c4d64 100644
--- a/offload/cmake/OpenMPTesting.cmake
+++ b/offload/cmake/OpenMPTesting.cmake
@@ -124,7 +124,7 @@ if (${OPENMP_STANDALONE_BUILD})
   # project is built which is too late for detecting the compiler...
   file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler)
   execute_process(
-    COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/DetectTestCompiler
+    COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${CMAKE_CURRENT_SOURCE_DIR}/../openmp/cmake/DetectTestCompiler
       -DCMAKE_C_COMPILER=${OPENMP_TEST_C_COMPILER}
       -DCMAKE_CXX_COMPILER=${OPENMP_TEST_CXX_COMPILER}
     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler



More information about the llvm-branch-commits mailing list