[Openmp-commits] [openmp] [Libomptarget] Make a plugin specific namespace for each library (PR #86315)

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Fri Mar 22 10:38:55 PDT 2024


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/86315

Summary:
Currently, we get to avoid function collisions due to the fact that
these are built as shared libraries. However, when moving to static
libraries these interface functions will all conflict with eachother.
This patch changes the existing `plugin::` namespace to be a macro
defined by the built library. This means that the resulting symbols will
look like `omp::target::amdgpu::...`.
Depends on https://github.com/llvm/llvm-project/pull/86191 


>From 731ebcb1ad3a28a383dc3a81d01c72abd5107a24 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Thu, 21 Mar 2024 15:05:18 -0500
Subject: [PATCH 1/2] [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.
---
 .../plugins-nextgen/CMakeLists.txt            |  97 ++++++++++++++-
 .../plugins-nextgen/amdgpu/CMakeLists.txt     |  80 +++----------
 .../plugins-nextgen/common/CMakeLists.txt     | 110 ------------------
 .../common/OMPT/CMakeLists.txt                |  70 -----------
 .../plugins-nextgen/cuda/CMakeLists.txt       |  40 +------
 .../plugins-nextgen/host/CMakeLists.txt       |  29 +----
 .../libomptarget/test/offloading/ompx_bare.c  |   4 +-
 .../struct_mapping_with_pointers.cpp          |   6 +-
 8 files changed, 124 insertions(+), 312 deletions(-)
 delete mode 100644 openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
 delete mode 100644 openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt

diff --git a/openmp/libomptarget/plugins-nextgen/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/CMakeLists.txt
index 75540f0558442e..998e033d7d5624 100644
--- a/openmp/libomptarget/plugins-nextgen/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/CMakeLists.txt
@@ -10,7 +10,102 @@
 #
 ##===----------------------------------------------------------------------===##
 
-add_subdirectory(common)
+# Common interface to handle creating a plugin library.
+set(common_dir ${CMAKE_CURRENT_SOURCE_DIR}/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
+    ${common_dir}/src/PluginInterface.cpp
+    ${common_dir}/src/GlobalHandler.cpp
+    ${common_dir}/src/JIT.cpp
+    ${common_dir}/src/RPC.cpp
+    ${common_dir}/src/Utils/ELF.cpp
+
+    NO_INSTALL_RPATH
+    BUILDTREE_ONLY
+  )
+
+  target_link_libraries(${target_name} PUBLIC ${llvm_libs} ${OPENMP_PTHREAD_LIB})
+  llvm_update_compile_flags(${target_name})
+
+  # Include the RPC server from the `libc` project if availible.
+  if(TARGET llvmlibc_rpc_server AND ${LIBOMPTARGET_GPU_LIBC_SUPPORT})
+    target_link_libraries(${target_name} PRIVATE llvmlibc_rpc_server)
+    target_compile_definitions(${target_name} PRIVATE LIBOMPTARGET_RPC_SUPPORT)
+  elseif(${LIBOMPTARGET_GPU_LIBC_SUPPORT})
+    find_library(llvmlibc_rpc_server NAMES llvmlibc_rpc_server
+                 PATHS ${LIBOMPTARGET_LLVM_LIBRARY_DIR} NO_DEFAULT_PATH)
+    if(llvmlibc_rpc_server)
+      target_link_libraries(${target_name} PRIVATE ${llvmlibc_rpc_server})
+      target_compile_definitions(${target_name} PRIVATE LIBOMPTARGET_RPC_SUPPORT)
+      # We may need to get the headers directly from the 'libc' source directory.
+      target_include_directories(${target_name} PRIVATE
+                                 ${CMAKE_SOURCE_DIR}/../libc/utils/gpu/server
+                                 ${CMAKE_SOURCE_DIR}/../libc/include)
+    endif()
+  endif()
+
+  # Only enable JIT for those targets that LLVM can support.
+  string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" TargetsSupported)
+  foreach(Target ${TargetsSupported})
+    target_compile_definitions(${target_name} PRIVATE "LIBOMPTARGET_JIT_${Target}")
+  endforeach()
+
+  target_compile_definitions(${target_name} PRIVATE TARGET_NAME=${lib_name})
+  target_compile_definitions(${target_name} PRIVATE 
+                             DEBUG_PREFIX="TARGET ${lib_name} RTL")
+
+  # If we have OMPT enabled include it in the list of sourced.
+  if (OMPT_TARGET_DEFAULT AND LIBOMPTARGET_OMPT_SUPPORT)
+    target_sources(${target_name} PRIVATE ${common_dir}/OMPT/OmptCallback.cpp)
+  endif()
+
+  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()
+
+  target_include_directories(${target_name} PRIVATE
+    ${LIBOMPTARGET_INCLUDE_DIR}
+    ${common_dir}/include
+  )
+  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)
diff --git a/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
index 8fbfe4d9b13f73..40df77102c78fb 100644
--- a/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -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)
@@ -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}/..")
diff --git a/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
deleted file mode 100644
index 085d443071650e..00000000000000
--- a/openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
+++ /dev/null
@@ -1,110 +0,0 @@
-##===----------------------------------------------------------------------===##
-#
-# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-##===----------------------------------------------------------------------===##
-#
-# Common parts which can be used by all plugins
-#
-##===----------------------------------------------------------------------===##
-
-# NOTE: Don't try to build `PluginInterface` using `add_llvm_library` because we
-# don't want to export `PluginInterface` while `add_llvm_library` requires that.
-add_library(PluginCommon OBJECT
-  src/PluginInterface.cpp
-  src/GlobalHandler.cpp
-  src/JIT.cpp
-  src/RPC.cpp
-  src/Utils/ELF.cpp
-)
-
-# Only enable JIT for those targets that LLVM can support.
-string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" TargetsSupported)
-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)
-	target_compile_definitions(PluginCommon PRIVATE LIBOMPTARGET_RPC_SUPPORT)
-elseif(${LIBOMPTARGET_GPU_LIBC_SUPPORT})
-  find_library(llvmlibc_rpc_server NAMES llvmlibc_rpc_server
-               PATHS ${LIBOMPTARGET_LLVM_LIBRARY_DIR} NO_DEFAULT_PATH)
-  if(llvmlibc_rpc_server)
-		target_link_libraries(PluginCommon PRIVATE ${llvmlibc_rpc_server})
-		target_compile_definitions(PluginCommon PRIVATE LIBOMPTARGET_RPC_SUPPORT)
-    # We may need to get the headers directly from the 'libc' source directory.
-    target_include_directories(PluginCommon PRIVATE
-                               ${CMAKE_SOURCE_DIR}/../libc/utils/gpu/server
-                               ${CMAKE_SOURCE_DIR}/../libc/include)
-  endif()
-endif()
-
-if ((OMPT_TARGET_DEFAULT) AND (LIBOMPTARGET_OMPT_SUPPORT))
-	target_link_libraries(PluginCommon PUBLIC OMPT)
-endif()
-
-# Define the TARGET_NAME and DEBUG_PREFIX.
-target_compile_definitions(PluginCommon PRIVATE
-  TARGET_NAME="PluginInterface"
-  DEBUG_PREFIX="PluginInterface"
-)
-
-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
-  ${CMAKE_CURRENT_SOURCE_DIR}/include
-)
-
-set_target_properties(PluginCommon PROPERTIES
-  POSITION_INDEPENDENT_CODE ON
-  CXX_VISIBILITY_PRESET protected)
-
-add_subdirectory(OMPT)
-
diff --git a/openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt
deleted file mode 100644
index be4c743665b3e9..00000000000000
--- a/openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt
+++ /dev/null
@@ -1,70 +0,0 @@
-##===----------------------------------------------------------------------===##
-#
-# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-##===----------------------------------------------------------------------===##
-#
-# Aggregation of parts which can be used by OpenMP tools
-#
-##===----------------------------------------------------------------------===##
-
-# NOTE: Don't try to build `OMPT` using `add_llvm_library` because we
-# don't want to export `OMPT` while `add_llvm_library` requires that.
-add_library(OMPT OBJECT
-  OmptCallback.cpp)
-
-# This is required when using LLVM libraries.
-llvm_update_compile_flags(OMPT)
-
-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(OMPT
-  PUBLIC
-    ${llvm_libs}
-)
-
-# Define the TARGET_NAME and DEBUG_PREFIX.
-target_compile_definitions(OMPT PRIVATE
-  TARGET_NAME="OMPT"
-  DEBUG_PREFIX="OMPT"
-)
-
-target_include_directories(OMPT
-  INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
-  PRIVATE ${LIBOMPTARGET_INCLUDE_DIR}
-)
-
-set_target_properties(OMPT PROPERTIES
-  POSITION_INDEPENDENT_CODE ON
-  CXX_VISIBILITY_PRESET protected)
diff --git a/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
index 2bfb47168a7f3b..b3530462aa19ba 100644
--- a/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
@@ -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)
@@ -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)
@@ -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}/..")
diff --git a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt
index 58a79898ff80dd..d30680e1043167 100644
--- a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt
@@ -2,11 +2,6 @@ if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux")
   return()
 endif()
 
