CUDA aarch64 cross compile fails to validate nvcc

I’m attempting to use a toolchain file to cross-compile from Linux x86_64 to aarch64.

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(CMAKE_TOOLS_PREFIX ${CMAKE_SYSTEM_PROCESSOR}-linux-gnu- CACHE STRING "")

set(CMAKE_C_COMPILER ${CMAKE_TOOLS_PREFIX}gcc)
set(CMAKE_C_COMPILER_TARGET ${CMAKE_SYSTEM_PROCESSOR})
set(CMAKE_C_COMPILER_AR ${CMAKE_TOOLS_PREFIX}ar)

set(CMAKE_CXX_COMPILER ${CMAKE_TOOLS_PREFIX}g++)
set(CMAKE_CXX_COMPILER_TARGET ${CMAKE_SYSTEM_PROCESSOR})
set(CMAKE_CXX_COMPILER_AR ${CMAKE_TOOLS_PREFIX}ar)

set(CMAKE_AR ${CMAKE_TOOLS_PREFIX}ar)

set(CMAKE_CUDA_COMPILER ${CUDA_HOST_TOOLKIT_ROOT_DIR}/bin/nvcc)
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER} CACHE INTERNAL "")

However, I’m running into major issues.

  1. With the above, the linker fails during the CUDA compiler detection.
Linking CUDA executable cmTC_89859                                                                                                                                                                                                       
    /home/utils/cmake-3.12.4/bin/cmake -E cmake_link_script CMakeFiles/cmTC_89859.dir/link.txt --verbose=1                                                                                                                                   
    ""   CMakeFiles/cmTC_89859.dir/main.cu.o CMakeFiles/cmTC_89859.dir/cmake_device_link.o -o cmTC_89859                                                                                                                          
    Error running link command: No such file or directory

I’ve tried to set up the linker command directly using the following code, but the necessary libraries are not applied such as -lcudart so the link still fails.

set(CMAKE_LINKER ${CMAKE_CXX_COMPILER} CACHE STRING "")
set(CMAKE_CUDA_HOST_LINK_LAUNCHER ${CMAKE_LINKER} CACHE STRING "")
Linking CUDA executable cmTC_3e539
    /home/utils/cmake-3.12.4/bin/cmake -E cmake_link_script CMakeFiles/cmTC_3e539.dir/link.txt --verbose=1
    aarch64-linux-gnu-g++   CMakeFiles/cmTC_3e539.dir/main.cu.o CMakeFiles/cmTC_3e539.dir/cmake_device_link.o -o cmTC_3e539
    CMakeFiles/cmTC_3e539.dir/main.cu.o: In function `__cudaUnregisterBinaryUtil()':
    tmpxft_00005923_00000000-5_main.cudafe1.cpp:(.text+0x70): undefined reference to `__cudaUnregisterFatBinary'
    CMakeFiles/cmTC_3e539.dir/main.cu.o: In function `__nv_init_managed_rt_with_module(void**)':
    tmpxft_00005923_00000000-5_main.cudafe1.cpp:(.text+0x90): undefined reference to `__cudaInitModule'
    CMakeFiles/cmTC_3e539.dir/main.cu.o: In function `__sti____cudaRegisterAll()':
    tmpxft_00005923_00000000-5_main.cudafe1.cpp:(.text+0xe0): undefined reference to `__cudaRegisterFatBinary'
    tmpxft_00005923_00000000-5_main.cudafe1.cpp:(.text+0x120): undefined reference to `__cudaRegisterFatBinaryEnd'
    CMakeFiles/cmTC_3e539.dir/cmake_device_link.o: In function `__cudaUnregisterBinaryUtil':
    link.stub:(.text+0x14): undefined reference to `__cudaUnregisterFatBinary'
    collect2: error: ld returned 1 exit status
  1. If I instead just force all the compilers to skip the checking, my compiles then fail because it seems my CMAKE_CXX_STANDARD and other related settings don’t get propagated to the compiler flags, so I get errors stating I need to apply -std=c++11. I’ve seen this can be an issue on Mac builds, but not for linux cross-complation.

Does CMake require you to specify all the CXX, CUDA, and linker flags manually if you do cross-compilation?

This is seen using CMake 3.12.4 and 3.13. I’m going to try a few others as well.

Thanks!

@robert.maynard