o
    k«Ïi`
  ã                   @  sd   d dl 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)Ú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	   ú_/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/mtia/mtia_graph.pyÚgraph_pool_handle   s   
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   :   s   
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útorch.mtia.Stream | NoneÚdefault_capture_streamÚ
mtia_graphr   r   ú_POOL_HANDLE | NoneÚstreamc                 C  sp   | j jd u rtj ¡ | j _|d u rdn|f| _|d ur|n| j j| _| jd u r+tdƒ‚tj | j¡| _	|| _
d S )Nr	   zcapture_stream must not be None)r   r)   r   ÚmtiaÚcurrent_streamr   Úcapture_streamÚAssertionErrorr,   Ú
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   r-   ÚsynchronizeÚempty_cacher1   Ú	__enter__r   r*   r   )r   Úpool_argr	   r	   r
   r5   V   s
   


zgraph.__enter__ÚargsÚobjectc                 G  s   | j  ¡  | jj|Ž  d S r   )r*   r   r1   Ú__exit__)r   r7   r	   r	   r
   r9   _   s   
zgraph.__exit__)NN)r*   r   r   r+   r,   r(   r    )r7   r8   r   r   )r"   r#   r$   r)   Ú__annotations__r2   r5   r9   r	   r	   r	   r
   r'   A   s   
 ü
	r'   )r   r'   r   r!   )Ú
__future__r   Útyping_extensionsr   r   ÚtupleÚintr   r   r   Ú
_MTIAGraphr   r'   Ú__all__r	   r	   r	   r
   Ú<module>   s   
-#