[llvm] [offload] Standalone build fixes (PR #118173)
Michał Górny via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 4 03:21:10 PST 2024
https://github.com/mgorny updated https://github.com/llvm/llvm-project/pull/118173
>From 8d221f65a00eef76577f0762001f6d4be34bde59 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 1/8] [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 e24f0faa912117..b464de16e8bc6d 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -129,6 +129,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 369c35f6e8a44aac59ebd2be8639e2dad9206a34 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 2/8] [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 5a6f637b57fa7b..f8bb7b60475d65 100644
--- a/offload/test/CMakeLists.txt
+++ b/offload/test/CMakeLists.txt
@@ -28,6 +28,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)
@@ -35,7 +40,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})
@@ -49,12 +54,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 447dc198ee8fb61e1d6f8ab7ec07dd46dc03b1ed 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 3/8] [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 b464de16e8bc6d..9dd988713de1f8 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -287,6 +287,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 3ad5b3bac7e9131b3328e45e508eb62e2df07737 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 4/8] [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 9dd988713de1f8..572a1cb77fbbb4 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -288,10 +288,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 b71f0f4a31fd086c42de893ef6ef647092da4a88 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:53:36 +0100
Subject: [PATCH 5/8] [offload] Fix path to llvm-offload-device-info in
standalone build
Fix path to `llvm-offload-device-info` tool in standalone build.
This tool is built as part of offload, so rather than looking it up
as a preinstalled tool, set correct `LLVM_RUNTIME_OUTPUT_INTDIR`
for the `llvm_add_tool()` call, and unconditionally set
`OFFLOAD_DEVICE_INFO_EXECUTABLE` using that directory.
---
offload/CMakeLists.txt | 3 +++
offload/cmake/OpenMPTesting.cmake | 13 +------------
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index 572a1cb77fbbb4..2d2413688183bc 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -64,6 +64,9 @@ if (OPENMP_STANDALONE_BUILD)
# Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}")
+ # Used by llvm_add_tool() and tests.
+ set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR})
+
# Group test settings.
set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
"C compiler to use for testing OpenMP runtime libraries.")
diff --git a/offload/cmake/OpenMPTesting.cmake b/offload/cmake/OpenMPTesting.cmake
index 6609d6301d0f93..567848a531bbc9 100644
--- a/offload/cmake/OpenMPTesting.cmake
+++ b/offload/cmake/OpenMPTesting.cmake
@@ -37,17 +37,6 @@ function(find_standalone_test_dependencies)
return()
endif()
- find_program(OFFLOAD_DEVICE_INFO_EXECUTABLE
- NAMES llvm-offload-device-info
- PATHS ${OPENMP_LLVM_TOOLS_DIR})
- if (NOT OFFLOAD_DEVICE_INFO_EXECUTABLE)
- message(STATUS "Cannot find 'llvm-offload-device-info'.")
- message(STATUS "Please put 'not' in your PATH, set OFFLOAD_DEVICE_INFO_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
- message(WARNING "The check targets will not be available!")
- set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
- return()
- endif()
-
find_program(OPENMP_NOT_EXECUTABLE
NAMES not
PATHS ${OPENMP_LLVM_TOOLS_DIR})
@@ -82,8 +71,8 @@ else()
set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck)
endif()
set(OPENMP_NOT_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/not)
- set(OFFLOAD_DEVICE_INFO_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-offload-device-info)
endif()
+set(OFFLOAD_DEVICE_INFO_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-offload-device-info)
# Macro to extract information about compiler from file. (no own scope)
macro(extract_test_compiler_information lang file)
>From 80887129f01186caf64af20a9cb3d70ae81298f4 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 17:50:05 +0100
Subject: [PATCH 6/8] [offload] [test] Add missing dependency on
llvm-offload-device-info
---
offload/test/CMakeLists.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/offload/test/CMakeLists.txt b/offload/test/CMakeLists.txt
index f8bb7b60475d65..8a827e0a625eff 100644
--- a/offload/test/CMakeLists.txt
+++ b/offload/test/CMakeLists.txt
@@ -54,12 +54,12 @@ add_offload_testsuite(check-libomptarget
"Running libomptarget tests"
${LIBOMPTARGET_LIT_TESTSUITES}
EXCLUDE_FROM_CHECK_ALL
- DEPENDS omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
+ DEPENDS llvm-offload-device-info 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_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
+ DEPENDS llvm-offload-device-info omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
ARGS ${LIBOMPTARGET_LIT_ARG_LIST})
>From dcdf3fbaea547700afe89a4c5dbf97b8400ca89b 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:20:25 +0100
Subject: [PATCH 7/8] [offload] Move additional plugin dependencies to
add_target_library
Move the dependencies on `LLVMFrontendOffloading` and `LLVMProfileData`
from amdgpu and common, respectively, to the base `add_target_library()`
macro. This means we can take advantage of LINK_COMPONENTS and do not
have to add extra complexity to handle dylib and standalone builds.
---
offload/plugins-nextgen/CMakeLists.txt | 2 ++
offload/plugins-nextgen/amdgpu/CMakeLists.txt | 3 +--
offload/plugins-nextgen/common/CMakeLists.txt | 3 +--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/offload/plugins-nextgen/CMakeLists.txt b/offload/plugins-nextgen/CMakeLists.txt
index d31bf557669eac..9b5b12bea7142f 100644
--- a/offload/plugins-nextgen/CMakeLists.txt
+++ b/offload/plugins-nextgen/CMakeLists.txt
@@ -12,6 +12,7 @@ function(add_target_library target_name lib_name)
CodeGen
Core
Extensions
+ FrontendOffloading
InstCombine
Instrumentation
IPO
@@ -20,6 +21,7 @@ function(add_target_library target_name lib_name)
MC
Object
Passes
+ ProfileData
Remarks
ScalarOpts
Support
diff --git a/offload/plugins-nextgen/amdgpu/CMakeLists.txt b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
index b40c62d43226f4..47cd2feefc7288 100644
--- a/offload/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -10,12 +10,11 @@ target_include_directories(omptarget.rtl.amdgpu PRIVATE
if(hsa-runtime64_FOUND AND NOT "amdgpu" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS)
message(STATUS "Building AMDGPU plugin linked against libhsa")
- target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64 LLVMFrontendOffloading)
+ target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64)
else()
message(STATUS "Building AMDGPU plugin for dlopened libhsa")
target_include_directories(omptarget.rtl.amdgpu PRIVATE dynamic_hsa)
target_sources(omptarget.rtl.amdgpu PRIVATE dynamic_hsa/hsa.cpp)
- target_link_libraries(omptarget.rtl.amdgpu PRIVATE LLVMFrontendOffloading)
endif()
# Configure testing for the AMDGPU plugin. We will build tests if we could a
diff --git a/offload/plugins-nextgen/common/CMakeLists.txt b/offload/plugins-nextgen/common/CMakeLists.txt
index f9598a1718b3e5..14c48f6ace9710 100644
--- a/offload/plugins-nextgen/common/CMakeLists.txt
+++ b/offload/plugins-nextgen/common/CMakeLists.txt
@@ -7,7 +7,7 @@ add_library(PluginCommon OBJECT
src/RPC.cpp
src/Utils/ELF.cpp
)
-add_dependencies(PluginCommon intrinsics_gen LLVMProfileData)
+add_dependencies(PluginCommon intrinsics_gen)
# Only enable JIT for those targets that LLVM can support.
set(supported_jit_targets AMDGPU NVPTX)
@@ -44,7 +44,6 @@ target_compile_definitions(PluginCommon PRIVATE
target_compile_options(PluginCommon PUBLIC ${offload_compile_flags})
target_link_options(PluginCommon PUBLIC ${offload_link_flags})
-target_link_libraries(PluginCommon PRIVATE LLVMProfileData)
target_include_directories(PluginCommon PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
>From 931cf3c34400272d3f6ba479510da69bc8e2e5f0 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 8/8] [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 567848a531bbc9..a808167eb6bb6c 100644
--- a/offload/cmake/OpenMPTesting.cmake
+++ b/offload/cmake/OpenMPTesting.cmake
@@ -125,7 +125,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-commits
mailing list