Skip to content

Fix libnvptxcompiler_static.a absolute path #115015

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

Conversation

MikaOvO
Copy link
Contributor

@MikaOvO MikaOvO commented Nov 5, 2024

Now when building llvm-solid with -DMLIR_ENABLE_NVPTXCOMPILER=ON, there will be an absolute path (/path/to/libnvptxcompiler_static.a) in MLIRNVVMTarget dependencies (in /build/path/install/lib/cmake/mlir/MLIRTargets.cmake). For example,

set_target_properties(MLIRNVVMTarget PROPERTIES
  INTERFACE_LINK_LIBRARIES "MLIRIR;MLIRExecutionEngineUtils;MLIRSupport;MLIRGPUDialect;MLIRTargetLLVM;MLIRNVVMToLLVMIRTranslation;LLVMSupport;/path/to/libnvptxcompiler_static.a"
)

If downstream project uses pre-built llvm and depends on MLIRNVVMTarget, it may fail to build due to the absence of the libnvptxcompiler_static.a absolute path.

After this commit, there will no absolute path in /build/path/install/lib/cmake/mlir/MLIRTargets.cmake

set_target_properties(MLIRNVVMTarget PROPERTIES
  INTERFACE_LINK_LIBRARIES "MLIRIR;MLIRExecutionEngineUtils;MLIRSupport;MLIRGPUDialect;MLIRTargetLLVM;MLIRNVVMToLLVMIRTranslation;LLVMSupport;\$<LINK_ONLY:MLIR_NVPTXCOMPILER_LIB>"
)

Then downstream project can modify libnvptxcompiler_static.a path and use cmake to build. For example,

# find_library(...)

add_library(MLIR_NVPTXCOMPILER_LIB STATIC IMPORTED GLOBAL)
set_property(TARGET MLIR_NVPTXCOMPILER_LIB PROPERTY IMPORTED_LOCATION ${...})  

Copy link

github-actions bot commented Nov 5, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-llvm

Author: Zichen Lu (MikaOvO)

Changes

Now when building llvm-solid with -DMLIR_ENABLE_NVPTXCOMPILER=ON, there will be an absolute path (/path/to/libnvptxcompiler_static.a) in MLIRNVVMTarget dependencies (in /build/path/install/lib/cmake/mlir/MLIRTargets.cmake). For example,

set_target_properties(MLIRNVVMTarget PROPERTIES
  INTERFACE_LINK_LIBRARIES "MLIRIR;MLIRExecutionEngineUtils;MLIRSupport;MLIRGPUDialect;MLIRTargetLLVM;MLIRNVVMToLLVMIRTranslation;LLVMSupport;/path/to/libnvptxcompiler_static.a"
)

If downstream project uses pre-built llvm-solid and depends on MLIRNVVMTarget, it may fail to build due to the absence of the libnvptxcompiler_static.a absolute path.

After this commit, there will no absolute path in /build/path/install/lib/cmake/mlir/MLIRTargets.cmake

set_target_properties(MLIRNVVMTarget PROPERTIES
  INTERFACE_LINK_LIBRARIES "MLIRIR;MLIRExecutionEngineUtils;MLIRSupport;MLIRGPUDialect;MLIRTargetLLVM;MLIRNVVMToLLVMIRTranslation;LLVMSupport;\$&lt;LINK_ONLY:MLIR_NVPTXCOMPILER_LIB&gt;"
)

Then downstream project can modify libnvptxcompiler_static.a path and use cmake to build. For example,

# find_library(...)

add_library(MLIR_NVPTXCOMPILER_LIB STATIC IMPORTED GLOBAL)
set_property(TARGET MLIR_NVPTXCOMPILER_LIB PROPERTY IMPORTED_LOCATION ${...})  

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

1 Files Affected:

  • (modified) mlir/lib/Target/LLVM/CMakeLists.txt (+6-3)
diff --git a/mlir/lib/Target/LLVM/CMakeLists.txt b/mlir/lib/Target/LLVM/CMakeLists.txt
index bc14c568e46be2..dea7c26dd92042 100644
--- a/mlir/lib/Target/LLVM/CMakeLists.txt
+++ b/mlir/lib/Target/LLVM/CMakeLists.txt
@@ -70,17 +70,20 @@ if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
     if(MLIR_ENABLE_NVPTXCOMPILER)
       # Find the `nvptxcompiler` library.
       # TODO: Bump the MLIR CMake version to 3.25 and use `CUDA::nvptxcompiler_static`.
-      find_library(MLIR_NVPTXCOMPILER_LIB nvptxcompiler_static
+      find_library(MLIR_NVPTXCOMPILER_LIB_PATH nvptxcompiler_static
                   PATHS ${CUDAToolkit_LIBRARY_DIR} NO_DEFAULT_PATH)
 
       # Fail if `nvptxcompiler_static` couldn't be found.
-      if(MLIR_NVPTXCOMPILER_LIB STREQUAL "MLIR_NVPTXCOMPILER_LIB-NOTFOUND")
+      if(MLIR_NVPTXCOMPILER_LIB_PATH STREQUAL "MLIR_NVPTXCOMPILER_LIB_PATH-NOTFOUND")
         message(FATAL_ERROR
                 "Requested using the `nvptxcompiler` library backend but it couldn't be found.")
       endif()
 
+      add_library(MLIR_NVPTXCOMPILER_LIB STATIC IMPORTED GLOBAL)
+      # Downstream project can modify this path and use it in CMake
+      set_property(TARGET MLIR_NVPTXCOMPILER_LIB PROPERTY IMPORTED_LOCATION ${MLIR_NVPTXCOMPILER_LIB_PATH})
       # Link against `nvptxcompiler_static`. TODO: use `CUDA::nvptxcompiler_static`.
-      target_link_libraries(MLIRNVVMTarget PRIVATE ${MLIR_NVPTXCOMPILER_LIB})
+      target_link_libraries(MLIRNVVMTarget PRIVATE MLIR_NVPTXCOMPILER_LIB)
       target_include_directories(obj.MLIRNVVMTarget PUBLIC ${CUDAToolkit_INCLUDE_DIRS})
     endif()
   else()

message(FATAL_ERROR
"Requested using the `nvptxcompiler` library backend but it couldn't be found.")
endif()

add_library(MLIR_NVPTXCOMPILER_LIB STATIC IMPORTED GLOBAL)
# Downstream project can modify this path and use it in CMake
Copy link
Collaborator

@joker-eph joker-eph Nov 5, 2024

Choose a reason for hiding this comment

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

Should we add the example you mentioned here:

Suggested change
# Downstream project can modify this path and use it in CMake
# Downstream projects can modify this path and use it in CMake. For example:
# add_library(MLIR_NVPTXCOMPILER_LIB STATIC IMPORTED GLOBAL)
# set_property(TARGET MLIR_NVPTXCOMPILER_LIB PROPERTY IMPORTED_LOCATION ${...})
# where `...` is to be replaced with the path to the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Let me add it.

@MikaOvO MikaOvO force-pushed the users/mikaovo/fix_libnvptxcompiler_absolute_path branch from 64ab6fb to 4c7e85f Compare November 6, 2024 02:39
@joker-eph joker-eph merged commit f87484d into llvm:main Nov 6, 2024
7 checks passed
Copy link

github-actions bot commented Nov 6, 2024

@MikaOvO Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

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