[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:21:07 PST 2023


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

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

>From a771d1c843200422bfde7393dbcc75b8a4bc2620 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 | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/GPU/CMakeLists.txt b/mlir/lib/Dialect/GPU/CMakeLists.txt
index b76d18e81246eb1..7da15974abc6565 100644
--- a/mlir/lib/Dialect/GPU/CMakeLists.txt
+++ b/mlir/lib/Dialect/GPU/CMakeLists.txt
@@ -135,11 +135,16 @@ 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)
+  message("CUDA_DRIVER_LIBRARY: ${CUDA_DRIVER_LIBRARY} ${CUDA_DRIVER_LIBRARY_PATH}")
+  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