Skip to content

Commit f658e4b

Browse files
authored
Documentation polishing (#224)
* Improvements to docs. * Small fixes. * Minor formatting fixes. * Add dpctl.program to API doc. * Few more edits...
1 parent d157ee0 commit f658e4b

File tree

10 files changed

+132
-51
lines changed

10 files changed

+132
-51
lines changed

docs/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ if (GIT_FOUND)
2323
OUTPUT_VARIABLE CURRENT_RELEASE
2424
OUTPUT_STRIP_TRAILING_WHITESPACE
2525
)
26+
set(CURRENT_COMMIT "")
27+
execute_process(
28+
COMMAND ${GIT_EXECUTABLE} describe --tags
29+
RESULT_VARIABLE result
30+
OUTPUT_VARIABLE CURRENT_COMMIT
31+
OUTPUT_STRIP_TRAILING_WHITESPACE
32+
)
33+
if (NOT "${CURRENT_RELEASE}" STREQUAL "${CURRENT_COMMIT}")
34+
set(CURRENT_RELEASE "master")
35+
endif ()
2636
endif (GIT_FOUND)
2737

2838
set(DOXYGEN_INPUT_DIR ../dpctl-capi)

docs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ What?
44
Generator scripts for dpCtl API documentation. To run these scripts, follow
55
the following steps:
66

7-
`mkdir build`
8-
`cd build`
9-
`cmake -DDPCTL_DOCGEN_PREFIX=<WHERE_YOU_WANT_DOCS_TO_BE_GENERATED>`
10-
`make Sphinx`
7+
`mkdir build` <br/>
8+
`cd build` <br/>
9+
`cmake -DDPCTL_DOCGEN_PREFIX=<WHERE_YOU_WANT_DOCS_TO_BE_GENERATED>` <br/>
10+
`make Sphinx` <br/>
1111

1212
The `DPCTL_DOCGEN_PREFIX` flag is optional and can be omitted to generate the
1313
documents in the current source directory in a sub-directory called

docs/dpCtl.dptensor_api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. _dpCtl.dptensor_api:
2+
3+
#########################
4+
dpCtl dptensor Python API
5+
#########################
6+
7+
.. automodule:: dpctl.dptensor
8+
:members:

docs/dpCtl.program_api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. _dpCtl.program_api:
2+
3+
########################
4+
dpCtl Program Python API
5+
########################
6+
7+
.. automodule:: dpctl.program
8+
:members:

docs/index.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ Indices and tables
1919
* :ref:`search`
2020

2121
.. toctree::
22-
:maxdepth: 2
22+
:maxdepth: 3
2323
:caption: Contents:
2424

2525
self
26-
dpCtl Python API <dpCtl_api>
27-
dpctl.memory Python API <dpCtl.memory_api>
26+
toc_pyapi
2827
api/dpCtl-CAPI_root

docs/toc_pyapi.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Python API
2+
================
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
dpctl - SYCL runtime wrapper classes and queue manager <dpCtl_api>
8+
dpctl.memory - USM memory manager <dpCtl.memory_api>
9+
dpctl.dptensor - Data-parallel tensor containers <dpCtl.dptensor_api>
10+
dpctl.program - Program manager <dpCtl.program_api>

dpctl/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# ===---------------- __init__.py - dpctl module -------*- Cython -*--------===#
2-
#
1+
# ===-----------------------------------------------------------------------===#
32
# Data Parallel Control (dpCtl)
43
#
54
# Copyright 2020 Intel Corporation
@@ -17,11 +16,7 @@
1716
# limitations under the License.
1817
#
1918
# ===-----------------------------------------------------------------------===#
20-
#
21-
# \file
22-
# The top-level dpctl module.
23-
#
24-
# ===-----------------------------------------------------------------------===#
19+
2520
"""
2621
**Data Parallel Control (dpCtl)**
2722
@@ -31,8 +26,14 @@
3126
a common runtime to manage specific SYCL resources, such as devices
3227
and USM memory, for SYCL-based Python packages and extension modules.
3328
34-
Currently, dpCtl has two main features: a global SYCL queue manager
35-
and a USM memory manager.
29+
The main features presently provided by dpCtl are:
30+
31+
* A SYCL queue manager exposed directly inside the top-level `dpctl`
32+
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.*
3637
"""
3738
__author__ = "Intel Corp."
3839

