Skip to content

[mlir] Fix the link of libcuda.so in MLIRGPUTransforms to not use fully qualified path #74018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2023

Conversation

joker-eph
Copy link
Collaborator

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

@joker-eph
Copy link
Collaborator Author

@stellaraccident : is this the right way to do this in CMake?

@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2023

@llvm/pr-subscribers-mlir

Author: Mehdi Amini (joker-eph)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/74018.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/GPU/CMakeLists.txt (+6-1)
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()

@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2023

@llvm/pr-subscribers-mlir-gpu

Author: Mehdi Amini (joker-eph)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/74018.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/GPU/CMakeLists.txt (+6-1)
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()

…ly 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
@joker-eph joker-eph force-pushed the remove_fullyqualified_path branch from a771d1c to ee3264c Compare December 1, 2023 01:29
Copy link
Contributor

@stellaraccident stellaraccident left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that should get the job done, and I can't think of a strictly better way to do it.

@joker-eph joker-eph merged commit 6402706 into llvm:main Dec 1, 2023
@joker-eph joker-eph deleted the remove_fullyqualified_path branch December 1, 2023 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants