dpctl.SyclContext¶
-
class
dpctl.SyclContext¶ Python class representing
cl::sycl::context. There are multiple ways to create adpctl.SyclContextobject:Invoking the constructor with no arguments creates a context using the default selector.
- Example
import dpctl # Create a default SyclContext ctx = dpctl.SyclContext() print(ctx.get_devices())
Invoking the constuctor with a specific filter string that creates a context for the device corresponding to the filter string.
- Example
import dpctl # Create SyclContext for a gpu device ctx = dpctl.SyclContext("gpu") d = ctx.get_devices()[0] assert(d.is_gpu)
Invoking the constuctor with a
dpctl.SyclDeviceobject creates a context for that device.
- Example
import dpctl # Create a level zero gpu device d = dpctl.SyclDevice("level_zero:gpu") ctx = dpctl.SyclContext(d) d = ctx.get_devices()[0] assert(d.is_gpu)
Invoking the constuctor with a list of
dpctl.SyclDeviceobjects creates a common context for all the devices. This constructor call is especially useful when creation a context for multiple sub-devices.
- Example
import dpctl # Create a CPU device using the opencl driver cpu_d = dpctl.SyclDevice("opencl:cpu") # Partition the CPU device into sub-devices, each with two cores. sub_devices = cpu_d.create_sub_devices(partition=2) # Create a context common to all the sub-devices. ctx = dpctl.SyclContext(sub_devices) assert(len(ctx.get_devices) == len(sub_devices))
Invoking the constuctor with a named
PyCapsulewith name “SyclContextRef” that carries a pointer to asycl::contextobject. The capsule will be renamed upon successful consumption to ensure one-time use. A new named capsule can be constructed by usingdpctl.SyclContext._get_capsule()method.
- Parameters
arg (optional) – Defaults to None. The argument can be a selector string, a
dpctl.SyclDeviceinstance, alistofdpctl.SyclDeviceobjects, or a namedPyCapsulecalled “SyclContextRef”.- Raises
MemoryError – If the constructor could not allocate necessary temporary memory.
ValueError – If the
dpctl.SyclContextobject creation failed.TypeError – If the list of
dpctl.SyclDeviceobjects was empty, or the input capsule contained a null pointer or could not be renamed.
Attributes:
device_countThe number of sycl devices associated with the
dpctl.SyclContextinstance.Private methods:
_get_capsuleReturns a copy of the underlying
sycl::contextpointer as a void pointer inside a namedPyCapsulethat has the name SyclContextRef.Public methods:
addressof_refReturns the address of the
DPCTLSyclContextRefpointer as asize_t.get_devicesReturns the list of
dpctl.SyclDeviceobjects associated withdpctl.SyclContextinstance.
Detail¶
Private methods¶
SyclContext._get_capsule()Returns a copy of the underlying
sycl::contextpointer as a void pointer inside a namedPyCapsulethat has the name SyclContextRef. The ownership of the pointer inside the capsule is passed to the caller, and pointer is deleted when the capsule goes out of scope.
- Returns
A capsule object storing a copy of the
sycl::contextpointer belonging to thusdpctl.SyclContextinstance.- Return type
pycapsule- Raises
ValueError – If the
DPCTLContext_Copyfails to copy thesycl::contextpointer.
Public methods¶
SyclContext.addressof_ref()Returns the address of the
DPCTLSyclContextRefpointer as asize_t.
- Returns
The address of the
DPCTLSyclContextRefobject used to create thisdpctl.SyclContextcast to asize_t.- Return type
int
SyclContext.device_countThe number of sycl devices associated with the
dpctl.SyclContextinstance.
- Returns
Number of devices associated with the context.
- Return type
int- Raises
ValueError – If
DPCTLContext_DeviceCountled to a failure.
SyclContext.get_devices()Returns the list of
dpctl.SyclDeviceobjects associated withdpctl.SyclContextinstance.
- Returns
A
listofdpctl.SyclDeviceobjects that belong to this context.- Return type
list- Raises
ValueError – If the
DPCTLContext_GetDevicescall returnedNULLinstead of aDPCTLDeviceVectorRefobject.