-  # build_generic_elf64("s390x" "S390X" "s390x" "systemz" "s390x-ibm-linux-gnu" "22")
-  # build_generic_elf64("aarch64" "aarch64" "aarch64" "aarch64" "aarch64-unknown-linux-gnu" "183")
-  # build_generic_elf64("ppc64" "PPC64" "ppc64" "ppc64" "powerpc64-ibm-linux-gnu" "21")
-  # build_generic_elf64("x86_64" "x86_64" "x86_64" "x86_64" "x86_64-pc-linux-gnu" "62")
-  # build_generic_elf64("ppc64le" "PPC64le" "ppc64" "ppc64le" "powerpc64le-ibm-linux-gnu" "21")
 set(supported_targets x86_64 aarch64 ppc64 ppc64le s390x)
 if(NOT ${CMAKE_SYSTEM_PROCESSOR} IN_LIST supported_targets)
   libomptarget_say("Not building ${machine} NextGen offloading plugin")
@@ -18,16 +13,10 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$")
   set(machine ppc64)
 endif()
 
-add_llvm_library(omptarget.rtl.${machine} SHARED
-  src/rtl.cpp
-  ADDITIONAL_HEADER_DIRS
-    ${LIBOMPTARGET_INCLUDE_DIR}
-  LINK_LIBS PRIVATE
-    PluginCommon
-    ${OPENMP_PTHREAD_LIB}
-  NO_INSTALL_RPATH
-  BUILDTREE_ONLY
-)
+# Create the library and add the default arguments.
+add_target_library(omptarget.rtl.${machine} ${machine})
+
+target_sources(omptarget.rtl.${machine} PRIVATE src/rtl.cpp)
 
 if(LIBOMPTARGET_DEP_LIBFFI_FOUND)
   libomptarget_say("Building ${machine} plugin linked with libffi")
