Skip to content

Commit 09df7ce

Browse files
committed
fix up the documentation for system
1 parent 1d137ad commit 09df7ce

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

cuda_core/cuda/core/experimental/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
from cuda.core.experimental._launcher import LaunchConfig, launch
88
from cuda.core.experimental._program import Program
99
from cuda.core.experimental._stream import Stream, StreamOptions
10-
from cuda.core.experimental._system import _system_instance as system
10+
from cuda.core.experimental._system import system

cuda_core/cuda/core/experimental/_system.py

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

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

11+
_instance = None
12+
1313
def __new__(cls):
14-
if not cls._instance:
14+
if cls._instance is None:
1515
cls._instance = super(System, cls).__new__(cls)
1616
return cls._instance
1717

1818
def __init__(self):
19-
if System._instance is not None:
20-
raise RuntimeError("System is a singleton class and should not be instantiated directly.")
19+
if hasattr(self, '_initialized') and self._initialized:
20+
return
21+
self._initialized = True
22+
# Initialize other attributes if needed
2123

2224
@property
2325
def driver_version(self) -> Tuple[int, int]:
@@ -32,8 +34,7 @@ def driver_version(self) -> Tuple[int, int]:
3234
version = handle_return(cuda.cuDriverGetVersion())
3335
major = version // 1000
3436
minor = (version % 1000) // 10
35-
self._driver_version = (major, minor)
36-
return self._driver_version
37+
return (major, minor)
3738

3839
@property
3940
def num_devices(self) -> int:
@@ -58,7 +59,9 @@ def devices(self) -> tuple:
5859
A tuple containing instances of available devices.
5960
"""
6061
total = self.num_devices
61-
self._devices = tuple(Device(device_id) for device_id in range(total))
62-
return self._devices
62+
return tuple(Device(device_id) for device_id in range(total))
6363

64-
_system_instance = System.__new__(System)
64+
system = System()
65+
system.__doc__ = """
66+
Singleton instance of the :obj:`~cuda.core.experimental._system.System` class.
67+
"""

cuda_core/docs/source/api_private.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CUDA runtime
1616
_memory.Buffer
1717
_stream.Stream
1818
_event.Event
19+
_system.System
1920

2021

2122
CUDA compilation toolchain

cuda_core/docs/source/conf.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@
1313
import sys
1414
from unittest.mock import MagicMock
1515

16-
# Add the path to your module
17-
sys.path.insert(0, os.path.abspath('../..'))
16+
# # Add the path to your module
17+
# sys.path.insert(0, os.path.abspath('../..'))
1818

19-
# Mock the cuda module and its submodules
20-
class Mock(MagicMock):
21-
@classmethod
22-
def __getattr__(cls, name):
23-
return MagicMock()
19+
# # Mock the cuda module and its submodules
20+
# class Mock(MagicMock):
21+
# @classmethod
22+
# def __getattr__(cls, name):
23+
# return MagicMock()
2424

25-
MOCK_MODULES = ['cuda.core.experimental._system']
26-
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
25+
# MOCK_MODULES = ['cuda.core.experimental._system']
26+
# sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
2727

28-
class SystemMock(MagicMock):
29-
__doc__ = "Singleton instance of :class:`cuda.core.experimental._system.System`"
28+
# class SystemMock(MagicMock):
29+
# __doc__ = "Singleton instance of :obj:`~cuda.core.experimental._system.System`"
3030

3131

32-
# Mock the System class within the _system module
33-
sys.modules['cuda.core.experimental._system'].System = SystemMock
32+
# # Mock the System class within the _system module
33+
# sys.modules['cuda.core.experimental._system'].System = SystemMock
3434

35-
# Create a specific mock for the system instance
36-
system_mock = SystemMock()
35+
# # Create a specific mock for the system instance
36+
# system_mock = SystemMock()
3737

38-
# Ensure the system instance is correctly mocked
39-
sys.modules['cuda.core.experimental._system']._system_instance = system_mock
38+
# # Ensure the system instance is correctly mocked
39+
# sys.modules['cuda.core.experimental._system']._system_instance = system_mock
4040

4141
# -- Project information -----------------------------------------------------
4242

0 commit comments

Comments
 (0)