+
    ˜°³jí+  ã                   óæ   € ^ RI Ht ^ RIt^ RIt^ RIHt ^ RIHt	 . ROt
 ! R R]P                  4      t ! R R]P                  4      t]P                  P!                  ]R	4       R
RRR/R R lltR# )é    )ÚAnyN)Ú
_to_dlpack)ÚDeviceÚDLDeviceTypeÚReadOnlyTensorWrapperc                   óR   € ] tR t^tRtRtRtRtRtRt	R	t
R
tRtRtRtRtRtRtRtRtR# )r   © N)é   )é   )é   )é   )é   )é   )é	   )é
   )é   )é   )é   )é   )é   )é   )é   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚkDLCPUÚkDLCUDAÚkDLCUDAHostÚ	kDLOpenCLÚ	kDLVulkanÚkDLMetalÚkDLVPIÚkDLROCMÚkDLROCMHostÚ	kDLExtDevÚkDLCUDAManagedÚ	kDLOneAPIÚ	kDLWebGPUÚ
kDLHexagonÚkDLMAIAÚ__static_attributes__r	   ó    ÚS/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/utils/dlpack.pyr   r      sM   † à€FØ€GØ€KØ€IØ€IØ€HØ€FØ€GØ€KØ€IØ€NØ€IØ€IØ€JØ„Gr-   c                   ó  a a€ ] tR t^"t oRt]P                  P                  4       t]	! ]P                  P                  ]P                  P                  04      t]V3R lR l4       t]R
R l4       tRR/V 3R lltV3R ltR	tVtV ;t# )r   a%  A zero-copy, read-only view of a tensor for DLPack interop only.

Wrapping a tensor with ``ReadOnlyTensorWrapper`` declares the intent that
consumers must not mutate its data. It changes only the DLPack export
behavior; the wrapper shares storage with the source tensor and does not
copy.

Both DLPack export paths are routed to read-only variants:

* the fast ``__dlpack_c_exchange_api__`` C exchange protocol (used by
  tvm-ffi / CuteDSL) points at the const exchange API, which exports
  through ``const_data_ptr()`` and sets
  ``DLPACK_FLAG_BITMASK_READ_ONLY``;
* the ``__dlpack__()`` capsule protocol forces ``read_only=True``.

Because the export uses ``const_data_ptr()``, exporting a copy-on-write
tensor does not materialize it.

The wrapper is export-only: every torch operation other than the DLPack
protocol methods raises ``RuntimeError``. Unwrap it (e.g. via the original
tensor) to operate on the data.

Example::

    x = torch.randn(8)
    ro = ReadOnlyTensorWrapper(x)
    cute.runtime.from_dlpack(ro, enable_tvm_ffi=True)  # read-only export
c                ó8   <€ V ^8„  d   QhRS[ P                  RR/# )r   ÚtensorÚreturnr   )ÚtorchÚTensor)ÚformatÚ__classdict__s   "€r.   Ú__annotate__Ú"ReadOnlyTensorWrapper.__annotate__L   s    ø€ ÷ 'ñ '™UŸ\™\ð 'Ð.Eñ 'r-   c                ó$   € VP                  V 4      # )N)Úas_subclass)Úclsr1   s   &&r.   Ú__new__ÚReadOnlyTensorWrapper.__new__K   s   € à×!Ñ! #Ó&Ð&r-   Nc           	     ó  € WP                   9   dD   \        P                  P                  4       ;_uu_ 4        T! T/ T;'       g    / B uuR R R 4       # \	        V P
                   R\        VRV4       R24      h  + '       g   i     L6; i)Nz only supports DLPack export; 'r   z;' is not allowed. Unwrap the tensor to operate on its data.)Ú_DLPACK_ALLOWEDr3   Ú_CÚDisableTorchFunctionSubclassÚRuntimeErrorr   Úgetattr)r;   ÚfuncÚtypesÚargsÚkwargss   &&&&&r.   Ú__torch_function__Ú(ReadOnlyTensorWrapper.__torch_function__O   s{   € à×&Ñ&Ô&ô —‘×6Ñ6×8Õ8Ù˜TÐ4 f§l l°Ñ4÷ 9Ò8äØ�|‰|ˆnð Ü˜˜j¨$Ó/Ð0ð 18ð8ó
ð 	
÷ 9×8ús   ·A:Á:B
	Úmax_versionc               ó8   <€ Vf   Rp\         SV `  ! RRVRR/VB # )NrJ   Ú	read_onlyT©r
   r   r	   )ÚsuperÚ
__dlpack__)ÚselfrJ   rG   Ú	__class__s   &$,€r.   rO   Ú ReadOnlyTensorWrapper.__dlpack__\   s+   ø€ àÒØ ˆKÜ‰wÒ!ÑT¨kÐTÀTÐTÈVÑTÐTr-   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )r   Ú__dlpack_c_exchange_api__)Úobject)r5   r6   s   "€r.   r7   r8   "   s   ø‡ ‚ ñB  &ÑMòC r-   r	   )r	   N)r   r   r   r   Ú__doc__r3   r@   Ú_const_dlpack_exchange_apirT   Ú	frozensetr4   rO   Ú__dlpack_device__r?   Ústaticmethodr<   ÚclassmethodrH   Ú__annotate_func__r,   Ú__classdictcell__Ú__classcell__)rQ   r6   s   @@r.   r   r   "   s†   ù‡ € ñð@ ).¯©×(KÑ(KÓ(MÐñ  Ø	�‰×	 Ñ	  %§,¡,×"@Ñ"@ÐAó€Oð ÷'ó ð'ð ó

ó ð

ðU¨÷ U÷u … r-   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Úcopyc                ó\   € V ^8„  d   QhR\         R\        R,          R\        R,          RR/# )r   Ú
ext_tensorr_   Nr`   r2   ztorch.Tensor)r   Ú_DeviceÚbool)r5   s   "r.   r7   r7   |   s@   € ÷ m-ñ m-Üðm-ô �d�Nðm-ô ��+ð	m-ð
 ñm-r-   c               óÆ  € \        V R4      '       Edg   / pRVR&   TpRpRpVe   W#R&   V P                  4       pVe³   \        V\        4      '       d   \        P
                  ! V4      p\        V\        P
                  4      '       g   \        R\        V4       24      h\        P                  P                  V4      pWx8g  pV'       g   WƒR&   V'       d   VRJ d   \        R	V R
