Skip to content

Commit a7d5f73

Browse files
authored
[Libomptarget] Consolidate CPU offloading into 'host' directory (#86014)
Summary: All of these CPU targets use the same underlying implementation. We should consolidate them into a single target to make it easier to update this to a static library based approach. I have decided to call this the 'host' target so it can be given a single name. We still only build these if the system processor matches and we are on Linux.
1 parent 61b24c6 commit a7d5f73

File tree

10 files changed

+118
-186
lines changed

10 files changed

+118
-186
lines changed

openmp/libomptarget/plugins-nextgen/CMakeLists.txt

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -11,106 +11,9 @@
1111
##===----------------------------------------------------------------------===##
1212

1313
add_subdirectory(common)
14-
15-
# void build_generic_elf64(string tmachine, string tmachine_name, string tmachine_libname,
16-
# string tmachine_llvm, string tmachine_triple, string elf_machine_id);
17-
# - build a plugin for an ELF based generic 64-bit target based on libffi.
18-
# - tmachine: name of the machine processor as used in the cmake build system.
19-
# - tmachine_name: name of the machine to be printed with the debug messages.
20-
# - tmachine_libname: machine name to be appended to the plugin library name.
21-
# - tmachine_llvm: LLVM triple for the processor
22-
# - tmachine_triple: GNU target triple
23-
macro(build_generic_elf64 tmachine tmachine_name tmachine_libname tmachine_llvm tmachine_triple elf_machine_id)
24-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "${tmachine}$")
25-
# Define macro to be used as prefix of the runtime messages for this target.
26-
add_definitions("-DTARGET_NAME=${tmachine_name}")
27-
28-
# Define debug prefix. TODO: This should be automatized in the Debug.h but
29-
# it requires changing the original plugins.
30-
add_definitions(-DDEBUG_PREFIX="TARGET ${tmachine_name} RTL")
31-
32-
# Define the macro with the ELF e_machine for this target.
33-
add_definitions("-DTARGET_ELF_ID=${elf_machine_id}")
34-
35-
# Define target triple
36-
add_definitions("-DLIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE=${tmachine_llvm}")
37-
38-
add_llvm_library("omptarget.rtl.${tmachine_libname}"
39-
SHARED
40-
41-
${CMAKE_CURRENT_SOURCE_DIR}/../generic-elf-64bit/src/rtl.cpp
42-
43-
ADDITIONAL_HEADER_DIRS
44-
${LIBOMPTARGET_INCLUDE_DIR}
45-
46-
LINK_LIBS
47-
PRIVATE
48-
PluginCommon
49-
${OPENMP_PTHREAD_LIB}
50-
51-
NO_INSTALL_RPATH
52-
BUILDTREE_ONLY
53-
)
54-
55-
if(LIBOMPTARGET_DEP_LIBFFI_FOUND)
56-
libomptarget_say("Building ${tmachine_libname} plugin linked with libffi")
57-
if(FFI_STATIC_LIBRARIES)
58-
target_link_libraries(
59-
"omptarget.rtl.${tmachine_libname}" PRIVATE FFI::ffi_static)
60-
else()
61-
target_link_libraries(
62-
"omptarget.rtl.${tmachine_libname}" PRIVATE FFI::ffi)
63-
endif()
64-
else()
65-
libomptarget_say("Building ${tmachine_libname} plugin for dlopened libffi")
66-
target_sources("omptarget.rtl.${tmachine_libname}" PRIVATE
67-
${CMAKE_CURRENT_SOURCE_DIR}/../generic-elf-64bit/dynamic_ffi/ffi.cpp)
68-
target_include_directories("omptarget.rtl.${tmachine_libname}" PRIVATE
69-
${CMAKE_CURRENT_SOURCE_DIR}/../generic-elf-64bit/dynamic_ffi)
70-
endif()
71-
72-
if(OMPT_TARGET_DEFAULT AND LIBOMPTARGET_OMPT_SUPPORT)
73-
target_link_libraries("omptarget.rtl.${tmachine_libname}" PRIVATE OMPT)
74-
endif()
75-
76-
if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
77-
target_link_libraries("omptarget.rtl.${tmachine_libname}" PRIVATE
78-
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports")
79-
endif()
80-
81-
# Install plugin under the lib destination folder.
82-
install(TARGETS "omptarget.rtl.${tmachine_libname}"
83-
LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
84-
set_target_properties("omptarget.rtl.${tmachine_libname}" PROPERTIES
85-
INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.."
86-
POSITION_INDEPENDENT_CODE ON
87-
CXX_VISIBILITY_PRESET protected)
88-
89-
target_include_directories("omptarget.rtl.${tmachine_libname}" PRIVATE
90-
${LIBOMPTARGET_INCLUDE_DIR})
91-
92-
if(LIBOMPTARGET_DEP_LIBFFI_FOUND)
93-
list(APPEND LIBOMPTARGET_TESTED_PLUGINS "omptarget.rtl.${tmachine_libname}")
94-
set(LIBOMPTARGET_TESTED_PLUGINS
95-
"${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE)
96-
set(LIBOMPTARGET_SYSTEM_TARGETS
97-
"${LIBOMPTARGET_SYSTEM_TARGETS} ${tmachine_triple}
98-
${tmachine_triple}-LTO" PARENT_SCOPE)
99-
else()
100-
libomptarget_say("Not generating ${tmachine_name} tests. LibFFI not found.")
101-
endif()
102-
else()
103-
libomptarget_say("Not building ${tmachine_name} NextGen offloading plugin: machine not found in the system.")
104-
endif()
105-
endmacro()
106-
107-
add_subdirectory(aarch64)
10814
add_subdirectory(amdgpu)
10915
add_subdirectory(cuda)
110-
add_subdirectory(ppc64)
111-
add_subdirectory(ppc64le)
112-
add_subdirectory(x86_64)
113-
add_subdirectory(s390x)
16+
add_subdirectory(host)
11417

11518
# Make sure the parent scope can see the plugins that will be created.
11619
set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE)

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

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux")
2+
return()
3+
endif()
4+
5+
# build_generic_elf64("s390x" "S390X" "s390x" "systemz" "s390x-ibm-linux-gnu" "22")
6+
# build_generic_elf64("aarch64" "aarch64" "aarch64" "aarch64" "aarch64-unknown-linux-gnu" "183")
7+
# build_generic_elf64("ppc64" "PPC64" "ppc64" "ppc64" "powerpc64-ibm-linux-gnu" "21")
8+
# build_generic_elf64("x86_64" "x86_64" "x86_64" "x86_64" "x86_64-pc-linux-gnu" "62")
9+
# build_generic_elf64("ppc64le" "PPC64le" "ppc64" "ppc64le" "powerpc64le-ibm-linux-gnu" "21")
10+
set(supported_targets x86_64 aarch64 ppc64 ppc64le s390x)
11+
if(NOT ${CMAKE_SYSTEM_PROCESSOR} IN_LIST supported_targets)
12+
libomptarget_say("Not building ${machine} NextGen offloading plugin")
13+
return()
14+
endif()
15+
16+
set(machine ${CMAKE_SYSTEM_PROCESSOR})
17+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$")
18+
set(machine ppc64)
19+
endif()
20+
21+
add_llvm_library(omptarget.rtl.${machine} SHARED
22+
src/rtl.cpp
23+
ADDITIONAL_HEADER_DIRS
24+
${LIBOMPTARGET_INCLUDE_DIR}
25+
LINK_LIBS PRIVATE
26+
PluginCommon
27+
${OPENMP_PTHREAD_LIB}
28+
NO_INSTALL_RPATH
29+
BUILDTREE_ONLY
30+
)
31+
32+
if(LIBOMPTARGET_DEP_LIBFFI_FOUND)
33+
libomptarget_say("Building ${machine} plugin linked with libffi")
34+
if(FFI_STATIC_LIBRARIES)
35+
target_link_libraries(omptarget.rtl.${machine} PRIVATE FFI::ffi_static)
36+
else()
37+
target_link_libraries(omptarget.rtl.${machine} PRIVATE FFI::ffi)
38+
endif()
39+
else()
40+
libomptarget_say("Building ${machine} plugin for dlopened libffi")
41+
target_sources(omptarget.rtl.${machine} PRIVATE dynamic_ffi/ffi.cpp)
42+
target_include_directories(omptarget.rtl.${machine} PRIVATE dynamic_ffi)
43+
endif()
44+
45+
if(OMPT_TARGET_DEFAULT AND LIBOMPTARGET_OMPT_SUPPORT)
46+
target_link_libraries(omptarget.rtl.${machine} PRIVATE OMPT)
47+
endif()
48+
49+
if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
50+
target_link_libraries(omptarget.rtl.${machine} PRIVATE
51+
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports")
52+
endif()
53+
54+
# Install plugin under the lib destination folder.
55+
install(TARGETS omptarget.rtl.${machine}
56+
LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
57+
set_target_properties(omptarget.rtl.${machine} PROPERTIES
58+
INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.."
59+
POSITION_INDEPENDENT_CODE ON
60+
CXX_VISIBILITY_PRESET protected)
61+
62+
target_include_directories(omptarget.rtl.${machine} PRIVATE
63+
${LIBOMPTARGET_INCLUDE_DIR})
64+
65+
if(LIBOMPTARGET_DEP_LIBFFI_FOUND)
66+
list(APPEND LIBOMPTARGET_TESTED_PLUGINS omptarget.rtl.${machine})
67+
set(LIBOMPTARGET_TESTED_PLUGINS
68+
"${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE)
69+
else()
70+
libomptarget_say("Not generating ${tmachine_name} tests. LibFFI not found.")
71+
endif()
72+
73+
# Define macro to be used as prefix of the runtime messages for this target.
74+
target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_NAME=${machine})
75+
# TODO: This should be automatized in Debug.h.
76+
target_compile_definitions(omptarget.rtl.${machine} PRIVATE
77+
DEBUG_PREFIX="TARGET ${machine} RTL")
78+
79+
# Define the target specific triples and ELF machine values.
80+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$" OR
81+
CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64$")
82+
target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_PPC64)
83+
target_compile_definitions(omptarget.rtl.${machine} PRIVATE
84+
LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE="powerpc64-ibm-linux-gnu")
85+
list(APPEND LIBOMPTARGET_SYSTEM_TARGETS
86+
"powerpc64-ibm-linux-gnu" "powerpc64-ibm-linux-gnu-LTO")
87+
set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE)
88+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64$")
89+
target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_X86_64)
90+
target_compile_definitions(omptarget.rtl.${machine} PRIVATE
91+
LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE="x86_64-pc-linux-gnu")
92+
list(APPEND LIBOMPTARGET_SYSTEM_TARGETS
93+
"x86_64-pc-linux-gnu" "x86_64-pc-linux-gnu-LTO")
94+
set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE)
95+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64$")
96+
target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_AARCH64)
97+
target_compile_definitions(omptarget.rtl.${machine} PRIVATE
98+
LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE="aarch64-unknown-linux-gnu")
99+
list(APPEND LIBOMPTARGET_SYSTEM_TARGETS
100+
"aarch64-unknown-linux-gnu" "aarch64-unknown-linux-gnu-LTO")
101+
set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE)
102+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x$")
103+
target_compile_definitions(omptarget.rtl.${machine} TARGET_ELF_ID=EM_S390)
104+
target_compile_definitions(omptarget.rtl.${machine} PRIVATE
105+
LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE="s390x-ibm-linux-gnu")
106+
list(APPEND LIBOMPTARGET_SYSTEM_TARGETS
107+
"s390x-ibm-linux-gnu" "s390x-ibm-linux-gnu-LTO")
108+
set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE)
109+
endif()

openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp renamed to openmp/libomptarget/plugins-nextgen/host/src/rtl.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535

3636
// The ELF ID should be defined at compile-time by the build system.
3737
#ifndef TARGET_ELF_ID
38-
#define TARGET_ELF_ID ELF::EM_NONE
38+
#define TARGET_ELF_ID EM_NONE
39+
#endif
40+
41+
// The target triple should be defined at compile-time by the build system.
42+
#ifndef LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE
43+
#define LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE ""
3944
#endif
4045

4146
namespace llvm {
@@ -395,7 +400,7 @@ struct GenELF64PluginTy final : public GenericPluginTy {
395400
Error deinitImpl() override { return Plugin::success(); }
396401

397402
/// Get the ELF code to recognize the compatible binary images.
398-
uint16_t getMagicElfBits() const override { return TARGET_ELF_ID; }
403+
uint16_t getMagicElfBits() const override { return ELF::TARGET_ELF_ID; }
399404

400405
/// This plugin does not support exchanging data between two devices.
401406
bool isDataExchangable(int32_t SrcDeviceId, int32_t DstDeviceId) override {
@@ -406,7 +411,7 @@ struct GenELF64PluginTy final : public GenericPluginTy {
406411
Expected<bool> isELFCompatible(StringRef) const override { return true; }
407412

408413
Triple::ArchType getTripleArch() const override {
409-
return Triple::LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE;
414+
return llvm::Triple(LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE).getArch();
410415
}
411416
};
412417

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)