Skip to content

Commit f3e7469

Browse files
committed
Move init doc to class with a cleanup
1 parent cc3b2fd commit f3e7469

File tree

7 files changed

+72
-94
lines changed

7 files changed

+72
-94
lines changed

Diff for: cuda_core/cuda/core/experimental/_device.py

+14-17
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
class Device:
22-
"""Represents a GPU and acts as an entry point for cuda.core features.
22+
"""Represent a GPU and act as an entry point for cuda.core features.
2323
2424
This is a singleton object that helps ensure interoperability
2525
across multiple libraries imported in the process to both see
@@ -30,26 +30,23 @@ class Device:
3030
resource created through this device, will continue to refer to
3131
this device's context.
3232
33-
"""
34-
__slots__ = ("_id", "_mr", "_has_inited")
35-
36-
def __new__(cls, device_id=None):
37-
"""Create and return a singleton :obj:`Device` object.
33+
Newly returend :obj:`Device` object are is a thread-local singleton
34+
for a specified device.
3835
39-
Creates and returns a thread-local singleton :obj:`Device` object
40-
corresponding to a specific device.
36+
Note
37+
----
38+
Will not initialize the GPU.
4139
42-
Note
43-
----
44-
Will not initialize the GPU.
40+
Parameters
41+
----------
42+
device_id : int, optional
43+
Device ordinal to return a :obj:`Device` object for.
44+
Default value of `None` return the currently used device.
4545
46-
Parameters
47-
----------
48-
device_id : int, optional
49-
Device ordinal to return a :obj:`Device` object for.
50-
Default value of `None` return the currently used device.
46+
"""
47+
__slots__ = ("_id", "_mr", "_has_inited")
5148

52-
"""
49+
def __new__(cls, device_id=None):
5350
# important: creating a Device instance does not initialize the GPU!
5451
if device_id is None:
5552
device_id = handle_return(cudart.cudaGetDevice())

Diff for: cuda_core/cuda/core/experimental/_event.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class EventOptions:
3636

3737

3838
class Event:
39-
"""Represents a record of a specific point of execution within a CUDA stream.
39+
"""Represent a record at a specific point of execution within a CUDA stream.
4040
4141
Applications can asynchronously record events at any point in
4242
the program. An event keeps a record of all previous work within
@@ -46,15 +46,13 @@ class Event:
4646
of work up to event's record, and help establish dependencies
4747
between GPU work submissions.
4848
49+
Directly creating an :obj:`Event` is not supported due to ambiguity,
50+
and they should instead be created through a :obj:`Stream` object.
51+
4952
"""
5053
__slots__ = ("_handle", "_timing_disabled", "_busy_waited")
5154

5255
def __init__(self):
53-
"""Unsupported function due to ambiguity.
54-
55-
New events should instead be created through a :obj:`Stream` object.
56-
57-
"""
5856
self._handle = None
5957
raise NotImplementedError(
6058
"directly creating an Event object can be ambiguous. Please call "

Diff for: cuda_core/cuda/core/experimental/_launcher.py

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def launch(kernel, config, *kernel_args):
110110
111111
Parameters
112112
----------
113+
kernel : :obj:`Kernel`
114+
Kernel to launch.
113115
config : Any
114116
Launch configurations inline with options provided by
115117
:obj:`LaunchConfig` dataclass.

Diff for: cuda_core/cuda/core/experimental/_memory.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
class Buffer:
25-
"""Represents a handle to allocated memory.
25+
"""Represent a handle to allocated memory.
2626
2727
This generic object provides a unified representation for how
2828
different memory resources are to give access to their memory
@@ -32,24 +32,21 @@ class Buffer:
3232
establishing both the DLPack and the Python-level buffer
3333
protocols.
3434
35+
Parameters
36+
----------
37+
ptr : Any
38+
Allocated buffer handle object
39+
size : Any
40+
Memory size of the buffer
41+
mr : :obj:`MemoryResource`, optional
42+
Memory resource associated with the buffer
43+
3544
"""
3645

3746
# TODO: handle ownership? (_mr could be None)
3847
__slots__ = ("_ptr", "_size", "_mr",)
3948

4049
def __init__(self, ptr, size, mr: MemoryResource=None):
41-
"""Initialize a new buffer object.
42-
43-
Parameters
44-
----------
45-
ptr : Any
46-
Allocated buffer handle object
47-
size : Any
48-
Memory size of the buffer
49-
mr : :obj:`MemoryResource`, optional
50-
Memory resource associated with the buffer
51-
52-
"""
5350
self._ptr = ptr
5451
self._size = size
5552
self._mr = mr

Diff for: cuda_core/cuda/core/experimental/_module.py

+28-34
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ def _lazy_init():
4646

4747

