Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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
31 changes: 20 additions & 11 deletions cuda_bindings/cuda/bindings/cyruntime.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -1885,35 +1885,44 @@ cdef cudaError_t cudaGraphicsVDPAURegisterOutputSurface(cudaGraphicsResource** r

{{if True}}

{{if 'Windows' != platform.system()}}
from libc.stdint cimport uintptr_t
from cuda.pathfinder import load_nvidia_dynamic_lib
{{if 'Windows' == platform.system()}}
cimport cuda.bindings._lib.windll as windll
{{else}}
cimport cuda.bindings._lib.dlfcn as dlfcn
{{endif}}

cdef cudaError_t getLocalRuntimeVersion(int* runtimeVersion) except ?cudaErrorCallRequiresNewerDriver nogil:
{{if 'Windows' == platform.system()}}
with gil:
raise NotImplementedError('"getLocalRuntimeVersion" is unsupported on Windows')
{{else}}

# Load
handle = dlfcn.dlopen('libcudart.so.13', dlfcn.RTLD_NOW)
if handle == NULL:
with gil:
raise RuntimeError(f'Failed to dlopen libcudart.so.13')
with gil:
lib = load_nvidia_dynamic_lib("cudart")
Comment thread
leofang marked this conversation as resolved.
Outdated
{{if 'Windows' == platform.system()}}
handle = <uintptr_t>lib._handle_uint
Comment thread
leofang marked this conversation as resolved.
Outdated
{{else}}
handle = <void *><uintptr_t>lib._handle_uint
Comment thread
leofang marked this conversation as resolved.
Outdated
Comment thread
leofang marked this conversation as resolved.
Outdated
{{endif}}

{{if 'Windows' == platform.system()}}
__cudaRuntimeGetVersion = windll.GetProcAddress(handle, b'cudaRuntimeGetVersion')
{{else}}
__cudaRuntimeGetVersion = dlfcn.dlsym(handle, 'cudaRuntimeGetVersion')
{{endif}}

if __cudaRuntimeGetVersion == NULL:
with gil:
raise RuntimeError(f'Function "cudaRuntimeGetVersion" not found in libcudart.so.13')
raise RuntimeError(f'Function "cudaRuntimeGetVersion" not found in {lib.abs_path}')

# Call
cdef cudaError_t err = cudaSuccess
err = (<cudaError_t (*)(int*) except ?cudaErrorCallRequiresNewerDriver nogil> __cudaRuntimeGetVersion)(runtimeVersion)

# Unload
{{if 'Windows' != platform.system()}}
dlfcn.dlclose(handle)
{{endif}}
Comment thread
leofang marked this conversation as resolved.

# Return
return err
{{endif}}
{{endif}}
11 changes: 11 additions & 0 deletions cuda_bindings/tests/test_cudart.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import cuda.bindings.driver as cuda
import cuda.bindings.runtime as cudart
from cuda import pathfinder
from cuda.bindings import runtime


Expand Down Expand Up @@ -1400,3 +1401,13 @@ def test_struct_pointer_comparison(target):
c = target(456)
assert a != c
assert hash(a) != hash(c)


def test_getLocalRuntimeVersion():
try:
err, version = cudart.getLocalRuntimeVersion()
except pathfinder.DynamicLibNotFoundError:
pass
Comment thread
leofang marked this conversation as resolved.
Outdated
else:
assertSuccess(err)
assert version >= 12000 # CUDA 12.0
Loading