ROCm / HIPIFY

HIPIFY: Convert CUDA to Portable C++ Code
https://rocm.docs.amd.com/projects/HIPIFY/en/latest/
MIT License
524 stars 75 forks source link

[HIPIFY][build] hipify-clang compile error on Linux #517

Closed dayatsin-amd closed 2 years ago

dayatsin-amd commented 2 years ago

When compiling on Linux, with LLVM Version 15, we get an error because of dependency on LLVMWindowsDriver. Could the LLVMWindowsDriver dependency only be added when building on Windows/MSVC only?

Error logs:

-- Found LLVM 15.0.0git: -- - CMake module path: /long_pathname_so_that_rpms_can_package_the_debug_info/src/out/ubuntu-18.04/18.04/llvm/lib/cmake/llvm -- - Include path : /long_pathname_so_that_rpms_can_package_the_debug_info/src/out/ubuntu-18.04/18.04/llvm/include -- - Binary path : /long_pathname_so_that_rpms_can_package_the_debug_info/src/out/ubuntu-18.04/18.04/llvm/bin -- Linker detection: GNU ld -- Configuring done -- Generating done -- Build files have been written to: /long_pathname_so_that_rpms_can_package_the_debug_info/src/out/ubuntu-18.04/18.04/build/long_pathname_so_that_rpms_can_package_the_debug_info/src/external/hipify make[1]: warning: -jN forced in submake: disabling jobserver mode. make[1]: Entering directory '/long_pathname_so_that_rpms_can_package_the_debug_info/src/out/ubuntu-18.04/18.04/build/long_pathname_so_that_rpms_can_package_the_debug_info/src/external/hipify' make[2]: Entering directory '/long_pathname_so_that_rpms_can_package_the_debug_info/src/out/ubuntu-18.04/18.04/build/long_pathname_so_that_rpms_can_package_the_debug_info/src/external/hipify' make[3]: Entering directory '/long_pathname_so_that_rpms_can_package_the_debug_info/src/out/ubuntu-18.04/18.04/build/long_pathname_so_that_rpms_can_package_the_debug_info/src/external/hipify' make[3]: Leaving directory '/long_pathname_so_that_rpms_can_package_the_debug_info/src/out/ubuntu-18.04/18.04/build/long_pathname_so_that_rpms_can_package_the_debug_info/src/external/hipify' make[3]: Entering directory '/long_pathname_so_that_rpms_can_package_the_debug_info/src/out/ubuntu-18.04/18.04/build/long_pathname_so_that_rpms_can_package_the_debug_info/src/external/hipify' [ 3%] Building CXX object CMakeFiles/hipify-clang.dir/src/ArgParse.cpp.o : : : [ 96%] Building CXX object CMakeFiles/hipify-clang.dir/src/CUDA2HIP_FFT_API_functions.cpp.o [100%] Linking CXX executable hipify-clang ld.lld: error: unable to find library -lLLVMWindowsDriver clang-15: error: linker command failed with exit code 1 (use -v to see invocation) CMakeFiles/hipify-clang.dir/build.make:621: recipe for target 'hipify-clang' failed make[3]: [hipify-clang] Error 1 make[3]: Leaving directory '/long_pathname_so_that_rpms_can_package_the_debug_info/src/out/ubuntu-18.04/18.04/build/long_pathname_so_that_rpms_can_package_the_debug_info/src/external/hipify' CMakeFiles/Makefile2:164: recipe for target 'CMakeFiles/hipify-clang.dir/all' failed make[2]: [CMakeFiles/hipify-clang.dir/all] Error 2

This is a proposed patch:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 822f8db..992efe4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,11 +66,11 @@ if(LLVM_PACKAGE_VERSION VERSION_GREATER "9.0.1")
     target_link_libraries(hipify-clang PRIVATE LLVMFrontendOpenMP)
endif()

-if(LLVM_PACKAGE_VERSION VERSION_EQUAL "15.0.0" OR LLVM_PACKAGE_VERSION VERSION_GREATER "15.0.0")
-    target_link_libraries(hipify-clang PRIVATE LLVMWindowsDriver)
-endif()

if(MSVC)
+    if(LLVM_PACKAGE_VERSION VERSION_EQUAL "15.0.0" OR LLVM_PACKAGE_VERSION VERSION_GREATER "15.0.0")
+        target_link_libraries(hipify-clang PRIVATE LLVMWindowsDriver)
+    endif()
     target_link_libraries(hipify-clang PRIVATE version)
     target_compile_options(hipify-clang PRIVATE /std:c++14 /Od /GR- /EHs- /EHc-)
     set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} /SUBSYSTEM:WINDOWS")
emankov commented 2 years ago

It looks like LLVM 15.0.0git has been changed again since fix #509, which was tested on Windows and Linux. Looks like they initially introduced LLVMWindowsDriver lib for both platforms, and then realized that it is a Windows-specific lib and removed it from the Linux configuration. Let me check the affecting LLVM/clang change.

emankov commented 2 years ago

@dayatsin-amd, did you build hipify-clang against the latest trunk LLVM sources?

dayatsin-amd commented 2 years ago

@emankov Sorry, hipify-clang compiles fine against latest trunk LLVM. Consider issue resolved. Thank you for looking into this.