Open Snektron opened 1 year ago
It seems like the issue can be resolved by "resetting" the language before the object file is passed by using -x none
. Manually invoking
/opt/rocm/llvm/bin/clang++ [...extra options omitted for brevity] -x hip main.hip -x none """/tmp/library.o""" -std=c++17 -fgpu-rdc -o "program"
seems to work fine.
cc @yxsamliu
That is a hipcc issue. hipcc by default adds -x hip before .cpp files. -x hip
applies to all input files after it.
hipcc is supposed to be a thin wrapper for clang and not intended for complicated command arguments handling. It is recommended to use clang++ instead of hipcc. Also it is recommended to use .hip as extension of HIP program instead of .cpp. If .cpp has to be used and .a file has to be after .cpp file, use '-x hip' before .cpp and '-x none' before .a file.
After creating a static library containing device functions using
-fgpu-rdc
andar
, the library is linked with a command like:This works fine, however, when the argument order is reversed and
main.cpp
is passed beforelibdevicelibrary.a
, the compiler tries to interpret the files fromlibdevicelibrary.a
as source file:This is caused by that placing
main.cpp
on the command line causeshipcc
to emit-x hip
before it, which causesclang++
to interpretlibrary.o
as a.hip
source file: