+
    –°³j�  ã                   óV   € ^ RI t ^ RIHt ^ RIHt ^ RIt^ RIHt  ! R R]4      tR.t	R# )é    N)ÚLiteral)ÚSelf)Ú_acceleratorGraphc                   ó^  a a€ ] tR t^	t oRtRRRRR/V3R lV 3R lllltRRRRR/V3R lV 3R	 lllltV3R
 lV 3R lltV3R lV 3R lltV3R lV 3R llt	V3R lV 3R llt
V3R lV 3R lltV3R lV 3R lltV3R lV 3R lltV3R lV 3R lltV3R lR ltV3R lR ltRtVtV ;t# ) ÚGraphaØ  
Wrapper around an :ref:`accelerator<accelerators>` graph that supports capture and replay.

A graph captures a sequence of operations and their dependencies, allowing them to be
replayed efficiently with reduced overhead. This class can be used as a context manager
to automatically capture operations on the current stream.

Arguments:
    keep_graph (bool, optional): If ``False``, the underlying graph is destroyed and the
        executable graph is instantiated on the GPU at the end of ``capture_end``.
        If ``True``, the underlying graph is preserved after ``capture_end``. In this case,
        the executable graph is not instantiated automatically; it must be explicitly created
        by calling ``instantiate``, or it will be instantiated on the first call to ``replay``.
        Defaults to ``False``.
    pool (tuple[int, int], optional): Memory pool identifier for this graph. Multiple graphs
        can share the same pool by passing the same identifier, which can reduce memory overhead.
        Defaults to ``None``.
    capture_error_mode (Literal["default", "global", "thread_local", "relaxed"], optional):
        Specifies the behavior of graph capture. The exact semantics are backend-specific.
        ``"default"``: backend-defined default capture behavior.
        ``"global"``: potentially unsafe API calls are prohibited. Errors may occur if capture
        in the current thread affects other threads.
        ``"thread_local"``: potentially unsafe API calls are prohibited. Errors occur only if
        capture in the current thread affects itself.
        ``"relaxed"``: the current thread is allowed to make potentially unsafe API calls, except
        for calls that inherently conflict with stream capture.
        Default: ``"default"``.

Example::

    >>> # xdoctest: +SKIP
    >>> x = torch.zeros([2000], device=0)

    >>> stream = torch.Stream()
    >>> graph = torch.accelerator.Graph()
    >>> with stream, graph:
    ...     x += 1

    >>> graph.replay()
ÚpoolNÚcapture_error_modeÚdefaultc                ód   <€ V ^8„  d   QhRS[ RS[S[S[3,          R,          RS[R,          RS[/# ©é   Ú
keep_graphr   Nr	   Úreturn)r
   ÚglobalÚthread_localÚrelaxed)ÚboolÚtupleÚintr   r   )ÚformatÚ__classdict__s   "€ÚY/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/accelerator/graphs.pyÚ__annotate__ÚGraph.__annotate__3   sH   ø€ ÷ 	0ñ 	0áð	0ñ ‘C™�H�o Õ$ð		0ñ
 $Ø:õ
ð	0ñ 
ñ	0ó    c               ó"   <€ \         SV `  W4      # ©N)ÚsuperÚ__new__)Úclsr   r   r	   Ú	__class__s   &&$$€r   r   ÚGraph.__new__3   s   ø€ ô ‰w‰˜sÓ/Ð/r   c                ób   <€ V ^8„  d   QhRS[ RS[S[S[3,          R,          RS[R,          RR/# r   )r   r   r   r   )r   r   s   "€r   r   r   >   sH   ø€ ÷ 5ñ 5áð5ñ ‘C™�H�o Õ$ð	5ñ
 $Ø:õ
ð5ð 
ñ5r   c               ó>   <€ \         SV `  V4       W n        W0n        R # r   )r   Ú__init__Ú
graph_poolr	   )Úselfr   r   r	   r!   s   &&$$€r   r%   ÚGraph.__init__>   s   ø€ ô 	‰Ñ˜Ô$ØŒØ"4Ör   c                ó   <€ V ^8„  d   QhRR/# ©r   r   N© )r   r   s   "€r   r   r   L   s   ø€ ÷ 	
ñ 	
˜tñ 	
r   c                óR   <€ \         SV `  V P                  V P                  R7       R# )zï
Begin graph capture on the current stream.

All operations on the current stream after this call will be recorded into the graph until
``capture_end`` is called, using the memory pool and capture error mode provided at construction time.
)r   r	   N)r   Úcapture_beginr&   r	   ©r'   r!   s   &€r   r-   ÚGraph.capture_beginL   s&   ø€ ô 	‰ÑØ—‘°T×5LÑ5Lð 	ö 	
r   c                ó   <€ V ^8„  d   QhRR/# r*   r+   )r   r   s   "€r   r   r   W   ó   ø€ ÷ ñ ˜Tñ r   c                ó$   <€ \         SV `  4        R# )z|
End graph capture on the current stream of the current device.

After this call, the graph can be replayed via ``replay``.
N)r   Úcapture_endr.   s   &€r   r3   ÚGraph.capture_endW   ó   ø€ ô 	‰ÑÖr   c                ó   <€ V ^8„  d   QhRR/# r*   r+   )r   r   s   "€r   r   r   _   r1   r   c                ó$   <€ \         SV `  4        R# )zÂ
Instantiate the underlying graph. Will be called by ``capture_end``
if ``keep_graph=False``, or by ``replay`` if ``keep_graph=True`` and
``instantiate`` has not already been explicitly called.
N)r   Úinstantiater.   s   &€r   r8   ÚGraph.instantiate_   r5   r   c                ó   <€ V ^8„  d   QhRR/# r*   r+   )r   r   s   "€r   r   r   g   s   ø€ ÷ ñ ˜ñ r   c                ó$   <€ \         SV `  4        R# )z'Replay the work captured by this graph.N)r   Úreplayr.   s   &€r   r<   ÚGraph.replayg   s   ø€ ä‰‰Ör   c                ó   <€ V ^8„  d   QhRR/# r*   r+   )r   r   s   "€r   r   r   k   s   ø€ ÷ ñ �tñ r   c                ó$   <€ \         SV `  4        R# )zÑ
Delete the graph currently held by this instance.

