Skip to content

Commit cefa733

Browse files
committed
fix the documentation build error
1 parent a991b90 commit cefa733

File tree

5 files changed

+63
-18
lines changed

5 files changed

+63
-18
lines changed

cuda_core/cuda/core/experimental/_system.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
from cuda.core.experimental._utils import handle_return
55

66
class System:
7-
"""Represent the system and provide information about the CUDA environment."""
7+
"""Represent the system and provide information about the CUDA environment.
8+
9+
This class is a singleton and should not be instantiated directly.
10+
Use the provided instance `system` instead.
11+
"""
812

913
def __new__(cls):
1014
if not cls._instance:
@@ -17,10 +21,13 @@ def __init__(self):
1721

1822
@property
1923
def driver_version(self) -> Tuple[int, int]:
20-
"""Query the CUDA driver version.
24+
"""
25+
Query the CUDA driver version.
2126
22-
Returns:
23-
tuple: a 2-tuple of (major, minor).
27+
Returns
28+
-------
29+
tuple of int
30+
A 2-tuple of (major, minor) version numbers.
2431
"""
2532
version = handle_return(cuda.cuDriverGetVersion())
2633
major = version // 1000
@@ -30,14 +37,28 @@ def driver_version(self) -> Tuple[int, int]:
3037

3138
@property
3239
def num_devices(self) -> int:
33-
"""Query the number of available GPUs."""
40+
"""
41+
Query the number of available GPUs.
42+
43+
Returns
44+
-------
45+
int
46+
The number of available GPU devices.
47+
"""
3448
return handle_return(cudart.cudaGetDeviceCount())
3549

3650
@property
3751
def devices(self) -> tuple:
38-
"""Query the available device instances."""
52+
"""
53+
Query the available device instances.
54+
55+
Returns
56+
-------
57+
tuple of Device
58+
A tuple containing instances of available devices.
59+
"""
3960
total = self.num_devices
4061
self._devices = tuple(Device(device_id) for device_id in range(total))
4162
return self._devices
4263

43-
_system = System.__new__(System)
64+
_system = System.__new__(System)

cuda_core/docs/source/conf.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
import os
13+
import sys
14+
from unittest.mock import MagicMock
1315

14-
# import sys
15-
# sys.path.insert(0, os.path.abspath('.'))
16+
# Add the path to your module
17+
sys.path.insert(0, os.path.abspath('../..'))
18+
19+
# Mock the cuda module and its submodules
20+
class Mock(MagicMock):
21+
@classmethod
22+
def __getattr__(cls, name):
23+
return MagicMock()
24+
25+
MOCK_MODULES = ['cuda.core.experimental._system']
26+
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
1627

1728

1829
# -- Project information -----------------------------------------------------

cuda_core/docs/source/release.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ maxdepth: 3
66
---
77
88
0.1.0 <release/0.1.0-notes>
9+
0.2.0 <release/0.2.0-notes>
10+
911
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# `cuda.core` Release notes
2+
3+
Released on <TODO>, 2024
4+
5+
## Hightlights
6+
- Addition of the system singleton
7+
8+
## Limitations
9+
10+
<TODO>

cuda_core/tests/test_system.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1-
# test_system.py
1+
# test_System.py
22

33
try:
44
from cuda.bindings import driver, runtime
55
except ImportError:
66
from cuda import cuda as driver
77
from cuda import cudart as runtime
88

9-
from cuda.core.experimental import Device, system
9+
from cuda.core.experimental import Device, System
1010

1111
from cuda.core.experimental import Device
1212
from cuda.core.experimental._utils import handle_return
1313

14-
def test_system_singleton():
15-
system1 = system
16-
system2 = system
17-
assert system1 is system2, "System is not a singleton"
14+
def test_System_singleton():
15+
System1 = System
16+
System2 = System
17+
assert System1 is System2, "System is not a singleton"
1818

1919
def test_driver_version():
20-
driver_version = system.driver_version
20+
driver_version = System.driver_version
21+
print(driver_version)
2122
version = handle_return(driver.cuDriverGetVersion())
2223
expected_driver_version = (version // 1000, (version % 1000) // 10)
2324
assert driver_version == expected_driver_version, "Driver version does not match expected value"
2425

2526
def test_num_devices():
26-
num_devices = system.num_devices
27+
num_devices = System.num_devices
2728
expected_num_devices = handle_return(runtime.cudaGetDeviceCount())
2829
assert num_devices == expected_num_devices, "Number of devices does not match expected value"
2930

3031
def test_devices():
31-
devices = system.devices
32+
devices = System.devices
3233
expected_num_devices = handle_return(runtime.cudaGetDeviceCount())
3334
expected_devices = tuple(Device(device_id) for device_id in range(expected_num_devices))
3435
assert len(devices) == len(expected_devices), "Number of devices does not match expected value"

0 commit comments

Comments
 (0)