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
DeviceStream
DeviceStream
class max.driver.DeviceStream(self, device: max.driver.Device)
Bases: object
Provides access to a stream of execution on a device.
A stream represents a sequence of operations that will be executed in order. Multiple streams on the same device can execute concurrently.
from max import driver
device = driver.Accelerator()
# Get the default stream for the device
stream = device.default_stream
# Create a new stream of execution on the device
new_stream = driver.DeviceStream(device)Creates a new stream of execution associated with the device.
-
Parameters:
-
device (Device) – The device to create the stream on.
-
Returns:
-
A new stream of execution.
-
Return type:
device
property device
The device this stream is executing on.
native_stream_handle
property native_stream_handle
The native stream handle as an integer, or 0 if there is none.
The handle is the CUDA CUstream / HIP hipStream_t; 0 means
the stream has no native handle (e.g. a CPU device). Lets native code
outside MLRT order its own work against this stream – for example,
record a CUDA event on it. The handle remains owned by this stream; do
not destroy it.
-
Returns:
-
The native stream handle, or
0if there is none. -
Return type:
record_event()
record_event(self) → max.driver.DeviceEvent
record_event(self, event: max.driver.DeviceEvent) → None
Overloaded function.
-
record_event(self) -> max.driver.DeviceEventRecords an event on this stream. Returns: : DeviceEvent: A new event that will be signaled when all operations : submitted to this stream before this call have completed.
- Raises:
- ValueError: If recording the event failed.
-
record_event(self, event: max.driver.DeviceEvent) -> NoneRecords an existing event on this stream.
- Args:
- event (DeviceEvent): The event to record on this stream.
- Raises:
- ValueError: If recording the event failed.
synchronize()
synchronize(self) → None
Ensures all operations on this stream complete before returning.
-
Raises:
-
ValueError – If any enqueued operations had an internal error.
wait_for()
wait_for(self, stream: max.driver.DeviceStream) → None
wait_for(self, device: max.driver.Device) → None
Overloaded function.
-
wait_for(self, stream: max.driver.DeviceStream) -> NoneEnsures all operations on the other stream complete before future work submitted to this stream is scheduled.
- Args:
- stream (DeviceStream): The stream to wait for.
-
wait_for(self, device: max.driver.Device) -> NoneEnsures all operations on device’s default stream complete before future work submitted to this stream is scheduled.
- Args:
- device (Device): The device whose default stream to wait for.
wait_for_host_value()
wait_for_host_value(self, flag: max.driver.CompletionFlag, value: int) → None
Stalls the stream until flag’s 64-bit value equals value.
Wraps the MLRT DeviceStream::enqueueWaitOnHostValue primitive
(CUDA’s cuStreamWaitValue64). Typically paired with
Device.__unsafe_enqueue_async_py_host_func to gate
downstream GPU work on a host-side AsyncRT task that signals
flag when it finishes – a stream-internal sync that
avoids a host synchronize() and captures cleanly into a
CUDA graph as a wait-value node.
-
Parameters:
-
- flag (CompletionFlag) – The completion flag to wait on.
The stream observes
flag.device_ptrvia the pinned device-mapped alias. - value (int) – The 64-bit value to wait for (equality).
- flag (CompletionFlag) – The completion flag to wait on.
The stream observes
-
Raises:
-
RuntimeError – If the underlying device does not support stream memory ops, or if the driver rejects the enqueue.