
    [Th!                     ^   S SK r S SKrS SKJr  \" \R
                  S5      (       d>  \" S5      \R
                  R                  S'   \" S5      \R
                  R                  S'    " S S\R
                  R                  5      r " S S\5      r	 " S	 S
\R
                  R                  5      rg)    N)_dummy_type_CudaStreamBase_CudaEventBasec                      ^  \ rS rSrSrSU 4S jjrSS jrSS jrSS jrS\	4U 4S jjr
SU 4S	 jjr\S
 5       rS\	4U 4S jjrS rS rSrU =r$ )Stream   a  Wrapper around a CUDA stream.

A CUDA stream is a linear sequence of execution that belongs to a specific
device, independent from other streams. It supports with statement as a
context manager to ensure the operators within the with block are running
on the corresponding stream.  See :ref:`cuda-semantics` for details.

Args:
    device(torch.device or int, optional): a device on which to allocate
        the stream. If :attr:`device` is ``None`` (default) or a negative
        integer, this will use the current device.
    priority(int, optional): priority of the stream, which can be positive, 0, or negative.
        A lower number indicates a higher priority. By default, the priority is set to 0.
        If the value falls outside of the allowed priority range, it will automatically be
        mapped to the nearest valid priority (lowest for large positive numbers or
        highest for large negative numbers).

c                    > Ub  SU;   a  SU;   a  [         TU ]  " U 4SU0UD6$ [        R                  R	                  U5         [         TU ]  " U 4SU0UD6sS S S 5        $ ! , (       d  f       g = f)N	stream_iddevice_indexpriority)super__new__torchcudadevice)clsr   r   kwargs	__class__s       J/var/www/auris/envauris/lib/python3.13/site-packages/torch/cuda/streams.pyr   Stream.__new__"   sc    >kV3&8P7?3DDVDD""6*wsHXHH +**s   A  
A.returnc                 &    UR                  U 5        g)a  Make all future work submitted to the stream wait for an event.

Args:
    event (torch.cuda.Event): an event to wait for.

.. note:: This is a wrapper around ``cudaStreamWaitEvent()``: see
   `CUDA Stream documentation`_ for more info.

   This function returns without waiting for :attr:`event`: only future
   operations are affected.

.. _CUDA Stream documentation:
   https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html
N)waitselfevents     r   
wait_eventStream.wait_event*   s     	

4    c                 B    U R                  UR                  5       5        g)aa  Synchronize with another stream.

All future work submitted to this stream will wait until all kernels
submitted to a given stream at the time of call complete.

Args:
    stream (Stream): a stream to synchronize.

.. note:: This function returns without waiting for currently enqueued
   kernels in :attr:`stream`: only future operations are affected.
N)r   record_event)r   streams     r   wait_streamStream.wait_stream;   s     	++-.r   c                 B    Uc
  [        5       nUR                  U 5        U$ )zRecord an event.

Args:
    event (torch.cuda.Event, optional): event to record. If not given, a new one
        will be allocated.

Returns:
    Recorded event.
)Eventrecordr   s     r   r!   Stream.record_eventI   s!     =GETr   c                     > [         TU ]  5       $ )zCheck if all the work submitted has been completed.

Returns:
    A boolean indicating if all kernels in this stream are completed.
r   queryr   r   s    r   r+   Stream.queryX   s     w}r   c                 "   > [         TU ]  5         g)zWait for all the kernels in this stream to complete.

.. note:: This is a wrapper around ``cudaStreamSynchronize()``: see
   `CUDA Stream documentation`_ for more info.