@@ -42,10 +31,6 @@ else()
   target_include_directories(omptarget.rtl.${machine} PRIVATE dynamic_ffi)
 endif()
 
-if(OMPT_TARGET_DEFAULT AND LIBOMPTARGET_OMPT_SUPPORT)
-  target_link_libraries(omptarget.rtl.${machine} PRIVATE OMPT)
-endif()
-
 if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
   target_link_libraries(omptarget.rtl.${machine} PRIVATE
     "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports")
@@ -70,12 +55,6 @@ else()
   libomptarget_say("Not generating ${tmachine_name} tests. LibFFI not found.")
 endif()
 
-# Define macro to be used as prefix of the runtime messages for this target.
-target_compile_definitions(omptarget.rtl.${machine} PRIVATE TARGET_NAME=${machine})
-# TODO: This should be automatized in Debug.h.
-target_compile_definitions(omptarget.rtl.${machine} PRIVATE
-                           DEBUG_PREFIX="TARGET ${machine} RTL")
-
 # Define the target specific triples and ELF machine values.
 if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le$" OR
    CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64$")
diff --git a/openmp/libomptarget/test/offloading/ompx_bare.c b/openmp/libomptarget/test/offloading/ompx_bare.c
index 3dabdcd15e0d8d..06a81f86ae1abe 100644
--- a/openmp/libomptarget/test/offloading/ompx_bare.c
+++ b/openmp/libomptarget/test/offloading/ompx_bare.c
@@ -20,7 +20,9 @@ int main(int argc, char *argv[]) {
   const int N = num_blocks * block_size;
   int *data = (int *)malloc(N * sizeof(int));
 
-  // CHECK: "PluginInterface" device 0 info: Launching kernel __omp_offloading_{{.*}} with 64 blocks and 64 threads in SPMD mode
+  // clang-format off
+// CHECK: {{.*}} device 0 info: Launching kernel __omp_offloading_{{.*}} with 64 blocks and 64 threads in SPMD mode
+  // clang-format on
 
 #pragma omp target teams ompx_bare num_teams(num_blocks) thread_limit(block_size) map(from: data[0:N])
   {
diff --git a/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp b/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp
index f0fde50889dace..49a5d0cf8db2af 100644
--- a/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp
+++ b/openmp/libomptarget/test/offloading/struct_mapping_with_pointers.cpp
@@ -49,7 +49,7 @@ int main() {
 
   // clang-format off
   // CHECK: omptarget --> Looking up mapping(HstPtrBegin=[[DAT_HST_PTR_BASE]], Size=288)...
-  // CHECK: PluginInterface --> MemoryManagerTy::allocate: size 288 with host pointer [[DAT_HST_PTR_BASE]].
+  // CHECK: {{.*}} --> MemoryManagerTy::allocate: size 288 with host pointer [[DAT_HST_PTR_BASE]].
   // CHECK: omptarget --> Creating new map entry with HstPtrBase=[[DAT_HST_PTR_BASE]], HstPtrBegin=[[DAT_HST_PTR_BASE]], TgtAllocBegin=[[DAT_DEVICE_PTR_BASE:0x.*]], TgtPtrBegin=[[DAT_DEVICE_PTR_BASE]], Size=288, DynRefCount=1, HoldRefCount=0, Name=unknown
   // CHECK: omptarget --> Moving 288 bytes (hst:[[DAT_HST_PTR_BASE]]) -> (tgt:[[DAT_DEVICE_PTR_BASE]])
   // clang-format on
@@ -57,7 +57,7 @@ int main() {
   /// Second argument is dat.datum:
   // clang-format off
   // CHECK: omptarget --> Looking up mapping(HstPtrBegin=[[DATUM_HST_PTR_BASE]], Size=40)...
-  // CHECK: PluginInterface --> MemoryManagerTy::allocate: size 40 with host pointer [[DATUM_HST_PTR_BASE]].
+  // CHECK: {{.*}} --> MemoryManagerTy::allocate: size 40 with host pointer [[DATUM_HST_PTR_BASE]].
   // CHECK: omptarget --> Creating new map entry with HstPtrBase=[[DATUM_HST_PTR_BASE]], HstPtrBegin=[[DATUM_HST_PTR_BASE]], TgtAllocBegin=[[DATUM_DEVICE_PTR_BASE:0x.*]], TgtPtrBegin=[[DATUM_DEVICE_PTR_BASE]], Size=40, DynRefCount=1, HoldRefCount=0, Name=unknown
   // CHECK: omptarget --> Moving 40 bytes (hst:[[DATUM_HST_PTR_BASE]]) -> (tgt:[[DATUM_DEVICE_PTR_BASE]])
   // clang-format on
@@ -65,7 +65,7 @@ int main() {
   /// Third argument is dat.more_datum:
   // clang-format off
   // CHECK: omptarget --> Looking up mapping(HstPtrBegin=[[MORE_DATUM_HST_PTR_BEGIN]], Size=80)...
-  // CHECK: PluginInterface --> MemoryManagerTy::allocate: size 80 with host pointer [[MORE_DATUM_HST_PTR_BEGIN]].
+  // CHECK: {{.*}} --> MemoryManagerTy::allocate: size 80 with host pointer [[MORE_DATUM_HST_PTR_BEGIN]].
   // CHECK: omptarget --> Creating new map entry with HstPtrBase=[[MORE_DATUM_HST_PTR_BEGIN]], HstPtrBegin=[[MORE_DATUM_HST_PTR_BEGIN]], TgtAllocBegin=[[MORE_DATUM_DEVICE_PTR_BEGIN:0x.*]], TgtPtrBegin=[[MORE_DATUM_DEVICE_PTR_BEGIN]], Size=80, DynRefCount=1, HoldRefCount=0, Name=unknown
   // CHECK: omptarget --> Moving 80 bytes (hst:[[MORE_DATUM_HST_PTR_BEGIN]]) -> (tgt:[[MORE_DATUM_DEVICE_PTR_BEGIN]])
   // clang-format on

>From 7d29dcf64e4df7187676b7aac0ba998699b24606 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 22 Mar 2024 12:28:31 -0500
Subject: [PATCH 2/2] [Libomptarget] Make a plugin specific namespace for each
 library

Summary:
Currently, we get to avoid function collisions due to the fact that
these are built as shared libraries. However, when moving to static
libraries these interface functions will all conflict with eachother.
This patch changes the existing `plugin::` namespace to be a macro
defined by the built library. This means that the resulting symbols will
look like `omp::target::amdgpu::...`.

Depends on https://github.com/llvm/llvm-project/pull/86191
---
 .../plugins-nextgen/CMakeLists.txt            |  3 +-
 .../plugins-nextgen/amdgpu/CMakeLists.txt     |  2 +-
 .../plugins-nextgen/amdgpu/src/rtl.cpp        |  4 +-
 .../amdgpu/utils/UtilitiesRTL.h               |  4 +-
 .../common/include/GlobalHandler.h            |  4 +-
 .../plugins-nextgen/common/include/JIT.h      |  6 +--
 .../common/include/PluginInterface.h          |  4 +-
 .../plugins-nextgen/common/include/RPC.h      | 20 ++++-----
 .../common/src/GlobalHandler.cpp              |  2 +-
 .../plugins-nextgen/common/src/JIT.cpp        |  2 +-
 .../common/src/PluginInterface.cpp            |  4 +-
 .../plugins-nextgen/common/src/RPC.cpp        | 44 +++++++++----------
 .../plugins-nextgen/cuda/CMakeLists.txt       |  2 +-
 .../plugins-nextgen/cuda/src/rtl.cpp          |  4 +-
 .../plugins-nextgen/host/CMakeLists.txt       |  2 +-
 .../plugins-nextgen/host/src/rtl.cpp          |  4 +-
 16 files changed, 56 insertions(+), 55 deletions(-)

diff --git a/openmp/libomptarget/plugins-nextgen/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/CMakeLists.txt
index 998e033d7d5624..3d9e1db6ad8b1c 100644
--- a/openmp/libomptarget/plugins-nextgen/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/CMakeLists.txt
@@ -12,7 +12,7 @@
 
 # Common interface to handle creating a plugin library.
 set(common_dir ${CMAKE_CURRENT_SOURCE_DIR}/common)
-function(add_target_library target_name lib_name)
+function(add_target_library target_name lib_name plugin_target)
   llvm_map_components_to_libnames(llvm_libs
     ${LLVM_TARGETS_TO_BUILD}
     AggressiveInstCombine
@@ -77,6 +77,7 @@ function(add_target_library target_name lib_name)
     target_compile_definitions(${target_name} PRIVATE "LIBOMPTARGET_JIT_${Target}")
   endforeach()
 
+  target_compile_definitions(${target_name} PRIVATE PLUGIN=${plugin_target})
   target_compile_definitions(${target_name} PRIVATE TARGET_NAME=${lib_name})
   target_compile_definitions(${target_name} PRIVATE 
                              DEBUG_PREFIX="TARGET ${lib_name} RTL")
diff --git a/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
index 40df77102c78fb..30d7d8defa9d1c 100644
--- a/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -28,7 +28,7 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)|(aarch64)$" AND CMAKE
 endif()
 
 # Create the library and add the default arguments.
-add_target_library(omptarget.rtl.amdgpu AMDGPU)
+add_target_library(omptarget.rtl.amdgpu AMDGPU amdgpu)
 
 target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
 target_include_directories(omptarget.rtl.amdgpu PRIVATE
diff --git a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
index fce7454bf2800d..6d92f526afe9bf 100644
--- a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -72,7 +72,7 @@
 namespace llvm {
 namespace omp {
 namespace target {
-namespace plugin {
+namespace PLUGIN {
 
 /// Forward declarations for all specialized data structures.
 struct AMDGPUKernelTy;
@@ -3441,7 +3441,7 @@ void *AMDGPUDeviceTy::allocate(size_t Size, void *, TargetAllocTy Kind) {
   return Alloc;
 }
 
-} // namespace plugin
+} // namespace PLUGIN
 } // namespace target
 } // namespace omp
 } // namespace llvm
diff --git a/openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h b/openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h
index 58a3b5df00fac6..8234fc81a8401f 100644
--- a/openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h
+++ b/openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h
@@ -32,7 +32,7 @@ using namespace llvm::ELF;
 namespace llvm {
 namespace omp {
 namespace target {
-namespace plugin {
+namespace PLUGIN {
 namespace utils {
 
 // The implicit arguments of COV5 AMDGPU kernels.
@@ -311,7 +311,7 @@ readAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer,
 }
 
 } // namespace utils
-} // namespace plugin
+} // namespace PLUGIN
 } // namespace target
 } // namespace omp
 } // namespace llvm
diff --git a/openmp/libomptarget/plugins-nextgen/common/include/GlobalHandler.h b/openmp/libomptarget/plugins-nextgen/common/include/GlobalHandler.h
index 829b4b72911935..e3f663879b1570 100644
--- a/openmp/libomptarget/plugins-nextgen/common/include/GlobalHandler.h
+++ b/openmp/libomptarget/plugins-nextgen/common/include/GlobalHandler.h
@@ -26,7 +26,7 @@
 namespace llvm {
 namespace omp {
 namespace target {
-namespace plugin {
+namespace PLUGIN {
 
 class DeviceImageTy;
 struct GenericDeviceTy;
@@ -166,7 +166,7 @@ class GenericGlobalHandlerTy {
   }
 };
 
-} // namespace plugin
+} // namespace PLUGIN
 } // namespace target
 } // namespace omp
 } // namespace llvm
diff --git a/openmp/libomptarget/plugins-nextgen/common/include/JIT.h b/openmp/libomptarget/plugins-nextgen/common/include/JIT.h
index b22197b8920838..2bcd016c6a61a2 100644
--- a/openmp/libomptarget/plugins-nextgen/common/include/JIT.h
+++ b/openmp/libomptarget/plugins-nextgen/common/include/JIT.h
@@ -34,9 +34,9 @@ class MemoryBuffer;
 
 namespace omp {
 namespace target {
-namespace plugin {
+namespace PLUGIN {
 struct GenericDeviceTy;
-} // namespace plugin
+} // namespace PLUGIN
 
 /// The JIT infrastructure and caching mechanism.
 struct JITEngine {
@@ -53,7 +53,7 @@ struct JITEngine {
   /// generated device image that could be loaded to the device directly.
   Expected<const __tgt_device_image *>
   process(const __tgt_device_image &Image,
-          target::plugin::GenericDeviceTy &Device);
+          target::PLUGIN::GenericDeviceTy &Device);
 
   /// Return true if \p Image is a bitcode image that can be JITed for the given
   /// architecture.
diff --git a/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h b/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
index b7be7b645ba33e..8753db090a9f62 100644
--- a/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
+++ b/openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h
@@ -49,7 +49,7 @@ namespace llvm {
 namespace omp {
 namespace target {
 
-namespace plugin {
+namespace PLUGIN {
 
 struct GenericPluginTy;
 struct GenericKernelTy;
@@ -1395,7 +1395,7 @@ template <typename ResourceRef> class GenericDeviceResourceManagerTy {
 /// A static check on whether or not we support RPC in libomptarget.
 bool libomptargetSupportsRPC();
 
-} // namespace plugin
+} // namespace PLUGIN
 } // namespace target
 } // namespace omp
 } // namespace llvm
diff --git a/openmp/libomptarget/plugins-nextgen/common/include/RPC.h b/openmp/libomptarget/plugins-nextgen/common/include/RPC.h
index 2e39b3f299c888..dfb342e11b5bae 100644
--- a/openmp/libomptarget/plugins-nextgen/common/include/RPC.h
+++ b/openmp/libomptarget/plugins-nextgen/common/include/RPC.h
@@ -21,11 +21,11 @@
 #include <cstdint>
 
 namespace llvm::omp::target {
-namespace plugin {
+namespace PLUGIN {
 struct GenericDeviceTy;
 class GenericGlobalHandlerTy;
 class DeviceImageTy;
-} // namespace plugin
+} // namespace PLUGIN
 
 /// A generic class implementing the interface between the RPC server provided
 /// by the 'libc' project and 'libomptarget'. If the RPC server is not availible
@@ -37,24 +37,24 @@ struct RPCServerTy {
   /// Check if this device image is using an RPC server. This checks for the
   /// precense of an externally visible symbol in the device image that will
   /// be present whenever RPC code is called.
-  llvm::Expected<bool> isDeviceUsingRPC(plugin::GenericDeviceTy &Device,
-                                        plugin::GenericGlobalHandlerTy &Handler,
-                                        plugin::DeviceImageTy &Image);
+  llvm::Expected<bool> isDeviceUsingRPC(PLUGIN::GenericDeviceTy &Device,
+                                        PLUGIN::GenericGlobalHandlerTy &Handler,
+                                        PLUGIN::DeviceImageTy &Image);
 
   /// Initialize the RPC server for the given device. This will allocate host
   /// memory for the internal server and copy the data to the client on the
   /// device. The device must be loaded before this is valid.
-  llvm::Error initDevice(plugin::GenericDeviceTy &Device,
-                         plugin::GenericGlobalHandlerTy &Handler,
-                         plugin::DeviceImageTy &Image);
+  llvm::Error initDevice(PLUGIN::GenericDeviceTy &Device,
+                         PLUGIN::GenericGlobalHandlerTy &Handler,
+                         PLUGIN::DeviceImageTy &Image);
 
   /// Runs the RPC server associated with the \p Device until the pending work
   /// is cleared.
-  llvm::Error runServer(plugin::GenericDeviceTy &Device);
+  llvm::Error runServer(PLUGIN::GenericDeviceTy &Device);
 
   /// Deinitialize the RPC server for the given device. This will free the
   /// memory associated with the k
-  llvm::Error deinitDevice(plugin::GenericDeviceTy &Device);
+  llvm::Error deinitDevice(PLUGIN::GenericDeviceTy &Device);
 
   ~RPCServerTy();
 };
diff --git a/openmp/libomptarget/plugins-nextgen/common/src/GlobalHandler.cpp b/openmp/libomptarget/plugins-nextgen/common/src/GlobalHandler.cpp
index ba0aa47f8e51c3..67151288757e54 100644
--- a/openmp/libomptarget/plugins-nextgen/common/src/GlobalHandler.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/src/GlobalHandler.cpp
@@ -23,7 +23,7 @@
 using namespace llvm;
 using namespace omp;
 using namespace target;
-using namespace plugin;
+using namespace PLUGIN;
 
 Expected<std::unique_ptr<ObjectFile>>
 GenericGlobalHandlerTy::getELFObjectFile(DeviceImageTy &Image) {
diff --git a/openmp/libomptarget/plugins-nextgen/common/src/JIT.cpp b/openmp/libomptarget/plugins-nextgen/common/src/JIT.cpp
index 9eb610cab4de66..074f9c36318930 100644
--- a/openmp/libomptarget/plugins-nextgen/common/src/JIT.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/src/JIT.cpp
@@ -316,7 +316,7 @@ JITEngine::compile(const __tgt_device_image &Image,
 
 Expected<const __tgt_device_image *>
 JITEngine::process(const __tgt_device_image &Image,
-                   target::plugin::GenericDeviceTy &Device) {
+                   target::PLUGIN::GenericDeviceTy &Device) {
   const std::string &ComputeUnitKind = Device.getComputeUnitKind();
 
   PostProcessingFn PostProcessing = [&Device](std::unique_ptr<MemoryBuffer> MB)
diff --git a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
index f39f913d85eec2..7999fd69c146a8 100644
--- a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
@@ -37,7 +37,7 @@
 using namespace llvm;
 using namespace omp;
 using namespace target;
-using namespace plugin;
+using namespace PLUGIN;
 
 GenericPluginTy *Plugin::SpecificPlugin = nullptr;
 
@@ -1565,7 +1565,7 @@ Expected<bool> GenericPluginTy::checkELFImage(StringRef Image) const {
   return isELFCompatible(Image);
 }
 
-bool llvm::omp::target::plugin::libomptargetSupportsRPC() {
+bool llvm::omp::target::PLUGIN::libomptargetSupportsRPC() {
 #ifdef LIBOMPTARGET_RPC_SUPPORT
   return true;
 #else
diff --git a/openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp b/openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp
index f46b27701b5b91..21cdfb90ef0a0e 100644
--- a/openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/src/RPC.cpp
@@ -30,9 +30,9 @@ RPCServerTy::RPCServerTy(uint32_t NumDevices) {
 }
 
 llvm::Expected<bool>
-RPCServerTy::isDeviceUsingRPC(plugin::GenericDeviceTy &Device,
-                              plugin::GenericGlobalHandlerTy &Handler,
-                              plugin::DeviceImageTy &Image) {
+RPCServerTy::isDeviceUsingRPC(PLUGIN::GenericDeviceTy &Device,
+                              PLUGIN::GenericGlobalHandlerTy &Handler,
+                              PLUGIN::DeviceImageTy &Image) {
 #ifdef LIBOMPTARGET_RPC_SUPPORT
   return Handler.isSymbolInImage(Device, Image, rpc_client_symbol_name);
 #else
@@ -40,21 +40,21 @@ RPCServerTy::isDeviceUsingRPC(plugin::GenericDeviceTy &Device,
 #endif
 }
 
-Error RPCServerTy::initDevice(plugin::GenericDeviceTy &Device,
-                              plugin::GenericGlobalHandlerTy &Handler,
-                              plugin::DeviceImageTy &Image) {
+Error RPCServerTy::initDevice(PLUGIN::GenericDeviceTy &Device,
+                              PLUGIN::GenericGlobalHandlerTy &Handler,
+                              PLUGIN::DeviceImageTy &Image) {
 #ifdef LIBOMPTARGET_RPC_SUPPORT
   uint32_t DeviceId = Device.getDeviceId();
   auto Alloc = [](uint64_t Size, void *Data) {
-    plugin::GenericDeviceTy &Device =
-        *reinterpret_cast<plugin::GenericDeviceTy *>(Data);
+    PLUGIN::GenericDeviceTy &Device =
+        *reinterpret_cast<PLUGIN::GenericDeviceTy *>(Data);
     return Device.allocate(Size, nullptr, TARGET_ALLOC_HOST);
   };
   uint64_t NumPorts =
       std::min(Device.requestedRPCPortCount(), RPC_MAXIMUM_PORT_COUNT);
   if (rpc_status_t Err = rpc_server_init(DeviceId, NumPorts,
                                          Device.getWarpSize(), Alloc, &Device))
-    return plugin::Plugin::error(
+    return PLUGIN::Plugin::error(
         "Failed to initialize RPC server for device %d: %d", DeviceId, Err);
 
   // Register a custom opcode handler to perform plugin specific allocation.
@@ -62,8 +62,8 @@ Error RPCServerTy::initDevice(plugin::GenericDeviceTy &Device,
     rpc_recv_and_send(
         Port,
         [](rpc_buffer_t *Buffer, void *Data) {
-          plugin::GenericDeviceTy &Device =
-              *reinterpret_cast<plugin::GenericDeviceTy *>(Data);
+          PLUGIN::GenericDeviceTy &Device =
+              *reinterpret_cast<PLUGIN::GenericDeviceTy *>(Data);
           Buffer->data[0] = reinterpret_cast<uintptr_t>(Device.allocate(
               Buffer->data[0], nullptr, TARGET_ALLOC_DEVICE_NON_BLOCKING));
         },
@@ -71,7 +71,7 @@ Error RPCServerTy::initDevice(plugin::GenericDeviceTy &Device,
   };
   if (rpc_status_t Err =
           rpc_register_callback(DeviceId, RPC_MALLOC, MallocHandler, &Device))
-    return plugin::Plugin::error(
+    return PLUGIN::Plugin::error(
         "Failed to register RPC malloc handler for device %d: %d\n", DeviceId,
         Err);
 
@@ -80,8 +80,8 @@ Error RPCServerTy::initDevice(plugin::GenericDeviceTy &Device,
     rpc_recv(
         Port,
         [](rpc_buffer_t *Buffer, void *Data) {
-          plugin::GenericDeviceTy &Device =
-              *reinterpret_cast<plugin::GenericDeviceTy *>(Data);
+          PLUGIN::GenericDeviceTy &Device =
+              *reinterpret_cast<PLUGIN::GenericDeviceTy *>(Data);
           Device.free(reinterpret_cast<void *>(Buffer->data[0]),
                       TARGET_ALLOC_DEVICE_NON_BLOCKING);
         },
@@ -89,13 +89,13 @@ Error RPCServerTy::initDevice(plugin::GenericDeviceTy &Device,
   };
   if (rpc_status_t Err =
           rpc_register_callback(DeviceId, RPC_FREE, FreeHandler, &Device))
-    return plugin::Plugin::error(
+    return PLUGIN::Plugin::error(
         "Failed to register RPC free handler for device %d: %d\n", DeviceId,
         Err);
 
   // Get the address of the RPC client from the device.
   void *ClientPtr;
-  plugin::GlobalTy ClientGlobal(rpc_client_symbol_name, sizeof(void *));
+  PLUGIN::GlobalTy ClientGlobal(rpc_client_symbol_name, sizeof(void *));
   if (auto Err =
           Handler.getGlobalMetadataFromDevice(Device, Image, ClientGlobal))
     return Err;
@@ -112,26 +112,26 @@ Error RPCServerTy::initDevice(plugin::GenericDeviceTy &Device,
   return Error::success();
 }
 
-Error RPCServerTy::runServer(plugin::GenericDeviceTy &Device) {
+Error RPCServerTy::runServer(PLUGIN::GenericDeviceTy &Device) {
 #ifdef LIBOMPTARGET_RPC_SUPPORT
   if (rpc_status_t Err = rpc_handle_server(Device.getDeviceId()))
-    return plugin::Plugin::error(
+    return PLUGIN::Plugin::error(
         "Error while running RPC server on device %d: %d", Device.getDeviceId(),
         Err);
 #endif
   return Error::success();
 }
 
-Error RPCServerTy::deinitDevice(plugin::GenericDeviceTy &Device) {
+Error RPCServerTy::deinitDevice(PLUGIN::GenericDeviceTy &Device) {
 #ifdef LIBOMPTARGET_RPC_SUPPORT
   auto Dealloc = [](void *Ptr, void *Data) {
-    plugin::GenericDeviceTy &Device =
-        *reinterpret_cast<plugin::GenericDeviceTy *>(Data);
+    PLUGIN::GenericDeviceTy &Device =
+        *reinterpret_cast<PLUGIN::GenericDeviceTy *>(Data);
     Device.free(Ptr, TARGET_ALLOC_HOST);
   };
   if (rpc_status_t Err =
           rpc_server_shutdown(Device.getDeviceId(), Dealloc, &Device))
-    return plugin::Plugin::error(
+    return PLUGIN::Plugin::error(
         "Failed to shut down RPC server for device %d: %d",
         Device.getDeviceId(), Err);
 #endif
diff --git a/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
index b3530462aa19ba..2beabeda734f61 100644
--- a/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
@@ -24,7 +24,7 @@ endif()
 libomptarget_say("Building CUDA NextGen offloading plugin.")
 
 # Create the library and add the default arguments.
-add_target_library(omptarget.rtl.cuda CUDA)
+add_target_library(omptarget.rtl.cuda CUDA cuda)
 
 target_sources(omptarget.rtl.cuda PRIVATE src/rtl.cpp)
 
diff --git a/openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp b/openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
index b862bc74909257..911aec7cbb4f0d 100644
--- a/openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
+++ b/openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
@@ -35,7 +35,7 @@
 namespace llvm {
 namespace omp {
 namespace target {
-namespace plugin {
+namespace PLUGIN {
 
 /// Forward declarations for all specialized data structures.
 struct CUDAKernelTy;
@@ -1509,7 +1509,7 @@ Error Plugin::check(int32_t Code, const char *ErrFmt, ArgsTy... Args) {
                                                     ErrFmt, Args..., Desc);
 }
 
-} // namespace plugin
+} // namespace PLUGIN
 } // namespace target
 } // namespace omp
 } // namespace llvm
diff --git a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt
index d30680e1043167..994703784d00af 100644
--- a/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/host/CMakeLists.txt
@@ -14,7 +14,7 @@ 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.${machine} ${machine}  host)
 
 target_sources(omptarget.rtl.${machine} PRIVATE src/rtl.cpp)
 
diff --git a/openmp/libomptarget/plugins-nextgen/host/src/rtl.cpp b/openmp/libomptarget/plugins-nextgen/host/src/rtl.cpp
index 1ef18814a26ac8..4598de2b83dace 100644
--- a/openmp/libomptarget/plugins-nextgen/host/src/rtl.cpp
+++ b/openmp/libomptarget/plugins-nextgen/host/src/rtl.cpp
@@ -46,7 +46,7 @@
 namespace llvm {
 namespace omp {
 namespace target {
-namespace plugin {
+namespace PLUGIN {
 
 /// Forward declarations for all specialized data structures.
 struct GenELF64KernelTy;
@@ -434,7 +434,7 @@ Error Plugin::check(int32_t Code, const char *ErrMsg, ArgsTy... Args) {
       inconvertibleErrorCode(), ErrMsg, Args..., std::to_string(Code).data());
 }
 
-} // namespace plugin
+} // namespace PLUGIN
 } // namespace target
 } // namespace omp
 } // namespace llvm



More information about the Openmp-commits mailing list