samples/nvcuda: support Linux arm64 cross-compilation
Merged
QI
3d ago+97+97+01234567890123456789-8-8-0123456789
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 }}) forapps-arm64andapps-vcpkg-arm64in addition toappsandapps-vcpkgso/usr/local/cuda/bin/nvccand host build tools are available. - Add an
Install CUDA for apps-arm64 and apps-vcpkg-arm64step that installscuda-repo-cross-sbsa-$distro_name-${{ env.CUDA_VERSION_MM }}-local_${{ env.CUDA_VERSION_MMP }}-1_all.debandcuda-cross-sbsa-${{ env.CUDA_VERSION_MM }}(which populates/usr/local/cuda/targets/sbsa-linux/{include,lib}).
- Run the host CUDA toolkit installation step (
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_cpuisaarch64orarm64, and chooselib64orlibaccordingly. - Verify that
-lcudartlinks (AC_CHECK_LIB([cudart], [cudaMalloc], ...)) in addition to checkingcuda_runtime.h, determineCUDA_CCBIN(falling back to${CUDA_CCBIN##* }ifCXXcontains a compiler wrapper such asccache), substituteCUDA_CCBINviaAC_SUBST, and export it insamples/Makefile.am.
- Select
samples/nvcuda/Makefile:- Detect
arm64/aarch64cross-compilation viaRELEASE_ARCH,TARGET_ARCH, oraarch64inCXX, and setCUDA_INCLUDE_PATHandCUDA_LIB_PATHto$(CUDA_INSTALL_PATH)/targets/sbsa-linux/{include,lib}(ortargets/aarch64-linux). - Pass
-ccbin "$(CUDA_CCBIN)"(defaultingCUDA_CCBIN ?= $(CXX)for standalone invokes) and the target include/library directories to$(CUDA_NVCC)when compilingcuda_kernel.cu. - Add an explicit
cuda.o: cuda.cpprule so GNU Make's built-in.cpp.orule does not pass$(TARGET_ARCH)as a compiler flag ifTARGET_ARCHis set in the environment.
- Detect
Testing
- Cross-compiled
samples/nvcuda/example_app_nvcudaon Linuxx86_64targetingaarch64-linux-gnu(./configure --host=aarch64-linux ...withCXX=aarch64-linux-gnu-g++and CUDA 13.3 +cuda-cross-sbsa-13-3):- Verified
configuredetects CUDA 13.3,cuda_runtime.h,-lcudart, andnvcc -ccbin aarch64-linux-gnu-g++. - Verified
samples/nvcuda/example_app_nvcudais built as anELF 64-bit LSB pie executable, ARM aarch64linked againstlibcudart.so.13.
- Verified
- Built
samples/nvcuda/example_app_nvcudanatively on Linuxx86_64with CUDA 13.3 and verified the resultingx86-64ELF 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-toolkitandcuda-cross-sbsain the Linux CI workflow for theapps-arm64andapps-vcpkg-arm64jobs. - Updates
m4/cuda.m4to selecttargets/sbsa-linux(ortargets/aarch64-linux) CUDA directories when cross-compiling for arm64, verifies-lcudartlinks for the target, and checksnvccworks with-ccbin $CXX. - Exports
CUDA_CCBINfromsamples/Makefile.amso the sample Makefile picks up the host compiler. - Updates
samples/nvcuda/Makefileto pass-ccbin "$(CUDA_CCBIN)"tonvccand use target-specific CUDA include and library paths for arm64.
Fixes #7162