Ë
    Q/æjQ=  ã                   ó.  — U d Z ddlZddlZddlmZ ddlmZmZmZm	Z	m
Z
mZmZ ddlZddlZddlmZ ddlmZmZ ddlmZ dd	lmZmZ d
a ej4                  «       Z ej8                  «       Zg ae	eeg df   e	e   f      e d<    e!ejD                  dd„ «      Z#eeee$df   Z% e«       a&dZ'eejD                  jP                     e d<   de)fd„Z* e*«       rCejD                  jV                  Z+ejD                  jX                  Z-ejD                  j\                  Z/n ed«      Z+de$de$fd„Z-de$de$fd„Z/ ed¬«      de$fd„«       Z0de)fd„Z1d„ Z2d„ Z3d„ Z4d„ Z5d„ Z6 G d„ d«      Z7 G d „ d«      Z G d!„ d"e«      Z8de%ddfd#„Z9d9de
e%   defd$„Z: ed«      d9de
e%   deeef   fd%„«       Z;d9de
e%   de+fd&„Z<de$fd'„Z=dee$eej                  f   dej                  fd(„Z> G d)„ d*«      Z?d+e
d,   de?fd-„Z@d.„ ZAd+efd/„ZBd9de
e%   defd0„ZCd9de%ddfd1„ZDdej                  dejD                  jP                  fd2„ZE	 d:d3e$dee$eej                  f   ddfd4„ZFd:dee$eej                  f   de$fd5„ZGdd6lHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQ dd7lRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[ g d8¢Z\y);zó
This package introduces support for the XPU backend, specifically tailored for
Intel GPU optimization.

This package is lazily initialized, so you can always import it, and use
:func:`is_available()` to determine if your system supports XPU.
é    N)Ú	lru_cache)ÚAnyÚCallableÚDictÚListÚOptionalÚTupleÚUnion©Údevice)Ú_dummy_typeÚ_LazySeedTrackeré   )Ú_get_device_index)ÚEventÚStreamFÚ_queued_callsÚ_xpu_isInBadForkc                   ó   — y©NF© r   ó    úU/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/torch/xpu/__init__.pyú<lambda>r      s   � r   r   Údefault_generatorsÚreturnc                  ó6   — t         j                  j                  S )z(Return true if compile with XPU support.)ÚtorchÚ_CÚ_has_xpur   r   r   Ú_is_compiledr!   #   s   € ä�8‰8×ÑÐr   Ú_XpuDevicePropertiesr   c                 ó   — t        d«      ‚©Nz(PyTorch was compiled without XPU support©ÚNotImplementedErrorr   s    r   Ú_exchange_devicer'   0   ó   € Ü!Ð"LÓMÐMr   c                 ó   — t        d«      ‚r$   r%   r   s    r   Ú_maybe_exchange_devicer*   3   r(   r   )Úmaxsizec                  óT   — t        «       syt        j                  j                  «       S )z*Return the number of XPU device available.r   )r!   r   r   Ú_xpu_getDeviceCountr   r   r   Údevice_countr.   7   s   € ô Œ>ØÜ�8‰8×'Ñ'Ó)Ð)r   c                  ó   — t        «       dkD  S )z7Return a bool indicating if XPU is currently available.r   )r.   r   r   r   Úis_availabler0   ?   s   € ô ‹>˜AÑÐr   c                   ó   — y)zKReturn a bool indicating if the current XPU device supports dtype bfloat16.Tr   r   r   r   Úis_bf16_supportedr2   E   s   € àr   c                  ó(   — t         xr t        «        S )z8Return whether PyTorch's XPU state has been initialized.)Ú_initializedÚ_is_in_bad_forkr   r   r   Úis_initializedr6   J   s   € äÒ1¤Ó 1Ð1Ð1r   c                 óf  — t        «       r | «        y |j                  dd«      r)t        j                  | t	        j
                  «       «       y |j                  dd«      r)t        j                  | t	        j
                  «       «       y t        j                  | t	        j
                  «       f«       y )NÚseed_allFÚseed)	r6   ÚgetÚ_lazy_seed_trackerÚqueue_seed_allÚ	tracebackÚformat_stackÚ
