Skip to content

Commit

Permalink
[Offload] Rework handling for loading vendor runtimes (#93073)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhuber6 committed May 22, 2024
1 parent 96378b3 commit c618ae1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions offload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ endif()
message(STATUS "Building the offload library with support for "
"the \"${LIBOMPTARGET_PLUGINS_TO_BUILD}\" plugins")

set(LIBOMPTARGET_DLOPEN_PLUGINS "${LIBOMPTARGET_PLUGINS_TO_BUILD}" CACHE STRING
"Semicolon-separated list of plugins to use 'dlopen' for runtime linking")

set(LIBOMPTARGET_ENUM_PLUGIN_TARGETS "")
foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
set(LIBOMPTARGET_ENUM_PLUGIN_TARGETS
Expand Down
8 changes: 0 additions & 8 deletions offload/cmake/Modules/LibomptargetGetDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
# libffi : required to launch target kernels given function and argument
# pointers.
# CUDA : required to control offloading to NVIDIA GPUs.

include (FindPackageHandleStandardArgs)

Expand Down Expand Up @@ -43,13 +42,6 @@ endif()
find_package(FFI QUIET)
set(LIBOMPTARGET_DEP_LIBFFI_FOUND ${FFI_FOUND})

################################################################################
# Looking for CUDA...
################################################################################

find_package(CUDAToolkit QUIET)
set(LIBOMPTARGET_DEP_CUDA_FOUND ${CUDAToolkit_FOUND})

################################################################################
# Looking for NVIDIA GPUs...
################################################################################
Expand Down
3 changes: 1 addition & 2 deletions offload/plugins-nextgen/amdgpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
target_include_directories(omptarget.rtl.amdgpu PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/utils)

option(LIBOMPTARGET_FORCE_DLOPEN_LIBHSA "Build with dlopened libhsa" ON)
if(hsa-runtime64_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBHSA)
if(hsa-runtime64_FOUND AND NOT "amdgpu" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS)
message(STATUS "Building AMDGPU plugin linked against libhsa")
target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64)
else()
Expand Down
4 changes: 2 additions & 2 deletions offload/plugins-nextgen/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ 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" ON)
if(LIBOMPTARGET_DEP_CUDA_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA)
find_package(CUDAToolkit QUIET)
if(CUDAToolkit_FOUND AND NOT "cuda" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS)
message(STATUS "Building CUDA plugin linked against libcuda")
target_link_libraries(omptarget.rtl.cuda PRIVATE CUDA::cuda_driver)
else()
Expand Down
9 changes: 9 additions & 0 deletions openmp/docs/SupportAndFAQ.rst
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ Q: What command line options can I use for OpenMP?
We recommend taking a look at the OpenMP
:doc:`command line argument reference <CommandLineArgumentReference>` page.

Q: Can I build the offloading runtimes without CUDA or HSA?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
By default, the offloading runtime will load the associated vendor runtime
during initialization rather than directly linking against them. This allows the
program to be built and run on many machine. If you wish to directly link
against these libraries, use the ``LIBOMPTARGET_DLOPEN_PLUGINS=""`` option to
suppress it for each plugin. The default value is every plugin enabled with
``LIBOMPTARGET_PLUGINS_TO_BUILD``.

Q: Why is my build taking a long time?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When installing OpenMP and other LLVM components, the build time on multicore
Expand Down

0 comments on commit c618ae1

Please sign in to comment.