Skip to content

Commit b1d9e1f

Browse files
authored
Doc improvements (#232)
* Some more improvements to the Python API documentation. * Restructure how various module members are displayed, now broken into Classes, Exceptions, Functions * Include `undoc-members` and `inherited-members` * More fixes to docstring errors. Document exception classes in sycl_core. * Change the dpctl's module level docstring.
1 parent e1aef83 commit b1d9e1f

File tree

9 files changed

+178
-64
lines changed

9 files changed

+178
-64
lines changed

docs/dpCtl.dptensor_api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dpCtl dptensor Python API
66

77
.. automodule:: dpctl.dptensor
88
:members:
9+
:undoc-members:

docs/dpCtl.memory_api.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@ dpCtl Memory Python API
55
#######################
66

77
.. automodule:: dpctl.memory
8+
9+
Classes
10+
-------
11+
12+
.. autoclass:: dpctl.memory.MemoryUSMDevice
813
:members:
14+
:inherited-members:
15+
:undoc-members:
916

10-
....
17+
.. autoclass:: dpctl.memory.MemoryUSMHost
18+
:members:
19+
:inherited-members:
20+
:undoc-members:
21+
22+
.. autoclass:: dpctl.memory.MemoryUSMShared
23+
:members:
24+
:inherited-members:
25+
:undoc-members:
1126

12-
**Comparing dpctl.memory to Rapids Memory Manager (RMM)**
27+
Comparison with Rapids Memory Manager (RMM)
28+
-------------------------------------------
1329

1430
RMM implements DeviceBuffer which is Cython native class wrapping around something similar to ``std::vector<unsigned char, custom_cuda_allocator (calls resource manager)>`` which is called device_buffer.
1531

docs/dpCtl.program_api.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,25 @@ dpCtl Program Python API
55
########################
66

77
.. automodule:: dpctl.program
8+
9+
Classes
10+
-------
11+
12+
.. autoclass:: dpctl.program.SyclKernel
13+
:members:
14+
:undoc-members:
15+
16+
.. autoclass:: dpctl.program.SyclProgram
817
:members:
18+
:undoc-members:
19+
20+
Exceptions
21+
----------
22+
23+
.. autoexception:: dpctl.program.SyclProgramCompilationError
24+
25+
Functions
26+
---------
27+
28+
.. autofunction:: create_program_from_source
29+
.. autofunction:: create_program_from_spirv

docs/dpCtl_api.rst

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,58 @@ dpCtl Python API
55
################
66

77
.. automodule:: dpctl
8-
:members:
8+
9+
Classes
10+
-------
11+
12+
.. autoclass:: dpctl.SyclContext
13+
:members:
14+
:undoc-members:
15+
16+
.. autoclass:: dpctl.SyclDevice
17+
:members:
18+
:undoc-members:
19+
20+
.. autoclass:: dpctl.SyclEvent
21+
:members:
22+
:undoc-members:
23+
24+
.. autoclass:: dpctl.SyclQueue
25+
:members:
26+
:undoc-members:
27+
28+
Enumerations
29+
------------
30+
31+
.. autoclass:: dpctl.backend_type
32+
:members:
33+
34+
.. autoclass:: dpctl.device_type
35+
:members:
36+
37+
Exceptions
38+
----------
39+
40+
.. autoexception:: dpctl.SyclKernelInvalidRangeError
41+
.. autoexception:: dpctl.SyclKernelSubmitError
42+
.. autoexception:: dpctl.SyclQueueCreationError
43+
.. autoexception:: dpctl.UnsupportedBackendError
44+
.. autoexception:: dpctl.UnsupportedDeviceError
45+
46+
Functions
47+
---------
48+
49+
.. autofunction:: device_context
50+
.. autofunction:: dump
51+
.. autofunction:: get_current_backend
52+
.. autofunction:: get_current_device_type
53+
.. autofunction:: get_current_queue
54+
.. autofunction:: get_include
55+
.. autofunction:: get_num_activated_queues
56+
.. autofunction:: get_num_platforms
57+
.. autofunction:: get_num_queues
58+
.. autofunction:: has_cpu_queues
59+
.. autofunction:: has_gpu_queues
60+
.. autofunction:: has_sycl_platforms
61+
.. autofunction:: is_in_device_context
62+
.. autofunction:: set_default_queue

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ Indices and tables
2222
:maxdepth: 3
2323
:caption: Contents:
2424

25-
self
2625
toc_pyapi
2726
api/dpCtl-CAPI_root

docs/toc_pyapi.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ Python API
55
:maxdepth: 1
66

77
dpctl - SYCL runtime wrapper classes and queue manager <dpCtl_api>
8-
dpctl.memory - USM memory manager <dpCtl.memory_api>
98
dpctl.dptensor - Data-parallel tensor containers <dpCtl.dptensor_api>
9+
dpctl.memory - USM memory manager <dpCtl.memory_api>
1010
dpctl.program - Program manager <dpCtl.program_api>

dpctl/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030
3131
* A SYCL queue manager exposed directly inside the top-level `dpctl`
3232
module.
33-
* A USM memory manager (`dpctl.memory`) that provides Python objects
34-
implementing the Python buffer protocol using USM shared and USM host
35-
allocators. The memory manager also exposes various utility functions
36-
to wrap SYCL's USM allocators, deallocators, `memcpy` functions, *etc.*
33+
* Python wrapper classes for the main SYCL runtime classes mentioned in
34+
Section 4.6 of SYCL provisional 2020 spec (https://bit.ly/3asQx07).
3735
"""
3836
__author__ = "Intel Corp."
3937

dpctl/_sycl_core.pyx

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ __all__ = [
5252
"SyclContext",
5353
"SyclDevice",
5454
"SyclEvent",
55-
"SyclQueue"
55+
"SyclQueue",
56+
"SyclKernelInvalidRangeError",
57+
"SyclKernelSubmitError",
58+
"SyclQueueCreationError",
59+
"UnsupportedBackendError",
60+
"UnsupportedDeviceError",
5661
]
5762

5863
_logger = logging.getLogger(__name__)
@@ -65,10 +70,10 @@ class device_type(Enum):
6570
================== ============
6671
Device type Enum value
6772
================== ============
68-
GPU 1
69-
CPU 2
70-
Accelerator 3
71-
Host 4
73+
gpu 1
74+
cpu 2
75+
accelerator 3
76+
host_device 4
7277
================== ============
7378
7479
"""
@@ -84,10 +89,10 @@ class backend_type(Enum):
8489
================== ============
8590
Name of backend Enum value
8691
================== ============
87-
OpenCL 1
88-
Level Zero 2
89-
Cuda 3
90-
Host 4
92+
opencl 1
93+
level_zero 2
94+
cuda 3
95+
host 4
9196
================== ============
9297
9398
"""
@@ -96,38 +101,50 @@ class backend_type(Enum):
96101
cuda = auto()
97102
host = auto()
98103

99-
cdef class UnsupportedBackendError (Exception):
100-
"""This exception is raised when a device type other than CPU or GPU is
101-
encountered.
104+
cdef class UnsupportedBackendError(Exception):
105+
"""
106+
An UnsupportedBackendError exception is raised when a backend value
107+
is other than `backend_type.opencl` or `backend_type.level_zero` is
108+
encountered. All other backends are currently not supported.
109+
102110
"""
103111
pass
104112

105-
cdef class UnsupportedDeviceError (Exception):
106-
"""This exception is raised when a device type other than CPU or GPU is
107-
encountered.
113+
cdef class UnsupportedDeviceError(Exception):
114+
"""
115+
An UnsupportedDeviceError exception is raised when a device type value
116+
other than `device_type.cpu` or `device_type.gpu` is encountered.
117+
108118
"""
109119
pass
110120

111-
cdef class SyclKernelSubmitError (Exception):
112-
"""This exception is raised when a SYCL program could not be built from
113-
either a SPIR-V binary file or a string source.
121+
cdef class SyclKernelSubmitError(Exception):
122+
"""
123+
A SyclKernelSubmitError exception is raised when the provided
124+
:class:`.SyclKernel` could not be submitted to the :class:`.SyclQueue`.
125+
114126
"""
115127
pass
116128

117-
cdef class SyclKernelInvalidRangeError (Exception):
118-
"""This exception is raised when a range that has more than three
119-
dimensions or less than one dimension.
129+
cdef class SyclKernelInvalidRangeError(Exception):
130+
"""
131+
A SyclKernelInvalidRangeError is raised when the provided range has less
132+
than one or more than three dimensions.
120133
"""
121134
pass
122135

123-
cdef class SyclQueueCreationError (Exception):
124-
"""This exception is raised when a range that has more than three
125-
dimensions or less than one dimension.
136+
cdef class SyclQueueCreationError(Exception):
137+
"""
138+
A SyclQueueCreationError exception is raised when a :class:`.SyclQueue`
139+
could not be created. :class:`.SyclQueue` creation can fail if the filter
140+
string is invalid, or the backend or device type values are not supported.
141+
126142
"""
127143
pass
128144

129145
cdef class SyclContext:
130-
146+
""" Python wrapper class for cl::sycl::context.
147+
"""
131148
@staticmethod
132149
cdef SyclContext _create (DPCTLSyclContextRef ctxt):
133150
cdef SyclContext ret = SyclContext.__new__(SyclContext)
@@ -147,17 +164,17 @@ cdef class SyclContext:
147164
return self._ctxt_ref
148165

149166
def addressof_ref (self):
150-
"""Returns the address of the DPCTLSyclContextRef pointer as a
151-
long.
167+
"""
168+
Returns the address of the DPCTLSyclContextRef pointer as a size_t.
152169
153170
Returns:
154171
The address of the DPCTLSyclContextRef object used to create this
155-
SyclContext cast to a long.
172+
SyclContext cast to a size_t.
156173
"""
157174
return int(<size_t>self._ctx_ref)
158175

159176
cdef class SyclDevice:
160-
""" Wrapper class for a Sycl Device
177+
""" Python wrapper class for cl::sycl::device.
161178
"""
162179

163180
@staticmethod
@@ -274,17 +291,17 @@ cdef class SyclDevice:
274291
return self._device_ref
275292

276293
def addressof_ref (self):
277-
"""Returns the address of the DPCTLSyclDeviceRef pointer as a
278-
long.
294+
"""
295+
Returns the address of the DPCTLSyclDeviceRef pointer as a size_t.
279296
280297
Returns:
281298
The address of the DPCTLSyclDeviceRef object used to create this
282-
SyclDevice cast to a long.
299+
SyclDevice cast to a size_t.
283300
"""
284301
return int(<size_t>self._device_ref)
285302

286303
cdef class SyclEvent:
287-
""" Wrapper class for a Sycl Event
304+
""" Python wrapper class for cl::sycl::event.
288305
"""
289306

290307
@staticmethod
@@ -308,18 +325,18 @@ cdef class SyclEvent:
308325

309326
def addressof_ref (self):
310327
""" Returns the address of the C API DPCTLSyclEventRef pointer as
311-
a long.
328+
a size_t.
312329
313330
Returns:
314331
The address of the DPCTLSyclEventRef object used to create this
315-
SyclEvent cast to a long.
332+
SyclEvent cast to a size_t.
316333
"""
317334
return int(<size_t>self._event_ref)
318335

319336
import ctypes
320337

321338
cdef class SyclQueue:
322-
""" Wrapper class for a Sycl queue.
339+
""" Python wrapper class for cl::sycl::queue.
323340
"""
324341

325342
@staticmethod
@@ -464,11 +481,12 @@ cdef class SyclQueue:
464481
return self._queue_ref
465482

466483
def addressof_ref (self):
467-
""" Returns the address of the C API DPCTLSyclQueueRef pointer as a long.
484+
"""
485+
Returns the address of the C API DPCTLSyclQueueRef pointer as a size_t.
468486
469487
Returns:
470488
The address of the DPCTLSyclQueueRef object used to create this
471-
SyclQueue cast to a long.
489+
SyclQueue cast to a size_t.
472490
"""
473491
return int(<size_t>self._queue_ref)
474492

@@ -618,7 +636,7 @@ cdef class SyclQueue:
618636

619637

620638
cdef class _SyclRTManager:
621-
""" Wrapper for the C API's sycl queue manager interface.
639+
""" Provides a wrapper for dpCtl's SYCL queue manager interface.
622640
"""
623641
cdef dict _backend_str_ty_dict
624642
cdef dict _device_str_ty_dict
@@ -1010,7 +1028,7 @@ from contextlib import contextmanager
10101028
@contextmanager
10111029
def device_context(str queue_str="opencl:gpu:0"):
10121030
"""
1013-
Yeilds a SYCL queue corresponding to the input filter string.
1031+
Yields a SYCL queue corresponding to the input filter string.
10141032
10151033
This context manager "activates", *i.e.*, sets as the currently usable
10161034
queue, the SYCL queue defined by the "backend:device type:device id" tuple.
@@ -1025,7 +1043,8 @@ def device_context(str queue_str="opencl:gpu:0"):
10251043
"backend:device-type:device-id", defaults to "opencl:gpu:0".
10261044
10271045
Yields:
1028-
SyclQueue: A SYCL queue corresponding to the specified filter string.
1046+
:class:`.SyclQueue`: A SYCL queue corresponding to the specified \
1047+
filter string.
10291048
10301049
Raises:
10311050
ValueError: If the filter string is malformed.

0 commit comments

Comments
 (0)