Skip to main content
Log in

Python module

driver

CPU​

class max.driver.CPU(id: int = -1)

This represents an instance of a logical cpu device.

CUDA​

class max.driver.CUDA(id: int = -1)

This represents a CUDA GPU device.

Device​

class max.driver.Device(id: int = -1)

Abstract device class. Base class for all device objects.

Tensor​

class max.driver.Tensor(shape: ~typing.Tuple[int, ...], dt: ~max.dtype.dtype.DType, device: ~max.driver.driver.Device = <max.driver.driver.CPU object>, **kwargs)

Device-resident tensor representation. Allocates memory onto a given device with the provided shape and dtype. Tensors can be sliced to provide strided views of the underlying memory, but any tensors input into model execution must be contiguous. Does not currently support setting items across multiple indices, but does support numpy-style slicing.

  • Parameters:

    • dt – DType of tensor
    • shape – Tuple of positive, non-zero integers denoting the tensor shape.
    • device – Device to allocate tensor onto.

contiguous()​

contiguous() β†’ Tensor

Creates a contiguous copy of the parent tensor.

copy_to()​

copy_to(device: Device) β†’ Tensor

Copies a tensor to the provided device.

dtype​

property dtype*: DType*

DType of constituent elements in tensor.

from_numpy()​

classmethod from_numpy(arr: ~numpy.ndarray, device: ~max.driver.driver.Device = <max.driver.driver.CPU object>) β†’ Tensor

Creates a tensor from a provided numpy array, allocated on the provided device. If the target device is a CPU, the underlying data will not be copied. If the target device is a GPU, the device will be copied to the target.

is_contiguous​

property is_contiguous*: bool*

Whether or not tensor is contiguously allocated in memory. Returns false if the tensor is a non-contiguous slice.

Currently, we consider certain situations that are contiguous as non-contiguous for the purposes of our engine. These situations include: * A tensor with negative steps. * A 1-dimensional tensor slice that is derived from a larger tensor.

is_host​

property is_host*: bool*

Whether or not tensor is host-resident. Returns false for GPU tensors, true for CPU tensors.

item()​

item() β†’ Any

Returns the scalar value at a given location. Currently implemented only for zero-rank tensors. The return type is converted to a Python built-in type.

rank​

property rank*: int*

Tensor rank.

shape​

property shape*: Tuple[int, ...]*

Shape of tensor.

Was this page helpful?