IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/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. /max/get-started.md).

Python class

DeviceEvent

DeviceEvent​

class max.driver.DeviceEvent(self, device: max.driver.Device, enable_timing: bool = False)

source

Bases: object

Provides access to an event object.

An event can be used to wait for the GPU execution to reach a certain point on the given stream.

from max import driver
device = driver.Accelerator()
# Create an event on the device
event = driver.DeviceEvent(device)
# Record an event on the device (default stream)
device.default_stream.record_event(event)
# Wait for execution on the default stream to reach the event
event.synchronize()

Creates an event for synchronization on the specified device.

Parameters:

  • device (Device) – The device on which to create the event.
  • enable_timing (bool) – If True, enable GPU timing on this event. Events created with enable_timing=True can be used with elapsed_time() to measure GPU execution time. Defaults to False.

Raises:

ValueError – If event creation failed.

from max import driver

device = driver.Accelerator()
event = driver.DeviceEvent(device)
timed_event = driver.DeviceEvent(device, enable_timing=True)

elapsed_time()​

elapsed_time(self, end_event: max.driver.DeviceEvent) β†’ float

source

Returns the elapsed GPU time in milliseconds between this event and end_event.

Both events must have been created with enable_timing=True and recorded on a stream before calling this method. The end event must be synchronized before calling this method.

Parameters:

end_event (DeviceEvent) – The ending event.

Returns:

Elapsed time in milliseconds.

Return type:

float

Raises:

RuntimeError – If either event was not created with timing enabled, or if the events have not been recorded.

from max import driver

device = driver.Accelerator()
start = driver.DeviceEvent(device, enable_timing=True)
end = driver.DeviceEvent(device, enable_timing=True)

stream = device.default_stream
stream.record_event(start)
# ... GPU work ...
stream.record_event(end)
end.synchronize()

elapsed_ms = start.elapsed_time(end)

is_ready()​

is_ready(self) β†’ bool

source

Returns whether this event is ready.

Returns:

True if the event is complete, otherwise false.

Return type:

bool

Raises:

ValueError – If querying the event status returned an error.

synchronize()​

synchronize(self) β†’ None

source

Ensures all operations on this stream complete before returning.

Raises:

ValueError – If any enqueued operations had an internal error.