Ë
    ùÿæi!  ã            	       óÎ   — d dl mZ d dlZd dlZd dlmZ d dlmZ	 ddgZ
 G d„ dej                  «      Zej                  j                  ed«       ddd	œd
ede	dz  dedz  ddfd„Zy)é    )ÚAnyN)Ú
_to_dlpack)ÚDeviceÚDLDeviceTypeÚfrom_dlpackc                   óH   — e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZy)r   )é   )é   )é   )é   )é   )é   )é	   )é
   )é   )é   )é   )é   )é   )é   )é   N)Ú__name__Ú
__module__Ú__qualname__ÚkDLCPUÚkDLCUDAÚkDLCUDAHostÚ	kDLOpenCLÚ	kDLVulkanÚkDLMetalÚkDLVPIÚkDLROCMÚkDLROCMHostÚ	kDLExtDevÚkDLCUDAManagedÚ	kDLOneAPIÚ	kDLWebGPUÚ
kDLHexagonÚkDLMAIA© ó    úg/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torch/utils/dlpack.pyr   r      sM   „ à€FØ€GØ€KØ€IØ€IØ€HØ€FØ€GØ€KØ€IØ€NØ€IØ€IØ€JØ�Gr+   aÙ  to_dlpack(tensor) -> PyCapsule

Returns an opaque object (a "DLPack capsule") representing the tensor.

.. note::
  ``to_dlpack`` is a legacy DLPack interface. The capsule it returns
  cannot be used for anything in Python other than use it as input to
  ``from_dlpack``. The more idiomatic use of DLPack is to call
  ``from_dlpack`` directly on the tensor object - this works when that
  object has a ``__dlpack__`` method, which PyTorch and most other
  libraries indeed have now.

.. warning::
  Only call ``from_dlpack`` once per capsule produced with ``to_dlpack``.
  Behavior when a capsule is consumed multiple times is undefined.

Args:
    tensor: a tensor to be exported

The DLPack capsule shares the tensor's memory.
)ÚdeviceÚcopyÚ
ext_tensorr-   r.   Úreturnztorch.Tensorc                ó
  — t        | d«      �ri }d|d<   |}d}d}|�||d<   | j                  «       }|�™t        |t        «      rt	        j
                  |«      }t        |t        j
                  «      st        dt        |«      › �«      ‚t        j                  j                  |«      }||k7  }|s||d	<   |r|du rt        d
|› d|› d�«      ‚|d   t        j                  t        j                  fv r_t        j                  j                  d|d   › �«      }	|d   t        j                  k(  }
|
r|	j                   dk(  rdn|	j                   }||d<   d}	  | j"                  di |¤Ž}|€%|j'                  dd«       	  | j"                  di |¤Ž}|€'|j'                  dd«       d}	  | j"                  di |¤Ž}|€$|j'                  d	d«        | j"                  di |¤Ž}t        j                  j)                  |«      }|du r|s|s|j+                  «       }|r|j-                  |«      }|S |€|�t        d«      ‚| }t        j                  j)                  |«      S # t$        $ r Y Œýw xY w# t$        $ r Y Œåw xY w# t$        $ r Y ŒËw xY w)a½  from_dlpack(ext_tensor) -> Tensor

    Converts a tensor from an external library into a ``torch.Tensor``.

    The returned PyTorch tensor will share the memory with the input tensor
    (which may have come from another library). Note that in-place operations
    will therefore also affect the data of the input tensor. This may lead to
    unexpected issues (e.g., other libraries may have read-only flags or
    immutable data structures), so the user should only do this if they know
    for sure that this is fine.

    Args:
        ext_tensor (object with ``__dlpack__`` attribute, or a DLPack capsule):
            The tensor or DLPack capsule to convert.

            If ``ext_tensor`` is a tensor (or ndarray) object, it must support
            the ``__dlpack__`` protocol (i.e., have a ``ext_tensor.__dlpack__``
            method). Otherwise ``ext_tensor`` may be a DLPack capsule, which is
            an opaque ``PyCapsule`` instance, typically produced by a
            ``to_dlpack`` function or method.

        device (torch.device or str or None): An optional PyTorch device
            specifying where to place the new tensor. If None (default), the
            new tensor will be on the same device as ``ext_tensor``.

        copy (bool or None): An optional boolean indicating whether or not to copy
            ``self``. If None, PyTorch will copy only if necessary.

    Examples::

        >>> import torch.utils.dlpack
        >>> t = torch.arange(4)

        # Convert a tensor directly (supported in PyTorch >= 1.10)
        >>> t2 = torch.from_dlpack(t)
        >>> t2[:2] = -1  # show that memory is shared
        >>> t2
        tensor([-1, -1,  2,  3])
        >>> t
        tensor([-1, -1,  2,  3])

        # The old-style DLPack usage, with an intermediate capsule object
        >>> capsule = torch.utils.dlpack.to_dlpack(t)
        >>> capsule
        <capsule object "dltensor" at ...>
        >>> t3 = torch.from_dlpack(capsule)
        >>> t3
        tensor([-1, -1,  2,  3])
        >>> t3[0] = -9  # now we're sharing memory between 3 tensors
        >>> t3
        tensor([-9, -1,  2,  3])
        >>> t2
        tensor([-9, -1,  2,  3])
        >>> t
        tensor([-9, -1,  2,  3])

    Ú
