HIP: HIP separable compilation linking fails when passed archives
Found while working on implementing HIP support in CMake Tested with compilers provided with ROCm 3.5 and 3.7
Given the following CMake:
cmake_minimum_required(VERSION 3.18)
project(static-lib-rdc HIP)
set(CMAKE_HIP_FLAGS "-fgpu-rdc")
set(CMAKE_HIP_ARCHITECTURES gfx908)
add_library(static-lib file1.cxx file2.hip.cxx file3.hip.cpp file4.hip file5.cu)
add_executable(verify main.cu)
target_link_libraries(verify PUBLIC static-lib)
set_source_files_properties(
file1.cxx file2.hip.cxx file3.hip.cpp file4.hip file5.cu main.cu
PROPERTIES
LANGUAGE "HIP"
)
We get the following error when trying to link the verify executable
/opt/rocm/bin/hipcc -fgpu-rdc --amdgpu-target=gfx908 CMakeFiles/verify.dir/main.cu.o -o verify libstatic-lib.a
clang-11: error: no such file or directory: '/tmp/hipcc0wDdnRUU/file1.cxx.o /tmp/hipcc0wDdnRUU/file2.hip.cxx.o /tmp/hipcc0wDdnRUU/file3.hip.cpp.o /tmp/hipcc0wDdnRUU/file4.hip.o /tmp/hipcc0wDdnRUU/file5.cu.o'
It looks something is going wrong and the clang-offload-bundler files are not being placed in the correct location or being removed before linking.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 21 (20 by maintainers)
@pfultz2 As far as I am aware the
clang++provided byrocmis not equivalent to upstreamclang++as it contains modifications that have not yet been accepted upstream. Therefore the ROCM provided clang compiler must be identified with a unique id and version number since it diverges from upstream.It would be great to have Rocm provide
clang++or some other alias inside the rocm/bin folder as currently the only easily discoverable compiler ishipcc.Yes long term would be to have CMake understand the following:
Due to how CMake’s internal compiler detection works, we simply can’t rely on the existence of
hip::devicetarget as compiler detection can occur before anyfindqueries. The approach for upstreamClangsupport most likely will follow how CMake added support forClangas a CUDA compiler in 3.18.Can you elaborate or point me towards more information on this?
Well there is no hipclang driver, its just
clang++(from rocm or upstream) with-x hip. For cmake,clang++with thehip::devicecmake target should be preferred overhipcc. hipcc is mainly for non-cmake users, and has lots of limitations(requires a lot custom env variables to find its dependencies, and doesnt work with upstream static libs).Sorry, you’re both right, when gpu-rdc is disabled, giving the path to static lib works fine.
upstream clang and hipclang both consider the line
/opt/rocm/bin/hipcc -fgpu-rdc --amdgpu-target=gfx908 CMakeFiles/verify.dir/main.cu.o -o verify libstatic-lib.ato be entirely valid whengpu-rdcis disabled.As a workaround, you may try this:
I will discuss with my team about consuming the libstatic-lib.a as an input.
It looks like switching the link line to the following does work:
Unfortunately this isn’t a solution that is acceptable for CMake.
Link lines like these are ambiguous espescially when linking to multiple numerous libraries in different locations. Since we haven’t given explicit paths to any of the libraries we could errantly pick up the wrong
static-libwhen given multiple link directories. CMake transforms link lines to use explicit paths whenever to possible to avoid such ambiguities.