samples/nvcuda: support Linux arm64 cross-compilation

Merged
QI
3d ago
+97-8

Summary

Currently, the samples/nvcuda sample application (example_app_nvcuda) is only built in Linux CI for native x86_64 (apps and apps-vcpkg), and is not cross-compiled for Linux arm64 (apps-arm64 and apps-vcpkg-arm64).

Change

Enable cross-compilation of samples/nvcuda/example_app_nvcuda for Linux arm64 (aarch64) using the NVIDIA CUDA SBSA cross-compilation toolkit:

  • .github/workflows/linux.yml:
    • Run the host CUDA toolkit installation step (cuda-toolkit-${{ env.CUDA_VERSION_MM }}) for apps-arm64 and apps-vcpkg-arm64 in addition to apps and apps-vcpkg so /usr/local/cuda/bin/nvcc and host build tools are available.
    • Add an Install CUDA for apps-arm64 and apps-vcpkg-arm64 step that installs cuda-repo-cross-sbsa-$distro_name-${{ env.CUDA_VERSION_MM }}-local_${{ env.CUDA_VERSION_MMP }}-1_all.deb and cuda-cross-sbsa-${{ env.CUDA_VERSION_MM }} (which populates /usr/local/cuda/targets/sbsa-linux/{include,lib}).
  • m4/cuda.m4 & samples/Makefile.am:
    • Select $cuda_root/targets/sbsa-linux (or $cuda_root/targets/aarch64-linux) as the target CUDA directory when $host_cpu is aarch64 or arm64, and choose lib64 or lib accordingly.
    • Verify that -lcudart links (AC_CHECK_LIB([cudart], [cudaMalloc], ...)) in addition to checking cuda_runtime.h, determine CUDA_CCBIN (falling back to ${CUDA_CCBIN##* } if CXX contains a compiler wrapper such as ccache), substitute CUDA_CCBIN via AC_SUBST, and export it in samples/Makefile.am.
  • samples/nvcuda/Makefile:
    • Detect arm64/aarch64 cross-compilation via RELEASE_ARCH, TARGET_ARCH, or aarch64 in CXX, and set CUDA_INCLUDE_PATH and CUDA_LIB_PATH to $(CUDA_INSTALL_PATH)/targets/sbsa-linux/{include,lib} (or targets/aarch64-linux).
    • Pass -ccbin "$(CUDA_CCBIN)" (defaulting CUDA_CCBIN ?= $(CXX) for standalone invokes) and the target include/library directories to $(CUDA_NVCC) when compiling cuda_kernel.cu.
    • Add an explicit cuda.o: cuda.cpp rule so GNU Make's built-in .cpp.o rule does not pass $(TARGET_ARCH) as a compiler flag if TARGET_ARCH is set in the environment.

Testing

  • Cross-compiled samples/nvcuda/example_app_nvcuda on Linux x86_64 targeting aarch64-linux-gnu (./configure --host=aarch64-linux ... with CXX=aarch64-linux-gnu-g++ and CUDA 13.3 + cuda-cross-sbsa-13-3):
    • Verified configure detects CUDA 13.3, cuda_runtime.h, -lcudart, and nvcc -ccbin aarch64-linux-gnu-g++.
    • Verified samples/nvcuda/example_app_nvcuda is built as an ELF 64-bit LSB pie executable, ARM aarch64 linked against libcudart.so.13.
  • Built samples/nvcuda/example_app_nvcuda natively on Linux x86_64 with CUDA 13.3 and verified the resulting x86-64 ELF executable.

Fixes #7162


Summary by cubic

Enables cross-compiling samples/nvcuda/example_app_nvcuda for Linux arm64 (aarch64) using the NVIDIA CUDA SBSA cross-compilation toolkit.

  • Installs cuda-toolkit and cuda-cross-sbsa in the Linux CI workflow for the apps-arm64 and apps-vcpkg-arm64 jobs.
  • Updates m4/cuda.m4 to select targets/sbsa-linux (or targets/aarch64-linux) CUDA directories when cross-compiling for arm64, verifies -lcudart links for the target, and checks nvcc works with -ccbin $CXX.
  • Exports CUDA_CCBIN from samples/Makefile.am so the sample Makefile picks up the host compiler.
  • Updates samples/nvcuda/Makefile to pass -ccbin "$(CUDA_CCBIN)" to nvcc and use target-specific CUDA include and library paths for arm64.

Fixes #7162