
    [iC
                        d dl mZ d dlmZmZ d dlmZ d dlZee	e	f         Z
ddZ G d d	ej        j                  Z G d
 d          Zg dZdS )    )annotations)OptionalUnion)SelfNreturn_POOL_HANDLEc                 >    t           j                                        S )zL
    Return an opaque token representing the id of a graph memory pool.
    )torch_C_mtia_graphPoolHandle     H/var/www/icac/venv/lib/python3.11/site-packages/torch/mtia/mtia_graph.pygraph_pool_handler      s     8))+++r   c                  n     e Zd ZdZdd fdZd fdZd fdZd fdZd fdZd fdZ	d fdZ
 xZS )	MTIAGraphz&
    Wrapper around a MTIA graph.
    F
keep_graphboolr   r   c                H    t                                          | |          S N)super__new__)clsr   	__class__s     r   r   zMTIAGraph.__new__   s    wwsJ///r   poolr   Nonec                J    t                                          |           dS )z/
        Begin capturing a MTIA graph.
        N)r   capture_begin)selfr   r   s     r   r   zMTIAGraph.capture_begin   s#     	d#####r   c                H    t                                                       dS )z2
        End the capture of a MTIA graph.
        N)r   capture_endr   r   s    r   r!   zMTIAGraph.capture_end"   !     	r   c                H    t                                                       dS )z6
        Instantiate the captured MTIA graph.
        N)r   instantiater"   s    r   r%   zMTIAGraph.instantiate(   r#   r   c                H    t                                                       dS )z1
        Replay the captured MTIA graph.
        N)r   replayr"   s    r   r'   zMTIAGraph.replay.   s     	r   c                H    t                                                       dS )zB
        Destroy the captured graph and reset the states.
        N)r   resetr"   s    r   r)   zMTIAGraph.reset4   s     	r   c                D    t                                                      S )zX
        Return an opaque token representing the id of this graph's memory pool
        )r   r   r"   s    r   r   zMTIAGraph.pool:   s     ww||~~r   )F)r   r   r   r   )r   r   r   r   r   r   r   r   )__name__
__module____qualname____doc__r   r   r!   r%   r'   r)   r   __classcell__)r   s   @r   r   r      s         0 0 0 0 0 0 0$ $ $ $ $ $                             r   r   c                  <    e Zd ZU dZded<   	 	 ddd	ZddZddZdS )graphNOptional[torch.mtia.Stream]default_capture_stream
mtia_graphr   r   Optional[_POOL_HANDLE]streamc                "   | j         j        (t          j                                        | j         _        |dn|f| _        ||n| j         j        | _        | j        J t          j                            | j                  | _        || _	        d S )Nr   )
r   r5   r
   mtiacurrent_streamr   capture_streamr8   
stream_ctxr6   )r   r6   r   r8   s       r   __init__zgraph.__init__D   s     >0849J4M4M4O4ODN1 ,BBTG 		 (FFdn.S 	 "...*++D,?@@$r   r   r   c                   t           j                                         t           j                                         | j                                         | j        r| j        d         nd}| j                            |           d S )Nr   )r   r   )	r
   r:   synchronizeempty_cacher=   	__enter__r   r6   r   )r   pool_args     r   rB   zgraph.__enter__W   sp    
   
   !!####'9849Q<<&%%h/////r   argsobjectc                V    | j                                           | j        j        |  d S r   )r6   r!   r=   __exit__)r   rD   s     r   rG   zgraph.__exit__`   s.    ##%%%  $''''r   )NN)r6   r   r   r7   r8   r4   r+   )rD   rE   r   r   )r-   r.   r/   r5   __annotations__r>   rB   rG   r   r   r   r3   r3   A   sq         :>>>>>
 (,.2	% % % % %&0 0 0 0( ( ( ( ( (r   r3   )r   r3   r   r,   )
__future__r   typingr   r   typing_extensionsr   r
   tupleintr   r   r   
_MTIAGraphr   r3   __all__r   r   r   <module>rP      s    " " " " " " " " " " " " " " " " " " " "  S#X, , , ,* * * * *# * * *Z!( !( !( !( !( !( !( !(H  r   