Skip to content

Commit 3d01a6f

Browse files
committed
[Libomptarget] Unify interface and compile each plugin separately
Summary: Currently we use a CMake object library to provide the unified interface between all the plugins that depend on the common utilities. We then use the public targets to propagate these to the actual plugins themselves. The problem with this is that it requires that the plugin interface files all be identical. For examplle, currently when you compile with debugging on the common utilities will show up as `PluginInterface` despite which plugin they are a part of. This is an issue for moving to a shared library interface. The shared libraries will need to provide a separate namespace for each RTL function, which means that they will all be separate implementations. This patch instead moves all of this logic into a helper function that sets up the target and the default arguments. In the future this will be changed to a `STATIC` target, but for now the interface is unchanged. The only effect this has is that the plugins will now always state `TARGET AMDGPU RTL` if it is executing from the AMDGPU plugin.
1 parent 8937174 commit 3d01a6f

File tree

8 files changed

+124
-312
lines changed

8 files changed

+124
-312
lines changed

openmp/libomptarget/plugins-nextgen/CMakeLists.txt

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,102 @@
1010
#
1111
##===----------------------------------------------------------------------===##
1212

13-
add_subdirectory(common)
13+
# Common interface to handle creating a plugin library.
14+
set(common_dir ${CMAKE_CURRENT_SOURCE_DIR}/common)
15+
function(add_target_library target_name lib_name)
16+
llvm_map_components_to_libnames(llvm_libs
17+
${LLVM_TARGETS_TO_BUILD}
18+
AggressiveInstCombine
19+
Analysis
20+
BinaryFormat
21+
BitReader
22+
BitWriter
23+
CodeGen
24+
Core
25+
Extensions
26+
InstCombine
27+
Instrumentation
28+
IPO
29+
IRReader
30+
Linker
31+
MC
32+
Object
33+
Passes
34+
Remarks
35+
ScalarOpts
36+
Support
37+
Target
38+
TargetParser
39+
TransformUtils
40+
Vectorize
41+
)
42+
43+
add_llvm_library(${target_name} SHARED
44+
${common_dir}/src/PluginInterface.cpp
45+
${common_dir}/src/GlobalHandler.cpp
46+
${common_dir}/src/JIT.cpp
47+
${common_dir}/src/RPC.cpp
48+
${common_dir}/src/Utils/ELF.cpp
49+
50+
NO_INSTALL_RPATH
51+
BUILDTREE_ONLY
52+
)
53+
54+
target_link_libraries(${target_name} PUBLIC ${llvm_libs} ${OPENMP_PTHREAD_LIB})
55+
llvm_update_compile_flags(${target_name})
56+
57+
# Include the RPC server from the `libc` project if availible.
58+
if(TARGET llvmlibc_rpc_server AND ${LIBOMPTARGET_GPU_LIBC_SUPPORT})
59+
target_link_libraries(${target_name} PRIVATE llvmlibc_rpc_server)
60+
target_compile_definitions(${target_name} PRIVATE LIBOMPTARGET_RPC_SUPPORT)
61+
elseif(${LIBOMPTARGET_GPU_LIBC_SUPPORT})
62+
find_library(llvmlibc_rpc_server NAMES llvmlibc_rpc_server
63+
PATHS ${LIBOMPTARGET_LLVM_LIBRARY_DIR} NO_DEFAULT_PATH)
64+
if(llvmlibc_rpc_server)
65+
target_link_libraries(${target_name} PRIVATE ${llvmlibc_rpc_server})
66+
target_compile_definitions(${target_name} PRIVATE LIBOMPTARGET_RPC_SUPPORT)
67+
# We may need to get the headers directly from the 'libc' source directory.
68+
target_include_directories(${target_name} PRIVATE
69+
${CMAKE_SOURCE_DIR}/../libc/utils/gpu/server
70+
${CMAKE_SOURCE_DIR}/../libc/include)
71+
endif()
72+
endif()
73+
74+
# Only enable JIT for those targets that LLVM can support.
75+
string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" TargetsSupported)
76+
foreach(Target ${TargetsSupported})
77+
target_compile_definitions(${target_name} PRIVATE "LIBOMPTARGET_JIT_${Target}")
78+
endforeach()
79+
80+
target_compile_definitions(${target_name} PRIVATE TARGET_NAME=${lib_name})
81+
target_compile_definitions(${target_name} PRIVATE
82+
DEBUG_PREFIX="TARGET ${lib_name} RTL")
83+
84+
# If we have OMPT enabled include it in the list of sourced.
85+
if (OMPT_TARGET_DEFAULT AND LIBOMPTARGET_OMPT_SUPPORT)
86+
target_sources(${target_name} PRIVATE ${common_dir}/OMPT/OmptCallback.cpp)
87+
endif()
88+
89+
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
90+
# On FreeBSD, the 'environ' symbol is undefined at link time, but resolved by
91+
# the dynamic linker at runtime. Therefore, allow the symbol to be undefined
92+
# when creating a shared library.
93+
target_link_libraries(${target_name} PRIVATE "-Wl,--allow-shlib-undefined")
94+
else()
95+
target_link_libraries(${target_name} PRIVATE "-Wl,-z,defs")
96+
endif()
97+
98+
target_include_directories(${target_name} PRIVATE
99+
${LIBOMPTARGET_INCLUDE_DIR}
100+
${common_dir}/include
101+
)
102+
if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
103+
target_link_libraries(${target_name} PRIVATE
104+
"-Wl,--version-script=${common_dir}/../exports")
105+
endif()
106+
set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET protected)
107+
endfunction()
108+
14109
add_subdirectory(amdgpu)
15110
add_subdirectory(cuda)
16111
add_subdirectory(host)

openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt

Lines changed: 13 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -27,76 +27,23 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)|(aarch64)$" AND CMAKE
2727
return()
2828
endif()
2929

30-
################################################################################
31-
# Define the suffix for the runtime messaging dumps.
32-
add_definitions(-DTARGET_NAME=AMDGPU)
33-
34-
# Define debug prefix. TODO: This should be automatized in the Debug.h but it
35-
# requires changing the original plugins.
36-
add_definitions(-DDEBUG_PREFIX="TARGET AMDGPU RTL")
30+
# Create the library and add the default arguments.
31+
add_target_library(omptarget.rtl.amdgpu AMDGPU)
3732

38-
set(LIBOMPTARGET_DLOPEN_LIBHSA OFF)
39-
option(LIBOMPTARGET_FORCE_DLOPEN_LIBHSA "Build with dlopened libhsa" ${LIBOMPTARGET_DLOPEN_LIBHSA})
40-
41-
if (${hsa-runtime64_FOUND} AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBHSA)
42-
libomptarget_say("Building AMDGPU NextGen plugin linked against libhsa")
43-
set(LIBOMPTARGET_EXTRA_SOURCE)
44-
set(LIBOMPTARGET_DEP_LIBRARIES hsa-runtime64::hsa-runtime64)
45-
else()
46-
libomptarget_say("Building AMDGPU NextGen plugin for dlopened libhsa")
47-
include_directories(dynamic_hsa)
48-
set(LIBOMPTARGET_EXTRA_SOURCE dynamic_hsa/hsa.cpp)
49-
set(LIBOMPTARGET_DEP_LIBRARIES)
50-
endif()
33+
target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
34+
target_include_directories(omptarget.rtl.amdgpu PRIVATE
35+
${CMAKE_CURRENT_SOURCE_DIR}/utils)
5136

52-
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
53-
# On FreeBSD, the 'environ' symbol is undefined at link time, but resolved by
54-
# the dynamic linker at runtime. Therefore, allow the symbol to be undefined
55-
# when creating a shared library.
56-
set(LDFLAGS_UNDEFINED "-Wl,--allow-shlib-undefined")
37+
option(LIBOMPTARGET_FORCE_DLOPEN_LIBHSA "Build with dlopened libhsa" OFF)
38+
if(hsa-runtime64_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBHSA)
39+
libomptarget_say("Building AMDGPU plugin linked against libhsa")
40+
target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64)
5741
else()
58-
set(LDFLAGS_UNDEFINED "-Wl,-z,defs")
42+
libomptarget_say("Building AMDGPU plugin for dlopened libhsa")
43+
target_include_directories(omptarget.rtl.amdgpu PRIVATE dynamic_hsa)
44+
target_sources(omptarget.rtl.amdgpu PRIVATE dynamic_hsa/hsa.cpp)
5945
endif()
6046

61-
add_llvm_library(omptarget.rtl.amdgpu SHARED
62-
src/rtl.cpp
63-
${LIBOMPTARGET_EXTRA_SOURCE}
64-
65-
ADDITIONAL_HEADER_DIRS
66-
${LIBOMPTARGET_INCLUDE_DIR}
67-
${CMAKE_CURRENT_SOURCE_DIR}/utils
68-
69-
LINK_COMPONENTS
70-
Support
71-
Object
72-
73-
LINK_LIBS
74-
PRIVATE
75-
PluginCommon
76-
${LIBOMPTARGET_DEP_LIBRARIES}
77-
${OPENMP_PTHREAD_LIB}
78-
${LDFLAGS_UNDEFINED}
79-
80-
NO_INSTALL_RPATH
81-
BUILDTREE_ONLY
82-
)
83-
84-
if ((OMPT_TARGET_DEFAULT) AND (LIBOMPTARGET_OMPT_SUPPORT))
85-
target_link_libraries(omptarget.rtl.amdgpu PRIVATE OMPT)
86-
endif()
87-
88-
if (LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
89-
target_link_libraries(omptarget.rtl.amdgpu PRIVATE
90-
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports")
91-
endif()
92-
93-
target_include_directories(
94-
omptarget.rtl.amdgpu
95-
PRIVATE
96-
${LIBOMPTARGET_INCLUDE_DIR}
97-
${CMAKE_CURRENT_SOURCE_DIR}/utils
98-
)
99-
10047
# Configure testing for the AMDGPU plugin. We will build tests if we could a
10148
# functional AMD GPU on the system, or if manually specifies by the user.
10249
option(LIBOMPTARGET_FORCE_AMDGPU_TESTS "Build AMDGPU libomptarget tests" OFF)
@@ -114,5 +61,4 @@ endif()
11461
# Install plugin under the lib destination folder.
11562
install(TARGETS omptarget.rtl.amdgpu LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
11663
set_target_properties(omptarget.rtl.amdgpu PROPERTIES
117-
INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.."
118-
CXX_VISIBILITY_PRESET protected)
64+
INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")

openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt

Lines changed: 0 additions & 110 deletions
This file was deleted.

openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)