Nr   synchronizer,   s    r   r0   Stream.synchronize`   s     	r   c                 B    [         R                  " U R                  5      $ N)ctypesc_void_pcuda_streamr   s    r   _as_parameter_Stream._as_parameter_h   s    t//00r   c                 N   > [        U[        5      (       a  [        TU ]  U5      $ g)NF)
isinstancer   r   __eq__)r   or   s     r   r<   Stream.__eq__l   s"    a  7>!$$r   c                 D    [        U R                  U R                  45      $ r3   )hashr6   r   r7   s    r   __hash__Stream.__hash__q   s    T%%t{{344r   c                 >    SU R                    SU R                  S S3$ )Nz<torch.cuda.Stream device=z cuda_stream=#x>)r   r6   r7   s    r   __repr__Stream.__repr__t   s&    +DKK=dFVFVWYEZZ[\\r    )Nr   r   Nr3   )__name__
__module____qualname____firstlineno____doc__r   r   r#   r!   boolr+   r0   propertyr8   r<   rA   rF   __static_attributes____classcell__r   s   @r   r   r      s_    &I"/t  1 14 
5] ]r   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )ExternalStreamx   a  Wrapper around an externally allocated CUDA stream.

This class is used to wrap streams allocated in other libraries in order
to facilitate data exchange and multi-library interactions.

.. note:: This class doesn't manage the stream life-cycle, it is the user
   responsibility to keep the referenced stream alive while this class is
   being used.

Args:
    stream_ptr(int): Integer representation of the `cudaStream_t` value.
        allocated externally.
    device(torch.device or int, optional): the device where the stream
        was originally allocated. If device is specified incorrectly,
        subsequent launches using this stream may fail.
c                    > [         R                  R                  U5         [        TU ]  " U 4SU0UD6sS S S 5        $ ! , (       d  f       g = f)N
stream_ptr)r   r   r   r   r   )r   rX   r   r   r   s       r   r   ExternalStream.__new__   s7    ZZv&7?3H:HH '&&s	   >
ArH   r3   )rJ   rK   rL   rM   rN   r   rQ   rR   rS   s   @r   rU   rU   x   s    "I Ir   rU   c                      ^  \ rS rSrSrSU 4S jjr\U 4S j5       rSU 4S jjrSSU 4S jjjr	U 4S jr
U 4S	 jrSU 4S
 jjrU 4S jr\S 5       rS\4S jrSrU =r$ )r&      aQ  Wrapper around a CUDA event.

CUDA events are synchronization markers that can be used to monitor the
device's progress, to accurately measure timing, and to synchronize CUDA
streams.

The underlying CUDA events are lazily initialized when the event is first
recorded or exported to another process. After creation, only streams on the
same device may record the event. However, streams on any device can wait on
the event.

Args:
    enable_timing (bool, optional): indicates if the event should measure time
        (default: ``False``)
    blocking (bool, optional): if ``True``, :meth:`wait` will be blocking (default: ``False``)
    interprocess (bool): if ``True``, the event can be shared between processes
        (default: ``False``)

.. _CUDA Event Documentation:
   https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__EVENT.html
c                 $   > [         TU ]  U UUUS9$ )N)enable_timingblockinginterprocess)r   r   )r   r]   r^   r_   r   s       r   r   Event.__new__   s%    w'%	  
 	
r   c                 "   > [         TU ]  X5      $ )z<Reconstruct an event from an IPC handle on the given device.)r   from_ipc_handle)r   r   handler   s      r   rb   Event.from_ipc_handle   s     w&v66r   c                 f   > Uc  [         R                  R                  5       n[        TU ]  U5        g)zRecord the event in a given stream.

Uses ``torch.cuda.current_stream()`` if no stream is specified. The
stream's device must match the event's device.
N)r   r   current_streamr   r'   r   r"   r   s     r   r'   Event.record   s(     >ZZ..0Fvr   r   c                 f   > Uc  [         R                  R                  5       n[        TU ]  U5        g)zMake all future work submitted to the given stream wait for this event.

Use ``torch.cuda.current_stream()`` if no stream is specified.

.. note:: This is a wrapper around ``cudaStreamWaitEvent()``: see
    `CUDA Event documentation`_ for more info.
N)r   r   rf   r   r   rg   s     r   r   
Event.wait   s(     >ZZ..0FVr   c                     > [         TU ]  5       $ )zCheck if all work currently captured by event has completed.

Returns:
    A boolean indicating if all work currently captured by event has
    completed.
r*   r,   s    r   r+   Event.query   s     w}r   c                 "   > [         TU ]  U5      $ )z|Return the time elapsed.

Time reported in milliseconds after the event was recorded and
before the end_event was recorded.
)r   elapsed_time)r   	end_eventr   s     r   rn   Event.elapsed_time   s     w#I..r   c                 "   > [         TU ]  5         g)a&  Wait for the event to complete.

Waits until the completion of all work currently captured in this event.
This prevents the CPU thread from proceeding until the event completes.

 .. note:: This is a wrapper around ``cudaEventSynchronize()``: see
    `CUDA Event documentation`_ for more info.
Nr/   r,   s    r   r0   Event.synchronize   s     	r   c                     > [         TU ]  5       $ )zaReturn an IPC handle of this event.

If not recorded yet, the event will use the current device.
)r   
ipc_handler,   s    r   rt   Event.ipc_handle   s    
 w!##r   c                 B    [         R                  " U R                  5      $ r3   )r4   r5   
cuda_eventr7   s    r   r8   Event._as_parameter_   s    t//r   c                 \    U R                   (       a  SU R                  R                  S S3$ g)Nz<torch.cuda.Event rD   rE   z <torch.cuda.Event uninitialized>)rw   r8   valuer7   s    r   rF   Event.__repr__   s*    ??'(;(;(A(A"'EQGG5r   rH   )FFFr3   rI   )rJ   rK   rL   rM   rN   r   classmethodrb   r'   r   r+   rn   r0   rt   rP   r8   strrF   rQ   rR   rS   s   @r   r&   r&      si    ,
 7 7
 
/	$ 0 06# 6 6r   r&   )r4   r   torch._utilsr   hasattr_C__dict__r   r   rU   r   r&   rH   r   r   <module>r      s      $ uxx*+++67H+IEHH'(*56F*GEHH&'g]UXX%% g]TIV I.e6EHH## e6r   