Skip to content

Commit

Permalink
gpu: Raise warning in case of CUDA runtime / driver incompat
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioLuporini committed Jan 31, 2022
1 parent d8e5d4a commit aca3717
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
28 changes: 28 additions & 0 deletions devito/arch/archinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from devito.tools import all_equal, memoized_func

__all__ = ['platform_registry', 'get_cpu_info', 'get_gpu_info', 'get_nvidia_cc',
'check_cuda_runtime',
'Platform', 'Cpu64', 'Intel64', 'Amd', 'Arm', 'Power', 'Device',
'NvidiaDevice', 'AmdDevice',
'INTEL64', 'SNB', 'IVB', 'HSW', 'BDW', 'SKX', 'KNL', 'KNL7210', # Intel
Expand Down Expand Up @@ -344,6 +345,33 @@ def get_nvidia_cc():
return 10*cc_major.value + cc_minor.value


@memoized_func
def check_cuda_runtime():
libnames = ('libcudart.so', 'libcudart.dylib', 'cudart.dll')
for libname in libnames:
try:
cuda = ctypes.CDLL(libname)
except OSError:
continue
else:
break
else:
warning("Unable to check compatibility of NVidia driver and runtime")

driver_version = ctypes.c_int()
runtime_version = ctypes.c_int()

if cuda.cudaDriverGetVersion(ctypes.byref(driver_version)) == 0 and \
cuda.cudaRuntimeGetVersion(ctypes.byref(runtime_version)) == 0:
driver_version = driver_version.value
runtime_version = runtime_version.value
if driver_version < runtime_version:
warning("The NVidia driver (v%d) on this system may not be compatible "
"with the CUDA runtime (v%d)" % (driver_version, runtime_version))
else:
warning("Unable to check compatibility of NVidia driver and runtime")


@memoized_func
def lscpu():
try:
Expand Down
9 changes: 8 additions & 1 deletion devito/arch/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from codepy.jit import compile_from_string
from codepy.toolchain import GCCToolchain

from devito.arch import AMDGPUX, NVIDIAX, SKX, POWER8, POWER9, get_nvidia_cc
from devito.arch import (AMDGPUX, NVIDIAX, SKX, POWER8, POWER9, get_nvidia_cc,
check_cuda_runtime)
from devito.exceptions import CompilationError
from devito.logger import debug, warning, error
from devito.parameters import configuration
Expand Down Expand Up @@ -494,6 +495,12 @@ def __init__(self, *args, **kwargs):

self.src_ext = 'cu'

# NOTE: not sure where we should place this. It definitely needs
# to be executed once to warn the user in case there's a CUDA/driver
# mismatch that would cause the program to run, but likely producing
# garbage, since the CUDA kernel behaviour would be undefined
check_cuda_runtime()

def __lookup_cmds__(self):
self.CC = 'nvcc'
self.CXX = 'nvcc'
Expand Down

0 comments on commit aca3717

Please sign in to comment.