4848
class Kernel:
49-
"""Represents a compiled kernel that had been loaded onto the device.
49+
"""Represent a compiled kernel that had been loaded onto the device.
5050
5151
Kernel instances can execution when passed directly into a
5252
launch function.
5353
54+
Directly creating a :obj:`Kernel` is not supported, and they
55+
should instead be created through a :obj:`ObjectCode` object.
56+
5457
"""
5558

5659
__slots__ = ("_handle", "_module",)
5760

5861
def __init__(self):
59-
"""Unsupported function whose creation is intended through an :obj:`ObjectCode` object."""
6062
raise NotImplementedError("directly constructing a Kernel instance is not supported")
6163

6264
@staticmethod
@@ -72,49 +74,41 @@ def _from_obj(obj, mod):
7274

7375

7476
class ObjectCode:
75-
"""Represents the compiled program loaded onto the device.
77+
"""Represent a compiled program that was loaded onto the device.
7678
7779
This object provides a unified interface for different types of
7880
compiled programs that are loaded onto the device.
7981
82+
Loads the module library with specified module code and JIT options.
83+
84+
Note
85+
----
86+
Usage under CUDA 11.x will only load to the current device
87+
context.
88+
89+
Parameters
90+
----------
91+
module : Union[bytes, str]
92+
Either a bytes object containing the module to load, or
93+
a file path string containing that module for loading.
94+
code_type : Any
95+
String of the compiled type.
96+
Supported options are "ptx", "cubin" and "fatbin".
97+
jit_options : Optional
98+
Mapping of JIT options to use during module loading.
99+
(Default to no options)
100+
symbol_mapping : Optional
101+
Keyword argument dictionary specifying how symbol names
102+
should be mapped before trying to retrieve them.
103+
(Default to no mappings)
104+
80105
"""
81106

82107
__slots__ = ("_handle", "_code_type", "_module", "_loader", "_sym_map")
83108
_supported_code_type = ("cubin", "ptx", "fatbin")
84109

85110
def __init__(self, module, code_type, jit_options=None, *,
86111
symbol_mapping=None):
87-
"""Create and return a compiled program as an instance of an :obj:`ObjectCode`.
88-
89-
Loads the module library with specified module code and JIT options.
90-
91-
Note
92-
----
93-
Usage under CUDA 11.x will only load to the current device
94-
context.
95-
96-
Parameters
97-
----------
98-
module : Union[bytes, str]
99-
Either a bytes object containing the module to load, or
100-
a file path string containing that module for loading.
101-
code_type : Any
102-
String of the compiled type.
103-
Supported options are "ptx", "cubin" and "fatbin".
104-
jit_options : Optional
105-
Mapping of JIT options to use during module loading.
106-
(Default to no options)
107-
symbol_mapping : Optional
108-
Keyword argument dictionary specifying how symbol names
109-
should be mapped before trying to retrieve them.
110-
(Default to no mappings)
111-
112-
Returns
113-
-------
114-
:obj:`ObjectCode`
115-
Newly created :obj:`ObjectCode`.
116-
117-
"""
118112
if code_type not in self._supported_code_type:
119113
raise ValueError
120114
_lazy_init()

Diff for: cuda_core/cuda/core/experimental/_program.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,26 @@
88

99

1010
class Program:
11-
"""Represents the compilation machinery for processing programs into :obj:`ObjectCode`.
11+
"""Represent a compilation machinery to process programs into :obj:`ObjectCode`.
1212
1313
This object provides a unified interface to multiple underlying
1414
compiler libraries. Compilation support is enabled for a wide
1515
range of code types and compilation types.
1616
17+
Parameters
18+
----------
19+
code : Any
20+
String of the CUDA Runtime Compilation program.
21+
code_type : Any
22+
String of the code type. Only "c++" is currently supported.
23+
1724
"""
1825

1926
__slots__ = ("_handle", "_backend", )
2027
_supported_code_type = ("c++", )
2128
_supported_target_type = ("ptx", "cubin", "ltoir", )
2229

2330
def __init__(self, code, code_type):
24-
"""Create an instance of a :obj:`Program` object.
25-
26-
Parameters
27-
----------
28-
code : Any
29-
String of the CUDA Runtime Compilation program.
30-
code_type : Any
31-
String of the code type. Only "c++" is currently supported.
32-
33-
Returns
34-
-------
35-
:obj:`Program`
36-
Newly created program object.
37-
38-
"""
3931
self._handle = None
4032
if code_type not in self._supported_code_type:
4133
raise NotImplementedError

Diff for: cuda_core/cuda/core/experimental/_stream.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class StreamOptions:
3636

3737

3838
class Stream:
39-
"""Represents a queue of GPU operations that are executed in a specific order.
39+
"""Represent a queue of GPU operations that are executed in a specific order.
4040
4141
Applications use streams to control the order of execution for
4242
GPU work. Work within a single stream are executed sequentially.
@@ -46,19 +46,17 @@ class Stream:
4646
Advanced users can utilize default streams for enforce complex
4747
implicit synchronization behaviors.
4848
49+
Directly creating a :obj:`Stream` is not supported due to ambiguity.
50+
New streams should instead be created through a :obj:`Device`
51+
object, or created directly through using an existing handle
52+
using Stream.from_handle().
53+
4954
"""
5055

5156
__slots__ = ("_handle", "_nonblocking", "_priority", "_owner", "_builtin",
5257
"_device_id", "_ctx_handle")
5358

5459
def __init__(self):
55-
"""Unsupported function due to ambiguity.
56-
57-
New streams should instead be created through a :obj:`Device`
58-
object, or created directly through using an existing handle
59-
using Stream.from_handle()
60-
61-
"""
6260
# minimal requirements for the destructor
6361
self._handle = None
6462
self._owner = None

0 commit comments

Comments
 (0)