From c618ae17341315af5fcc97ffd3ed2b19f6d9e412 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 22 May 2024 13:04:52 -0500 Subject: [PATCH] [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 https://github.com/llvm/llvm-project/pull/91264. --- offload/CMakeLists.txt | 3 +++ offload/cmake/Modules/LibomptargetGetDependencies.cmake | 8 -------- offload/plugins-nextgen/amdgpu/CMakeLists.txt | 3 +-- offload/plugins-nextgen/cuda/CMakeLists.txt | 4 ++-- openmp/docs/SupportAndFAQ.rst | 9 +++++++++ 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt index c3dcebfb7301..8bbdb94c0f65 100644 --- a/offload/CMakeLists.txt +++ b/offload/CMakeLists.txt @@ -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 diff --git a/offload/cmake/Modules/LibomptargetGetDependencies.cmake b/offload/cmake/Modules/LibomptargetGetDependencies.cmake index e37b86b2a81f..c296f7ea3863 100644 --- a/offload/cmake/Modules/LibomptargetGetDependencies.cmake +++ b/offload/cmake/Modules/LibomptargetGetDependencies.cmake @@ -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) @@ -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... ################################################################################ diff --git a/offload/plugins-nextgen/amdgpu/CMakeLists.txt b/offload/plugins-nextgen/amdgpu/CMakeLists.txt index 7630e3788dae..cb9ab8c24084 100644 --- a/offload/plugins-nextgen/amdgpu/CMakeLists.txt +++ b/offload/plugins-nextgen/amdgpu/CMakeLists.txt @@ -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() diff --git a/offload/plugins-nextgen/cuda/CMakeLists.txt b/offload/plugins-nextgen/cuda/CMakeLists.txt index fa5559c5e7dc..3a3ed6867049 100644 --- a/offload/plugins-nextgen/cuda/CMakeLists.txt +++ b/offload/plugins-nextgen/cuda/CMakeLists.txt @@ -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() diff --git a/openmp/docs/SupportAndFAQ.rst b/openmp/docs/SupportAndFAQ.rst index 9e6974dfbb13..a158422befd0 100644 --- a/openmp/docs/SupportAndFAQ.rst +++ b/openmp/docs/SupportAndFAQ.rst @@ -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 ` 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