Python class
DeviceRef
DeviceRef
class max.graph.DeviceRef(device_type, id=0)
Bases: object
A symbolic device representation.
DeviceRef type representation consists of a DeviceKind and an id. This is a direct representation of the device attribute in MLIR.
The following example demonstrates how to create and use device references:
from max.graph import DeviceRef
gpu_device = DeviceRef.GPU()
print(gpu_device) # Outputs: gpu:0
# Create a CPU device with specific id
cpu_device = DeviceRef.CPU(id=1)
print(cpu_device) # Outputs: cpu:1-
Parameters:
-
- device_type (DeviceKind)
- id (int)
CPU()
static CPU(id=0)
Creates a CPU device reference.
GPU()
static GPU(id=0)
Creates a GPU device reference.
device_type
device_type: DeviceKind
from_device()
static from_device(device)
Converts a Device or DeviceRef to a DeviceRef.
from_mlir()
static from_mlir(attr)
Returns a device reference from an MLIR attribute.
-
Parameters:
-
attr (DeviceRefAttr)
-
Return type:
id
id: int
is_cpu()
is_cpu()
Returns True if the device is a CPU device.
-
Return type:
is_gpu()
is_gpu()
Returns True if the device is a GPU device.
-
Return type:
to_device()
to_device()
Converts a device reference to a concrete driver Device.
-
Return type:
to_mlir()
to_mlir()
Returns an MLIR attribute representing the device.
-
Return type:
-
DeviceRefAttr
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!