Skip to content

[Libomptarget] Unify and simplify plugin CMake #86191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions openmp/libomptarget/plugins-nextgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,66 @@
#
##===----------------------------------------------------------------------===##

# Common interface to handle creating a plugin library.
set(common_dir ${CMAKE_CURRENT_SOURCE_DIR}/common)
add_subdirectory(common)
function(add_target_library target_name lib_name)
llvm_map_components_to_libnames(llvm_libs
${LLVM_TARGETS_TO_BUILD}
AggressiveInstCombine
Analysis
BinaryFormat
BitReader
BitWriter
CodeGen
Core
Extensions
InstCombine
Instrumentation
IPO
IRReader
Linker
MC
Object
Passes
Remarks
ScalarOpts
Support
Target
TargetParser
TransformUtils
Vectorize
)

add_llvm_library(${target_name} SHARED
NO_INSTALL_RPATH
BUILDTREE_ONLY
)

llvm_update_compile_flags(${target_name})
target_link_libraries(${target_name} PUBLIC
PluginCommon ${llvm_libs} ${OPENMP_PTHREAD_LIB})

target_compile_definitions(${target_name} PRIVATE TARGET_NAME=${lib_name})
target_compile_definitions(${target_name} PRIVATE
DEBUG_PREFIX="TARGET ${lib_name} RTL")

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
# when creating a shared library.
target_link_libraries(${target_name} PRIVATE "-Wl,--allow-shlib-undefined")
else()
target_link_libraries(${target_name} PRIVATE "-Wl,-z,defs")
endif()

if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
target_link_libraries(${target_name} PRIVATE
"-Wl,--version-script=${common_dir}/../exports")
endif()
set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET protected)
endfunction()

add_subdirectory(amdgpu)
add_subdirectory(cuda)
add_subdirectory(host)
Expand Down
80 changes: 13 additions & 67 deletions openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,76 +27,23 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)|(aarch64)$" AND CMAKE
return()
endif()

################################################################################
# Define the suffix for the runtime messaging dumps.
add_definitions(-DTARGET_NAME=AMDGPU)

# Define debug prefix. TODO: This should be automatized in the Debug.h but it
# requires changing the original plugins.
add_definitions(-DDEBUG_PREFIX="TARGET AMDGPU RTL")
# Create the library and add the default arguments.
add_target_library(omptarget.rtl.amdgpu AMDGPU)

set(LIBOMPTARGET_DLOPEN_LIBHSA OFF)
option(LIBOMPTARGET_FORCE_DLOPEN_LIBHSA "Build with dlopened libhsa" ${LIBOMPTARGET_DLOPEN_LIBHSA})

