Skip to content

Commit cd9eb48

Browse files
committed
dependencies/cuda: Add support for disabling the cuda runtime
1 parent f4fbb17 commit cd9eb48

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

docs/markdown/Dependencies.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ set the path using `CUDA_PATH` explicitly.
391391
Cuda does not honor the `prefer_static` option, and will link statically unless
392392
the `static` keyword argument is set to `false`.
393393

394+
A special set of modules called `cudart`, `cudart_static` and `cudart_none` can
395+
be used to control the Cuda Runtime used. If none of these are passed
396+
`cudart_static` is automatically added unless the `static` keyword argument is
397+
set to `false`, then `cudart` is chosen.
398+
394399
## CUPS
395400

396401
`method` may be `auto`, `config-tool`, `pkg-config`, `cmake` or `extraframework`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Cuda dependency with cudart_none
2+
3+
The Cuda dependency can now be initialize as `dependency('cuda', modules : ['cudart_none'])`,
4+
which will result in no runtime. This is equivalent to `--cudart none` on the command line.

mesonbuild/dependencies/cuda.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .base import DependencyException, SystemDependency
1515
from .detect import packages
1616
from ..mesonlib import LibType
17+
from ..interpreterbase import FeatureNew
1718

1819
if T.TYPE_CHECKING:
1920
from ..environment import Environment
@@ -40,7 +41,10 @@ def __init__(self, environment: 'Environment', kwargs: DependencyObjectKWs) -> N
4041
super().__init__('cuda', environment, kwargs, language=language)
4142
self.lib_modules: T.Dict[str, T.List[str]] = {}
4243
self.requested_modules = kwargs.get('modules', [])
43-
if not any(runtime in self.requested_modules for runtime in ['cudart', 'cudart_static']):
44+
if 'cudart_none' in self.requested_modules:
45+
self.featurechecks.append(FeatureNew('Cuda module cudart_none', '1.10'))
46+
47+
if not any(runtime in self.requested_modules for runtime in ['cudart', 'cudart_static', 'cudart_none']):
4448
# By default, we prefer to link the static CUDA runtime, since this is what nvcc also does by default:
4549
# https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#cudart-none-shared-static-cudart
4650
req_modules = ['cudart']
@@ -273,6 +277,10 @@ def _find_requested_libraries(self) -> bool:
273277
all_found = True
274278

275279
for module in self.requested_modules:
280+
if module == 'cudart_none':
281+
self.lib_modules[module] = []
282+
continue
283+
276284
# You should only ever link to libraries inside the cuda tree, nothing outside of it.
277285
# For instance, there is a
278286
#
@@ -319,6 +327,7 @@ def get_link_args(self, language: T.Optional[str] = None, raw: bool = False) ->
319327
REWRITE_MODULES = {
320328
'cudart': ['-cudart', 'shared'],
321329
'cudart_static': ['-cudart', 'static'],
330+
'cudart_none': ['-cudart', 'none'],
322331
'cudadevrt': ['-cudadevrt'],
323332
}
324333

0 commit comments

Comments
 (0)