IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

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 and Accelerator for any hardware accelerator.

from max import driver

cpu = driver.CPU()
device = driver.Accelerator() if driver.accelerator_count() else driver.CPU()

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.
  • metal for Apple GPUs.
from max import driver

device = driver.Accelerator() if driver.accelerator_count() else 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(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 – The other device to check peer access against.

Returns:

True if peer access is possible, False otherwise.

cpu()​

cpu(id: int = 0) → max.driver.CPU

source

Creates a CPU device.

Parameters:

id – The device ID. Currently ignored.

default_queue​

property default_queue

source

Returns the default queue for this device.

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

Returns:

The default execution queue for this device.

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, such as gpu:0 or gpu:1.

from max import driver

device = driver.Accelerator() if driver.accelerator_count() else driver.CPU()
device_id = device.id

Returns:

The device ID.

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.

is_host​

property is_host

source

Whether this device is the CPU (host) device.

from max import driver

device = driver.Accelerator() if driver.accelerator_count() else driver.CPU()
device.is_host

is_host_unified​

property is_host_unified

source

Whether this device and the host draw from one physical memory pool.

Reports hardware topology, so it does not predict whether a particular buffer is readable from the host.

from max import driver

device = driver.Accelerator() if driver.accelerator_count() else driver.CPU()
device.is_host_unified

label​

property label

source

Returns device label.

Possible values are:

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

device = driver.Accelerator() if driver.accelerator_count() else driver.CPU()
device.label

max_single_alloc_size​

property max_single_alloc_size

source

Largest single contiguous allocation, in bytes.

model_name​

property model_name

source

Returns the model name of the device.

Examples of possible values:

  • NVIDIA H100 80GB HBM3 for an H100.
  • NVIDIA B200 for a B200.
  • AMD Instinct MI300X for an MI300X.
  • cpu for a CPU device.
from max import driver

device = driver.Accelerator() if driver.accelerator_count() else driver.CPU()
device.model_name

stats​

property stats

source

Returns utilization data for the device.

from max import driver

device = driver.Accelerator() if driver.accelerator_count() else driver.CPU()
stats = device.stats

Returns:

A dictionary containing device utilization statistics.

synchronize()​

synchronize() → None

source

Ensures all operations on this device complete before returning.

Raises:

ValueError – If any enqueued operations had an internal error.