if (${hsa-runtime64_FOUND} AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBHSA)
libomptarget_say("Building AMDGPU NextGen plugin linked against libhsa")
set(LIBOMPTARGET_EXTRA_SOURCE)
set(LIBOMPTARGET_DEP_LIBRARIES hsa-runtime64::hsa-runtime64)
else()
libomptarget_say("Building AMDGPU NextGen plugin for dlopened libhsa")
include_directories(dynamic_hsa)
set(LIBOMPTARGET_EXTRA_SOURCE dynamic_hsa/hsa.cpp)
set(LIBOMPTARGET_DEP_LIBRARIES)
endif()
target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
target_include_directories(omptarget.rtl.amdgpu PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/utils)

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
# when creating a shared library.
set(LDFLAGS_UNDEFINED "-Wl,--allow-shlib-undefined")
option(LIBOMPTARGET_FORCE_DLOPEN_LIBHSA "Build with dlopened libhsa" OFF)
if(hsa-runtime64_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBHSA)
libomptarget_say("Building AMDGPU plugin linked against libhsa")
target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64)
else()
set(LDFLAGS_UNDEFINED "-Wl,-z,defs")
libomptarget_say("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)
endif()

add_llvm_library(omptarget.rtl.amdgpu SHARED
src/rtl.cpp
${LIBOMPTARGET_EXTRA_SOURCE}

ADDITIONAL_HEADER_DIRS
${LIBOMPTARGET_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/utils

LINK_COMPONENTS
Support
Object

LINK_LIBS
PRIVATE
PluginCommon
${LIBOMPTARGET_DEP_LIBRARIES}
${OPENMP_PTHREAD_LIB}
${LDFLAGS_UNDEFINED}

NO_INSTALL_RPATH
BUILDTREE_ONLY
)

if ((OMPT_TARGET_DEFAULT) AND (LIBOMPTARGET_OMPT_SUPPORT))
target_link_libraries(omptarget.rtl.amdgpu PRIVATE OMPT)
endif()

if (LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
target_link_libraries(omptarget.rtl.amdgpu PRIVATE
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports")
endif()

target_include_directories(
omptarget.rtl.amdgpu
PRIVATE
${LIBOMPTARGET_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/utils
)

# Configure testing for the AMDGPU plugin. We will build tests if we could a
# functional AMD GPU on the system, or if manually specifies by the user.
option(LIBOMPTARGET_FORCE_AMDGPU_TESTS "Build AMDGPU libomptarget tests" OFF)
Expand All @@ -114,5 +61,4 @@ endif()
# 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}/.."
CXX_VISIBILITY_PRESET protected)
INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
54 changes: 6 additions & 48 deletions openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,6 @@ foreach(Target ${TargetsSupported})
target_compile_definitions(PluginCommon PRIVATE "LIBOMPTARGET_JIT_${Target}")
endforeach()

# This is required when using LLVM libraries.
llvm_update_compile_flags(PluginCommon)

if (LLVM_LINK_LLVM_DYLIB)
set(llvm_libs LLVM)
else()
llvm_map_components_to_libnames(llvm_libs
${LLVM_TARGETS_TO_BUILD}
AggressiveInstCombine
Analysis
BinaryFormat
BitReader
BitWriter
CodeGen
Core
Extensions
InstCombine
Instrumentation
IPO
IRReader
Linker
MC
Object
Passes
Remarks
ScalarOpts
Support
Target
TargetParser
TransformUtils
Vectorize
)
endif()

target_link_libraries(PluginCommon
PUBLIC
${llvm_libs}
)

# Include the RPC server from the `libc` project if availible.
if(TARGET llvmlibc_rpc_server AND ${LIBOMPTARGET_GPU_LIBC_SUPPORT})
target_link_libraries(PluginCommon PRIVATE llvmlibc_rpc_server)
Expand All @@ -82,8 +43,10 @@ elseif(${LIBOMPTARGET_GPU_LIBC_SUPPORT})
endif()
endif()

if ((OMPT_TARGET_DEFAULT) AND (LIBOMPTARGET_OMPT_SUPPORT))
target_link_libraries(PluginCommon PUBLIC OMPT)
# If we have OMPT enabled include it in the list of sources.
if (OMPT_TARGET_DEFAULT AND LIBOMPTARGET_OMPT_SUPPORT)
target_sources(PluginCommon PRIVATE OMPT/OmptCallback.cpp)
target_include_directories(PluginCommon PRIVATE OMPT)
endif()

# Define the TARGET_NAME and DEBUG_PREFIX.
Expand All @@ -95,16 +58,11 @@ target_compile_definitions(PluginCommon PRIVATE
target_compile_options(PluginCommon PUBLIC ${offload_compile_flags})
target_link_options(PluginCommon PUBLIC ${offload_link_flags})

target_include_directories(PluginCommon
PRIVATE
${LIBOMPTARGET_INCLUDE_DIR}
PUBLIC
target_include_directories(PluginCommon PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${LIBOMPTARGET_INCLUDE_DIR}
)

set_target_properties(PluginCommon PROPERTIES
POSITION_INDEPENDENT_CODE ON
CXX_VISIBILITY_PRESET protected)

add_subdirectory(OMPT)

70 changes: 0 additions & 70 deletions openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt

This file was deleted.

40 changes: 5 additions & 35 deletions openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,12 @@ endif()

libomptarget_say("Building CUDA NextGen offloading plugin.")

set(LIBOMPTARGET_DLOPEN_LIBCUDA OFF)
option(LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA "Build with dlopened libcuda" ${LIBOMPTARGET_DLOPEN_LIBCUDA})

add_llvm_library(omptarget.rtl.cuda SHARED
src/rtl.cpp

LINK_COMPONENTS
Support
Object

LINK_LIBS PRIVATE
PluginCommon
${OPENMP_PTHREAD_LIB}

NO_INSTALL_RPATH
BUILDTREE_ONLY
)

if ((OMPT_TARGET_DEFAULT) AND (LIBOMPTARGET_OMPT_SUPPORT))
target_link_libraries(omptarget.rtl.cuda PRIVATE OMPT)
endif()

if (LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
target_link_libraries(omptarget.rtl.cuda PRIVATE
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports,-z,defs")
endif()
# Create the library and add the default arguments.
add_target_library(omptarget.rtl.cuda CUDA)

target_sources(omptarget.rtl.cuda PRIVATE src/rtl.cpp)

option(LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA "Build with dlopened libcuda" OFF)
if(LIBOMPTARGET_DEP_CUDA_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA)
libomptarget_say("Building CUDA plugin linked against libcuda")
target_link_libraries(omptarget.rtl.cuda PRIVATE CUDA::cuda_driver)
Expand All @@ -60,13 +38,6 @@ else()
target_sources(omptarget.rtl.cuda PRIVATE dynamic_cuda/cuda.cpp)
endif()

# Define debug prefix. TODO: This should be automatized in the Debug.h but it
# requires changing the original plugins.
target_compile_definitions(omptarget.rtl.cuda PRIVATE TARGET_NAME="CUDA")
target_compile_definitions(omptarget.rtl.cuda PRIVATE DEBUG_PREFIX="TARGET CUDA RTL")

target_include_directories(omptarget.rtl.cuda PRIVATE ${LIBOMPTARGET_INCLUDE_DIR})

# Configure testing for the CUDA plugin. We will build tests if we could a
# functional NVIDIA GPU on the system, or if manually specifies by the user.
option(LIBOMPTARGET_FORCE_NVIDIA_TESTS "Build NVIDIA libomptarget tests" OFF)
Expand All @@ -84,5 +55,4 @@ endif()
# 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}/.."
CXX_VISIBILITY_PRESET protected)
INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
Loading