queue_seedr   Úappend)ÚcallableÚkwargss     r   Ú
_lazy_callrC   O   s{   € ÜÔÙ�
ð �:‰:�j %Ô(Ü×-Ñ-¨h¼	×8NÑ8NÓ8PÕQØ�Z‰Z˜ Ô&Ü×)Ñ)¨(´I×4JÑ4JÓ4LÕMô × Ñ  (¬I×,BÑ,BÓ,DÐ!EÕFr   c                  ó   — t        «        y)z×Initialize PyTorch's XPU state.
    This is a Python API about lazy initialization that avoids initializing
    XPU until the first time it is accessed. Does nothing if the XPU state is
    already initialized.
    N)Ú
_lazy_initr   r   r   ÚinitrF   ]   s	   € ô …Lr   c            	      ó˜  — t        «       st        t        d«      ry t        5  t        «       r
	 d d d «       y t	        «       rt        d«      ‚t        «       st        d«      ‚t        j                  j                  «        dt        _        t        j                  «       D ]  } | sŒt        j                  | «       Œ 	 t        D ]  \  }}	  |«        Œ 	 t'        t        d«       dad d d «       y # t         $ r1}dt#        |«      › ddj%                  |«      › �}t!        |«      |‚d }~ww xY w# t'        t        d«       w xY w# 1 sw Y   y xY w)NÚis_initializingzuCannot re-initialize XPU in forked subprocess. To use XPU with multiprocessing, you must use the 'spawn' start methodz#Torch not compiled with XPU enabledTz5XPU call failed lazily at initialization with error: z'

XPU call was originally invoked at:

Ú )r6   ÚhasattrÚ_tlsÚ_initialization_lockr5   ÚRuntimeErrorr!   ÚAssertionErrorr   r   Ú	_xpu_initrH   r;   Ú	get_callsr   r@   Ú	ExceptionÚstrÚjoinÚdelattrr4   )ÚcallsÚqueued_callÚorig_tracebackÚeÚmsgs        r   rE   rE   f   sL  € äÔœ7¤4Ð):Ô;ØÜ	ñ #ô ÔØ÷	#ð #ô ÔÜðIóð ô Œ~Ü Ð!FÓGÐGä�‰×ÑÔð  $ŒÔä'×1Ñ1Ó3ò 	,ˆEÚÜ×$Ñ$ UÕ+ð	,ð	-Ü/<ò 0Ñ+�˜^ð0Ù•Mñ0ô ”DÐ+Ô,Øˆ÷G#ð #øô6 !ò 0àOÔPSÐTUÓPVÈxð XBØBDÇ'Á'È.ÓBYÐAZð\ð ô $ C›.¨aÐ/ûð0ûô ”DÐ+Õ,ú÷E#ð #úsS   ¢E ·A,E Â$E Â<D+Ã	C.ÃD+ÃE Ã.	D(Ã7,D#Ä#D(Ä(D+Ä+D=Ä=E Å E	c                   ó2   — e Zd Zdefd„Zd„ Zdededefd„Zy)	Ú_DeviceGuardÚindexc                 ó    — || _         d| _        y ©Néÿÿÿÿ)ÚidxÚprev_idx)Úselfr\   s     r   Ú__init__z_DeviceGuard.__init__‘   s   € ØˆŒØˆ�r   c                 ó`   — t         j                  j                  | j                  «      | _        y ©N©r   Úxpur'   r`   ra   ©rb   s    r   Ú	__enter__z_DeviceGuard.__enter__•   ó   € ÜŸ	™	×2Ñ2°4·8±8Ó<ˆ�r   ÚtypeÚvaluer=   c                 ó`   — t         j                  j                  | j                  «      | _        yr   ©r   rg   r*   ra   r`   ©rb   rk   rl   r=   s       r   Ú__exit__z_DeviceGuard.__exit__˜   ó   € Ü—9‘9×3Ñ3°D·M±MÓBˆŒØr   N)Ú__name__Ú
__module__Ú__qualname__Úintrc   ri   r   rp   r   r   r   r[   r[   �   s-   „ ð˜có ò=ð˜Sð ¨ð ¸ô r   r[   c                   ó6   — e Zd ZdZd efd„Zd„ Zdededefd„Zy)	r   zÓContext-manager that changes the selected device.

    Args:
        device (torch.device or int or str): device index to select. It's a no-op if
            this argument is a negative integer or ``None``.
    c                 ó6   — t        |d¬«      | _        d| _        y )NT©Úoptionalr_   )r   r`   ra   )rb   r   s     r   rc   zdevice.__init__¥   s   € Ü$ V°dÔ;ˆŒØˆ�r   c                 ó`   — t         j                  j                  | j                  «      | _        y re   rf   rh   s    r   ri   zdevice.__enter__©   rj   r   rk   rl   r=   c                 ó`   — t         j                  j                  | j                  «      | _        yr   rn   ro   s       r   rp   zdevice.__exit__¬   rq   r   N)rr   rs   rt   Ú__doc__r   rc   ri   rp   r   r   r   r   r   �   s2   „ ñð˜só ò=ð˜Sð ¨ð ¸ô r   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )Ú	device_ofa  Context-manager that changes the current device to that of given object.

    You can use both tensors and storages as arguments. If a given object is
    not allocated on a XPU, this is a no-op.

    Args:
        obj (Tensor or Storage): object allocated on the selected device.
    c                 ó`   •— |j                   r|j                  «       nd}t        ‰| �  |«       y r^   )Úis_xpuÚ
