
    sg                          d dl Z  G d d      Zy)    Nc                   <    e Zd ZdZd
dZd Zd Zd Zd Zd Z	d Z
y	)EventaA  Wrapper around an MPS event.

    MPS events are synchronization markers that can be used to monitor the
    device's progress, to accurately measure timing, and to synchronize MPS streams.

    Args:
        enable_timing (bool, optional): indicates if the event should measure time
            (default: ``False``)
    c                 L    t         j                  j                  |      | _        y )N)torch_C_mps_acquireEvent_Event__eventId)selfenable_timings     B/var/www/html/venv/lib/python3.12/site-packages/torch/mps/event.py__init__zEvent.__init__   s    33MB    c                     t        t        j                  d      r:| j                  dkD  r*t        j                  j	                  | j                         y y y )N_mps_releaseEventr   )hasattrr   r   r	   r   r
   s    r   __del__zEvent.__del__   s;    58801dnnq6HHH&&t~~6 7I1r   c                 V    t         j                  j                  | j                         y)z(Records the event in the default stream.N)r   r   _mps_recordEventr	   r   s    r   recordzEvent.record   s    !!$..1r   c                 V    t         j                  j                  | j                         y)zJMakes all future work submitted to the default stream wait for this event.N)r   r   _mps_waitForEventr	   r   s    r   waitz
Event.wait   s    ""4>>2r   c                 T    t         j                  j                  | j                        S )zCReturns True if all work currently captured by event has completed.)r   r   _mps_queryEventr	   r   s    r   queryzEvent.query    s    xx''77r   c                 V    t         j                  j                  | j                         y)zWaits until the completion of all work currently captured in this event.
        This prevents the CPU thread from proceeding until the event completes.
        N)r   r   _mps_synchronizeEventr	   r   s    r   synchronizezEvent.synchronize$   s     	&&t~~6r   c                 j    t         j                  j                  | j                  |j                        S )z}Returns the time elapsed in milliseconds after the event was
        recorded and before the end_event was recorded.
        )r   r   _mps_elapsedTimeOfEventsr	   )r
   	end_events     r   elapsed_timezEvent.elapsed_time*   s%     xx00ATATUUr   N)F)__name__
__module____qualname____doc__r   r   r   r   r   r   r#    r   r   r   r      s,    C7
2387Vr   r   )r   r   r(   r   r   <module>r)      s    )V )Vr   