After this call, the graph can be recaptured. Set :attr:`graph_pool` or
:attr:`capture_error_mode` beforehand to use different settings on the next capture.
N)r   Úresetr.   s   &€r   r@   ÚGraph.resetk   s   ø€ ô 	‰‰Žr   c                ó6   <€ V ^8„  d   QhRS[ S[S[3,          /# )r   r   )r   r   )r   r   s   "€r   r   r   t   s   ø€ ÷ ñ ‘e™C¡˜H•oñ r   c                ó    <€ \         SV `  4       # )aì  
Return an opaque token representing the id of this graph's memory pool.

This id can optionally be passed to another graph's ``capture_begin``,
which hints the other graph may share the same memory pool.

Example::
    >>> # xdoctest: +SKIP
    >>> g1 = torch.accelerator.Graph()
    >>> g1.capture_begin()
    >>> # ... operations ...
    >>> g1.capture_end()

    >>> # Share g1's memory pool with a new graph
    >>> pool_id = g1.pool()
    >>> g2 = torch.accelerator.Graph(pool=pool_id)
)r   r   r.   s   &€r   r   Ú
Graph.poolt   s   ø€ ô$ ‰w‰|‹~Ðr   c                ó   <€ V ^8„  d   QhRR/# r*   r+   )r   r   s   "€r   r   r   ˆ   s   ø€ ÷ +ñ + 4ñ +r   c                ó    <€ \         SV `  4       # )z)Enable debugging mode for ``debug_dump``.)r   Úenable_debug_moder.   s   &€r   rG   ÚGraph.enable_debug_modeˆ   s   ø€ ä‰wÑ(Ó*Ð*r   c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   Úpathr   N)Ústr)r   r   s   "€r   r   r   Œ   s   ø€ ÷ (ñ (™sð ( tñ (r   c                ó"   <€ \         SV `  V4      # )a¾  
Dump the captured graph to a file for debugging purposes if the debugging is
enabled via ``enable_debug_mode``.

Arguments:
    path (str): Path to dump the graph to.

Example::
    >>> # xdoctest: +SKIP
    >>> s = torch.Stream()
    >>> g = torch.accelerator.Graph()
    >>> g.enable_debug_mode()

    >>> with s, g:
    >>> # ... operations ...

    >>> # Dump captured graph to a file "graph_dump.dot"
    >>> g.debug_dump("graph_dump.dot")
)r   Ú
debug_dump)r'   rJ   r!   s   &&€r   rM   ÚGraph.debug_dumpŒ   s   ø€ ô( ‰wÑ! $Ó'Ð'r   c                ó   <€ V ^8„  d   QhRR/# r*   r+   )r   r   s   "€r   r   r   ¢   s   ø€ ÷ 	ñ 	˜4ñ 	r   c                óX  € \         P                  P                  4        \         P                  P                  P
                  '       d   \        P                  ! 4        \         P                  P                  4        \         P                  P                  4        V P                  4        R # r   )ÚtorchÚacceleratorÚsynchronizeÚcompilerÚconfigÚforce_cudagraph_gcÚgcÚcollectÚempty_cacheÚempty_host_cacher-   )r'   s   &r   Ú	__enter__ÚGraph.__enter__¢   se   € Ü×Ñ×%Ñ%Ô'Ü�>‰>× Ñ ×3×3Ð3ô �JŠJŒLÜ×Ñ×%Ñ%Ô'Ü×Ñ×*Ñ*Ô,Ø×ÑÖr   c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   Úexc_infor   N)Úobject)r   r   s   "€r   r   r   ­   s   ø€ ÷ ñ ¡&ð ¨Tñ r   c                ó&   € V P                  4        R # r   )r3   )r'   r^   s   &*r   Ú__exit__ÚGraph.__exit__­   s   € Ø×ÑÖr   )r	   r&   )F)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r%   r-   r3   r8   r<   r@   r   rG   rM   r[   ra   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r!   r   s   @@r   r   r   	   s°   ù‡ € ñ'ñR	0ð (,ð		0ð ÷	0ö 	0ñ5ð (,ð	5ð ÷5ö 5÷	
ó 	
÷ó ÷ó ÷ó ÷ó ÷ó ÷(+ó +÷(ó (÷,	ð 	÷÷ ð r   r   )
rW   Útypingr   Útyping_extensionsr   rQ   Útorch._Cr   r   Ú__all__r+   r   r   Ú<module>ro      s-   ðÛ 	Ý Ý "ã Ý &ôeÐô eðP ˆ)‚r   