get_deviceÚsuperrc   )rb   Úobjr`   Ú	__class__s      €r   rc   zdevice_of.__init__»   s$   ø€ Ø"%§*¢*ˆc�n‰nÔ°"ˆÜ‰Ñ˜Õr   )rr   rs   rt   r|   rc   Ú__classcell__)r„   s   @r   r~   r~   ±   s   ø„ ñ÷ð r   r~   c                 óx   — t        «        t        | «      } | dk\  r t        j                  j	                  | «       yy)z¨Set the current device.

    Args:
        device (torch.device or int or str): selected device. This function is a
            no-op if this argument is negative.
    r   N)rE   r   r   r   Ú_xpu_setDevicer   s    r   Ú
set_devicerˆ   À   s1   € ô „LÜ˜vÓ&€FØ�‚{Ü�‰×Ñ Õ'ð r   c                 ó,   — t        | «      j                  S )a�  Get the name of a device.

    Args:
        device (torch.device or int or str, optional): device for which to
            return the name. This function is a no-op if this argument is a
            negative integer. It uses the current device, given by :func:`~torch.xpu.current_device`,
            if :attr:`device` is ``None`` (default).

    Returns:
        str: the name of the device
    )Úget_device_propertiesÚnamer   s    r   Úget_device_namerŒ   Í   s   € ô ! Ó(×-Ñ-Ð-r   c                 óŽ   — t        | «      }t        |«      D �ci c]!  }|j                  d«      rŒ|t        ||«      “Œ# c}S c c}w )aÐ  Get the xpu capability of a device.

    Args:
        device (torch.device or int or str, optional): device for which to
            return the device capability. This function is a no-op if this
            argument is a negative integer. It uses the current device, given by
            :func:`~torch.xpu.current_device`, if :attr:`device` is ``None``
            (default).

    Returns:
        Dict[str, Any]: the xpu capability dictionary of the device
    Ú__)rŠ   ÚdirÚ
startswithÚgetattr)r   ÚpropsÚprops      r   Úget_device_capabilityr”   Ü   sG   € ô " &Ó)€Eä/2°5«zöØ'+ÀÇÁÐQUÕAVˆŒg�e˜TÓ"Ñ"òð ùò s
   ™A°Ac                 ó€   — t        «        t        | d¬«      } | dk  s| t        «       k\  rt        d«      ‚t	        | «      S )zêGet the properties of a device.

    Args:
        device (torch.device or int or str): device for which to return the
            properties of the device.

    Returns:
        _XpuDeviceProperties: the properties of the device
    Trx   r   zInvalid device index)rE   r   r.   rN   Ú_get_device_propertiesr   s    r   rŠ   rŠ   ð   s<   € ô „LÜ˜v°Ô5€FØ�‚z�Vœ|›~Ò-ÜÐ3Ó4Ð4Ü! &Ó)Ð)r   c                  óR   — t        «        t        j                  j                  «       S )z0Return the index of a currently selected device.)rE   r   r   Ú_xpu_getDevicer   r   r   Úcurrent_devicer™     s   € ä„LÜ�8‰8×"Ñ"Ó$Ð$r   c                 ó    — t        | t        «      rt        j                  | «      } | S t        | t        «      rt        j                  d| «      } | S )zŒReturn the torch.device type object from the passed in device.

    Args:
        device (torch.device or int or str): selected device.
    rg   )Ú
isinstancerR   r   r   ru   r   s    r   Ú_get_devicerœ     sD   € ô �&œ#ÔÜ—‘˜fÓ%ˆð €Mô 
�FœCÔ	 Ü—‘˜e VÓ,ˆØ€Mr   c                   óN   — e Zd ZU dZed   ed<   ded   fd„Zd„ Zdeded	efd
„Z	y)ÚStreamContexta  Context-manager that selects a given stream.

    All XPU kernels queued within its context will be enqueued on a selected
    stream.

    Args:
        Stream (Stream): selected stream. This manager is a no-op if it's
            ``None``.
    .. note:: Streams are per-device.
    útorch.xpu.StreamÚ
cur_streamÚstreamc                 ó\   — || _         t        d d«      | _        | j                  €d| _        y y )NTr_   )r¡   r   r`   )rb   r¡   s     r   rc   zStreamContext.__init__!  s-   € ØˆŒÜ$ T¨4Ó0ˆŒØ�8‰8ÐØˆD�Hð r   c                 ó¼  — | j                   }|�| j                  dk(  ry t        j                  j	                  d «      | _        | j
                  j                  |j                  k7  rLt        |j                  «      5  t        j                  j	                  |j                  «      | _        d d d «       t        j                  j                  |«       y # 1 sw Y   Œ)xY wr^   )	r¡   r`   r   rg   Úcurrent_streamÚsrc_prev_streamr   Údst_prev_streamÚ
set_stream)rb   r    s     r   ri   zStreamContext.__enter__'  s§   € Ø—[‘[ˆ
ØÐ §¡¨R¢ØÜ$Ÿy™y×7Ñ7¸Ó=ˆÔð ×Ñ×&Ñ&¨*×*;Ñ*;Ò;Ü˜
×)Ñ)Ó*ñ SÜ',§y¡y×'?Ñ'?À
×@QÑ@QÓ'R�Ô$÷Sä�	‰	×Ñ˜ZÕ(÷Sð Sús   Á;/CÃCrk   rl   r=   c                 ó*  — | j                   }|�| j                  dk(  ry | j                  j                  |j                  k7  r)t        j
                  j                  | j                  «       t        j
                  j                  | j                  «       y r^   )r¡   r`   r¥   r   r   rg   r§   r¦   )rb   rk   rl   r=   r    s        r   rp   zStreamContext.__exit__3  sj   € Ø—[‘[ˆ
ØÐ §¡¨R¢Øð ×Ñ×&Ñ&¨*×*;Ñ*;Ò;Ü�I‰I× Ñ  ×!5Ñ!5Ô6Ü�	‰	×Ñ˜T×1Ñ1Õ2r   N)
rr   rs   rt   r|   r   Ú__annotations__rc   ri   r   rp   r   r   r   rž   rž     sF   … ñ	ð Ð+Ñ,Ó,ð˜xÐ(:Ñ;ó ò
)ð3˜Sð 3¨ð 3¸ô 3r   rž   r¡   rŸ   c                 ó   — t        | «      S )z³Wrap around the Context-manager StreamContext that selects a given stream.

    Arguments:
        stream (Stream): selected stream. This manager is a no-op if it's ``None``.
    )rž   ©r¡   s    r   r¡   r¡   >  s   € ô ˜Ó Ð r   c                 óH   — t         j                  j                  | ||¬«       y)a  set stream specified by the stream id, device index and device type

    Args: stream_id (int): not visible to the user, used to assigned to the specific stream.
          device_index (int): selected device index.
          device_type (int): selected device type.
    ©Ú	stream_idÚdevice_indexÚdevice_typeN)r   r   Ú_xpu_setStreamr­   s      r   Ú_set_stream_by_idr²   G  s$   € ô 
‡H�H×ÑØØ!Øð õ r   c                 óv   — | €yt        «        t        | j                  | j                  | j                  ¬«       y)a  Set the current stream.This is a wrapper API to set the stream.
        Usage of this function is discouraged in favor of the ``stream``
        context manager.

    Args:
        stream (Stream): selected stream. This function is a no-op
            if this argument is ``None``.
    Nr­   )rE   r²   r®   r¯   r°   r«   s    r   r§   r§   U  s4   € ð €~ØÜ„LÜØ×"Ñ"Ø×(Ñ(Ø×&Ñ&ör   c                 ó˜   — t        «        t        j                  j                  t	        | d¬«      «      }t        |d   |d   |d   ¬«      S )aR  Return the currently selected :class:`Stream` for a given device.

    Args:
        device (torch.device or int, optional): selected device. Returns
            the currently selected :class:`Stream` for the current device, given
            by :func:`~torch.xpu.current_device`, if :attr:`device` is ``None``
            (default).
    Trx   r   r   é   r­   )rE   r   r   Ú_xpu_getCurrentStreamr   r   )r   Ú
streamdatas     r   r¤   r¤   h  sJ   € ô „LÜ—‘×/Ñ/Ü˜&¨4Ô0ó€Jô Ø˜Q‘-¨j¸©mÈÐTUÉôð r   c                 ón   — t        «        t        | d¬«      } t        j                  j	                  | «      S )a*  Wait for all kernels in all streams on a XPU device to complete.

    Args:
        device (torch.device or int, optional): device for which to synchronize.
            It uses the current device, given by :func:`~torch.xpu.current_device`,
            if :attr:`device` is ``None`` (default).
    Trx   )rE   r   r   r   Ú_xpu_synchronizer   s    r   Úsynchronizerº   z  s*   € ô „LÜ˜v°Ô5€FÜ�8‰8×$Ñ$ VÓ,Ð,r   c                 ól   — | j                   }|€
t        «       }t        j                  j                  |   S )zuReturn the XPU Generator object for the given device.

    Args:
        device (torch.device): selected device.
    )r\   r™   r   rg   r   )r   r`   s     r   Ú_get_generatorr¼   ‡  s/   € ð �,‰,€CØ
