[Openmp-commits] [openmp] a3804a3 - [Libomptarget] Make the plugins link as LLVM libraries
Joseph Huber via Openmp-commits
openmp-commits at lists.llvm.org
Fri Jul 22 06:34:20 PDT 2022
Author: Joseph Huber
Date: 2022-07-22T09:34:12-04:00
New Revision: a3804a3145536b773f734d37d72ac5725ed0a9b3
URL: https://github.com/llvm/llvm-project/commit/a3804a3145536b773f734d37d72ac5725ed0a9b3
DIFF: https://github.com/llvm/llvm-project/commit/a3804a3145536b773f734d37d72ac5725ed0a9b3.diff
LOG: [Libomptarget] Make the plugins link as LLVM libraries
Previously we made `libomptarget` link as an LLVM library so we have
access to the LLVM core libraries. After the initial patch stuck we can
now apply the same changes to the plugins. This will allow us to use
LLVM in all of `libomptarget` when we have uses for them. In the future
this should allow us to remove the dependencies on `libelf`, `libffi`,
and `dl`.
Reviewed By: JonChesterfield
Differential Revision: https://reviews.llvm.org/D130262
Added:
Modified:
openmp/libomptarget/plugins/CMakeLists.txt
openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
openmp/libomptarget/plugins/cuda/CMakeLists.txt
openmp/libomptarget/plugins/ve/CMakeLists.txt
openmp/libomptarget/src/CMakeLists.txt
Removed:
################################################################################
diff --git a/openmp/libomptarget/plugins/CMakeLists.txt b/openmp/libomptarget/plugins/CMakeLists.txt
index c8c484da89500..64c25394150c3 100644
--- a/openmp/libomptarget/plugins/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/CMakeLists.txt
@@ -30,26 +30,38 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "${tmachine}$")
# Define macro with the ELF ID for this target.
add_definitions("-DTARGET_ELF_ID=${elf_machine_id}")
- add_library("omptarget.rtl.${tmachine_libname}" SHARED
- ${CMAKE_CURRENT_SOURCE_DIR}/../generic-elf-64bit/src/rtl.cpp)
+ add_llvm_library("omptarget.rtl.${tmachine_libname}"
+ SHARED
- # Install plugin under the lib destination folder.
- install(TARGETS "omptarget.rtl.${tmachine_libname}"
- LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
+ ${CMAKE_CURRENT_SOURCE_DIR}/../generic-elf-64bit/src/rtl.cpp
- target_include_directories( "omptarget.rtl.${tmachine_libname}" PRIVATE
+ ADDITIONAL_HEADER_DIRS
${LIBOMPTARGET_INCLUDE_DIR}
${LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIR}
- ${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR})
+ ${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR}
- target_link_libraries(
- "omptarget.rtl.${tmachine_libname}"
+ LINK_LIBS
+ PRIVATE
elf_common
${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES}
${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
dl
${OPENMP_PTHREAD_LIB}
- "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports")
+ "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports"
+
+ NO_INSTALL_RPATH
+ )
+
+ # Install plugin under the lib destination folder.
+ install(TARGETS "omptarget.rtl.${tmachine_libname}"
+ LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
+ set_target_properties("omptarget.rtl.${tmachine_libname}" PROPERTIES
+ INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
+
+ target_include_directories( "omptarget.rtl.${tmachine_libname}" PRIVATE
+ ${LIBOMPTARGET_INCLUDE_DIR}
+ ${LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIR}
+ ${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR})
list(APPEND LIBOMPTARGET_TESTED_PLUGINS
"omptarget.rtl.${tmachine_libname}")
diff --git a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
index f658828ef6c48..66bf680d15c79 100644
--- a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
@@ -57,23 +57,6 @@ else()
set(LIBOMPTARGET_DEP_LIBRARIES)
endif()
-add_library(omptarget.rtl.amdgpu SHARED
- impl/impl.cpp
- impl/interop_hsa.cpp
- impl/data.cpp
- impl/get_elf_mach_gfx_name.cpp
- impl/system.cpp
- impl/msgpack.cpp
- src/rtl.cpp
- ${LIBOMPTARGET_EXTRA_SOURCE}
- )
-add_dependencies(omptarget.rtl.amdgpu omptarget.devicertl.amdgpu)
-
-# Install plugin under the lib destination folder.
-# When we build for debug, OPENMP_LIBDIR_SUFFIX get set to -debug
-install(TARGETS omptarget.rtl.amdgpu LIBRARY DESTINATION "lib${OPENMP_LIBDIR_SUFFIX}")
-set_property(TARGET omptarget.rtl.amdgpu PROPERTY INSTALL_RPATH_USE_LINK_PATH ON)
-
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
# On FreeBSD, the 'environ' symbol is undefined at link time, but resolved by
# the dynamic linker at runtime. Therefore, allow the symbol to be undefined
@@ -83,15 +66,21 @@ else()
set(LDFLAGS_UNDEFINED "-Wl,-z,defs")
endif()
-target_include_directories(
- omptarget.rtl.amdgpu
- PRIVATE
+add_llvm_library(omptarget.rtl.amdgpu SHARED
+ impl/impl.cpp
+ impl/interop_hsa.cpp
+ impl/data.cpp
+ impl/get_elf_mach_gfx_name.cpp
+ impl/system.cpp
+ impl/msgpack.cpp
+ src/rtl.cpp
+ ${LIBOMPTARGET_EXTRA_SOURCE}
+
+ ADDITIONAL_HEADER_DIRS
${LIBOMPTARGET_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/impl
-)
-target_link_libraries(
- omptarget.rtl.amdgpu
+ LINK_LIBS
PRIVATE
elf_common
${LIBOMPTARGET_DEP_LIBRARIES}
@@ -100,7 +89,23 @@ target_link_libraries(
${OPENMP_PTHREAD_LIB}
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports"
${LDFLAGS_UNDEFINED}
- )
+
+ NO_INSTALL_RPATH
+)
+add_dependencies(omptarget.rtl.amdgpu omptarget.devicertl.amdgpu)
+
+target_include_directories(
+ omptarget.rtl.amdgpu
+ PRIVATE
+ ${LIBOMPTARGET_INCLUDE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/impl
+)
+
+
+# Install plugin under the lib destination folder.
+install(TARGETS omptarget.rtl.amdgpu LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
+set_target_properties(omptarget.rtl.amdgpu PROPERTIES
+ INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
# in case of amdgcn, skip running tests if amdgpu-arch was not built or fails
if (NOT TARGET amdgpu-arch)
diff --git a/openmp/libomptarget/plugins/cuda/CMakeLists.txt b/openmp/libomptarget/plugins/cuda/CMakeLists.txt
index c152d24de4e04..46e04c3225533 100644
--- a/openmp/libomptarget/plugins/cuda/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/cuda/CMakeLists.txt
@@ -40,33 +40,64 @@ endif()
if (LIBOMPTARGET_CAN_LINK_LIBCUDA AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA)
libomptarget_say("Building CUDA plugin linked against libcuda")
include_directories(${LIBOMPTARGET_DEP_CUDA_INCLUDE_DIRS})
- add_library(omptarget.rtl.cuda SHARED src/rtl.cpp)
- set (LIBOMPTARGET_DEP_LIBRARIES ${LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES})
+ add_llvm_library(omptarget.rtl.cuda SHARED
+
+ src/rtl.cpp
+
+ ADDITIONAL_HEADER_DIRS
+ ${LIBOMPTARGET_INCLUDE_DIR}
+ ${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS}
+
+ LINK_LIBS
+ PRIVATE
+ elf_common
+ MemoryManager
+ ${LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES}
+ ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
+ ${OPENMP_PTHREAD_LIB}
+ "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports"
+ "-Wl,-z,defs"
+
+ NO_INSTALL_RPATH
+ )
else()
libomptarget_say("Building CUDA plugin for dlopened libcuda")
include_directories(dynamic_cuda)
- add_library(omptarget.rtl.cuda SHARED src/rtl.cpp dynamic_cuda/cuda.cpp)
- set (LIBOMPTARGET_DEP_LIBRARIES ${CMAKE_DL_LIBS})
+ add_llvm_library(omptarget.rtl.cuda
+ SHARED
+
+ src/rtl.cpp
+ dynamic_cuda/cuda.cpp
+
+ ADDITIONAL_HEADER_DIRS
+ ${LIBOMPTARGET_INCLUDE_DIR}
+ ${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS}
+
+ LINK_LIBS
+ PRIVATE
+ elf_common
+ MemoryManager
+ ${CMAKE_DL_LIBS}
+ ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
+ ${OPENMP_PTHREAD_LIB}
+ "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports"
+ "-Wl,-z,defs"
+
+ NO_INSTALL_RPATH
+ )
endif()
add_dependencies(omptarget.rtl.cuda omptarget.devicertl.nvptx)
# Install plugin under the lib destination folder.
install(TARGETS omptarget.rtl.cuda LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
+set_target_properties(omptarget.rtl.cuda PROPERTIES
+ INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
target_include_directories(omptarget.rtl.cuda PRIVATE
${LIBOMPTARGET_INCLUDE_DIR}
${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS}
)
-target_link_libraries(omptarget.rtl.cuda
- elf_common
- MemoryManager
- ${LIBOMPTARGET_DEP_LIBRARIES}
- ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
- ${OPENMP_PTHREAD_LIB}
- "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports"
- "-Wl,-z,defs")
-
# Report to the parent scope that we are building a plugin for CUDA.
# This controls whether tests are run for the nvptx offloading target
# Run them if libcuda is available, or if the user explicitly asked for dlopen
diff --git a/openmp/libomptarget/plugins/ve/CMakeLists.txt b/openmp/libomptarget/plugins/ve/CMakeLists.txt
index 1b10af039d98a..5aded32812d5f 100644
--- a/openmp/libomptarget/plugins/ve/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/ve/CMakeLists.txt
@@ -23,12 +23,30 @@ if(${LIBOMPTARGET_DEP_VEO_FOUND})
# Define macro with the ELF ID for this target.
add_definitions("-DTARGET_ELF_ID=${elf_machine_id}")
- add_library("omptarget.rtl.${tmachine_libname}" SHARED
- ${CMAKE_CURRENT_SOURCE_DIR}/src/rtl.cpp)
+ add_llvm_library("omptarget.rtl.${tmachine_libname}"
+ SHARED
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/rtl.cpp
+
+ ADDITIONAL_HEADER_DIRS
+ ${LIBOMPTARGET_INCLUDE_DIR}
+ ${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR}
+ ${LIBOMPTARGET_DEP_VEO_INCLUDE_DIR}
+
+ LINK_LIBS
+ PRIVATE
+ elf_common
+ ${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES}
+ ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
+ ${additional_libs}
+ "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports -Wl,-z,defs"
+
+ NO_INSTALL_RPATH
+ )
# Install plugin under the lib destination folder.
- install(TARGETS "omptarget.rtl.${tmachine_libname}"
- LIBRARY DESTINATION lib${OPENMP_LIBDIR_SUFFIX})
+ install(TARGETS "omptarget.rtl.${tmachine_libname}" LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
+ set_target_properties("omptarget.rtl.${tmachine_libname}" PROPERTIES
+ INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
target_include_directories("omptarget.rtl.${tmachine_libname}" PRIVATE
${LIBOMPTARGET_INCLUDE_DIR}
diff --git a/openmp/libomptarget/src/CMakeLists.txt b/openmp/libomptarget/src/CMakeLists.txt
index 3cd91e56c27a6..071ec61889a29 100644
--- a/openmp/libomptarget/src/CMakeLists.txt
+++ b/openmp/libomptarget/src/CMakeLists.txt
@@ -30,7 +30,8 @@ add_llvm_library(omptarget
Support
Object
- LINK_LIBS
+ LINK_LIBS
+ PRIVATE
${CMAKE_DL_LIBS}
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports"
NO_INSTALL_RPATH
More information about the Openmp-commits
mailing list