Add a CUDA linker object

Fixes issue #5870
pull/5891/head
Kramer Peace 5 years ago committed by Dylan Baker
parent bd37147b4b
commit fb9a5ce867
  1. 6
      mesonbuild/compilers/cuda.py
  2. 4
      mesonbuild/environment.py
  3. 29
      mesonbuild/linkers.py

@ -34,7 +34,7 @@ class CudaCompiler(Compiler):
super().__init__(exelist, version, for_machine, **kwargs)
self.is_cross = is_cross
self.exe_wrapper = exe_wrapper
self.id = 'nvcc'
self.id = CudaCompiler.cuda_id()
default_warn_args = []
self.warn_args = {'0': [],
'1': default_warn_args,
@ -42,6 +42,10 @@ class CudaCompiler(Compiler):
'3': default_warn_args + ['-Xcompiler=-Wextra',
'-Xcompiler=-Wpedantic']}
@staticmethod
def cuda_id():
return 'nvcc'
def needs_static_linker(self):
return False

@ -55,6 +55,7 @@ from .linkers import (
XildAppleDynamicLinker,
XildLinuxDynamicLinker,
XilinkDynamicLinker,
CudaLinker,
)
from functools import lru_cache
from .compilers import (
@ -696,6 +697,9 @@ class Environment:
`-Xlinker=--version`) you must pass as a list.
:extra_args: Any addtional arguments rquired (such as a source file)
"""
if CudaCompiler.cuda_id() in compiler:
return CudaLinker(compiler, for_machine, 'nvlink', prefix, version=CudaLinker.parse_version())
extra_args = typing.cast(typing.List[str], extra_args or [])
if isinstance(prefix, str):
check_args = [prefix + '--version'] + extra_args

@ -909,3 +909,32 @@ class OptlinkDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
def get_allow_undefined_args(self) -> typing.List[str]:
return []
class CudaLinker(DynamicLinker):
"""Cuda linker (nvlink)"""
@staticmethod
def parse_version():
version_cmd = ['nvlink', '--version']
try:
_, out, _ = mesonlib.Popen_safe(version_cmd)
except OSError:
return 'unknown version'
# Output example:
# nvlink: NVIDIA (R) Cuda linker
# Copyright (c) 2005-2018 NVIDIA Corporation
# Built on Sun_Sep_30_21:09:22_CDT_2018
# Cuda compilation tools, release 10.0, V10.0.166
# we need the most verbose version output. Luckily starting with V
return out.strip().split('V')[-1]
def get_output_args(self, outname: str) -> typing.List[str]:
return ['-o', outname]
def get_search_args(self, dirname: str) -> typing.List[str]:
return ['-L', dirname]
def fatal_warnings(self) -> typing.List[str]:
return ['--warning-as-error']
def get_allow_undefined_args(self) -> typing.List[str]:
return []

Loading…
Cancel
Save