[PATCH] D143768: [Clang] Add options to disable direct linking of arch tools

Joseph Huber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 10 10:28:24 PST 2023


jhuber6 created this revision.
jhuber6 added reviewers: aaronmondal, JonChesterfield, tra, jdoerfert, tianshilei1992.
Herald added subscribers: kosarev, mattd, asavonic, kerbowa, tpr, jvesely.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We use the `nvptx-arch` and `amdgpu-arch` tools to identify the system's
installed GPUs. These are used across LLVM to handle setting up unit
tests and the `--offload-arch=native` option. This patch adds the
`CLANG_FORCE_DLOPEN_LIBCUDA` and `CLANG_FORCE_DLOPEN_LIBHSA` CMake
options to enable disabling these directly.

Fixes: https://github.com/llvm/llvm-project/issues/60660


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143768

Files:
  clang/tools/amdgpu-arch/CMakeLists.txt
  clang/tools/nvptx-arch/CMakeLists.txt


Index: clang/tools/nvptx-arch/CMakeLists.txt
===================================================================
--- clang/tools/nvptx-arch/CMakeLists.txt
+++ clang/tools/nvptx-arch/CMakeLists.txt
@@ -9,10 +9,12 @@
 set(LLVM_LINK_COMPONENTS Support)
 add_clang_tool(nvptx-arch NVPTXArch.cpp)
 
-find_package(CUDAToolkit QUIET)
+option(CLANG_FORCE_DLOPEN_LIBCUDA "Build with 'dlopened' libcuda" OFF)
 
 # If we found the CUDA library directly we just dynamically link against it.
-if(CUDAToolkit_FOUND AND NOT (LLVM_BUILD_32_BITS OR CMAKE_SIZEOF_VOID_P EQUAL 4))
+find_package(CUDAToolkit QUIET)
+if(CUDAToolkit_FOUND AND NOT
+   (LLVM_BUILD_32_BITS OR CMAKE_SIZEOF_VOID_P EQUAL 4 OR CLANG_FORCE_DLOPEN_LIBCUDA))
   target_link_libraries(nvptx-arch PRIVATE CUDA::cuda_driver)
 else()
   target_compile_definitions(nvptx-arch PRIVATE "DYNAMIC_CUDA")
Index: clang/tools/amdgpu-arch/CMakeLists.txt
===================================================================
--- clang/tools/amdgpu-arch/CMakeLists.txt
+++ clang/tools/amdgpu-arch/CMakeLists.txt
@@ -10,9 +10,12 @@
 
 add_clang_tool(amdgpu-arch AMDGPUArch.cpp)
 
+option(CLANG_FORCE_DLOPEN_LIBHSA "Build with 'dlopened' libhsa" OFF)
+
 # If we find the HSA runtime we link with it directly.
 find_package(hsa-runtime64 QUIET 1.2.0 HINTS ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm)
-if(hsa-runtime64_FOUND AND NOT (LLVM_BUILD_32_BITS OR CMAKE_SIZEOF_VOID_P EQUAL 4))
+if(hsa-runtime64_FOUND AND NOT
+   (LLVM_BUILD_32_BITS OR CMAKE_SIZEOF_VOID_P EQUAL 4 OR CLANG_FORCE_DLOPEN_LIBHSA))
   set_target_properties(amdgpu-arch PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON)
   target_link_libraries(amdgpu-arch PRIVATE hsa-runtime64::hsa-runtime64)
 else()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143768.496547.patch
Type: text/x-patch
Size: 1696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230210/acb5dc70/attachment.bin>


More information about the cfe-commits mailing list