Skip to content

[OpenMP] Allow to specify what plugins to look for #74538

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

jdoerfert
Copy link
Member

@jdoerfert jdoerfert commented Dec 5, 2023

By default we now only look for the plugins we build, but the user can overwrite that with LIBOMPTARGET_PLUGINS_TO_LOAD="cuda,amdgpu,x86_64"

@jdoerfert jdoerfert added openmp openmp:libomptarget OpenMP offload runtime labels Dec 5, 2023
@jdoerfert jdoerfert requested a review from jhuber6 December 5, 2023 23:51
@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2023

@llvm/pr-subscribers-openmp

Author: Johannes Doerfert (jdoerfert)

Changes

By default we now only look for the plugins we build, but the user can overwrite that with LIBOMPTARGET_PLUGINS_TO_LOAD="plugA.so","plugB.so"


Full diff: https://github.com/llvm/llvm-project/pull/74538.diff

3 Files Affected:

  • (modified) openmp/libomptarget/CMakeLists.txt (+4-4)
  • (modified) openmp/libomptarget/src/CMakeLists.txt (+22)
  • (modified) openmp/libomptarget/src/PluginManager.cpp (+4)
diff --git a/openmp/libomptarget/CMakeLists.txt b/openmp/libomptarget/CMakeLists.txt
index 972b887c7c952..115189a28ce16 100644
--- a/openmp/libomptarget/CMakeLists.txt
+++ b/openmp/libomptarget/CMakeLists.txt
@@ -110,10 +110,6 @@ set(LIBOMPTARGET_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
 message(STATUS "OpenMP tools dir in libomptarget: ${LIBOMP_OMP_TOOLS_INCLUDE_DIR}")
 include_directories(${LIBOMP_OMP_TOOLS_INCLUDE_DIR})
 
-# Build target agnostic offloading library.
-set(LIBOMPTARGET_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
-add_subdirectory(${LIBOMPTARGET_SRC_DIR})
-
 # Definitions for testing, for reuse when testing libomptarget-nvptx.
 set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMP_INCLUDE_DIR}" CACHE STRING
   "Path to folder containing omp.h")
@@ -129,5 +125,9 @@ add_subdirectory(plugins-nextgen)
 add_subdirectory(DeviceRTL)
 add_subdirectory(tools)
 
+# Build target agnostic offloading library.
+set(LIBOMPTARGET_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
+add_subdirectory(${LIBOMPTARGET_SRC_DIR})
+
 # Add tests.
 add_subdirectory(test)
diff --git a/openmp/libomptarget/src/CMakeLists.txt b/openmp/libomptarget/src/CMakeLists.txt
index 7c311f738ac8e..f5e0672087c38 100644
--- a/openmp/libomptarget/src/CMakeLists.txt
+++ b/openmp/libomptarget/src/CMakeLists.txt
@@ -55,6 +55,28 @@ target_compile_definitions(omptarget PRIVATE
   DEBUG_PREFIX="omptarget"
 )
 
+macro(check_plugin_target target)
+if (TARGET ${target})
+	if (NOT LIBOMPTARGET_PLUGINS_TO_LOAD)
+		set(LIBOMPTARGET_PLUGINS_TO_LOAD "\"lib${target}\"")
+	else()
+		set(LIBOMPTARGET_PLUGINS_TO_LOAD ${LIBOMPTARGET_PLUGINS_TO_LOAD},"lib${target}")
+	endif()
+endif()
+endmacro()
+
+set(LIBOMPTARGET_PLUGINS_TO_LOAD "" CACHE STRING
+  "Comma separated list of plugin names to look for at runtime")
+if (NOT LIBOMPTARGET_PLUGINS_TO_LOAD)
+	check_plugin_target(omptarget.rtl.ppc64)
+	check_plugin_target(omptarget.rtl.x86_64)
+	check_plugin_target(omptarget.rtl.cuda)
+	check_plugin_target(omptarget.rtl.aarch64)
+	check_plugin_target(omptarget.rtl.amdgpu)
+endif()
+
+target_compile_definitions(omptarget PRIVATE ENABLED_OFFLOAD_PLUGINS=${LIBOMPTARGET_PLUGINS_TO_LOAD})
+
 # libomptarget.so needs to be aware of where the plugins live as they
 # are now separated in the build directory.
 set_target_properties(omptarget PROPERTIES
diff --git a/openmp/libomptarget/src/PluginManager.cpp b/openmp/libomptarget/src/PluginManager.cpp
index 931143ad2347d..f9f19240a17b5 100644
--- a/openmp/libomptarget/src/PluginManager.cpp
+++ b/openmp/libomptarget/src/PluginManager.cpp
@@ -23,11 +23,15 @@ PluginManager *PM;
 
 // List of all plugins that can support offloading.
 static const char *RTLNames[] = {
+#ifdef ENABLED_OFFLOAD_PLUGINS
+    ENABLED_OFFLOAD_PLUGINS
+#else
     /* PowerPC target       */ "libomptarget.rtl.ppc64",
     /* x86_64 target        */ "libomptarget.rtl.x86_64",
     /* CUDA target          */ "libomptarget.rtl.cuda",
     /* AArch64 target       */ "libomptarget.rtl.aarch64",
     /* AMDGPU target        */ "libomptarget.rtl.amdgpu",
+#endif
 };
 
 PluginAdaptorTy::PluginAdaptorTy(const std::string &Name) : Name(Name) {

@shiltian
Copy link
Contributor

shiltian commented Dec 6, 2023

Can we just use arch name, such as cuda, ppc64, instead of the full name?

By default we now only look for the plugins we build, but the user can
overwrite that with LIBOMPTARGET_PLUGINS_TO_LOAD="cuda,amdgpu,x86_64"
@jdoerfert
Copy link
Member Author

Can we just use arch name, such as cuda, ppc64, instead of the full name?

Done.

Copy link

github-actions bot commented Dec 6, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@shiltian shiltian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@jdoerfert jdoerfert merged commit 2a1bcf1 into llvm:main Dec 6, 2023
@jdoerfert jdoerfert deleted the offload_prep12 branch December 6, 2023 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openmp:libomptarget OpenMP offload runtime openmp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants