11
11
12
12
from .. import mesonlib
13
13
from .. import mlog
14
- from ..environment import detect_cpu_family
15
14
from .base import DependencyException , SystemDependency
16
15
from .detect import packages
17
16
@@ -27,8 +26,11 @@ class CudaDependency(SystemDependency):
27
26
supported_languages = ['cpp' , 'c' , 'cuda' ] # see also _default_language
28
27
29
28
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 ]
31
32
language = self ._detect_language (compilers )
33
+
32
34
if language not in self .supported_languages :
33
35
raise DependencyException (f'Language \' { language } \' is not supported by the CUDA Toolkit. Supported languages are { self .supported_languages } .' )
34
36
@@ -50,14 +52,21 @@ def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> No
50
52
if not os .path .isabs (self .cuda_path ):
51
53
raise DependencyException (f'CUDA Toolkit path must be absolute, got \' { self .cuda_path } \' .' )
52
54
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
+
53
62
# nvcc already knows where to find the CUDA Toolkit, but if we're compiling
54
63
# a mixed C/C++/CUDA project, we still need to make the include dir searchable
55
64
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' )
57
66
self .compile_args += [f'-I{ self .incdir } ' ]
58
67
59
68
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 )
61
70
mlog .debug ('CUDA library directory is' , mlog .bold (self .libdir ))
62
71
63
72
self .is_found = self ._find_requested_libraries ()
@@ -211,19 +220,16 @@ def _strip_patch_version(cls, version: str) -> str:
211
220
return '.' .join (version .split ('.' )[:2 ])
212
221
213
222
def _detect_arch_libdir (self ) -> str :
214
- arch = detect_cpu_family (self .env .coredata .compilers .host )
215
223
machine = self .env .machines [self .for_machine ]
224
+ arch = machine .cpu_family
216
225
msg = '{} architecture is not supported in {} version of the CUDA Toolkit.'
217
226
if machine .is_windows ():
218
227
libdirs = {'x86' : 'Win32' , 'x86_64' : 'x64' }
219
228
if arch not in libdirs :
220
229
raise DependencyException (msg .format (arch , 'Windows' ))
221
230
return os .path .join ('lib' , libdirs [arch ])
222
231
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"
227
233
elif machine .is_darwin ():
228
234
libdirs = {'x86_64' : 'lib64' }
229
235
if arch not in libdirs :
0 commit comments