Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion devito/arch/archinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def get_cuda_version():
out = run(nvc_version_command, capture_output=True, text=True)
except (FileNotFoundError, CalledProcessError):
pass
finally:
else:
if out.returncode == 0:
start = out.stdout.find('release')
start = out.stdout.find(',', start) + 1
Expand Down
3 changes: 2 additions & 1 deletion devito/arch/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,8 @@ def __init_finalize__(self, **kwargs):
@property
def std(self):
# Since CUDA 13, code needs compiling with C++17 standard
_cxxstd = 'c++17' if get_cuda_version().major >= 13 else 'c++14'
cuda_version = get_cuda_version()
_cxxstd = 'c++17' if cuda_version and cuda_version.major >= 13 else 'c++14'
return _cxxstd if self._cpp else self._cstd

def __lookup_cmds__(self):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from devito import configuration, switchconfig
from devito.arch import BLACKWELL, NVIDIAX
from devito.arch.archinfo import get_cuda_version
from devito.arch.compiler import (
CudaCompiler, GNUCompiler, compiler_registry, sniff_compiler_version
)
Expand Down Expand Up @@ -93,3 +94,26 @@ def test_cuda_target(monkeypatch, platform, cc, target):

flags = [i for i in compiler.cflags if i.startswith(('-arch=', '-gencode='))]
assert flags == [target]


def test_get_cuda_version_without_nvcc(monkeypatch):
def missing(*args, **kwargs):
raise FileNotFoundError('nvcc')

monkeypatch.setattr('devito.arch.archinfo.run', missing)
# `.func` skips the cache
assert get_cuda_version.func() is None


def test_cuda_std_without_nvcc(monkeypatch):
def std(version):
with switchconfig(mpi=False), monkeypatch.context() as m:
m.setattr('devito.arch.compiler.get_cuda_version', lambda: version)
m.setattr('devito.arch.compiler.check_cuda_runtime', lambda: None)
return CudaCompiler(platform=NVIDIAX).std

assert std(Version('13.0')) == 'c++17'
assert std(Version('12.8')) == 'c++14'
# No `nvcc`: fall back to the pre-CUDA 13 standard
assert std(None) == 'c++14'