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)
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 withenable_timing=Truecan be used withelapsed_time()to measure GPU execution time. Defaults toFalse.
-
Raises:
-
ValueError – If event creation failed.
elapsed_time()
elapsed_time(end_event: max.driver.DeviceEvent) → float
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
Returns whether this event is ready.
-
Returns:
-
Trueif the event is complete,Falseotherwise. -
Raises:
-
ValueError – If querying the event status returned an error.
synchronize()
synchronize() → None
Ensures all operations on this queue complete before returning.
-
Raises:
-
ValueError – If any enqueued operations had an internal error.