__dlpack__)r	   r   Úmax_versionTFNr.   z&from_dlpack: unsupported device type: Ú	dl_devicez&cannot move DLPack tensor from device z to z- without copying. Set copy=None or copy=True.r   zcuda:r	   ÚstreamzQdevice and copy kwargs not supported when ext_tensor is already a DLPack capsule.r*   )ÚhasattrÚ__dlpack_device__Ú
isinstanceÚstrÚtorchr-   ÚAssertionErrorÚtypeÚ_CÚ_torchDeviceToDLDeviceÚ
ValueErrorr   r   r"   ÚcudaÚcurrent_streamÚcuda_streamr2   Ú	TypeErrorÚpopÚ_from_dlpackÚcloneÚto)r/   r-   r.   ÚkwargsÚrequested_copyÚproducer_handled_copyÚcross_device_transferÚ
ext_deviceÚtarget_dl_devicer5   Úis_cudaÚ
stream_ptrÚdlpackÚtensors                 r,   r   r   :   sä  € ô@ ˆz˜<Õ(ð "$ˆØ &ˆˆ}Ñð ˆØ $ÐØ %ÐàÐØ!ˆF�6‰Nð  ×1Ñ1Ó3ˆ
àÐÜ˜&¤#Ô&ÜŸ™ fÓ-�Ü˜f¤e§l¡lÔ3Ü$Ð'MÌdÐSYËlÈ^Ð%\Ó]Ð]ô  %Ÿx™x×>Ñ>¸vÓFÐð &0Ð3CÑ%CÐ!ñ )Ø&6��{Ñ#ñ %¨°©Ü Ø<¸Z¸LÈÐM]ÐL^ð _Cð Cóð ð �a‰=œ\×1Ñ1´<×3GÑ3GÐHÑHÜ—Z‘Z×.Ñ.°°zÀ!±}°oÐ/FÓGˆFð ! ‘m¤|×';Ñ';Ñ;ˆGñ &¨&×*<Ñ*<ÀÒ*A™Àv×GYÑGYˆJØ)ˆF�8Ñð ˆð	Ø*�Z×*Ñ*Ñ4¨VÑ4ˆFð
 ˆ>Ø�J‰J�} dÔ+ðØ.˜×.Ñ.Ñ8°Ñ8�ð
 ˆ>Ø�J‰J�v˜tÔ$Ø$)Ð!ðØ.˜×.Ñ.Ñ8°Ñ8�ð
 ˆ>Ø�J‰J�{ DÔ)Ø*�Z×*Ñ*Ñ4¨VÑ4ˆFä—‘×&Ñ& vÓ.ˆð ˜TÑ!Ñ*?ÑH]Ø—\‘\“^ˆFñ !Ø—Y‘Y˜vÓ&ˆFàˆð Ð Ð!1Ü Øcóð ð ˆÜ�x‰x×$Ñ$ VÓ,Ð,øôY ò 	Ùð	ûô ò Ùðûô ò Ùðús6   ÅI Å;I' Æ$I6 É	I$É#I$É'	I3É2I3É6	JÊJ)Útypingr   r:   ÚenumÚtorch._Cr   Ú	to_dlpackÚtorch.typesr   Ú_DeviceÚ__all__ÚIntEnumr   r=   Ú_add_docstrÚboolr   r*   r+   r,   Ú<module>r\      sŽ   ðÝ ã Û å ,Ý )ð Øð€ô
�4—<‘<ô ð& ‡�× Ñ �Yð !ô ð8 "Øò	m-Øðm-ð �d‰Nðm-ð �‰+ð	m-ð
 ôm-r+   