Skip to content

Commit f87484d

Browse files
authored
Fix libnvptxcompiler_static.a absolute path (#115015)
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, ```cmake 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` ```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, ```cmake # find_library(...) add_library(MLIR_NVPTXCOMPILER_LIB STATIC IMPORTED GLOBAL) set_property(TARGET MLIR_NVPTXCOMPILER_LIB PROPERTY IMPORTED_LOCATION ${...}) ```
1 parent 5a16ed9 commit f87484d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mlir/lib/Target/LLVM/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,23 @@ if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
7070
if(MLIR_ENABLE_NVPTXCOMPILER)
7171
# Find the `nvptxcompiler` library.
7272
# TODO: Bump the MLIR CMake version to 3.25 and use `CUDA::nvptxcompiler_static`.
73-
find_library(MLIR_NVPTXCOMPILER_LIB nvptxcompiler_static
73+
find_library(MLIR_NVPTXCOMPILER_LIB_PATH nvptxcompiler_static
7474
PATHS ${CUDAToolkit_LIBRARY_DIR} NO_DEFAULT_PATH)
7575

7676
# Fail if `nvptxcompiler_static` couldn't be found.
77-
if(MLIR_NVPTXCOMPILER_LIB STREQUAL "MLIR_NVPTXCOMPILER_LIB-NOTFOUND")
77+
if(MLIR_NVPTXCOMPILER_LIB_PATH STREQUAL "MLIR_NVPTXCOMPILER_LIB_PATH-NOTFOUND")
7878
message(FATAL_ERROR
7979
"Requested using the `nvptxcompiler` library backend but it couldn't be found.")
8080
endif()
8181

82+
add_library(MLIR_NVPTXCOMPILER_LIB STATIC IMPORTED GLOBAL)
83+
# Downstream projects can modify this path and use it in CMake. For example:
84+
# add_library(MLIR_NVPTXCOMPILER_LIB STATIC IMPORTED GLOBAL)
85+
# set_property(TARGET MLIR_NVPTXCOMPILER_LIB PROPERTY IMPORTED_LOCATION ${...})
86+
# where `...` is to be replaced with the path to the library.
87+
set_property(TARGET MLIR_NVPTXCOMPILER_LIB PROPERTY IMPORTED_LOCATION ${MLIR_NVPTXCOMPILER_LIB_PATH})
8288
# Link against `nvptxcompiler_static`. TODO: use `CUDA::nvptxcompiler_static`.
83-
target_link_libraries(MLIRNVVMTarget PRIVATE ${MLIR_NVPTXCOMPILER_LIB})
89+
target_link_libraries(MLIRNVVMTarget PRIVATE MLIR_NVPTXCOMPILER_LIB)
8490
target_include_directories(obj.MLIRNVVMTarget PUBLIC ${CUDAToolkit_INCLUDE_DIRS})
8591
endif()
8692
else()

0 commit comments

Comments
 (0)