Skip to main content

Python class

Device

Device

class max.driver.Device

source

Bases: object

Represents a compute device available for tensor operations.

This is the base class for CPU and Accelerator. Do not instantiate this class directly; use CPU for host devices or Accelerator for GPU devices.

from max import driver

cpu = driver.CPU()
gpu = driver.Accelerator()

api

property api

source

Returns the API used to program the device.

Possible values are:

  • cpu for host devices.
  • cuda for NVIDIA GPUs.
  • hip for AMD GPUs.
from max import driver

device = driver.CPU()
device.api

architecture_name

property architecture_name

source

Returns the architecture name of the device.

Examples of possible values:

  • gfx90a, gfx942 for AMD GPUs.
  • sm_80, sm_86 for NVIDIA GPUs.
  • CPU devices raise an exception.
from max import driver

device = driver.Accelerator()
device.architecture_name

can_access()

can_access(self, other: max.driver.Device) → bool

source

Checks if this device can directly access memory of another device.

from max import driver

gpu0 = driver.Accelerator(id=0)
gpu1 = driver.Accelerator(id=1)

if gpu0.can_access(gpu1):
    print("GPU0 can directly access GPU1 memory.")

Parameters:

other (Device) – The other device to check peer access against.

Returns:

True if peer access is possible, False otherwise.

Return type:

bool

cpu

cpu = <nanobind.nb_func object>

source

default_stream

property default_stream

source

Returns the default stream for this device.

The default stream is initialized when the device object is created.

Returns:

The default execution stream for this device.

Return type:

DeviceStream

id

property id

source

Returns a zero-based device id.

For a CPU device this is always 0. For GPU accelerators this is the id of the device relative to this host. Along with the label, an id can uniquely identify a device, e.g. gpu:0, gpu:1.

from max import driver

device = driver.Accelerator()
device_id = device.id

Returns:

The device ID.

Return type:

int

is_compatible

property is_compatible

source

Returns whether this device is compatible with MAX.

Returns:

True if the device is compatible with MAX, False otherwise.

Return type:

bool

is_host

property is_host

source

Whether this device is the CPU (host) device.

from max import driver

device = driver.CPU()
device.is_host

label

property label

source

Returns device label.

Possible values are:

  • cpu for host devices.
  • gpu for accelerators.
from max import driver

device = driver.CPU()
device.label

stats

property stats

source

Returns utilization data for the device.

from max import driver

device = driver.CPU()
stats = device.stats

Returns:

A dictionary containing device utilization statistics.

Return type:

dict

synchronize()

synchronize(self) → None

source

Ensures all operations on this device complete before returning.

Raises:

ValueError – If any enqueued operations had an internal error.