- Add openmp-Remove-omptarget-soname.patch to fix rpmlint issue: Upstream decided to remove the soname from libomptarget.so (the interface is apparently not stable yet), so we can still package it in libomp-devel if we port that back. OBS-URL: https://build.opensuse.org/request/show/993563 OBS-URL: https://build.opensuse.org/package/show/devel:tools:compiler/llvm12?expand=0&rev=14
239 lines
9.5 KiB
Diff
239 lines
9.5 KiB
Diff
From f2f88f3e7a110b2d4d9da446e45f0dba040e62b2 Mon Sep 17 00:00:00 2001
|
|
From: Vyacheslav Zakharin <vyacheslav.p.zakharin@intel.com>
|
|
Date: Fri, 7 May 2021 12:42:04 -0700
|
|
Subject: [PATCH] An attempt to abandon omptarget out-of-tree builds.
|
|
|
|
I want to start using LLVM component libraries in libomptarget
|
|
to stop duplicating implementations already available in LLVM
|
|
(e.g. LLVMObject, LLVMSupport, etc.). Without relying on LLVM
|
|
in all libomptarget builds one has to provide fallback implementation
|
|
for each used LLVM feature.
|
|
|
|
This is an attempt to stop supporting out-of-llvm-tree builds of libomptarget.
|
|
|
|
I understand that I may need to revert this,
|
|
if this affects downstream projects in a bad way.
|
|
|
|
Differential Revision: https://reviews.llvm.org/D101509
|
|
|
|
NOTE: Rebased past e.g. https://reviews.llvm.org/D95572 and other changes.
|
|
---
|
|
openmp/CMakeLists.txt | 16 -------
|
|
openmp/README.rst | 9 ++++
|
|
.../Modules/LibomptargetGetDependencies.cmake | 44 ++++++++---------
|
|
.../deviceRTLs/amdgcn/CMakeLists.txt | 47 +++++++------------
|
|
openmp/libomptarget/src/CMakeLists.txt | 32 +++++--------
|
|
5 files changed, 57 insertions(+), 91 deletions(-)
|
|
|
|
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
|
|
index b8a2822877e3..45c400351f32 100644
|
|
--- a/openmp/CMakeLists.txt
|
|
+++ b/openmp/CMakeLists.txt
|
|
@@ -39,8 +39,6 @@ else()
|
|
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
|
|
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
|
|
endif()
|
|
-
|
|
- list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include)
|
|
endif()
|
|
|
|
# Check and set up common compiler flags.
|
|
@@ -63,20 +61,6 @@ if (APPLE OR WIN32 OR NOT OPENMP_HAVE_STD_CPP14_FLAG)
|
|
set(ENABLE_LIBOMPTARGET OFF)
|
|
endif()
|
|
|
|
-# Attempt to locate LLVM source, required by libomptarget
|
|
-if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
|
|
- if (LLVM_MAIN_INCLUDE_DIR)
|
|
- list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR})
|
|
- elseif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include)
|
|
- list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include)
|
|
- endif()
|
|
-endif()
|
|
-
|
|
-if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
|
|
- message(STATUS "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS, disabling libomptarget")
|
|
- set(ENABLE_LIBOMPTARGET OFF)
|
|
-endif()
|
|
-
|
|
option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
|
|
${ENABLE_LIBOMPTARGET})
|
|
option(OPENMP_ENABLE_LIBOMPTARGET_PROFILING "Enable time profiling for libomptarget."
|
|
diff --git a/openmp/README.rst b/openmp/README.rst
|
|
index 59301c513d59..bd8071f43f95 100644
|
|
--- a/openmp/README.rst
|
|
+++ b/openmp/README.rst
|
|
@@ -243,6 +243,15 @@ These flags are **appended**, they do not overwrite any of the preset flags.
|
|
Options for ``libomptarget``
|
|
----------------------------
|
|
|
|
+An installed LLVM package is a prerequisite for building ``libomptarget``
|
|
+library. So ``libomptarget`` may only be built in two cases:
|
|
+
|
|
+- As a project of a regular LLVM build via **LLVM_ENABLE_PROJECTS**,
|
|
+ **LLVM_EXTERNAL_PROJECTS**, or **LLVM_ENABLE_RUNTIMES** or
|
|
+- as a standalone project build that uses a pre-installed LLVM package.
|
|
+ In this mode one has to make sure that the default CMake
|
|
+ ``find_package(LLVM)`` call `succeeds <https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure>`_.
|
|
+
|
|
**LIBOMPTARGET_OPENMP_HEADER_FOLDER** = ``""``
|
|
Path of the folder that contains ``omp.h``. This is required for testing
|
|
out-of-tree builds.
|
|
diff --git a/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake b/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
|
|
index bc3c5d2d4a41..73ab8023773c 100644
|
|
--- a/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
|
|
+++ b/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
|
|
@@ -19,6 +19,25 @@
|
|
|
|
include (FindPackageHandleStandardArgs)
|
|
|
|
+################################################################################
|
|
+# Looking for LLVM...
|
|
+################################################################################
|
|
+
|
|
+if (OPENMP_STANDALONE_BUILD)
|
|
+ # Complete LLVM package is required for building libomptarget
|
|
+ # in an out-of-tree mode.
|
|
+ find_package(LLVM REQUIRED)
|
|
+ message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
|
|
+ message(STATUS "Using LLVM in: ${LLVM_DIR}")
|
|
+ list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS})
|
|
+ list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR})
|
|
+ include(AddLLVM)
|
|
+else()
|
|
+ list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS
|
|
+ ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include
|
|
+ )
|
|
+endif()
|
|
+
|
|
################################################################################
|
|
# Looking for libelf...
|
|
################################################################################
|
|
diff --git a/openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt b/openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt
|
|
index ce5e5b820d0f..c6183c56c9da 100644
|
|
--- a/openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt
|
|
+++ b/openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt
|
|
@@ -10,33 +10,20 @@
|
|
#
|
|
##===----------------------------------------------------------------------===##
|
|
|
|
-find_package(LLVM QUIET CONFIG
|
|
- PATHS
|
|
- $ENV{AOMP}
|
|
- $ENV{HOME}/rocm/aomp
|
|
- /opt/rocm/aomp
|
|
- /usr/lib/rocm/aomp
|
|
- ${LIBOMPTARGET_NVPTX_CUDA_COMPILER_DIR}
|
|
- ${LIBOMPTARGET_NVPTX_CUDA_LINKER_DIR}
|
|
- ${CMAKE_CXX_COMPILER_DIR}
|
|
- NO_DEFAULT_PATH)
|
|
-
|
|
-if (LLVM_DIR)
|
|
- libomptarget_say("Found LLVM ${LLVM_PACKAGE_VERSION}. Configure: ${LLVM_DIR}/LLVMConfig.cmake")
|
|
-else()
|
|
- libomptarget_say("Not building AMDGCN device RTL: AOMP not found")
|
|
- return()
|
|
-endif()
|
|
-
|
|
-set(AOMP_INSTALL_PREFIX ${LLVM_INSTALL_PREFIX})
|
|
-
|
|
-if (AOMP_INSTALL_PREFIX)
|
|
- set(AOMP_BINDIR ${AOMP_INSTALL_PREFIX}/bin)
|
|
-else()
|
|
- set(AOMP_BINDIR ${LLVM_BUILD_BINARY_DIR}/bin)
|
|
-endif()
|
|
-
|
|
-libomptarget_say("Building AMDGCN device RTL. LLVM_COMPILER_PATH=${AOMP_BINDIR}")
|
|
+if (LLVM_DIR)
|
|
+ # Builds that use pre-installed LLVM have LLVM_DIR set.
|
|
+ find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
|
|
+ find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR}
|
|
+ NO_DEFAULT_PATH)
|
|
+ find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
|
|
+ libomptarget_say("Building AMDGCN device RTL. Using clang: ${CLANG_TOOL}")
|
|
+else()
|
|
+ # LLVM in-tree builds may use CMake target names to discover the tools.
|
|
+ set(CLANG_TOOL $<TARGET_FILE:clang>)
|
|
+ set(LINK_TOOL $<TARGET_FILE:llvm-link>)
|
|
+ set(OPT_TOOL $<TARGET_FILE:opt>)
|
|
+ libomptarget_say("Building AMDGCN device RTL. Using clang from in-tree build")
|
|
+endif()
|
|
|
|
project(omptarget-amdgcn)
|
|
|
|
@@ -109,7 +96,7 @@ if (DEFINED LIBOMPTARGET_AMDGCN_GFXLIST)
|
|
endif()
|
|
|
|
macro(add_cuda_bc_library)
|
|
- set(cu_cmd ${AOMP_BINDIR}/clang++
|
|
+ set(cu_cmd ${CLANG_TOOL}
|
|
-std=c++14
|
|
-fcuda-rdc
|
|
-fvisibility=default
|
|
@@ -145,7 +132,7 @@ macro(add_cuda_bc_library)
|
|
|
|
add_custom_command(
|
|
OUTPUT linkout.cuda.${mcpu}.bc
|
|
- COMMAND ${AOMP_BINDIR}/llvm-link ${bc1_files} -o linkout.cuda.${mcpu}.bc
|
|
+ COMMAND ${LINK_TOOL} ${bc1_files} -o linkout.cuda.${mcpu}.bc
|
|
DEPENDS ${bc1_files})
|
|
|
|
list(APPEND bc_files linkout.cuda.${mcpu}.bc)
|
|
@@ -160,7 +147,7 @@ foreach(mcpu ${mcpus})
|
|
set(bc_libname lib${libname}-${mcpu}.bc)
|
|
add_custom_command(
|
|
OUTPUT ${bc_libname}
|
|
- COMMAND ${AOMP_BINDIR}/llvm-link ${bc_files} | ${AOMP_BINDIR}/opt --always-inline -o ${OUTPUTDIR}/${bc_libname}
|
|
+ COMMAND ${LINK_TOOL} ${bc_files} | ${OPT_TOOL} --always-inline -o ${OUTPUTDIR}/${bc_libname}
|
|
DEPENDS ${bc_files})
|
|
|
|
add_custom_target(lib${libname}-${mcpu} ALL DEPENDS ${bc_libname})
|
|
diff --git a/openmp/libomptarget/src/CMakeLists.txt b/openmp/libomptarget/src/CMakeLists.txt
|
|
index 15e6c3bbaf1f..46387e203bd0 100644
|
|
--- a/openmp/libomptarget/src/CMakeLists.txt
|
|
+++ b/openmp/libomptarget/src/CMakeLists.txt
|
|
@@ -24,29 +24,19 @@ set(LIBOMPTARGET_SRC_FILES ${LIBOMPTARGET_SRC_FILES} PARENT_SCOPE)
|
|
|
|
include_directories(${LIBOMPTARGET_LLVM_INCLUDE_DIRS})
|
|
|
|
-# Build libomptarget library with libdl dependency. Add LLVMSupport
|
|
-# dependency if building in-tree with profiling enabled.
|
|
-if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMPTARGET_PROFILING))
|
|
- add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES})
|
|
- target_link_libraries(omptarget
|
|
- ${CMAKE_DL_LIBS}
|
|
- "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
|
|
-else()
|
|
- set(LLVM_LINK_COMPONENTS
|
|
- Support
|
|
- )
|
|
- add_llvm_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES}
|
|
- LINK_LIBS ${CMAKE_DL_LIBS}
|
|
- "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports"
|
|
- )
|
|
+# Build libomptarget library with libdl dependency.
|
|
+add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES})
|
|
+if (OPENMP_ENABLE_LIBOMPTARGET_PROFILING)
|
|
+ # Add LLVMSupport dependency if profiling is enabled.
|
|
+ # Linking with LLVM component libraries also requires
|
|
+ # aligning the compile flags.
|
|
+ llvm_update_compile_flags(omptarget)
|
|
target_compile_definitions(omptarget PUBLIC OMPTARGET_PROFILE_ENABLED)
|
|
+ target_link_libraries(omptarget PRIVATE LLVMSupport)
|
|
endif()
|
|
-
|
|
-# libomptarget needs to be set separately because add_llvm_library doesn't
|
|
-# conform with location configuration of its parent scope.
|
|
-set_target_properties(omptarget
|
|
- PROPERTIES
|
|
- LIBRARY_OUTPUT_DIRECTORY ${LIBOMPTARGET_LIBRARY_DIR})
|
|
+target_link_libraries(omptarget PRIVATE
|
|
+ ${CMAKE_DL_LIBS}
|
|
+ "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
|
|
|
|
# Install libomptarget under the lib destination folder.
|
|
install(TARGETS omptarget LIBRARY COMPONENT omptarget
|
|
--
|
|
2.37.1
|
|
|