Skip to content

Meson CUDA dependency ignores target-specific CUDA library paths during cross-compilation (aarch64) #14595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MaxandreOgeret opened this issue May 12, 2025 · 0 comments · Fixed by #14612

Comments

@MaxandreOgeret
Copy link
Contributor

MaxandreOgeret commented May 12, 2025

Describe the bug

When cross-compiling CUDA-based projects for aarch64 platforms, Meson's built-in CUDA dependency
dependency('cuda', modules: ['cudart'])
always provides the host link directory /usr/local/cuda/lib64 instead of the target architecture's /usr/local/cuda/targets/aarch64-linux/lib

To Reproduce

Any cross compiled project which uses dependency('cuda')

Expected behavior

dependency('cuda') should use the target's include and link dir when available.

--

Issues I noticed in the cuda dependency:

  • cuda dependency will always include the build machine libdir:
    def _detect_arch_libdir(self) -> str:
    arch = detect_cpu_family(self.env.coredata.compilers.host)

    return libdirs[arch]

    Arch should be looked up via the compilers "for_machine" entry instead.
  • lib64 is hardcoded.
    elif machine.is_linux():
    libdirs = {'x86_64': 'lib64', 'ppc64': 'lib', 'aarch64': 'lib64', 'loongarch64': 'lib64'}

    When the actual NVIDIA cross-compilation toolchain uses lib
    ( /usr/local/cuda/targets/aarch64-linux/lib)
    This prevents setting CUDA_PATH=/usr/local/cuda/targets/aarch64-linux as a workaround.
  • The host machine target is totally ignored, and only the build machine lib dir is used.
    arch_libdir = self._detect_arch_libdir()
    self.libdir = os.path.join(self.cuda_path, arch_libdir)

Approaches to fix the issue

With some guidance I'd be honored to make a PR, I have the following thoughts on how to solve the issues:

  • _detect_arch_libdir should use "for_machine" entry instead of detect_cpu_family.
  • When cross compiling the lib directory is forced to lib (or make configurable ?)
  • When cross-compiling, the dependency detector should search for target-specific CUDA toolkit paths in /usr/local/cuda/targets/{target_arch}-linux/.

--

system parameters

  • cross-build (build machine: x86_64; host_machine: aarch64)
  • OS: Ubuntu 18.04 x86_64
  • Python version: Python 3.8.0
  • Meson version: 1.8.0
  • Ninja version: 1.11.1.git.kitware.jobserver-1

Thanks to @eli-schwartz for guidance on Matrix chat about this issue! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant