ó
    EñiB*  ã                   óØ  • S r SSKJr  SSKJr  SSKJr  SSKrSSKJ	r	J
r
  SSKJrJrJrJrJrJrJrJrJr  / S	QrS
\4S jrS
\4S jrSS\S
\R4                  S-  4S jjrS
\4S jr\" S\S9" \5      rS\l         \SS\	S
\\ \4   4S jj5       r!S\	S
S4S jr"\" S\S9" \"5      r#S\#l         SS\	S
\RH                  4S jjr%S\RH                  S
S4S jr&SS\	S
S4S jjr' " S S5      r(g) z]
This package introduces support for the current :ref:`accelerator<accelerators>` in python.
é    )Úcache)ÚAny)Ú
deprecatedNé   )Ú	_device_tÚ_get_device_index)	Úempty_cacheÚget_memory_infoÚmax_memory_allocatedÚmax_memory_reservedÚmemory_allocatedÚmemory_reservedÚmemory_statsÚreset_accumulated_memory_statsÚreset_peak_memory_stats)Úcurrent_acceleratorÚcurrent_device_idxÚcurrent_device_indexÚget_device_capabilityÚcurrent_streamÚdevice_countÚdevice_indexr	   r
   Úis_availabler   r   r   r   r   r   r   Úset_device_idxÚset_device_indexÚ
set_streamÚsynchronizeÚreturnc                  ój   • [        5       n U c  g[        R                  " U 5      nUR                  5       $ )aÉ  Return the number of current :ref:`accelerator<accelerators>` available.

Returns:
    int: the number of the current :ref:`accelerator<accelerators>` available.
        If there is no available accelerators, return 0.

.. note:: This API delegates to the device-specific version of `device_count`.
    On CUDA, this API will NOT poison fork if NVML discovery succeeds.
    Otherwise, it will. For more details, see :ref:`multiprocessing-poison-fork-note`.
r   )r   ÚtorchÚget_device_moduler   ©ÚaccÚmods     ÚW/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/accelerator/__init__.pyr   r   2   s3   € ô Ó
€CØ
�{Øä
×
!Ò
! #Ó
&€CØ×ÑÓÐó    c                  ój   • [        5       n U c  g[        R                  " U 5      nUR                  5       $ )a±  Check if the current accelerator is available at runtime: it was build, all the
required drivers are available and at least one device is visible.
See :ref:`accelerator<accelerators>` for details.

Returns:
    bool: A boolean indicating if there is an available :ref:`accelerator<accelerators>`.

.. note:: This API delegates to the device-specific version of `is_available`.
    On CUDA, when the environment variable ``PYTORCH_NVML_BASED_CUDA_CHECK=1`` is set,
    this function will NOT poison fork. Otherwise, it will. For more details, see
    :ref:`multiprocessing-poison-fork-note`.

Example::

    >>> assert torch.accelerator.is_available() "No available accelerators detected."
F)r   r    r!   r   r"   s     r%   r   r   E   s3   € ô* Ó
€CØ
�{Øä
×
!Ò
! #Ó
&€CØ×ÑÓÐr&   Úcheck_availablec                 ó„   • [         R                  R                  5       =nb  U (       a  U (       a  [        5       (       a  U$ g)aþ  Return the device of the accelerator available at compilation time.
If no accelerator were available at compilation time, returns None.
See :ref:`accelerator<accelerators>` for details.

Args:
    check_available (bool, optional): if True, will also do a runtime check to see
        if the device :func:`torch.accelerator.is_available` on top of the compile-time
        check.
        Default: ``False``

Returns:
    torch.device: return the current accelerator as :class:`torch.device`.

.. note:: The index of the returned :class:`torch.device` will be ``None``, please use
    :func:`torch.accelerator.current_device_index` to know the current index being used.
    This API does NOT poison fork. For more details, see :ref:`multiprocessing-poison-fork-note`.

Example::

    >>> # xdoctest:
    >>> # If an accelerator is available, sent the model to it
    >>> model = torch.nn.Linear(2, 2)
    >>> if (current_device := current_accelerator(check_available=True)) is not None:
    >>>     model.to(current_device)
N)r    Ú_CÚ_accelerator_getAcceleratorr   )r(   r#   s     r%   r   r   b   s/   € ô4 �x‰x×3Ñ3Ó5Ð5ˆÑBÞ¦_¼¿¹ØˆJØr&   c                  ó>   • [         R                  R                  5       $ )zŸReturn the index of a currently selected device for the current :ref:`accelerator<accelerators>`.

Returns:
    int: the index of a currently selected device.
)r    r*   Ú_accelerator_getDeviceIndex© r&   r%   r   r   ‚   s   € ô �8‰8×/Ñ/Ó1Ð1r&   z#Use `current_device_index` instead.)Úcategorya‡  
    (Deprecated) Return the index of a currently selected device for the current :ref:`accelerator<accelerators>`.

    Returns:
        int: the index of a currently selected device.

    .. warning::

        :func:`torch.accelerator.current_device_idx` is deprecated in favor of :func:`torch.accelerator.current_device_index`
        and will be removed in a future PyTorch release.
    Údevicec                óT   • [        U SS9n[        R                  R                  U5      $ )aî  Return the capability of the currently selected device.

Args:
    device (:class:`torch.device`, str, int, optional): The device to query capabilities for
        :ref:`accelerator<accelerators>` device type. If not given,
        use :func:`torch.accelerator.current_device_index` by default.

Returns:
    dict[str, Any]: A dictionary containing device capability information. The dictionary includes:
        - ``supported_dtypes`` (set(torch.dtype)): Set of PyTorch data types supported by the device

Examples:
    >>> # xdoctest: +SKIP("requires cuda")
    >>> # Query capabilities for current device
    >>> capabilities = torch.accelerator.get_device_capability("cuda:0")
    >>> print("Supported dtypes:", capabilities["supported_dtypes"])
T©Úoptional)r   r    r*   Ú _accelerator_getDeviceCapability©r0   r   s     r%   r   r   �   s%   € ô& % V°dÑ;€Lä�8‰8×4Ñ4°\ÓBÐBr&   c                óV   • [        U SS9n[        R                  R                  U5        g)a  Set the current device index to a given device.

Args:
    device (:class:`torch.device`, str, int): a given device that must match the current
        :ref:`accelerator<accelerators>` device type.

.. note:: This function is a no-op if this device index is negative.
Fr2   N)r   r    r*   Ú_accelerator_setDeviceIndexr5   s     r%   r   r   µ   s"   € ô % V°eÑ<€LÜ	‡H�H×(Ñ(¨Õ6r&   zUse `set_device_index` instead.aª  
    (Deprecated) Set the current device index to a given device.

    Args:
        device (:class:`torch.device`, str, int): a given device that must match the current
            :ref:`accelerator<accelerators>` device type.

    .. warning::

        :func:`torch.accelerator.set_device_idx` is deprecated in favor of :func:`torch.accelerator.set_device_index`
        and will be removed in a future PyTorch release.
    c                óT   • [        U SS9n[        R                  R                  U5      $ )a|  Return the currently selected stream for a given device.

Args:
    device (:class:`torch.device`, str, int, optional): a given device that must match the current
        :ref:`accelerator<accelerators>` device type. If not given,
        use :func:`torch.accelerator.current_device_index` by default.

Returns:
    torch.Stream: the currently selected stream for a given device.
Tr2   )r   r    r*   Ú_accelerator_getStreamr5   s     r%   r   r   Õ   s%   € ô % V°dÑ;€LÜ�8‰8×*Ñ*¨<Ó8Ð8r&   Ústreamc                 óB   • [         R                  R                  U 5        g)a	  Set the current stream to a given stream.

Args:
    stream (torch.Stream): a given stream that must match the current :ref:`accelerator<accelerators>` device type.

.. note:: This function will set the current device index to the device index of the given stream.
N)r    r*   Ú_accelerator_setStream)r:   s    r%   r   r   ä   s   € ô 
‡H�H×#Ñ# FÕ+r&   c                óV   • [        U SS9n[        R                  R                  U5        g)aÄ  Wait for all kernels in all streams on the given device to complete.

Args:
    device (:class:`torch.device`, str, int, optional): device for which to synchronize. It must match
        the current :ref:`accelerator<accelerators>` device type. If not given,
        use :func:`torch.accelerator.current_device_index` by default.

.. note:: This function is a no-op if the current :ref:`accelerator<accelerators>` is not initialized.

Example::

    >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
    >>> assert torch.accelerator.is_available() "No available accelerators detected."
    >>> start_event = torch.Event(enable_timing=True)
    >>> end_event = torch.Event(enable_timing=True)
    >>> start_event.record()
    >>> tensor = torch.randn(100, device=torch.accelerator.current_accelerator())
    >>> sum = torch.sum(tensor)
    >>> end_event.record()
    >>> torch.accelerator.synchronize()
    >>> elapsed_time_ms = start_event.elapsed_time(end_event)
Tr2   N)r   r    r*   Ú_accelerator_synchronizeDevicer5   s     r%   r   r   ï   s"   € ô. % V°dÑ;€LÜ	‡H�H×+Ñ+¨LÕ9r&   c                   óL   • \ rS rSrSrS\S-  SS4S jrSS jrS\SS4S	 jr	S
r
g)r   i
  aM  Context manager to set the current device index for the current :ref:`accelerator<accelerators>`.
Temporarily changes the current device index to the specified value for the duration
of the context, and automatically restores the previous device index when exiting
the context.

Args:
    device (Optional[int]): a given device index to temporarily set. If None,
        no device index switching occurs.

Examples:

    >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
    >>> # Set device 0 as the current device temporarily
    >>> with torch.accelerator.device_index(0):
    ...     # Code here runs with device 0 as the current device
    ...     pass
    >>> # Original device is now restored
    >>> # No-op when None is passed
    >>> with torch.accelerator.device_index(None):
    ...     # No device switching occurs
    ...     pass
r0   Nr   c                ó   • Xl         SU l        g )Néÿÿÿÿ©ÚidxÚprev_idx)Úselfr0   s     r%   Ú__init__Údevice_index.__init__"  s   € ØŒØˆ�r&   c                 ó|   • U R                   b/  [        R                  R                  U R                   5      U l        g g ©N)rC   r    r*   Ú_accelerator_exchangeDevicerD   )rE   s    r%   Ú	__enter__Údevice_index.__enter__&  s+   € Ø�8‰8ÑÜ!ŸH™H×@Ñ@ÀÇÁÓJˆD�Mð  r&   Úexc_infoc                 ór   • U R                   b*  [        R                  R                  U R                  5        g g rI   )rC   r    r*   Ú _accelerator_maybeExchangeDevicerD   )rE   rM   s     r%   Ú__exit__Údevice_index.__exit__*  s'   € Ø�8‰8ÑÜ�H‰H×5Ñ5°d·m±mÕDð  r&   rB   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚintrF   rK   ÚobjectrP   Ú__static_attributes__r.   r&   r%   r   r   
  s:   † ñð.˜s T™zð °ô ôKðE &ð E¨T÷ Er&   r   )FrI   ))rV   Ú	functoolsr   Útypingr   Útyping_extensionsr   r    Ú_utilsr   r   Úmemoryr	   r
   r   r   r   r   r   r   r   Ú__all__rW   r   Úboolr   r0   r   r   ÚFutureWarningr   ÚdictÚstrr   r   r   ÚStreamr   r   r   r   r.   r&   r%   Ú<module>re      sN  ðñõ Ý Ý (ã ç 0÷
÷ 
õ 
ò€ð2�cô ð&�dô ñ:¨ð ¸%¿,¹,ÈÑ:Mõ ð@2˜cô 2ñ  Ø)Øòð óÐ ð

Ð Ô ð ñC )ð C¸$¸sÀC¸x¹.ô Có ðCð.
7˜Yð 
7¨dô 
7ñ Ø%Øòð ó€ð
€Ô ñ9˜9ð 9°5·<±<õ 9ð,�u—|‘|ð ,¨ô ,ñ:˜	ð :°õ :÷6"Eò "Er&   