[clang] [llvm] [openmp] [Libomptarget] Statically link all plugin runtimes (PR #87009)
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/87009 >From d9e2231c179e3ae321883203ad4799971a982110 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 27 Mar 2024 15:27:16 -0500 Subject: [PATCH 1/3] [Libomptarget] Rename `libomptarget.rtl.x86_64` to `libomptarget.rtl.host` Summary: All of these are functionally the same code, just compiled for separate architectures. We currently do not expose a way to execute these on separate architectures as the host plugin works using `dlopen` into the same process, and therefore cannot possibly be an incompatible architecture. (This could work with a remote plugin, but this is not supported yet). This patch simply renames all of these to the same thing so we no longer need to check around for its varying definitions. --- .../plugins-nextgen/host/CMakeLists.txt | 36 +-- openmp/libomptarget/src/CMakeLists.txt| 5 +-- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt index ccbf7d033fd663..0954f8367654f6 100644 --- a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt +++ b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt @@ -14,36 +14,36 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$") endif() # Create the library and add the default arguments. -add_target_library(omptarget.rtl.${machine} ${machine}) +add_target_library(omptarget.rtl.host ${machine}) -target_sources(omptarget.rtl.${machine} PRIVATE src/rtl.cpp) +target_sources(omptarget.rtl.host PRIVATE src/rtl.cpp) if(LIBOMPTARGET_DEP_LIBFFI_FOUND) libomptarget_say("Building ${machine} plugin linked with libffi") if(FFI_STATIC_LIBRARIES) -target_link_libraries(omptarget.rtl.${machine} PRIVATE FFI::ffi_static) +target_link_libraries(omptarget.rtl.host PRIVATE FFI::ffi_static) else() -target_link_libraries(omptarget.rtl.${machine} PRIVATE FFI::ffi) +target_link_libraries(omptarget.rtl.host PRIVATE FFI::ffi) endif() else() libomptarget_say("Building ${machine} plugin for dlopened libffi") - target_sources(omptarget.rtl.${machine} PRIVATE dynamic_ffi/ffi.cpp) - target_include_directories(omptarget.rtl.${machine} PRIVATE dynamic_ffi) + target_sources(omptarget.rtl.host PRIVATE dynamic_ffi/ffi.cpp) + target_include_directories(omptarget.rtl.host PRIVATE dynamic_ffi) endif() # Install plugin under the lib destination folder. -install(TARGETS omptarget.rtl.${machine} +install(TARGETS omptarget.rtl.host LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}") -set_target_properties(omptarget.rtl.${machine} PROPERTIES +set_target_properties(omptarget.rtl.host PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.." POSITION_INDEPENDENT_CODE ON CXX_VISIBILITY_PRESET protected) -target_include_directories(omptarget.rtl.${machine} PRIVATE +target_include_directories(omptarget.rtl.host PRIVATE ${LIBOMPTARGET_INCLUDE_DIR}) if(LIBOMPTARGET_DEP_LIBFFI_FOUND) - list(APPEND LIBOMPTARGET_TESTED_PLUGINS omptarget.rtl.${machine}) + list(APPEND LIBOMPTARGET_TESTED_PLUGINS omptarget.rtl.host) set(LIBOMPTARGET_TESTED_PLUGINS "${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE) else() @@ -53,29 +53,29 @@ endif() # Define the target specific triples and ELF machine values. if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$" OR CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64$") - target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_PPC64) - target_compile_definitions(omptarget.rtl.${machine} PRIVATE + target_compile_definitions(omptarget.rtl.host PRIVATE TARGET_ELF_ID=EM_PPC64) + target_compile_definitions(omptarget.rtl.host PRIVATE LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE="powerpc64-ibm-linux-gnu") list(APPEND LIBOMPTARGET_SYSTEM_TARGETS "powerpc64-ibm-linux-gnu" "powerpc64-ibm-linux-gnu-LTO") set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64$") - target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_X86_64) - target_compile_definitions(omptarget.rtl.${machine} PRIVATE + target_compile_definitions(omptarget.rtl.host PRIVATE TARGET_ELF_ID=EM_X86_64) + target_compile_definitions(omptarget.rtl.host PRIVATE LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE="x86_64-pc-linux-gnu") list(APPEND LIBOMPTARGET_SYSTEM_TARGETS "x86_64-pc-linux-gnu" "x86_64-pc-linux-gnu-LTO") set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64$") - target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_AARCH64) - target_compile_definitions(omptarget.rtl.${machine} PRIVATE + target_compile_definitions(omptarget.rtl.host PRIVATE TARGET_ELF_ID=EM_AARCH64) +
[clang] [llvm] [openmp] [Libomptarget] Statically link all plugin runtimes (PR #87009)
@@ -3043,10 +3043,6 @@ struct AMDGPUPluginTy final : public GenericPluginTy { // HSA functions from now on, e.g., hsa_shut_down. Initialized = true; -#ifdef OMPT_SUPPORT -ompt::connectLibrary(); jhuber6 wrote: Ah, well that can be a follow-up patch since it seems to work here. Would be nice to get all of this OMPT stuff out of the plugins, which this should also help since we have actual `init` and `deinit` calls from `libomptarget` now. https://github.com/llvm/llvm-project/pull/87009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Libomptarget] Statically link all plugin runtimes (PR #87009)
@@ -3043,10 +3043,6 @@ struct AMDGPUPluginTy final : public GenericPluginTy { // HSA functions from now on, e.g., hsa_shut_down. Initialized = true; -#ifdef OMPT_SUPPORT -ompt::connectLibrary(); dhruvachak wrote: There is a connectLibrary definition in libomptarget and another in the common plugin. Since the call is now removed from the plugins, the definition in the plugin should also go away. It seems like the entire OmptCallback.cpp can be removed. Don't know whether something breaks then. https://github.com/llvm/llvm-project/pull/87009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Libomptarget] Statically link all plugin runtimes (PR #87009)
jhuber6 wrote: > Some OMPT variables with the same name used to be present in both > libomptarget and the common plugin interface. These should probably be > re-worked in the new scheme of static linking? e.g. > llvm::omp::target::ompt::Initialized Unsure, there was an issue where each plugin called `Initialize` separately that is no longer needed. I just deleted those. Are there any other cases that need to be handled? https://github.com/llvm/llvm-project/pull/87009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Libomptarget] Statically link all plugin runtimes (PR #87009)
dhruvachak wrote: Some OMPT variables with the same name used to be present in both libomptarget and the common plugin interface. These should probably be re-worked in the new scheme of static linking? e.g. llvm::omp::target::ompt::Initialized https://github.com/llvm/llvm-project/pull/87009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Libomptarget] Statically link all plugin runtimes (PR #87009)
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/87009 >From bb5f330cc3d5e0758825b25e3b8209fb7af6be79 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 27 Mar 2024 15:27:16 -0500 Subject: [PATCH 1/3] [Libomptarget] Rename `libomptarget.rtl.x86_64` to `libomptarget.rtl.host` Summary: All of these are functionally the same code, just compiled for separate architectures. We currently do not expose a way to execute these on separate architectures as the host plugin works using `dlopen` into the same process, and therefore cannot possibly be an incompatible architecture. (This could work with a remote plugin, but this is not supported yet). This patch simply renames all of these to the same thing so we no longer need to check around for its varying definitions. --- .../plugins-nextgen/host/CMakeLists.txt | 36 +-- openmp/libomptarget/src/CMakeLists.txt| 5 +-- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt index ccbf7d033fd663..0954f8367654f6 100644 --- a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt +++ b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt @@ -14,36 +14,36 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$") endif() # Create the library and add the default arguments. -add_target_library(omptarget.rtl.${machine} ${machine}) +add_target_library(omptarget.rtl.host ${machine}) -target_sources(omptarget.rtl.${machine} PRIVATE src/rtl.cpp) +target_sources(omptarget.rtl.host PRIVATE src/rtl.cpp) if(LIBOMPTARGET_DEP_LIBFFI_FOUND) libomptarget_say("Building ${machine} plugin linked with libffi") if(FFI_STATIC_LIBRARIES) -target_link_libraries(omptarget.rtl.${machine} PRIVATE FFI::ffi_static) +target_link_libraries(omptarget.rtl.host PRIVATE FFI::ffi_static) else() -target_link_libraries(omptarget.rtl.${machine} PRIVATE FFI::ffi) +target_link_libraries(omptarget.rtl.host PRIVATE FFI::ffi) endif() else() libomptarget_say("Building ${machine} plugin for dlopened libffi") - target_sources(omptarget.rtl.${machine} PRIVATE dynamic_ffi/ffi.cpp) - target_include_directories(omptarget.rtl.${machine} PRIVATE dynamic_ffi) + target_sources(omptarget.rtl.host PRIVATE dynamic_ffi/ffi.cpp) + target_include_directories(omptarget.rtl.host PRIVATE dynamic_ffi) endif() # Install plugin under the lib destination folder. -install(TARGETS omptarget.rtl.${machine} +install(TARGETS omptarget.rtl.host LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}") -set_target_properties(omptarget.rtl.${machine} PROPERTIES +set_target_properties(omptarget.rtl.host PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.." POSITION_INDEPENDENT_CODE ON CXX_VISIBILITY_PRESET protected) -target_include_directories(omptarget.rtl.${machine} PRIVATE +target_include_directories(omptarget.rtl.host PRIVATE ${LIBOMPTARGET_INCLUDE_DIR}) if(LIBOMPTARGET_DEP_LIBFFI_FOUND) - list(APPEND LIBOMPTARGET_TESTED_PLUGINS omptarget.rtl.${machine}) + list(APPEND LIBOMPTARGET_TESTED_PLUGINS omptarget.rtl.host) set(LIBOMPTARGET_TESTED_PLUGINS "${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE) else() @@ -53,29 +53,29 @@ endif() # Define the target specific triples and ELF machine values. if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$" OR CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64$") - target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_PPC64) - target_compile_definitions(omptarget.rtl.${machine} PRIVATE + target_compile_definitions(omptarget.rtl.host PRIVATE TARGET_ELF_ID=EM_PPC64) + target_compile_definitions(omptarget.rtl.host PRIVATE LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE="powerpc64-ibm-linux-gnu") list(APPEND LIBOMPTARGET_SYSTEM_TARGETS "powerpc64-ibm-linux-gnu" "powerpc64-ibm-linux-gnu-LTO") set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64$") - target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_X86_64) - target_compile_definitions(omptarget.rtl.${machine} PRIVATE + target_compile_definitions(omptarget.rtl.host PRIVATE TARGET_ELF_ID=EM_X86_64) + target_compile_definitions(omptarget.rtl.host PRIVATE LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE="x86_64-pc-linux-gnu") list(APPEND LIBOMPTARGET_SYSTEM_TARGETS "x86_64-pc-linux-gnu" "x86_64-pc-linux-gnu-LTO") set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64$") - target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_AARCH64) - target_compile_definitions(omptarget.rtl.${machine} PRIVATE + target_compile_definitions(omptarget.rtl.host PRIVATE TARGET_ELF_ID=EM_AARCH64) +
[clang] [llvm] [openmp] [Libomptarget] Statically link all plugin runtimes (PR #87009)
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/87009 >From fe0b6725e9aa89cc378ffd97f19354d59ab4fa93 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 27 Mar 2024 15:27:16 -0500 Subject: [PATCH 1/4] [Libomptarget] Rename `libomptarget.rtl.x86_64` to `libomptarget.rtl.host` Summary: All of these are functionally the same code, just compiled for separate architectures. We currently do not expose a way to execute these on separate architectures as the host plugin works using `dlopen` into the same process, and therefore cannot possibly be an incompatible architecture. (This could work with a remote plugin, but this is not supported yet). This patch simply renames all of these to the same thing so we no longer need to check around for its varying definitions. --- .../plugins-nextgen/host/CMakeLists.txt | 36 +-- openmp/libomptarget/src/CMakeLists.txt| 5 +-- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt index ccbf7d033fd663..0954f8367654f6 100644 --- a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt +++ b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt @@ -14,36 +14,36 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$") endif() # Create the library and add the default arguments. -add_target_library(omptarget.rtl.${machine} ${machine}) +add_target_library(omptarget.rtl.host ${machine}) -target_sources(omptarget.rtl.${machine} PRIVATE src/rtl.cpp) +target_sources(omptarget.rtl.host PRIVATE src/rtl.cpp) if(LIBOMPTARGET_DEP_LIBFFI_FOUND) libomptarget_say("Building ${machine} plugin linked with libffi") if(FFI_STATIC_LIBRARIES) -target_link_libraries(omptarget.rtl.${machine} PRIVATE FFI::ffi_static) +target_link_libraries(omptarget.rtl.host PRIVATE FFI::ffi_static) else() -target_link_libraries(omptarget.rtl.${machine} PRIVATE FFI::ffi) +target_link_libraries(omptarget.rtl.host PRIVATE FFI::ffi) endif() else() libomptarget_say("Building ${machine} plugin for dlopened libffi") - target_sources(omptarget.rtl.${machine} PRIVATE dynamic_ffi/ffi.cpp) - target_include_directories(omptarget.rtl.${machine} PRIVATE dynamic_ffi) + target_sources(omptarget.rtl.host PRIVATE dynamic_ffi/ffi.cpp) + target_include_directories(omptarget.rtl.host PRIVATE dynamic_ffi) endif() # Install plugin under the lib destination folder. -install(TARGETS omptarget.rtl.${machine} +install(TARGETS omptarget.rtl.host LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}") -set_target_properties(omptarget.rtl.${machine} PROPERTIES +set_target_properties(omptarget.rtl.host PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.." POSITION_INDEPENDENT_CODE ON CXX_VISIBILITY_PRESET protected) -target_include_directories(omptarget.rtl.${machine} PRIVATE +target_include_directories(omptarget.rtl.host PRIVATE ${LIBOMPTARGET_INCLUDE_DIR}) if(LIBOMPTARGET_DEP_LIBFFI_FOUND) - list(APPEND LIBOMPTARGET_TESTED_PLUGINS omptarget.rtl.${machine}) + list(APPEND LIBOMPTARGET_TESTED_PLUGINS omptarget.rtl.host) set(LIBOMPTARGET_TESTED_PLUGINS "${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE) else() @@ -53,29 +53,29 @@ endif() # Define the target specific triples and ELF machine values. if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$" OR CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64$") - target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_PPC64) - target_compile_definitions(omptarget.rtl.${machine} PRIVATE + target_compile_definitions(omptarget.rtl.host PRIVATE TARGET_ELF_ID=EM_PPC64) + target_compile_definitions(omptarget.rtl.host PRIVATE LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE="powerpc64-ibm-linux-gnu") list(APPEND LIBOMPTARGET_SYSTEM_TARGETS "powerpc64-ibm-linux-gnu" "powerpc64-ibm-linux-gnu-LTO") set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64$") - target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_X86_64) - target_compile_definitions(omptarget.rtl.${machine} PRIVATE + target_compile_definitions(omptarget.rtl.host PRIVATE TARGET_ELF_ID=EM_X86_64) + target_compile_definitions(omptarget.rtl.host PRIVATE LIBOMPTARGET_NEXTGEN_GENERIC_PLUGIN_TRIPLE="x86_64-pc-linux-gnu") list(APPEND LIBOMPTARGET_SYSTEM_TARGETS "x86_64-pc-linux-gnu" "x86_64-pc-linux-gnu-LTO") set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}" PARENT_SCOPE) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64$") - target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_ELF_ID=EM_AARCH64) - target_compile_definitions(omptarget.rtl.${machine} PRIVATE + target_compile_definitions(omptarget.rtl.host PRIVATE TARGET_ELF_ID=EM_AARCH64) +
[clang] [llvm] [openmp] [Libomptarget] Statically link all plugin runtimes (PR #87009)
jhuber6 wrote: This contains three other dependent commits until they land. For now just browse the most recent commit for the relevant changes. https://github.com/llvm/llvm-project/pull/87009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Libomptarget] Statically link all plugin runtimes (PR #87009)
llvmbot wrote: @llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-backend-amdgpu @llvm/pr-subscribers-clang Author: Joseph Huber (jhuber6) Changes This patch overhauls the `libomptarget` and plugin interface. Currently, we define a C API and compile each plugin as a separate shared library. Then, `libomptarget` loads these API functions and forwards its internal calls to them. This was originally designed to allow multiple implementations of a library to be live. However, since then no one has used this functionality and it prevents us from using much nicer interfaces. If the old behavior is desired it should instead be implemented as a separate plugin. This patch replaces the `PluginAdaptorTy` interface with the `GenericPluginTy` that is used by the plugins. Each plugin exports a `createPlugin_name` function that is used to get the specific implementation. This code is now shared with `libomptarget`. There are some notable improvements to this. 1. Massively improved lifetimes of life runtime objects 2. The plugins can use a C++ interface 3. Global state does not need to be duplicated for each plugin + libomptarget 4. Easier to use and add features and improve error handling 5. Less function call overhead / Improved LTO performance. Additional changes in this plugin are related to contending with the fact that state is now shared. Initialization and deinitialization is now handled correctly and in phase with the underlying runtime, allowing us to actually know when something is getting deallocated. Depends on https://github.com/llvm/llvm-project/pull/86971 https://github.com/llvm/llvm-project/pull/86875 https://github.com/llvm/llvm-project/pull/86868 --- Patch is 71.10 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/87009.diff 28 Files Affected: - (modified) clang/test/Driver/linker-wrapper-image.c (+1-1) - (modified) llvm/lib/Frontend/Offloading/OffloadWrapper.cpp (+4-3) - (modified) openmp/libomptarget/CMakeLists.txt (+26) - (modified) openmp/libomptarget/include/PluginManager.h (+24-70) - (removed) openmp/libomptarget/include/Shared/PluginAPI.h (-232) - (removed) openmp/libomptarget/include/Shared/PluginAPI.inc (-51) - (added) openmp/libomptarget/include/Shared/Targets.def.in (+20) - (modified) openmp/libomptarget/include/device.h (+5-3) - (modified) openmp/libomptarget/plugins-nextgen/CMakeLists.txt (+9-19) - (modified) openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt (-5) - (modified) openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp (+8-6) - (modified) openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt (+2-3) - (modified) openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h (+4-90) - (modified) openmp/libomptarget/plugins-nextgen/common/include/Utils/ELF.h (-2) - (modified) openmp/libomptarget/plugins-nextgen/common/src/JIT.cpp (+17-23) - (modified) openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp (-205) - (modified) openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt (-5) - (modified) openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp (+8-6) - (modified) openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt (+16-24) - (modified) openmp/libomptarget/plugins-nextgen/host/src/rtl.cpp (+8-6) - (modified) openmp/libomptarget/src/CMakeLists.txt (+8-18) - (modified) openmp/libomptarget/src/OffloadRTL.cpp (+1) - (modified) openmp/libomptarget/src/OpenMP/InteropAPI.cpp (+2-2) - (modified) openmp/libomptarget/src/PluginManager.cpp (+72-113) - (modified) openmp/libomptarget/src/device.cpp (+1-2) - (modified) openmp/libomptarget/src/interface.cpp (+1-1) - (modified) openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp (-2) - (modified) openmp/libomptarget/unittests/Plugins/NextgenPluginsTest.cpp (-1) ``diff diff --git a/clang/test/Driver/linker-wrapper-image.c b/clang/test/Driver/linker-wrapper-image.c index d01445e3aed04e..5d5d62805e174d 100644 --- a/clang/test/Driver/linker-wrapper-image.c +++ b/clang/test/Driver/linker-wrapper-image.c @@ -30,8 +30,8 @@ // OPENMP: define internal void @.omp_offloading.descriptor_reg() section ".text.startup" { // OPENMP-NEXT: entry: -// OPENMP-NEXT: %0 = call i32 @atexit(ptr @.omp_offloading.descriptor_unreg) // OPENMP-NEXT: call void @__tgt_register_lib(ptr @.omp_offloading.descriptor) +// OPENMP-NEXT: %0 = call i32 @atexit(ptr @.omp_offloading.descriptor_unreg) // OPENMP-NEXT: ret void // OPENMP-NEXT: } diff --git a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp index 7241d15ed1c670..8b6f9ea1f4cca3 100644 --- a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp +++ b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp @@ -232,12 +232,13 @@ void createRegisterFunction(Module , GlobalVariable *BinDesc, // Construct function body IRBuilder<> Builder(BasicBlock::Create(C, "entry", Func)); +
[clang] [llvm] [openmp] [Libomptarget] Statically link all plugin runtimes (PR #87009)
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/87009 This patch overhauls the `libomptarget` and plugin interface. Currently, we define a C API and compile each plugin as a separate shared library. Then, `libomptarget` loads these API functions and forwards its internal calls to them. This was originally designed to allow multiple implementations of a library to be live. However, since then no one has used this functionality and it prevents us from using much nicer interfaces. If the old behavior is desired it should instead be implemented as a separate plugin. This patch replaces the `PluginAdaptorTy` interface with the `GenericPluginTy` that is used by the plugins. Each plugin exports a `createPlugin_` function that is used to get the specific implementation. This code is now shared with `libomptarget`. There are some notable improvements to this. 1. Massively improved lifetimes of life runtime objects 2. The plugins can use a C++ interface 3. Global state does not need to be duplicated for each plugin + libomptarget 4. Easier to use and add features and improve error handling 5. Less function call overhead / Improved LTO performance. Additional changes in this plugin are related to contending with the fact that state is now shared. Initialization and deinitialization is now handled correctly and in phase with the underlying runtime, allowing us to actually know when something is getting deallocated. Depends on https://github.com/llvm/llvm-project/pull/86971 https://github.com/llvm/llvm-project/pull/86875 https://github.com/llvm/llvm-project/pull/86868 >From fe0b6725e9aa89cc378ffd97f19354d59ab4fa93 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 27 Mar 2024 15:27:16 -0500 Subject: [PATCH 1/4] [Libomptarget] Rename `libomptarget.rtl.x86_64` to `libomptarget.rtl.host` Summary: All of these are functionally the same code, just compiled for separate architectures. We currently do not expose a way to execute these on separate architectures as the host plugin works using `dlopen` into the same process, and therefore cannot possibly be an incompatible architecture. (This could work with a remote plugin, but this is not supported yet). This patch simply renames all of these to the same thing so we no longer need to check around for its varying definitions. --- .../plugins-nextgen/host/CMakeLists.txt | 36 +-- openmp/libomptarget/src/CMakeLists.txt| 5 +-- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt index ccbf7d033fd663..0954f8367654f6 100644 --- a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt +++ b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt @@ -14,36 +14,36 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$") endif() # Create the library and add the default arguments. -add_target_library(omptarget.rtl.${machine} ${machine}) +add_target_library(omptarget.rtl.host ${machine}) -target_sources(omptarget.rtl.${machine} PRIVATE src/rtl.cpp) +target_sources(omptarget.rtl.host PRIVATE src/rtl.cpp) if(LIBOMPTARGET_DEP_LIBFFI_FOUND) libomptarget_say("Building ${machine} plugin linked with libffi") if(FFI_STATIC_LIBRARIES) -target_link_libraries(omptarget.rtl.${machine} PRIVATE FFI::ffi_static) +target_link_libraries(omptarget.rtl.host PRIVATE FFI::ffi_static) else() -target_link_libraries(omptarget.rtl.${machine} PRIVATE FFI::ffi) +target_link_libraries(omptarget.rtl.host PRIVATE FFI::ffi) endif() else() libomptarget_say("Building ${machine} plugin for dlopened libffi") - target_sources(omptarget.rtl.${machine} PRIVATE dynamic_ffi/ffi.cpp) - target_include_directories(omptarget.rtl.${machine} PRIVATE dynamic_ffi) + target_sources(omptarget.rtl.host PRIVATE dynamic_ffi/ffi.cpp) + target_include_directories(omptarget.rtl.host PRIVATE dynamic_ffi) endif() # Install plugin under the lib destination folder. -install(TARGETS omptarget.rtl.${machine} +install(TARGETS omptarget.rtl.host LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}") -set_target_properties(omptarget.rtl.${machine} PROPERTIES +set_target_properties(omptarget.rtl.host PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.." POSITION_INDEPENDENT_CODE ON CXX_VISIBILITY_PRESET protected) -target_include_directories(omptarget.rtl.${machine} PRIVATE +target_include_directories(omptarget.rtl.host PRIVATE ${LIBOMPTARGET_INCLUDE_DIR}) if(LIBOMPTARGET_DEP_LIBFFI_FOUND) - list(APPEND LIBOMPTARGET_TESTED_PLUGINS omptarget.rtl.${machine}) + list(APPEND LIBOMPTARGET_TESTED_PLUGINS omptarget.rtl.host) set(LIBOMPTARGET_TESTED_PLUGINS "${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE) else() @@ -53,29 +53,29 @@ endif() # Define the target specific triples and ELF machine values.