dpctl/_sycl_core.pyx

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ cdef class SyclQueue:
303303
"""
304304

305305
@staticmethod
306-
cdef SyclQueue _create (DPCTLSyclQueueRef qref):
306+
cdef SyclQueue _create(DPCTLSyclQueueRef qref):
307307
if qref is NULL:
308308
raise SyclQueueCreationError("Queue creation failed.")
309309
cdef SyclQueue ret = SyclQueue.__new__(SyclQueue)
@@ -605,7 +605,7 @@ cdef class _SyclRTManager:
605605
cdef dict _backend_enum_ty_dict
606606
cdef dict _device_enum_ty_dict
607607

608-
def __cinit__ (self):
608+
def __cinit__(self):
609609

610610
self._backend_str_ty_dict = {
611611
"opencl" : _backend_type._OPENCL,
@@ -627,7 +627,7 @@ cdef class _SyclRTManager:
627627
device_type.gpu : _device_type._GPU,
628628
}
629629

630-
def _set_as_current_queue (self, backend_ty, device_ty, device_id):
630+
def _set_as_current_queue(self, backend_ty, device_ty, device_id):
631631
cdef DPCTLSyclQueueRef queue_ref
632632

633633
try :
@@ -642,45 +642,47 @@ cdef class _SyclRTManager:
642642
raise UnsupportedBackendError("Backend can only be opencl or "
643643
"level-0")
644644

645-
def _remove_current_queue (self):
645+
def _remove_current_queue(self):
646646
DPCTLQueueMgr_PopQueue()
647647

648-
def dump (self):
648+
def dump(self):
649649
""" Prints information about the Runtime object.
650650
"""
651651
DPCTLPlatform_DumpInfo()
652652

653-
def print_available_backends (self):
654-
""" Prints the available backends.
653+
def print_available_backends(self):
654+
""" Prints the available SYCL backends.
655655
"""
656656
print(self._backend_str_ty_dict.keys())
657657

658-
cpdef get_current_backend (self):
659-
""" Returns the backend for the current queue as `backend_type` enum
658+
cpdef get_current_backend(self):
659+
""" Returns the backend for the current queue as a `backend_type` enum
660660
"""
661661
return self.get_current_queue().get_sycl_backend()
662662

663-
cpdef get_current_device_type (self):
664-
""" Returns current device type as `device_type` enum
663+
cpdef get_current_device_type(self):
664+
""" Returns current device type as a `device_type` enum
665665
"""
666666
return self.get_current_queue().get_sycl_device().get_device_type()
667667

668-
cpdef SyclQueue get_current_queue (self):
669-
""" Returns the activated SYCL queue as a PyCapsule.
668+
cpdef SyclQueue get_current_queue(self):
669+
""" Returns the currently activate SYCL queue as a new SyclQueue object.
670+
If there are no active queues then a SyclQueueCreationError exception is
671+
raised.
670672
"""
671673
return SyclQueue._create(DPCTLQueueMgr_GetCurrentQueue())
672674

673-
def get_num_activated_queues (self):
674-
""" Return the number of currently activated queues for this thread.
675+
def get_num_activated_queues(self):
676+
""" Returns the number of currently activated queues for this thread.
675677
"""
676678
return DPCTLQueueMgr_GetNumActivatedQueues()
677679

678-
def get_num_platforms (self):
680+
def get_num_platforms(self):
679681
""" Returns the number of available non-host SYCL platforms.
680682
"""
681683
return DPCTLPlatform_GetNumNonHostPlatforms()
682684

683-
def get_num_queues (self, backend_ty, device_ty):
685+
def get_num_queues(self, backend_ty, device_ty):
684686
cdef size_t num = 0
685687
try :
686688
beTy = self._backend_enum_ty_dict[backend_ty]
@@ -699,7 +701,7 @@ cdef class _SyclRTManager:
699701

700702
return num
701703

702-
def has_gpu_queues (self, backend_ty=backend_type.opencl):
704+
def has_gpu_queues(self, backend_ty=backend_type.opencl):
703705
cdef size_t num = 0
704706
try :
705707
beTy = self._backend_enum_ty_dict[backend_ty]
@@ -714,7 +716,7 @@ cdef class _SyclRTManager:
714716
else:
715717
return False
716718

717-
def has_cpu_queues (self, backend_ty=backend_type.opencl):
719+
def has_cpu_queues(self, backend_ty=backend_type.opencl):
718720
cdef size_t num = 0
719721
try :
720722
beTy = self._backend_enum_ty_dict[backend_ty]
@@ -729,21 +731,21 @@ cdef class _SyclRTManager:
729731
else:
730732
return False
731733

732-
def has_sycl_platforms (self):
734+
def has_sycl_platforms(self):
733735
cdef size_t num_platforms = DPCTLPlatform_GetNumNonHostPlatforms()
734736
if num_platforms:
735737
return True
736738
else:
737739
return False
738740

739-
def is_in_device_context (self):
741+
def is_in_device_context(self):
740742
cdef size_t num = DPCTLQueueMgr_GetNumActivatedQueues()
741743
if num:
742744
return True
743745
else:
744746
return False
745747

746-
def set_default_queue (self, backend_ty, device_ty, device_id):
748+
def set_default_queue(self, backend_ty, device_ty, device_id):
747749
cdef DPCTLSyclQueueRef ret
748750
try :
749751
if isinstance(backend_ty, str):
@@ -785,8 +787,17 @@ set_default_queue = _mgr.set_default_queue
785787
is_in_device_context = _mgr.is_in_device_context
786788

787789
cpdef SyclQueue get_current_queue():
788-
"""
789-
Obtain current Sycl Queue from Data Parallel Control package.
790+
""" Returns the currently activate SYCL queue as a new SyclQueue object.
791+
792+
Returns:
793+
SyclQueue: If there is a currently active SYCL queue that queue
794+
is returned wrapped in a SyclQueue object. The SyclQueue object
795+
owns a copy of the currently active SYCL queue as an opaque
796+
`DPCTLSyclQueueRef` pointer. The pointer is freed when the SyclQueue
797+
is garbage collected.
798+
799+
Raises:
800+
SyclQueueCreationError: If no currently active SYCL queue found.
790801
"""
791802
return _mgr.get_current_queue()
792803

@@ -805,7 +816,7 @@ cpdef get_current_backend():
805816
from contextlib import contextmanager
806817

807818
@contextmanager
808-
def device_context (str queue_str="opencl:gpu:0"):
819+
def device_context(str queue_str="opencl:gpu:0"):
809820
"""
810821
The SYCL queue defined by the "backend:device type:device id" tuple is
811822
set as the currently active queue, *i.e.*, a subsequent call to

dpctl/dptensor/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1+
# ===-----------------------------------------------------------------------===#
2+
# Data Parallel Control (dpCtl)
3+
#
4+
# Copyright 2020 Intel Corporation
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# ===-----------------------------------------------------------------------===#
19+
"""
20+
**Data Parallel Tensor Collection**
21+
22+
`dpctl.dptensor` is an experimental collection of tensor implementations
23+
that will implement future Python data API (https://data-apis.github.io/array-api/latest/).
24+
25+
Available tensor implementations:
26+
27+
* `numpy_usm_shared`: Provides a `numpy.ndarray` sub-class whose \
28+
underlying memory buffer is allocated with a USM shared memory allocator.
29+
30+
"""
31+
132
import dpctl.dptensor.numpy_usm_shared

dpctl/dptensor/numpy_usm_shared.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def __array_finalize__(self, obj):
190190
return
191191
# When called in new-from-template, `obj` is another instance of our own
192192
# subclass, that we might use to update the new `self` instance.
193-
# However, when called from view casting, `obj` can be an instance of any
194-
# subclass of ndarray, including our own.
193+
# However, when called from view casting, `obj` can be an instance of
194+
# any subclass of ndarray, including our own.
195195
if hasattr(obj, array_interface_property):
196196
return
197197
for ext_checker in ndarray.external_usm_checkers:
@@ -204,14 +204,16 @@ def __array_finalize__(self, obj):
204204
return
205205
ob = ob.base
206206

207-
# Just raise an exception since __array_ufunc__ makes all reasonable cases not
208-
# need the code below.
207+
# Just raise an exception since __array_ufunc__ makes all
208+
# reasonable cases not need the code below.
209209
raise ValueError(
210-
"Non-USM allocated ndarray can not viewed as a USM-allocated one without a copy"
210+
"Non-USM allocated ndarray can not viewed as a USM-allocated \
211+
one without a copy"
211212
)
212213

213-
# Tell Numba to not treat this type just like a NumPy ndarray but to propagate its type.
214-
# This way it will use the custom numpy_usm_shared allocator.
214+
# Tell Numba to not treat this type just like a NumPy ndarray but to
215+
# propagate its type. This way it will use the custom numpy_usm_shared
216+
# allocator.
215217
__numba_no_subtype_ndarray__ = True
216218

217219
# Convert to a NumPy ndarray.
@@ -257,8 +259,8 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
257259
out_as_np = np.ndarray(out.shape, out.dtype, out)
258260
kwargs["out"] = out_as_np
259261
else:
260-
# If they manually gave numpy_usm_shared as out kwarg then we have to also
261-
# cast as regular NumPy ndarray to avoid recursion.
262+
# If they manually gave numpy_usm_shared as out kwarg then we
263+
# have to also cast as regular NumPy ndarray to avoid recursion.
262264
if isinstance(kwargs["out"], ndarray):
263265
out = kwargs["out"]
264266
kwargs["out"] = np.ndarray(out.shape, out.dtype, out)
@@ -282,7 +284,8 @@ def isdef(x):
282284
cname = c[0]
283285
if isdef(cname):
284286
continue
285-
# For now we do the simple thing and copy the types from NumPy module into numpy_usm_shared module.
287+
# For now we do the simple thing and copy the types from NumPy module
288+
# into numpy_usm_shared module.
286289
new_func = "%s = np.%s" % (cname, cname)
287290
try:
288291
the_code = compile(new_func, "__init__", "exec")

0 commit comments

Comments
 (0)