
    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y)    )annotations)OptionalUnion)SelfNc                 >    t         j                  j                         S )zL
    Return an opaque token representing the id of a graph memory pool.
    )torch_C_mtia_graphPoolHandle     O/var/www/html/engine/venv/lib/python3.12/site-packages/torch/mtia/mtia_graph.pygraph_pool_handler      s     88))++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.
    c                $    t         |   | |      S N)super__new__)cls
keep_graph	__class__s     r   r   zMTIAGraph.__new__   s    wsJ//r   c                $    t         |   |       y)z/
        Begin capturing a MTIA graph.
        N)r   capture_begin)selfpoolr   s     r   r   zMTIAGraph.capture_begin   s     	d#r   c                "    t         |           y)z2
        End the capture of a MTIA graph.
        N)r   capture_endr   r   s    r   r   zMTIAGraph.capture_end"        	r   c                "    t         |           y)z6
        Instantiate the captured MTIA graph.
        N)r   instantiater   s    r   r!   zMTIAGraph.instantiate(   r   r   c                "    t         |           y)z1
        Replay the captured MTIA graph.
        N)r   replayr   s    r   r#   zMTIAGraph.replay.   s     	r   c                "    t         |           y)zB
        Destroy the captured graph and reset the states.
        N)r   resetr   s    r   r%   zMTIAGraph.reset4   s     	r   c                     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     w|~r   )F)r   boolreturnr   )r   _POOL_HANDLEr(   Noner(   r*   r(   r)   )__name__
__module____qualname____doc__r   r   r   r!   r#   r%   r   __classcell__)r   s   @r   r   r      s0    0$ r   r   c                  D    e Zd ZU dZded<   	 	 d	 	 	 	 	 ddZd	dZd
dZy)graphNOptional[torch.mtia.Stream]default_capture_streamc                f   | j                   j                  -t        j                  j	                         | j                   _        |dn|f| _        ||n| j                   j                  | _        | j                  J t        j                  j                  | j                        | _        || _	        y )Nr   )
r   r5   r   mtiacurrent_streamr   capture_streamstream
stream_ctx
mtia_graph)r   r<   r   r:   s       r   __init__zgraph.__init__D   s     >>00849JJ4M4M4ODNN1 ,BTG 		 (Fdnn.S.S 	 ""...**++D,?,?@$r   c                    t         j                  j                          t         j                  j                          | j                  j                          | j                  r| j                  d   nd}| j                  j                  |       y )Nr   )r   r   )	r   r7   synchronizeempty_cacher;   	__enter__r   r<   r   )r   pool_args     r   rA   zgraph.__enter__W   sY    

 

 !!##'99499Q<&%%h/r   c                j    | j                   j                           | j                  j                  |  y r   )r<   r   r;   __exit__)r   argss     r   rD   zgraph.__exit__`   s&    ##%   $'r   )NN)r<   r   r   zOptional[_POOL_HANDLE]r:   r4   r+   )rE   objectr(   r*   )r-   r.   r/   r5   __annotations__r=   rA   rD   r   r   r   r3   r3   A   sA    :>7>
 (,.2	%% %% ,	%&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>rO      sN    " " "  S#X,*## *Z!( !(Hr   