§
    �Štj!  ã            	       óÊ   — 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                             ed¦  «         ddd	œd
ede	dz  dedz  ddfd„ZdS )é    )ÚAnyN)Ú
_to_dlpack)ÚDeviceÚDLDeviceTypeÚfrom_dlpackc                   óJ   — 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dS )r   )é   )é   )é   )é   )é   )é   )é	   )é
   )é   )é   )é   )é   )é   )é   )é   N)Ú__name__Ú
__module__Ú__qualname__ÚkDLCPUÚkDLCUDAÚkDLCUDAHostÚ	kDLOpenCLÚ	kDLVulkanÚkDLMetalÚkDLVPIÚkDLROCMÚkDLROCMHostÚ	kDLExtDevÚkDLCUDAManagedÚ	kDLOneAPIÚ	kDLWebGPUÚ
kDLHexagonÚkDLMAIA© ó    úP/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/utils/dlpack.pyr   r      sY   € € € € € à€FØ€GØ€KØ€IØ€IØ€HØ€FØ€GØ€KØ€IØ€NØ€IØ€IØ€JØ€G€G€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¦  «        �rWi }d|d<   |}d}d}|�||d<   |                      ¦   «         }|�ªt          |t          ¦  «        rt	          j        |¦  «        }t          |t          j        ¦  «        st          dt          |¦  «        › �¦  «        ‚t          j         	                    |¦  «        }||k    }|s||d	<   |r|du rt          d
|› d|› d�¦  «        ‚|d         t          j        t          j        fv rYt          j                             d|d         › �¦  «        }	|d         t          j        k    }
|
r|	j        dk    rdn|	j        }||d<   d}	  | j        di |¤Ž}n# t$          $ r Y nw xY w|€5|                     dd¦  «         	  | j        di |¤Ž}n# t$          $ r Y nw xY w|€7|                     dd¦  «         d}	  | j        di |¤Ž}n# t$          $ r Y nw xY w|€#|                     d	d¦  «          | j        di |¤Ž}t          j                             |¦  «        }|du r|s|s|                     ¦   «         }|r|                     |¦  «        }|S |€|�t          d¦  «        ‚| }t          j                             |¦  «        S )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˜<Ñ(Ô(ñ m-ð "$ˆØ &ˆˆ}Ñð ˆØ $ÐØ %ÐàÐØ!ˆF�6‰Nð  ×1Ò1Ñ3Ô3ˆ
àÐÝ˜&¥#Ñ&Ô&ð .Ýœ fÑ-Ô-�Ý˜f¥e¤lÑ3Ô3ð ^Ý$Ð%\ÍdÐSYÉlÌlÐ%\Ð%\Ñ]Ô]Ð]õ  %œx×>Ò>¸vÑFÔFÐð &0Ð3CÒ%CÐ!ð )ð 7Ø&6��{Ñ#ð %ð ¨°¨¨Ý ðC¸Zð Cð CÐM]ð Cð Cð Cñô ð ð �aŒ=�\Ô1µ<Ô3GÐHÐHÐHÝ”Z×.Ò.Ð/F°zÀ!´}Ð/FÐ/FÑGÔGˆFð ! ”m¥|Ô';Ò;ˆGð &ÐY¨&Ô*<ÀÒ*AÐ*A˜˜ÀvÔGYˆJØ)ˆF�8Ñð ˆð	Ø*�ZÔ*Ð4Ð4¨VÐ4Ð4ˆFˆFøÝð 	ð 	ð 	ØˆDð	øøøð ˆ>Ø�JŠJ�} dÑ+Ô+Ð+ðØ.˜Ô.Ð8Ð8°Ð8Ð8��øÝð ð ð Ø�ðøøøð ˆ>Ø�JŠJ�v˜tÑ$Ô$Ð$Ø$)Ð!ðØ.˜Ô.Ð8Ð8°Ð8Ð8��øÝð ð ð Ø�ðøøøð ˆ>Ø�JŠJ�{ DÑ)Ô)Ð)Ø*�ZÔ*Ð4Ð4¨VÐ4Ð4ˆFå”×&Ò& vÑ.Ô.ˆð ˜TÐ!Ð!Ð*?Ð!ÐH]Ð!Ø—\’\‘^”^ˆFð !ð 	'Ø—Y’Y˜vÑ&Ô&ˆFàˆð Ð Ð!1Ý Øcñô ð ð ˆÝŒx×$Ò$ VÑ,Ô,Ð,s6   Å"E0 Å0
E=Å<E=ÆF' Æ'
F4Æ3F4ÇG  Ç 
G-Ç,G-)Ú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-ð m-Øðm-ð �d‰Nðm-ð �‰+ð	m-ð
 ðm-ð m-ð m-ð m-ð m-ð m-r+   