Skip to content

Commit 8fdd06b

Browse files
cuda: use target-specific paths under CUDA Toolkit on Linux
1 parent 979805f commit 8fdd06b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

mesonbuild/dependencies/cuda.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from .. import mesonlib
1313
from .. import mlog
14-
from ..environment import detect_cpu_family
1514
from .base import DependencyException, SystemDependency
1615
from .detect import packages
1716

@@ -27,8 +26,11 @@ class CudaDependency(SystemDependency):
2726
supported_languages = ['cpp', 'c', 'cuda'] # see also _default_language
2827

2928
def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> None:
30-
compilers = environment.coredata.compilers[self.get_for_machine_from_kwargs(kwargs)]
29+
for_machine = self.get_for_machine_from_kwargs(kwargs)
30+
compilers = environment.coredata.compilers[for_machine]
31+
machine = environment.machines[for_machine]
3132
language = self._detect_language(compilers)
33+
3234
if language not in self.supported_languages:
3335
raise DependencyException(f'Language \'{language}\' is not supported by the CUDA Toolkit. Supported languages are {self.supported_languages}.')
3436

@@ -50,14 +52,21 @@ def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> No
5052
if not os.path.isabs(self.cuda_path):
5153
raise DependencyException(f'CUDA Toolkit path must be absolute, got \'{self.cuda_path}\'.')
5254

55+
# Cuda target directory relative to cuda path.
56+
if machine.is_linux():
57+
# E.g. targets/x86_64-linux
58+
self.target_path = os.path.join('targets', f"{machine.cpu_family}-{machine.system}")
59+
else:
60+
self.target_path = "."
61+
5362
# nvcc already knows where to find the CUDA Toolkit, but if we're compiling
5463
# a mixed C/C++/CUDA project, we still need to make the include dir searchable
5564
if self.language != 'cuda' or len(compilers) > 1:
56-
self.incdir = os.path.join(self.cuda_path, 'include')
65+
self.incdir = os.path.join(self.cuda_path, self.target_path, 'include')
5766
self.compile_args += [f'-I{self.incdir}']
5867

5968
arch_libdir = self._detect_arch_libdir()
60-
self.libdir = os.path.join(self.cuda_path, arch_libdir)
69+
self.libdir = os.path.join(self.cuda_path, self.target_path, arch_libdir)
6170
mlog.debug('CUDA library directory is', mlog.bold(self.libdir))
6271

6372
self.is_found = self._find_requested_libraries()
@@ -211,19 +220,16 @@ def _strip_patch_version(cls, version: str) -> str:
211220
return '.'.join(version.split('.')[:2])
212221

213222
def _detect_arch_libdir(self) -> str:
214-
arch = detect_cpu_family(self.env.coredata.compilers.host)
215223
machine = self.env.machines[self.for_machine]
224+
arch = machine.cpu_family
216225
msg = '{} architecture is not supported in {} version of the CUDA Toolkit.'
217226
if machine.is_windows():
218227
libdirs = {'x86': 'Win32', 'x86_64': 'x64'}
219228
if arch not in libdirs:
220229
raise DependencyException(msg.format(arch, 'Windows'))
221230
return os.path.join('lib', libdirs[arch])
222231
elif machine.is_linux():
223-
libdirs = {'x86_64': 'lib64', 'ppc64': 'lib', 'aarch64': 'lib64', 'loongarch64': 'lib64'}
224-
if arch not in libdirs:
225-
raise DependencyException(msg.format(arch, 'Linux'))
226-
return libdirs[arch]
232+
return "lib"
227233
elif machine.is_darwin():
228234
libdirs = {'x86_64': 'lib64'}
229235
if arch not in libdirs:

0 commit comments

Comments
 (0)