[Mlir-commits] [mlir] [mlir] Fix the link of libcuda.so in MLIRGPUTransforms to not use fully qualified path (PR #74018)

Mehdi Amini llvmlistbot at llvm.org
Thu Nov 30 17:29:16 PST 2023


https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/74018

>From ee3264cf359b67dba4b266b54d459744608fe33d Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Thu, 30 Nov 2023 17:07:26 -0800
Subject: [PATCH] [mlir] Fix the link of libcuda.so in MLIRGPUTransforms to not
 use fully qualified path

At the moment we find libcuda.so in a path like:

  /usr/local/cuda/targets/x86_64-linux/lib/stubs/libcuda.so

and directly add this to `target_link_libraries`. The problem is that our
installed MLIR package will include the full path to the library, and a user
downstream when including our cmake installed package will inherit this full
path.

We're changing this to instead

 -L /usr/local/cuda/targets/x86_64-linux/lib/stubs/ -lcuda
---
 mlir/lib/Dialect/GPU/CMakeLists.txt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/GPU/CMakeLists.txt b/mlir/lib/Dialect/GPU/CMakeLists.txt
index b76d18e81246eb1..e8b69879ad6a7ed 100644
--- a/mlir/lib/Dialect/GPU/CMakeLists.txt
+++ b/mlir/lib/Dialect/GPU/CMakeLists.txt
@@ -135,11 +135,15 @@ if(MLIR_ENABLE_CUDA_RUNNER)
     ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
   )
 
+  # Add link path for the cuda driver library.
   find_library(CUDA_DRIVER_LIBRARY cuda HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)
+  get_filename_component(CUDA_DRIVER_LIBRARY_PATH "${CUDA_DRIVER_LIBRARY}" DIRECTORY)
+  target_link_directories(MLIRGPUTransforms PRIVATE ${CUDA_DRIVER_LIBRARY_PATH})
+
   target_link_libraries(MLIRGPUTransforms
     PRIVATE
     MLIRNVVMToLLVMIRTranslation
-    ${CUDA_DRIVER_LIBRARY}
+    cuda
   )
 
 endif()



More information about the Mlir-commits mailing list