[llvm] [Offload] Do not link every target for JIT (PR #92013)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Mon May 13 19:53:18 PDT 2024


https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/92013

>From 6173d712933aca8de264e21cd01d97f1ef518b4c Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 13 May 2024 14:15:48 -0500
Subject: [PATCH] [Offload] Do not link every target for JIT

Summary:
The offload library supports basic JIT functionality, however we
currently link against every single target even though only AMDGPU and
NVPTX are supported. This somewhat bloats the dynamic library list, so
we should constrain it to what's actually used.
---
 offload/plugins-nextgen/CMakeLists.txt        | 1 -
 offload/plugins-nextgen/amdgpu/CMakeLists.txt | 6 ++++++
 offload/plugins-nextgen/cuda/CMakeLists.txt   | 6 ++++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/offload/plugins-nextgen/CMakeLists.txt b/offload/plugins-nextgen/CMakeLists.txt
index d1079f8a3e9cc..79f1c6dc66e85 100644
--- a/offload/plugins-nextgen/CMakeLists.txt
+++ b/offload/plugins-nextgen/CMakeLists.txt
@@ -16,7 +16,6 @@ add_subdirectory(common)
 function(add_target_library target_name lib_name)
   add_llvm_library(${target_name} STATIC
     LINK_COMPONENTS
-      ${LLVM_TARGETS_TO_BUILD}
       AggressiveInstCombine
       Analysis
       BinaryFormat
diff --git a/offload/plugins-nextgen/amdgpu/CMakeLists.txt b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
index 738183f8945ed..5573d5562d99a 100644
--- a/offload/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -34,6 +34,12 @@ target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
 target_include_directories(omptarget.rtl.amdgpu PRIVATE
                            ${CMAKE_CURRENT_SOURCE_DIR}/utils)
 
+# Link in the AMDGPU backend for JIT compilation if supported.
+if("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
+  llvm_map_components_to_libnames(llvm_libs AMDGPU)
+  target_link_libraries(omptarget.rtl.amdgpu PRIVATE ${llvm_libs})
+endif()
+
 option(LIBOMPTARGET_FORCE_DLOPEN_LIBHSA "Build with dlopened libhsa" OFF)
 if(hsa-runtime64_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBHSA)
   libomptarget_say("Building AMDGPU plugin linked against libhsa")
diff --git a/offload/plugins-nextgen/cuda/CMakeLists.txt b/offload/plugins-nextgen/cuda/CMakeLists.txt
index dd684bb223431..f0b5094ce0d5d 100644
--- a/offload/plugins-nextgen/cuda/CMakeLists.txt
+++ b/offload/plugins-nextgen/cuda/CMakeLists.txt
@@ -28,6 +28,12 @@ add_target_library(omptarget.rtl.cuda CUDA)
 
 target_sources(omptarget.rtl.cuda PRIVATE src/rtl.cpp)
 
+# Link in the NVPTX backend for JIT compilation if supported.
+if("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
+  llvm_map_components_to_libnames(llvm_libs NVPTX)
+  target_link_libraries(omptarget.rtl.cuda PRIVATE ${llvm_libs})
+endif()
+
 option(LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA "Build with dlopened libcuda" OFF)
 if(LIBOMPTARGET_DEP_CUDA_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA)
   libomptarget_say("Building CUDA plugin linked against libcuda")



More information about the llvm-commits mailing list