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

DeviceEvent

DeviceEvent​

class max.driver.DeviceEvent(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 queue.

For example, create an event, record it on the default queue, and wait for the queue to reach it:

from max import driver

device = driver.Accelerator() if driver.accelerator_count() else driver.CPU()
event = driver.DeviceEvent(device)
device.default_queue.record_event(event)
event.synchronize()

Parameters:

  • device – The device on which to create the event.
  • enable_timing – If True, enables 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.

elapsed_time()​

elapsed_time(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 queue before calling this method. The end event must be synchronized before calling this method.

For example, time the GPU work enqueued between two recorded events:

from max import driver

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

queue = device.default_queue
queue.record_event(start)
queue.record_event(end)
end.synchronize()

elapsed_ms = start.elapsed_time(end)

Parameters:

end_event – The ending event.

Returns:

The elapsed time in milliseconds.

Raises:

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

is_ready()​

is_ready() → bool

source

Returns whether this event is ready.

Returns:

True if the event is complete, False otherwise.

Raises:

ValueError – If querying the event status returned an error.

synchronize()​

synchronize() → None

source

Ensures all operations on this queue complete before returning.

Raises:

ValueError – If any enqueued operations had an internal error.