Python class
DeviceEvent
DeviceEvent
class max.driver.DeviceEvent(self, 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 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=Truecan be used withelapsed_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
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:
-
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
Returns whether this event is ready.
-
Returns:
-
True if the event is complete, otherwise false.
-
Return type:
-
Raises:
-
ValueError – If querying the event status returned an error.
synchronize()
synchronize(self) → None
Ensures all operations on this stream complete before returning.
-
Raises:
-
ValueError – If any enqueued operations had an internal error.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!