U
    E‹ÑhŸ  ã                   @   s(   G d d„ dƒZ e ƒ Zdd„ Zdd„ ZdS )c                   @   sL   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚCompilationCallbackHandlerc                 C   s   g | _ g | _d S )N)Ústart_callbacksÚend_callbacks©Úself© r   úD/tmp/user/2202/pip-unpacked-wheel-bf9o3bgk/torch/_dynamo/callback.pyÚ__init__   s    z#CompilationCallbackHandler.__init__c                 C   s   | j  |¡ |S )z©
        Register a callback function to be called when the compilation starts.

        Args:
        - callback (callable): The callback function to register.
        )r   Úappend©r   Úcallbackr   r   r   Úregister_start_callback   s    z2CompilationCallbackHandler.register_start_callbackc                 C   s   | j  |¡ |S )z§
        Register a callback function to be called when the compilation ends.

        Args:
        - callback (callable): The callback function to register.
        )r   r	   r
   r   r   r   Úregister_end_callback   s    z0CompilationCallbackHandler.register_end_callbackc                 C   s   | j  |¡ dS )z�
        Remove a registered start callback function.

        Args:
        - callback (callable): The callback function to remove.
        N)r   Úremover
   r   r   r   Úremove_start_callback   s    z0CompilationCallbackHandler.remove_start_callbackc                 C   s   | j  |¡ dS )z‹
        Remove a registered end callback function.

        Args:
        - callback (callable): The callback function to remove.
        N)r   r   r
   r   r   r   Úremove_end_callback$   s    z.CompilationCallbackHandler.remove_end_callbackc                 C   s   | j D ]
}|ƒ  qdS )z9
        Execute all registered start callbacks.
        N)r   r
   r   r   r   Úrun_start_callbacks-   s    
z.CompilationCallbackHandler.run_start_callbacksc                 C   s   | j D ]
}|ƒ  qdS )z7
        Execute all registered end callbacks.
        N)r   r
   r   r   r   Úrun_end_callbacks4   s    
z,CompilationCallbackHandler.run_end_callbacksc                 C   s   | j  ¡  | j ¡  dS )z1
        Clear all registered callbacks.
        N)r   Úclearr   r   r   r   r   r   ;   s    
z CompilationCallbackHandler.clearN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r   r   r   r   r      s   

		r   c                 C   s   t  | ¡ | S )zU
    Decorator to register a callback function for the start of the compilation.
    )Úcallback_handlerr   ©r   r   r   r   Úon_compile_startF   s    
r   c                 C   s   t  | ¡ | S )zS
    Decorator to register a callback function for the end of the compilation.
    )r   r   r   r   r   r   Úon_compile_endN   s    
r   N)r   r   r   r   r   r   r   r   Ú<module>   s   A