U
    Å9%ex  ã                   @   s   d dl Z G dd„ dƒZdS )é    Nc                   @   sJ   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )Ú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``)
    Fc                 C   s   t j |¡| _d S )N)ÚtorchÚ_CZ_mps_acquireEventÚ_Event__eventId)ÚselfZenable_timing© r   úN/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/torch/mps/event.pyÚ__init__   s    zEvent.__init__c                 C   s(   t tjdƒr$| jdkr$tj | j¡ d S )NÚ_mps_releaseEventr   )Úhasattrr   r   r   r
   ©r   r   r   r   Ú__del__   s    zEvent.__del__c                 C   s   t j | j¡ dS )z(Records the event in the default stream.N)r   r   Z_mps_recordEventr   r   r   r   r   Úrecord   s    zEvent.recordc                 C   s   t j | j¡ dS )zJMakes all future work submitted to the default stream wait for this event.N)r   r   Z_mps_waitForEventr   r   r   r   r   Úwait   s    z
Event.waitc                 C   s   t j | j¡S )zCReturns True if all work currently captured by event has completed.)r   r   Z_mps_queryEventr   r   r   r   r   Úquery   s    zEvent.queryc                 C   s   t j | j¡ dS )z¡Waits 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   Z_mps_synchronizeEventr   r   r   r   r   Úsynchronize#   s    zEvent.synchronizec                 C   s   t 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   Z_mps_elapsedTimeOfEventsr   )r   Z	end_eventr   r   r   Úelapsed_time)   s    zEvent.elapsed_timeN)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r   r   r   r   r   r   r      s   

r   )r   r   r   r   r   r   Ú<module>   s   