@@ -100,68 +100,68 @@ cdef class SyclContext(_SyclContext):
100
100
101
101
There are multiple ways to create a :class:`dpctl.SyclContext` object:
102
102
103
- - Invoking the constructor with no arguments creates a context using
104
- the default selector.
103
+ - Invoking the constructor with no arguments creates a context using
104
+ the default selector.
105
105
106
- :Example:
107
- .. code-block:: python
106
+ :Example:
107
+ .. code-block:: python
108
108
109
- import dpctl
109
+ import dpctl
110
110
111
- # Create a SyclContext for default-selected device
112
- ctx = dpctl.SyclContext()
113
- print(ctx.get_devices())
111
+ # Create a SyclContext for default-selected device
112
+ ctx = dpctl.SyclContext()
113
+ print(ctx.get_devices())
114
114
115
- - Invoking the constructor with a specific filter string that creates a
116
- context for the device corresponding to the filter string.
115
+ - Invoking the constructor with a specific filter string that creates a
116
+ context for the device corresponding to the filter string.
117
117
118
- :Example:
119
- .. code-block:: python
118
+ :Example:
119
+ .. code-block:: python
120
120
121
- import dpctl
121
+ import dpctl
122
122
123
- # Create SyclContext for a gpu device
124
- ctx = dpctl.SyclContext("gpu")
125
- d = ctx.get_devices()[0]
126
- assert(d.is_gpu)
123
+ # Create SyclContext for a gpu device
124
+ ctx = dpctl.SyclContext("gpu")
125
+ d = ctx.get_devices()[0]
126
+ assert(d.is_gpu)
127
127
128
- - Invoking the constructor with a :class:`dpctl.SyclDevice` object
129
- creates a context for that device.
128
+ - Invoking the constructor with a :class:`dpctl.SyclDevice` object
129
+ creates a context for that device.
130
130
131
- :Example:
132
- .. code-block:: python
131
+ :Example:
132
+ .. code-block:: python
133
133
134
- import dpctl
134
+ import dpctl
135
135
136
- # Create a level zero gpu device
137
- d = dpctl.SyclDevice("level_zero:gpu")
138
- ctx = dpctl.SyclContext(d)
139
- d = ctx.get_devices()[0]
140
- assert(d.is_gpu)
136
+ # Create a level zero gpu device
137
+ d = dpctl.SyclDevice("level_zero:gpu")
138
+ ctx = dpctl.SyclContext(d)
139
+ d = ctx.get_devices()[0]
140
+ assert(d.is_gpu)
141
141
142
- - Invoking the constructor with a list of :class:`dpctl.SyclDevice`
143
- objects creates a common context for all the devices. This
144
- constructor call is especially useful when creation a context for
145
- multiple sub-devices.
142
+ - Invoking the constructor with a list of :class:`dpctl.SyclDevice`
143
+ objects creates a common context for all the devices. This
144
+ constructor call is especially useful when creation a context for
145
+ multiple sub-devices.
146
146
147
- :Example:
148
- .. code-block:: python
147
+ :Example:
148
+ .. code-block:: python
149
149
150
- import dpctl
150
+ import dpctl
151
151
152
- # Create a CPU device using the opencl driver
153
- cpu_d = dpctl.SyclDevice("opencl:cpu")
154
- # Partition the CPU device into sub-devices with two cores each.
155
- sub_devices = cpu_d.create_sub_devices(partition=2)
156
- # Create a context common to all the sub-devices.
157
- ctx = dpctl.SyclContext(sub_devices)
158
- assert(len(ctx.get_devices) == len(sub_devices))
159
-
160
- - Invoking the constructor with a named ``PyCapsule`` with name
161
- **"SyclContextRef"** that carries a pointer to a ``sycl::context``
162
- object. The capsule will be renamed upon successful consumption
163
- to ensure one-time use. A new named capsule can be constructed by
164
- using :func:`dpctl.SyclContext._get_capsule` method.
152
+ # Create a CPU device using the opencl driver
153
+ cpu_d = dpctl.SyclDevice("opencl:cpu")
154
+ # Partition the CPU device into sub-devices with two cores each.
155
+ sub_devices = cpu_d.create_sub_devices(partition=2)
156
+ # Create a context common to all the sub-devices.
157
+ ctx = dpctl.SyclContext(sub_devices)
158
+ assert(len(ctx.get_devices) == len(sub_devices))
159
+
160
+ - Invoking the constructor with a named ``PyCapsule`` with name
161
+ **"SyclContextRef"** that carries a pointer to a ``sycl::context``
162
+ object. The capsule will be renamed upon successful consumption
163
+ to ensure one-time use. A new named capsule can be constructed by
164
+ using :func:`dpctl.SyclContext._get_capsule` method.
165
165
166
166
Args:
167
167
arg (optional): Defaults to ``None``.
@@ -170,21 +170,24 @@ cdef class SyclContext(_SyclContext):
170
170
named ``PyCapsule`` called **"SyclContextRef"**.
171
171
172
172
Raises:
173
- MemoryError: If the constructor could not allocate necessary
174
- temporary memory.
175
- SyclContextCreationError: If the :class:`dpctl.SyclContext` object
176
- creation failed.
177
- TypeError: If the list of :class:`dpctl.SyclDevice` objects was empty,
178
- or the input capsule contained a null pointer or could not
179
- be renamed.
173
+ MemoryError:
174
+ If the constructor could not allocate necessary
175
+ temporary memory.
176
+ SyclContextCreationError:
177
+ If the :class:`.SyclContext` object creation failed.
178
+ TypeError:
179
+ If the list of :class:`dpctl.SyclDevice` objects was empty,
180
+ or the input capsule contained a null pointer or could not
181
+ be renamed.
180
182
181
183
"""
182
184
@staticmethod
183
185
cdef SyclContext _create(DPCTLSyclContextRef ctxt):
184
186
"""
185
- Calls DPCTLContext_Delete(ctxt).
187
+ Calls `` DPCTLContext_Delete(ctxt)`` .
186
188
187
- Users should pass a copy if they intend to keep the argument ctxt alive.
189
+ Users should pass a copy if they intend to keep the argument
190
+ ``ctxt`` alive.
188
191
"""
189
192
cdef _SyclContext ret = < _SyclContext> _SyclContext.__new__ (_SyclContext)
190
193
_init_helper(ret, ctxt)
@@ -335,22 +338,24 @@ cdef class SyclContext(_SyclContext):
335
338
:class:`dpctl.SyclContext` instance.
336
339
337
340
Returns:
338
- :obj:`bool`: ``True`` if the two :class:`dpctl.SyclContext` objects
339
- point to the same ``DPCTLSyclContextRef`` object, otherwise
340
- ``False``.
341
+ bool:
342
+ ``True`` if the two :class:`dpctl.SyclContext` objects
343
+ point to the same ``DPCTLSyclContextRef`` object, otherwise
344
+ ``False``.
341
345
"""
342
346
return DPCTLContext_AreEq(self ._ctxt_ref, ctxt.get_context_ref())
343
347
344
348
def __eq__ (self , other ):
345
349
"""
346
- Returns True if the :class:`dpctl.SyclContext` argument has the
350
+ Returns `` True`` if the :class:`dpctl.SyclContext` argument has the
347
351
same underlying ``DPCTLSyclContextRef`` object as this
348
352
:class:`dpctl.SyclContext` instance.
349
353
350
354
Returns:
351
- :obj:`bool`: ``True`` if the two :class:`dpctl.SyclContext` objects
352
- point to the same ``DPCTLSyclContextRef`` object, otherwise
353
- ``False``.
355
+ :obj:`bool`:
356
+ ``True`` if the two :class:`dpctl.SyclContext` objects
357
+ point to the same ``DPCTLSyclContextRef`` object, otherwise
358
+ ``False``.
354
359
"""
355
360
if isinstance (other, SyclContext):
356
361
return self .equals(< SyclContext> other)
@@ -361,6 +366,10 @@ cdef class SyclContext(_SyclContext):
361
366
"""
362
367
Returns a hash value by hashing the underlying ``sycl::context`` object.
363
368
369
+ Returns:
370
+ int:
371
+ Hash value.
372
+
364
373
"""
365
374
return DPCTLContext_Hash(self ._ctxt_ref)
366
375
@@ -373,9 +382,10 @@ cdef class SyclContext(_SyclContext):
373
382
``size_t``.
374
383
375
384
Returns:
376
- :obj:`int`: The address of the ``DPCTLSyclContextRef`` object
377
- used to create this :class:`dpctl.SyclContext` cast to a
378
- ``size_t``.
385
+ int:
386
+ The address of the ``DPCTLSyclContextRef`` object
387
+ used to create this :class:`dpctl.SyclContext` cast to a
388
+ ``size_t``.
379
389
"""
380
390
return < size_t> self ._ctxt_ref
381
391
@@ -385,12 +395,14 @@ cdef class SyclContext(_SyclContext):
385
395
:class:`dpctl.SyclContext` instance.
386
396
387
397
Returns:
388
- :obj:`list`: A :obj:`list` of :class:`dpctl.SyclDevice` objects
389
- that belong to this context.
398
+ list:
399
+ A :obj:`list` of :class:`dpctl.SyclDevice` objects
400
+ that belong to this context.
390
401
391
402
Raises:
392
- ValueError: If the ``DPCTLContext_GetDevices`` call returned
393
- ``NULL`` instead of a ``DPCTLDeviceVectorRef`` object.
403
+ ValueError:
404
+ If the ``DPCTLContext_GetDevices`` call returned
405
+ ``NULL`` instead of a ``DPCTLDeviceVectorRef`` object.
394
406
"""
395
407
cdef DPCTLDeviceVectorRef DVRef = DPCTLContext_GetDevices(
396
408
self .get_context_ref()
@@ -415,11 +427,13 @@ cdef class SyclContext(_SyclContext):
415
427
:class:`dpctl.SyclContext` instance.
416
428
417
429
Returns:
418
- :obj:`int`: Number of devices associated with the context.
430
+ int:
431
+ Number of devices associated with the context.
419
432
420
433
Raises:
421
- ValueError: If ``DPCTLContext_DeviceCount`` led to a
422
- failure.
434
+ ValueError:
435
+ If ``DPCTLContext_DeviceCount`` call led to a
436
+ failure.
423
437
"""
424
438
cdef size_t num_devs = DPCTLContext_DeviceCount(self .get_context_ref())
425
439
if num_devs:
@@ -454,8 +468,8 @@ cdef class SyclContext(_SyclContext):
454
468
print(ctx2)
455
469
456
470
Returns:
457
- :obj:` str`: A string representation of the
458
- :class:`dpctl .SyclContext` object .
471
+ str:
472
+ A string representation of this :class:`.SyclContext` instance .
459
473
460
474
"""
461
475
cdef size_t n = self .device_count
@@ -477,13 +491,15 @@ cdef class SyclContext(_SyclContext):
477
491
of scope.
478
492
479
493
Returns:
480
- :class:`pycapsule`: A capsule object storing a copy of the
481
- ``sycl::context`` pointer belonging to thus
482
- :class:`dpctl.SyclContext` instance.
494
+ :class:`pycapsule`:
495
+ A capsule object storing a copy of the
496
+ ``sycl::context`` pointer belonging to thus
497
+ :class:`dpctl.SyclContext` instance.
483
498
484
499
Raises:
485
- ValueError: If the ``DPCTLContext_Copy`` fails to copy the
486
- ``sycl::context`` pointer.
500
+ ValueError:
501
+ If the ``DPCTLContext_Copy`` fails to copy the
502
+ ``sycl::context`` pointer.
487
503
"""
488
504
cdef DPCTLSyclContextRef CRef = NULL
489
505
CRef = DPCTLContext_Copy(self ._ctxt_ref)
0 commit comments