Skip to content

Commit 86cde46

Browse files
SyclQueue/SyclContext docstring changes
1 parent 77c81e2 commit 86cde46

File tree

2 files changed

+102
-20
lines changed

2 files changed

+102
-20
lines changed

dpctl/_sycl_context.pyx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ cdef class SyclContext(_SyclContext):
9393
9494
import dpctl
9595
96-
# Create a default SyclContext
96+
# Create SyclContext for a gpu device
9797
ctx = dpctl.SyclContext("gpu")
9898
d = ctx.get_devices()[0]
9999
assert(d.is_gpu)
@@ -125,20 +125,22 @@ cdef class SyclContext(_SyclContext):
125125
# Create a CPU device using the opencl driver
126126
cpu_d = dpctl.SyclDevice("opencl:cpu")
127127
# Partition the CPU device into sub-devices, each with two cores.
128-
sub_devices = create_sub_devices(partition=2)
128+
sub_devices = cpu_d.create_sub_devices(partition=2)
129129
# Create a context common to all the sub-devices.
130130
ctx = dpctl.SyclContext(sub_devices)
131131
assert(len(ctx.get_devices) == len(sub_devices))
132132
133-
- Invoking the constuctor with a named ``PyCapsule`` with the name
134-
**SyclContextRef** that carries a pointer to a ``sycl::context``
135-
object.
133+
- Invoking the constuctor with a named ``PyCapsule`` with name
134+
**"SyclContextRef"** that carries a pointer to a ``sycl::context``
135+
object. The capsule will be renamed upon successful consumption
136+
to ensure one-time use. A new named capsule can be constructed by
137+
using :func:`dpctl.SyclContext._get_capsule` method.
136138
137139
Args:
138140
arg (optional): Defaults to None.
139-
The argument can be a :class:`dpctl.SyclDevice` instance,
140-
a :obj:`list` of :class:`dpctl.SyclDevice` objects, or a named
141-
``PyCapsule`` called **SyclContextRef**.
141+
The argument can be a selector string, a :class:`dpctl.SyclDevice`
142+
instance, a :obj:`list` of :class:`dpctl.SyclDevice` objects, or a
143+
named ``PyCapsule`` called **"SyclContextRef"**.
142144
143145
Raises:
144146
MemoryError: If the constructor could not allocate necessary
@@ -228,7 +230,7 @@ cdef class SyclContext(_SyclContext):
228230

229231
cdef int _init_context_from_capsule(self, object cap):
230232
"""
231-
For named ``PyCapsule`` with name **SyclContextRef**, which carries
233+
For named ``PyCapsule`` with name **"SyclContextRef"**, which carries
232234
pointer to ``sycl::context`` object, interpreted as
233235
``DPCTLSyclContextRef``, creates corresponding
234236
:class:`dpctl.SyclContext`.

dpctl/_sycl_queue.pyx

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,97 @@ cdef class _SyclQueue:
158158

159159

160160
cdef class SyclQueue(_SyclQueue):
161-
""" Python class representing cl::sycl::queue.
162-
163-
SyclQueue(*, /, property=None)
164-
create SyclQueue from default selector
165-
SyclQueue(filter_string, *, /, propery=None)
166-
create SyclQueue from filter selector string
167-
SyclQueue(SyclDevice, *, /, property=None)
168-
create SyclQueue from give SyclDevice automatically
169-
finding/creating SyclContext.
170-
SyclQueue(SyclContext, SyclDevice, *, /, property=None)
171-
create SyclQueue from give SyclContext, SyclDevice
161+
"""
162+
Python class representing ``cl::sycl::queue``. There are multiple
163+
ways to create a :class:`dpctl.SyclQueue` object:
164+
165+
- Invoking the constructor with no arguments creates a context using
166+
the default selector.
167+
168+
:Example:
169+
.. code-block:: python
170+
171+
import dpctl
172+
173+
# Create a default SyclQueue
174+
q = dpctl.SyclQueue()
175+
print(q.sycl_device)
176+
177+
- Invoking the constructor with specific filter selector string that
178+
creates a queue for the device corresponding to the filter string.
179+
180+
:Example:
181+
.. code-block:: python
182+
183+
import dpctl
184+
185+
# Create in-order SyclQueue for either gpu, or cpu device
186+
q = dpctl.SyclQueue("gpu,cpu", property="in_order")
187+
print([q.sycl_device.is_gpu, q.sycl_device.is_cpu])
188+
189+
- Invoking the constructor with a :class:`dpctl.SyclDevice` object
190+
creates a queue for that device, automatically finding/creating
191+
a :class:`dpctl.SyclContext` for the given device.
192+
193+
:Example:
194+
.. code-block:: python
195+
196+
import dpctl
197+
198+
d = dpctl.SyclDevice("gpu")
199+
q = dpctl.SyclQueue(d)
200+
ctx = q.sycl_context
201+
print(q.sycl_device == d)
202+
print(any([ d == ctx_d for ctx_d in ctx.get_devices()]))
203+
204+
- Invoking the constructor with a :class:`dpctl.SyclContext` and a
205+
:class:`dpctl.SyclDevice` creates a queue for given context and
206+
device.
207+
208+
:Example:
209+
.. code-block:: python
210+
211+
import dpctl
212+
213+
# Create a CPU device using the opencl driver
214+
cpu_d = dpctl.SyclDevice("opencl:cpu")
215+
# Partition the CPU device into sub-devices, each with two cores.
216+
sub_devices = cpu_d.create_sub_devices(partition=2)
217+
# Create a context common to all the sub-devices.
218+
ctx = dpctl.SyclContext(sub_devices)
219+
# create a queue for each sub-device using the common context
220+
queues = [dpctl.SyclQueue(ctx, sub_d) for sub_d in sub_devices]
221+
222+
- Invoking the constuctor with a named ``PyCapsule`` with the name
223+
**"SyclQueueRef"** that carries a pointer to a ``sycl::queue``
224+
object. The capsule will be renamed upon successful consumption
225+
to ensure one-time use. A new named capsule can be constructed by
226+
using :func:`dpctl.SyclQueue._get_capsule` method.
227+
228+
Args:
229+
ctx (:class:`dpctl.SyclContext`, optional): Sycl context to create
230+
:class:`dpctl.SyclQueue` from. If not specified, a single-device
231+
context will be created from the specified device.
232+
dev (str, :class:`dpctl.SyclDevice`, capsule, optional): Sycl device
233+
to create :class:`dpctl.SyclQueue` from. If not specified, sycl
234+
device selected by ``cl::sycl::default_selector`` is used.
235+
The argument must be explicitly specified if `ctxt` argument is
236+
provided.
237+
238+
If `dev` is a named ``PyCapsule`` called **"SyclQueueRef"** and
239+
`ctxt` is not specified, :class:`dpctl.SyclQueue` instance is
240+
created from foreign `sycl::queue` object referenced by the
241+
capsule.
242+
property (str, tuple(str), list(str), optional): Defaults to None.
243+
The argument can be either "default", "in_order",
244+
"enable_profiling", or a tuple containing these.
245+
246+
Raises:
247+
SyclQueueCreationError: If the :class:`dpctl.SyclQueue` object creation failed.
248+
TypeError: In case of incorrect arguments given to constructors, unexpected types
249+
of input arguments, or in the case the input capsule contained a null
250+
pointer or could not be renamed.
251+
172252
"""
173253
def __cinit__(self, *args, **kwargs):
174254
cdef int len_args

0 commit comments

Comments
 (0)