V R24      hV^ ,          \        P                  \        P                  39   do   \        P                  P                  RV^,           24      p	V^ ,          \        P                  8H  p
V
'       d   V	P                   ^ 8X  d   ^MV	P                   pW³R&   Rp V P"                  ! R/ VB pVf&   VP'                  RR4        V P"                  ! R/ VB pVf(   VP'                  RR4       Rp V P"                  ! R/ VB pVf%   VP'                  RR4       V P"                  ! R/ VB p\        P                  P)                  V4      pVRJ d!   V'       g   V'       g   VP+                  4       pV'       d   VP-                  V4      pV# Vf   Ve   \        R4      hT p\        P                  P)                  V4      #   \$         d     ELi ; i  \$         d     ELi ; i  \$         d     Líi ; i)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])

rO   rJ   TFNr`   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.zcuda:ÚstreamzQdevice and copy kwargs not supported when ext_tensor is already a DLPack capsule.rM   r	   )ÚhasattrrY   Ú
isinstanceÚstrr3   r_   ÚAssertionErrorÚtyper@   Ú_torchDeviceToDLDeviceÚ
ValueErrorr   r   r$   ÚcudaÚcurrent_streamÚcuda_streamrO   Ú	TypeErrorÚpopÚ_from_dlpackÚcloneÚto)rb   r_   r`   rG   Úrequested_copyÚproducer_handled_copyÚcross_device_transferÚ
ext_deviceÚtarget_dl_devicerg   Úis_cudaÚ
stream_ptrÚdlpackr1   s   &$$           r.   Úfrom_dlpackr   |   sÜ  € ô@ ˆz˜<×(Ó(ð "$ˆØ &ˆˆ}Ñð ˆØ $ÐØ %ÐàÒØ!�6‰Nð  ×1Ñ1Ó3ˆ
àÒÜ˜&¤#×&Ò&ÜŸš fÓ-�Ü˜f¤e§l¡l×3Ò3Ü$Ð'MÌdÐSYËlÈ^Ð%\Ó]Ð]ô  %Ÿx™x×>Ñ>¸vÓFÐð &0Ñ%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Ø)�8Ñð ˆð	Ø×*Ò*Ñ4¨VÑ4ˆFð
 Š>Ø�J‰J�} dÔ+ðØ#×.Ò.Ñ8°Ñ8�ð
 Š>Ø�J‰J�v˜tÔ$Ø$)Ð!ðØ#×.Ò.Ñ8°Ñ8�ð
 Š>Ø�J‰J�{ DÔ)Ø×*Ò*Ñ4¨VÑ4ˆFä—‘×&Ñ& vÓ.ˆð ˜TÓ!×*?×H]Ø—\‘\“^ˆF÷ !Ø—Y‘Y˜vÓ&ˆFàˆð Ò Ò!1Ü Øcóð ð ˆÜ�x‰x×$Ñ$ VÓ,Ð,øôY ô 	Úð	ûô ô Úðûô ô Ùðús6   ÆJ. Æ5K  Ç K Ê.J=Ê<J=Ë KËKËK ËK )r   r   r   )Útypingr   r3   ÚenumÚtorch._Cr   Ú	to_dlpackÚtorch.typesr   rc   Ú__all__ÚIntEnumr   r4   r   r@   Ú_add_docstrr   r	   r-   r.   Ú<module>rˆ      s{   ðÝ ã Û å ,Ý )ò€ô�4—<‘<ô ô&>U˜EŸL™Lô >UðB ‡�× Ñ �Yð !ô ð2m-ð "ðm-ð ÷	m-ñ m-r-   