Skip to content

Commit c618ae1

Browse files
authored
[Offload] Rework handling for loading vendor runtimes (#93073)
Summary: We previously had multiple options for this, this patch replaces them with `LIBOMPTARGET_DLOPEN_PLUGINS=` to be a list of plugins to dynamically use. It defaults to everything right now. This ignores the `host` plugin because the `libffi` dependency is going to be removed soon hopefully in #91264.
1 parent 96378b3 commit c618ae1

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

offload/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ endif()
146146
message(STATUS "Building the offload library with support for "
147147
"the \"${LIBOMPTARGET_PLUGINS_TO_BUILD}\" plugins")
148148

149+
set(LIBOMPTARGET_DLOPEN_PLUGINS "${LIBOMPTARGET_PLUGINS_TO_BUILD}" CACHE STRING
150+
"Semicolon-separated list of plugins to use 'dlopen' for runtime linking")
151+
149152
set(LIBOMPTARGET_ENUM_PLUGIN_TARGETS "")
150153
foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
151154
set(LIBOMPTARGET_ENUM_PLUGIN_TARGETS

offload/cmake/Modules/LibomptargetGetDependencies.cmake

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#
44
# libffi : required to launch target kernels given function and argument
55
# pointers.
6-
# CUDA : required to control offloading to NVIDIA GPUs.
76

87
include (FindPackageHandleStandardArgs)
98

@@ -43,13 +42,6 @@ endif()
4342
find_package(FFI QUIET)
4443
set(LIBOMPTARGET_DEP_LIBFFI_FOUND ${FFI_FOUND})
4544

46-
################################################################################
47-
# Looking for CUDA...
48-
################################################################################
49-
50-
find_package(CUDAToolkit QUIET)
51-
set(LIBOMPTARGET_DEP_CUDA_FOUND ${CUDAToolkit_FOUND})
52-
5345
################################################################################
5446
# Looking for NVIDIA GPUs...
5547
################################################################################

offload/plugins-nextgen/amdgpu/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
1313
target_include_directories(omptarget.rtl.amdgpu PRIVATE
1414
${CMAKE_CURRENT_SOURCE_DIR}/utils)
1515

16-
option(LIBOMPTARGET_FORCE_DLOPEN_LIBHSA "Build with dlopened libhsa" ON)
17-
if(hsa-runtime64_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBHSA)
16+
if(hsa-runtime64_FOUND AND NOT "amdgpu" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS)
1817
message(STATUS "Building AMDGPU plugin linked against libhsa")
1918
target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64)
2019
else()

offload/plugins-nextgen/cuda/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ add_target_library(omptarget.rtl.cuda CUDA)
1010

1111
target_sources(omptarget.rtl.cuda PRIVATE src/rtl.cpp)
1212

13-
option(LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA "Build with dlopened libcuda" ON)
14-
if(LIBOMPTARGET_DEP_CUDA_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA)
13+
find_package(CUDAToolkit QUIET)
14+
if(CUDAToolkit_FOUND AND NOT "cuda" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS)
1515
message(STATUS "Building CUDA plugin linked against libcuda")
1616
target_link_libraries(omptarget.rtl.cuda PRIVATE CUDA::cuda_driver)
1717
else()

openmp/docs/SupportAndFAQ.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,15 @@ Q: What command line options can I use for OpenMP?
454454
We recommend taking a look at the OpenMP
455455
:doc:`command line argument reference <CommandLineArgumentReference>` page.
456456

457+
Q: Can I build the offloading runtimes without CUDA or HSA?
458+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
459+
By default, the offloading runtime will load the associated vendor runtime
460+
during initialization rather than directly linking against them. This allows the
461+
program to be built and run on many machine. If you wish to directly link
462+
against these libraries, use the ``LIBOMPTARGET_DLOPEN_PLUGINS=""`` option to
463+
suppress it for each plugin. The default value is every plugin enabled with
464+
``LIBOMPTARGET_PLUGINS_TO_BUILD``.
465+
457466
Q: Why is my build taking a long time?
458467
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
459468
When installing OpenMP and other LLVM components, the build time on multicore

0 commit comments

Comments
 (0)