€{ÜÓˆÜ�9‰9×'Ñ'¨Ñ,Ð,r   Úoffsetc                 ó@   ‡ ‡— t        |«      Šˆˆ fd„}t        |«       y)a$  Set the random number generator state offset of the specified GPU.

    Args:
        offset (int): The desired offset
        device (torch.device or int, optional): The device to set the RNG state.
            Default: ``'xpu'`` (i.e., ``torch.device('xpu')``, the current XPU device).
    c                  ó>   •— t        ‰«      } | j                  ‰«       y re   )r¼   Ú
set_offset)Údefault_generatorÚfinal_devicer½   s    €€r   Úcbz!_set_rng_state_offset.<locals>.cbŸ  s   ø€ Ü*¨<Ó8ÐØ×$Ñ$ VÕ,r   N)rœ   rC   )r½   r   rÃ   rÂ   s   `  @r   Ú_set_rng_state_offsetrÄ   “  s   ù€ ô ˜vÓ&€Lõ-ô ˆr…Nr   c                 ób   — t        «        t        | «      }t        |«      }|j                  «       S )aL  Return the random number generator state offset of the specified GPU.

    Args:
        device (torch.device or int, optional): The device to return the RNG state offset of.
            Default: ``'xpu'`` (i.e., ``torch.device('xpu')``, the current XPU device).

    .. warning::
        This function eagerly initializes XPU.
    )rE   rœ   r¼   Ú
get_offset)r   rÂ   rÁ   s      r   Ú_get_rng_state_offsetrÇ   ¦  s-   € ô „LÜ˜vÓ&€LÜ& |Ó4ÐØ×'Ñ'Ó)Ð)r   )	Úempty_cacheÚmax_memory_allocatedÚmax_memory_reservedÚmemory_allocatedÚmemory_reservedÚmemory_statsÚmemory_stats_as_nested_dictÚreset_accumulated_memory_statsÚreset_peak_memory_stats)	Úget_rng_stateÚget_rng_state_allÚinitial_seedÚmanual_seedÚmanual_seed_allr9   r8   Úset_rng_stateÚset_rng_state_all)(r   r   rž   r™   r¤   r   r   r~   r.   rÈ   r”   rŒ   rŠ   rÑ   rÒ   Ú
get_streamrF   rÓ   r0   r2   r6   rÔ   rÕ   rÉ   rÊ   rË   rÌ   rÍ   rÎ   rÏ   rÐ   r9   r8   rˆ   rÖ   r×   r§   r¡   Ústreamsrº   re   )rg   )]r|   Ú	threadingr=   Ú	functoolsr   Útypingr   r   r   r   r   r	   r
   r   Útorch._Cr   Ú_deviceÚtorch._utilsr   r   Ú_utilsr   rÙ   r   r   r4   ÚlocalrK   ÚLockrL   r   rR   r©   r‘   r   r5   ru   Ú	_device_tr;   r   Ú	GeneratorÚboolr!   r"   Ú_xpu_exchangeDevicer'   Ú_xpu_maybeExchangeDevicer*   r.   r0   r2   r6   rC   rF   rE   r[   r~   rˆ   rŒ   r”   rŠ   r™   rœ   rž   r¡   r²   r§   r¤   rº   r¼   rÄ   rÇ   ÚmemoryrÈ   rÉ   rÊ   rË   rÌ   rÍ   rÎ   rÏ   rÐ   ÚrandomrÑ   rÒ   rÓ   rÔ   rÕ   r9   r8   rÖ   r×   Ú__all__r   r   r   ú<module>rë      sX  ðòó Û Ý ß D× DÑ Dã Û Ý #ß 6å %ß "ð €Ø€y‡�Ó€Ø%�y—~‘~Ó'Ð ð ð ˆtØ	ˆ(�2�t�8Ñ
˜d 3™iÐ
'Ñ(ñó ñ ˜%Ÿ(™(Ð$6¹ÓF€Ø�'˜3  TÐ)Ñ*€	Ù%Ó'Ð Ø02Ð �E˜%Ÿ(™(×,Ñ,Ñ-Ó 2ð�dó ñ
 „>Ø Ÿ8™8×8Ñ8ÐØ—x‘x×3Ñ3ÐØ"ŸX™X×>Ñ>Ññ 'Ð'=Ó>ÐðN ð N¨ó NðN sð N¨só Nñ �1Ôð*�cò *ó ð*ð�dó òò
2ò
Gòò'÷T
ñ 
÷ñ ô(�ô ð
(�yð 
( Tó 
(ñ.˜H YÑ/ð .¸3ó .ñ ˆ4ƒñ (¨9Ñ"5ð ÀÀcÈ3ÀhÁò ó ðñ&* (¨9Ñ"5ð *ÐAUó *ð"%˜ó %ð
˜˜c 3¨¯©Ð4Ñ5ð 
¸%¿,¹,ó 
÷'3ñ '3ðT!�8Ð.Ñ/ð !°Mó !òð�vó ñ&˜8 IÑ.ð ¸&ó ñ$
-˜	ð 
-¨Tó 
-ð	-˜5Ÿ<™<ð 	-¨E¯H©H×,>Ñ,>ó 	-ð :?ñØðØ˜s C¨¯©Ð5Ñ6ðà	óñ&* %¨¨S°%·,±,Ð(>Ñ"?ð *ÈCó *÷"
÷ 
õ 
÷
÷ 
õ 
ò)�r   