o
     …›iC
  ã                   @  st   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d„ZG d	d
„ d
ejjƒZG dd„ dƒZg d¢ZdS )é    )Úannotations)ÚOptionalÚUnion)ÚSelfNÚreturnÚ_POOL_HANDLEc                   C  s
   t j ¡ S )zL
    Return an opaque token representing the id of a graph memory pool.
    )ÚtorchÚ_CÚ_mtia_graphPoolHandle© r   r   úW/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/torch/mtia/mtia_graph.pyÚgraph_pool_handle   ó   
r   c                      sx   e Zd ZdZdd‡ fdd„Zd‡ fdd„Zd‡ fdd„Zd‡ fdd„Zd‡ fdd„Zd‡ fdd„Z	d‡ fdd„Z
‡  ZS )Ú	MTIAGraphz&
    Wrapper around a MTIA graph.
    FÚ
keep_graphÚboolr   r   c                   s   t ƒ  | |¡S ©N)ÚsuperÚ__new__)Úclsr   ©Ú	__class__r   r   r      s   zMTIAGraph.__new__Úpoolr   ÚNonec                   s   t ƒ  |¡ dS )z/
        Begin capturing a MTIA graph.
        N)r   Úcapture_begin)Úselfr   r   r   r   r      s   zMTIAGraph.capture_beginc                   ó   t ƒ  ¡  dS )z2
        End the capture of a MTIA graph.
        N)r   Úcapture_end©r   r   r   r   r   "   ó   zMTIAGraph.capture_endc                   r   )z6
        Instantiate the captured MTIA graph.
        N)r   Úinstantiater   r   r   r   r    (   r   zMTIAGraph.instantiatec                   r   )z1
        Replay the captured MTIA graph.
        N)r   Úreplayr   r   r   r   r!   .   r   zMTIAGraph.replayc                   r   )zB
        Destroy the captured graph and reset the states.
        N)r   Úresetr   r   r   r   r"   4   r   zMTIAGraph.resetc                   s
   t ƒ  ¡ S )zX
        Return an opaque token representing the id of this graph's memory pool
        )r   r   r   r   r   r   r   :   r   zMTIAGraph.pool)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   r   r   r   r      s    r   c                   @  s>   e Zd ZU dZded< 		ddd	d
„Zddd„Zddd„ZdS )ÚgraphNúOptional[torch.mtia.Stream]Údefault_capture_streamÚ
mtia_graphr   r   úOptional[_POOL_HANDLE]Ústreamc                 C  sl   | j jd u rtj ¡ | j _|d u rdn|f| _|d ur|n| j j| _| jd us)J ‚tj | j¡| _|| _	d S )Nr   )
r   r,   r   ÚmtiaÚcurrent_streamr   Úcapture_streamr/   Ú
stream_ctxr-   )r   r-   r   r/   r   r   r   Ú__init__D   s   ÿÿ
zgraph.__init__r   r   c                 C  sB   t j ¡  t j ¡  | j ¡  | jr| jd nd}| j |¡ d S )Nr   )r   r   )	r   r0   ÚsynchronizeÚempty_cacher3   Ú	__enter__r   r-   r   )r   Úpool_argr   r   r   r7   W   s
   


zgraph.__enter__ÚargsÚobjectc                 G  s   | j  ¡  | jj|Ž  d S r   )r-   r   r3   Ú__exit__)r   r9   r   r   r   r;   `   s   
zgraph.__exit__)NN)r-   r   r   r.   r/   r+   r#   )r9   r:   r   r   )r%   r&   r'   r,   Ú__annotations__r4   r7   r;   r   r   r   r   r*   A   s   
 ü
	r*   )r   r*   r   r$   )Ú
__future__r   Útypingr   r   Útyping_extensionsr   r   ÚtupleÚintr   r   r	   Ú
_MTIAGraphr   r*   Ú__all__r   r   r   r   Ú<module>   s   
-$