
    Ǆg                     R   d dl Z d dlZd dlmZmZ ddlmZ  eej                  d      s> ed      ej                  j                  d<    ed      ej                  j                  d<    G d dej                  j                  e      Z G d	 d
ej                  j                  e      Zy)    N)
_EventBase_StreamBase   )_dummy_type_XpuStreamBase_XpuEventBasec                   ~     e Zd ZdZd fd	ZddZddZddZdef fdZ	d fdZ
ed	        Z fd
Zd Zd Z xZS )Streama9  Wrapper around a XPU stream.

    A XPU stream is a linear sequence of execution that belongs to a specific
    device, independent from other streams.

    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, should be 0 or
            negative, where negative numbers indicate higher priority. By default,
            streams have priority 0.
    c                     |d|v rd|v rt        |   | fd|i|S t        j                  j	                  |      5  t        |   | fd|i|cd d d        S # 1 sw Y   y xY w)N	stream_iddevice_indexpriority)super__new__torchxpudevice)clsr   r   kwargs	__class__s       Y/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/torch/xpu/streams.pyr   zStream.__new__   sp    >kV3&8P7?3DDVDD!!&) IwsHXHHI I Is   AA"returnc                 &    |j                  |        y)zMake all future work submitted to the stream wait for an event.

        Args:
            event (torch.xpu.Event): an event to wait for.
        N)waitselfevents     r   
wait_eventzStream.wait_event'   s     	

4    c                 B    | j                  |j                                y)zSynchronize 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.
        N)r   record_event)r   streams     r   wait_streamzStream.wait_stream/   s     	++-.r   c                 @    |
t               }|j                  |        |S )zRecord an event.

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

        Returns:
            Recorded event.
        )Eventrecordr   s     r   r!   zStream.record_event:   s!     =GETr   c                      t         |          S )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)   zStream.queryI   s     w}r   c                 "    t         |           y)z4Wait for all the kernels in this stream to complete.Nr   synchronizer*   s    r   r-   zStream.synchronizeQ   s    r   c                 @    t        j                  | j                        S N)ctypesc_void_p
sycl_queuer   s    r   _as_parameter_zStream._as_parameter_U       t//r   c                 D    t        |t              rt        |   |      S y)NF)
isinstancer
   r   __eq__)r   or   s     r   r8   zStream.__eq__Y   s    a 7>!$$r   c                 D    t        | j                  | j                  f      S r/   )hashr2   r   r3   s    r   __hash__zStream.__hash__^   s    T__dkk233r   c                 >    d| j                    d| j                  ddS )Nztorch.xpu.Stream(device=z sycl_queue=#x))r   r2   r3   s    r   __repr__zStream.__repr__a   s$    )$++l4??SUBVVWXXr   )Nr   r   Nr/   )__name__
__module____qualname____doc__r   r   r#   r!   boolr)   r-   propertyr4   r8   r<   r@   __classcell__r   s   @r   r
   r
      sR    I	/t  0 0
4Yr   r
   c                   |     e Zd ZdZd fd	Zdd fdZdd fdZdef fdZ fdZ	d fdZ
ed	        Zd
 Z xZS )r%   a  Wrapper around a XPU event.

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

    The underlying XPU events are lazily initialized when the event is first
    recorded. 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``)
    c                 &    t         |   | |      S )N)enable_timing)r   r   )r   rL   r   s     r   r   zEvent.__new__t   s    ws-@@r   r   c                 d    |t         j                  j                         }t        |   |       y)zRecord the event in a given stream.

        Uses ``torch.xpu.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&   zEvent.recordw   s(     >YY--/Fvr   c                 d    |t         j                  j                         }t        |   |       y)zMake all future work submitted to the given stream wait for this event.

        Use ``torch.xpu.current_stream()`` if no stream is specified.
        N)r   r   rN   r   r   rO   s     r   r   z
Event.wait   s(    
 >YY--/FVr   c                      t         |          S )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)   zEvent.query   s     w}r   c                 "    t         |   |      S )zReturn 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   rS   zEvent.elapsed_time   s     w#I..r   c                 "    t         |           y)zWait 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.
        Nr,   r*   s    r   r-   zEvent.synchronize   s     	r   c                 @    t        j                  | j                        S r/   )r0   r1   
sycl_eventr3   s    r   r4   zEvent._as_parameter_   r5   r   c                 >    | j                   rd| j                   ddS y)Nztorch.xpu.Event(sycl_event=r>   r?   ztorch.xpu.Event(uninitialized))rW   r3   s    r   r@   zEvent.__repr__   s"    ??00DAFF3r   )Fr/   rA   )rB   rC   rD   rE   r   r&   r   rF   r)   rS   r-   rG   r4   r@   rH   rI   s   @r   r%   r%   e   sG    At / 0 04r   r%   )r0   r   torch._streambaser   r   _utilsr   hasattr_C__dict__r   r
   r   r%    r   r   <module>r_      s      5   uxx)**56F*GEHH&')4_)EEHHo&RYUXX$$k RYjF4EHH""J F4r   