Skip to content

Commit 2eeb904

Browse files
committed
Pass #2 of porting driver to cybind
1 parent 6c5ecf9 commit 2eeb904

40 files changed

Lines changed: 47646 additions & 2656 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ repos:
108108
rev: "3e8a8703264a2f4a69428a0aa4dcb512790b2c8c" # frozen: v6.0.0
109109
hooks:
110110
- id: check-added-large-files
111-
exclude: cuda_bindings/cuda/bindings/nvml.pyx
111+
exclude: cuda_bindings/cuda/bindings/nvml.pyx|cuda_bindings/cuda/bindings/_v2/driver.pyx
112112
- id: check-case-conflict
113113
- id: check-docstring-first
114114
- id: check-merge-conflict

cuda_bindings/cuda/bindings/_example_helpers/common.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import numpy as np
99

1010
from cuda import pathfinder
11-
from cuda.bindings import driver as cuda
1211
from cuda.bindings import runtime as cudart
12+
from cuda.bindings._v2 import driver as cuda
1313
from cuda.bindings._v2 import nvrtc
1414

1515
from .helper_cuda import check_cuda_errors
@@ -84,7 +84,9 @@ def __init__(self, code, dev_id):
8484
else:
8585
data = nvrtc.get_ptx(prog)
8686

87-
self.module = check_cuda_errors(cuda.cuModuleLoadData(np.char.array(data)))
87+
self.module = cuda.module_load_data(np.char.array(data))
8888

8989
def get_function(self, name):
90-
return check_cuda_errors(cuda.cuModuleGetFunction(self.module, name))
90+
if isinstance(name, bytes):
91+
name = name.decode()
92+
return cuda.module_get_function(self.module, name)

cuda_bindings/cuda/bindings/_example_helpers/helper_cuda.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from cuda.bindings import driver as cuda
55
from cuda.bindings import nvrtc
66
from cuda.bindings import runtime as cudart
7+
from cuda.bindings._v2 import driver as cuda_v2
78

89
from .helper_string import check_cmd_line_flag, get_cmd_line_argument_int
910

@@ -43,6 +44,6 @@ def find_cuda_device_drv():
4344
dev_id = 0
4445
if check_cmd_line_flag("device="):
4546
dev_id = get_cmd_line_argument_int("device=")
46-
check_cuda_errors(cuda.cuInit(0))
47-
cu_device = check_cuda_errors(cuda.cuDeviceGet(dev_id))
47+
cuda_v2.init(0)
48+
cu_device = cuda_v2.device_get(dev_id)
4849
return cu_device

cuda_bindings/cuda/bindings/_internal/_fast_enum.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=581469c1fadb5f72c43b478d73f2b905562136c8723a25e2f4240b5b681e2894
5+
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=8e5f9b5cdfa1966fc26d3fd6782a41f08bc8b6c24321b0fe5fd1ddd92393bea8
66
"""
77
This is a replacement for the stdlib enum.IntEnum.
88
@@ -22,6 +22,7 @@ def __init__(cls, name, bases, namespace):
2222

2323
cls.__singletons__ = {}
2424
cls.__members__ = {}
25+
aliases = {}
2526
for name, value in cls.__dict__.items():
2627
if name.startswith("__") and name.endswith("__"):
2728
continue
@@ -33,6 +34,14 @@ def __init__(cls, name, bases, namespace):
3334
else:
3435
continue
3536

37+
# A name sharing a value with an already-processed member is an
38+
# alias (e.g. a deprecated name kept for backward compatibility):
39+
# it resolves to the same singleton, but isn't a distinct member
40+
# (excluded from __members__, iteration, and len()).
41+
if value in cls.__singletons__:
42+
aliases[name] = cls.__singletons__[value]
43+
continue
44+
3645
singleton = int.__new__(cls, value)
3746
singleton.__doc__ = doc
3847
singleton._name = name
@@ -41,6 +50,8 @@ def __init__(cls, name, bases, namespace):
4150

4251
for name, member in cls.__members__.items():
4352
setattr(cls, name, member)
53+
for name, member in aliases.items():
54+
setattr(cls, name, member)
4455

4556
def __repr__(cls) -> str:
4657
return f"<enum '{cls.__name__}'>"

cuda_bindings/cuda/bindings/_v2/driver.pxd

Lines changed: 725 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)