CHIP-SPV / chipStar

chipStar is a tool for compiling and running HIP/CUDA on SPIR-V via OpenCL or Level Zero APIs.
Other
227 stars 34 forks source link

--relocatable-device-code=true and --device-c (-dc) nvcc flags are not handled by cucc wrapper #882

Closed jjennychen closed 4 months ago

jjennychen commented 4 months ago

When compiling CUDA programs with flags --relocatable-device-code=true or --device-c (--device-c is the same as -dc or --relocatable-device-code=true --compile according to this CUDA documentation), chipStar doesn't recognize the flags and instead directly use them for compiling without converting them to the corresponding clang flags (-fgpu-rdc flag for --relocatable-device-code=true and -fgpu-rdc -c for --device-c (-dc)).

[Reproducer] Have the following three files, main.cu, function.hpp, and function.cu:

main.cu

#include "function.hpp"

int main() {
  test();
}

function.hpp

void test();

function.cu

#include "function.hpp"

void test() {
  printf("hello\n");
}

Then, compile main.cu first with nvcc -dc main.cu. The following errors will appear (with the -dc flag in the compilation command line):

/usr/bin/ld: /tmp/main-9ac6a2.o: in function `main':
main.cu:(.text+0x5): undefined reference to `test()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

failed to execute:/home/tsaini.chen/install/llvm/17.0/bin/clang++ -include /home/tsaini.chen/install/chipStar/chipStar_06272024/include/hip/spirv_fixups.h -I//home/tsaini.chen/install/chipStar/chipStar_06272024/include -isystem /home/tsaini.chen/install/chipStar/chipStar_06272024/include/cuspv -include /home/tsaini.chen/install/chipStar/chipStar_06272024/include/cuspv/cuda_runtime.h -D__NVCC__ -D__CHIP_CUDA_COMPATIBILITY__ -dc -x hip main.cu -D__HIP_PLATFORM_SPIRV__= --offload=spirv64 -nohipwrapperinc --hip-path=/home/tsaini.chen/install/chipStar/chipStar_06272024 --target=x86_64-unknown-linux-gnu   -L/home/tsaini.chen/install/chipStar/chipStar_06272024/lib -lCHIP -no-hip-rt -Wl,-rpath,/home/tsaini.chen/install/chipStar/chipStar_06272024/lib