Skip to content

Commit 2a1bcf1

Browse files
authored
[OpenMP] Allow to specify what plugins to look for (#74538)
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"`
1 parent 4db54e6 commit 2a1bcf1

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

openmp/libomptarget/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ set(LIBOMPTARGET_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
110110
message(STATUS "OpenMP tools dir in libomptarget: ${LIBOMP_OMP_TOOLS_INCLUDE_DIR}")
111111
include_directories(${LIBOMP_OMP_TOOLS_INCLUDE_DIR})
112112

113-
# Build target agnostic offloading library.
114-
set(LIBOMPTARGET_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
115-
add_subdirectory(${LIBOMPTARGET_SRC_DIR})
116-
117113
# Definitions for testing, for reuse when testing libomptarget-nvptx.
118114
set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMP_INCLUDE_DIR}" CACHE STRING
119115
"Path to folder containing omp.h")
@@ -129,5 +125,9 @@ add_subdirectory(plugins-nextgen)
129125
add_subdirectory(DeviceRTL)
130126
add_subdirectory(tools)
131127

128+
# Build target agnostic offloading library.
129+
set(LIBOMPTARGET_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
130+
add_subdirectory(${LIBOMPTARGET_SRC_DIR})
131+
132132
# Add tests.
133133
add_subdirectory(test)

openmp/libomptarget/src/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ target_compile_definitions(omptarget PRIVATE
5555
DEBUG_PREFIX="omptarget"
5656
)
5757

58+
macro(check_plugin_target target)
59+
if (TARGET omptarget.rtl.${target})
60+
list(APPEND LIBOMPTARGET_PLUGINS_TO_LOAD ${target})
61+
endif()
62+
endmacro()
63+
64+
set(LIBOMPTARGET_PLUGINS_TO_LOAD "" CACHE STRING
65+
"Comma separated list of plugin names to look for at runtime")
66+
if (NOT LIBOMPTARGET_PLUGINS_TO_LOAD)
67+
check_plugin_target(ppc64)
68+
check_plugin_target(x86_64)
69+
check_plugin_target(cuda)
70+
check_plugin_target(aarch64)
71+
check_plugin_target(amdgpu)
72+
endif()
73+
74+
list(TRANSFORM LIBOMPTARGET_PLUGINS_TO_LOAD PREPEND "\"libomptarget.rtl.")
75+
list(TRANSFORM LIBOMPTARGET_PLUGINS_TO_LOAD APPEND "\"")
76+
list(JOIN LIBOMPTARGET_PLUGINS_TO_LOAD "," ENABLED_OFFLOAD_PLUGINS)
77+
target_compile_definitions(omptarget PRIVATE ENABLED_OFFLOAD_PLUGINS=${ENABLED_OFFLOAD_PLUGINS})
78+
5879
# libomptarget.so needs to be aware of where the plugins live as they
5980
# are now separated in the build directory.
6081
set_target_properties(omptarget PROPERTIES

openmp/libomptarget/src/PluginManager.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ using namespace llvm::sys;
2323
PluginManager *PM;
2424

2525
// List of all plugins that can support offloading.
26-
static const char *RTLNames[] = {
27-
/* PowerPC target */ "libomptarget.rtl.ppc64",
28-
/* x86_64 target */ "libomptarget.rtl.x86_64",
29-
/* CUDA target */ "libomptarget.rtl.cuda",
30-
/* AArch64 target */ "libomptarget.rtl.aarch64",
31-
/* AMDGPU target */ "libomptarget.rtl.amdgpu",
32-
};
26+
static const char *RTLNames[] = {ENABLED_OFFLOAD_PLUGINS};
3327

3428
Expected<std::unique_ptr<PluginAdaptorTy>>
3529
PluginAdaptorTy::create(const std::string &Name) {

0 commit comments

Comments
 (0)