I tried to build & install MLIR with cuda runner enabled. But I got some errors when linking.
Here are my build commands:
mkdir llvm-project/build
cd llvm-project/build
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_BUILD_EXAMPLES=ON \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_INSTALL_PREFIX=/path/to/llvm/install \
-DMLIR_ENABLE_CUDA_RUNNER=ON
ninja -j32 && ninja install
And I got the following error:
[1/2] Linking CXX shared library lib/libMLIR.so.16git
FAILED: lib/libMLIR.so.16git
<a number of linked files but no libcuda.so>:
tools/mlir/lib/Dialect/GPU/CMakeFiles/obj.MLIRGPUTransforms.dir/Transforms/SerializeToCubin.cpp.o: In function `emitCudaError(llvm::Twine const&, char const*, cudaError_enum, mlir::Location)':
SerializeToCubin.cpp:(.text._ZL13emitCudaErrorRKN4llvm5TwineEPKc14cudaError_enumN4mlir8LocationE+0x48): undefined reference to `cuGetErrorString'
tools/mlir/lib/Dialect/GPU/CMakeFiles/obj.MLIRGPUTransforms.dir/Transforms/SerializeToCubin.cpp.o: In function `(anonymous namespace)::SerializeToCubinPass::serializeISA(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
SerializeToCubin.cpp:(.text._ZN12_GLOBAL__N_120SerializeToCubinPass12serializeISAERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x7b): undefined reference to `cuInit'
SerializeToCubin.cpp:(.text._ZN12_GLOBAL__N_120SerializeToCubinPass12serializeISAERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0xeb): undefined reference to `cuDeviceGet'
SerializeToCubin.cpp:(.text._ZN12_GLOBAL__N_120SerializeToCubinPass12serializeISAERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x161): undefined reference to `cuCtxCreate_v2'
SerializeToCubin.cpp:(.text._ZN12_GLOBAL__N_120SerializeToCubinPass12serializeISAERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x222): undefined reference to `cuLinkCreate_v2'
SerializeToCubin.cpp:(.text._ZN12_GLOBAL__N_120SerializeToCubinPass12serializeISAERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x324): undefined reference to `cuLinkAddData_v2'
SerializeToCubin.cpp:(.text._ZN12_GLOBAL__N_120SerializeToCubinPass12serializeISAERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x3a4): undefined reference to `cuLinkComplete'
SerializeToCubin.cpp:(.text._ZN12_GLOBAL__N_120SerializeToCubinPass12serializeISAERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x455): undefined reference to `cuLinkDestroy'
SerializeToCubin.cpp:(.text._ZN12_GLOBAL__N_120SerializeToCubinPass12serializeISAERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x4c0): undefined reference to `cuCtxDestroy_v2'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
I tried to modify CMakeLists to add libcuda.so manually but the problem remains.
I don’t know how to solve the problem, hope someone can help me, thanks!