dpctl.SyclContext¶
- class dpctl.SyclContext(arg=None)¶
- A Python wrapper for the - sycl::contextC++ class.- There are multiple ways to create a - dpctl.SyclContextobject:- Invoking the constructor with no arguments creates a context using the default selector. 
 - Example:
- import dpctl # Create a SyclContext for default-selected device ctx = dpctl.SyclContext() print(ctx.get_devices()) 
 - Invoking the constructor 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 constructor 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 constructor 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 with two cores each. 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 constructor with a named - PyCapsulewith name “SyclContextRef” that carries a pointer to a- sycl::contextobject. The capsule will be renamed upon successful consumption to ensure one-time use. A new named capsule can be constructed by using- dpctl.SyclContext._get_capsule()method.
 - Parameters:
- arg (optional) – Defaults to - None. The argument can be a selector string, a- dpctl.SyclDeviceinstance, a- listof- dpctl.SyclDeviceobjects, or a named- PyCapsulecalled “SyclContextRef”.
- Raises:
- MemoryError – If the constructor could not allocate necessary temporary memory. 
- SyclContextCreationError – If the - 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.
 
 - Methods - Returns the address of the - DPCTLSyclContextRefpointer as a- size_t.- Returns the list of - dpctl.SyclDeviceobjects associated with- dpctl.SyclContextinstance.- Attributes - The number of sycl devices associated with the - dpctl.SyclContextinstance.