+
    ˜°³j~#  ã                   óB  a € R& t0 t R t^ RIt^ RIHt ]! ]P
                  RR 4      tRs] ^ k R R ltR R lt	R	 R
 lt
R'R R lltR'R R lltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR tR  R! ltR" R# lt^R$IHt ^R%IHt . R(OtR# ))ag  
This package enables an interface for accessing MPS (Metal Performance Shaders) backend in Python.
Metal is Apple's API for programming metal GPU (graphics processor unit). Using MPS means that increased
performance can be achieved, by running work on the metal GPU(s).
See https://developer.apple.com/documentation/metalperformanceshaders for more details.
N)ÚTensorÚ_mps_is_in_bad_forkc                  ó   € R # )F© r   ó    ÚS/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/mps/__init__.pyÚ<lambda>r      s   € Á5r   c                óL   € V ^8„  d   QhR\         P                  P                  /# ©é   Úreturn)ÚtorchÚ_CÚ	Generator)Úformats   "r   Ú__annotate__r      s   € ÷ "ñ "¤E§H¡H×$6Ñ$6ñ "r   c                  óZ   € \         f   \        P                  P                  4       s \         # )N)Ú_default_mps_generatorr   r   Ú_mps_get_default_generatorr   r   r   Ú_get_default_mps_generatorr      s!   € äÒ%Ü!&§¡×!DÑ!DÓ!FÐÜ!Ð!r   c                ó$   € V ^8„  d   QhR\         /# r
   ©Úint)r   s   "r   r   r      s   € ÷ Cñ C”cñ Cr   c                 ó”   € \        \        P                  P                  ;'       d    \        P                  P	                  4       4      # )z,Returns the number of available MPS devices.)r   r   r   Ú_has_mpsÚ_mps_is_availabler   r   r   Údevice_countr      s,   € äŒu�x‰x× Ñ ×AÐA¤U§X¡X×%?Ñ%?Ó%AÓBÐBr   c                ó   € V ^8„  d   QhRR/# ©r   r   Nr   )r   s   "r   r   r      s   € ÷ -ñ -�Tñ -r   c                 ó>   € \         P                  P                  4       # )zAWaits for all kernels in all streams on a MPS device to complete.)r   r   Ú_mps_deviceSynchronizer   r   r   Úsynchronizer!      s   € ä�8‰8×*Ñ*Ó,Ð,r   c                óp   € V ^8„  d   QhR\         \        ,          \        P                  ,          R\        /# )r   Údevicer   )r   Ústrr   r#   r   )r   s   "r   r   r   #   s'   € ÷ 4ñ 4œ#¤�)¤e§l¡lÕ2ð 4¼vñ 4r   c                ó2   € \        4       P                  4       # )zéReturns the random number generator state as a ByteTensor.

Args:
    device (torch.device or int, optional): The device to return the RNG state of.
        Default: ``'mps'`` (i.e., ``torch.device('mps')``, the current MPS device).
)r   Ú	get_state)r#   s   &r   Úget_rng_stater'   #   s   € ô &Ó'×1Ñ1Ó3Ð3r   c                ót   € V ^8„  d   QhR\         R\        \        ,          \        P                  ,          RR/# )r   Ú	new_stater#   r   N)r   r   r$   r   r#   )r   s   "r   r   r   -   s/   € ÷ 	;ñ 	;œVð 	;¬S´3­Y¼¿¹Õ-Eð 	;ÐRVñ 	;r   c                óx   € V P                  \        P                  R7      p\        4       P	                  V4       R# )a  Sets the random number generator state.

Args:
    new_state (torch.ByteTensor): The desired state
    device (torch.device or int, optional): The device to set the RNG state.
        Default: ``'mps'`` (i.e., ``torch.device('mps')``, the current MPS device).
)Úmemory_formatN)Úcloner   Úcontiguous_formatr   Ú	set_state)r)   r#   Únew_state_copys   && r   Úset_rng_stater0   -   s+   € ð —_‘_´5×3JÑ3J�_ÓK€NÜÓ ×*Ñ*¨>Ö:r   c                ó(   € V ^8„  d   QhR\         RR/# )r   Úseedr   Nr   )r   s   "r   r   r   9   s   € ÷ 3ñ 3”cð 3˜dñ 3r   c                ó’   € \         P                  P                  '       g   R# \        V 4      p \	        4       P                  V 4       R# )zVSets the seed for generating random numbers.

Args:
    seed (int): The desired seed.
N)r   r   r   r   r   Úmanual_seed)r2   s   &r   r4   r4   9   s1   € ô �8‰8××ÐÙÜˆt‹9€DÜÓ ×,Ñ,¨TÖ2r   c                ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   r   I   s   € ÷ (ñ (ˆdñ (r   c                 ó6   € \        4       P                  4        R# )z?Sets the seed for generating random numbers to a random number.N)r   r2   r   r   r   r2   r2   I   s   € äÓ ×%Ñ%Ö'r   c                ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   r   N   s   € ÷ ñ �Tñ r   c                 óB   € \         P                  P                  4        R# )zƒReleases all unoccupied cached memory currently held by the caching
allocator so that those can be used in other GPU applications.
N)r   r   Ú_mps_emptyCacher   r   r   Úempty_cacher:   N   s   € ô 
‡H�H×ÑÖr   c                ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r   r   U   s   € ÷ .ñ .°ñ .r   c                óÀ   € \        V \        4      '       g   \        R4      hV ^ 8  g   V ^8”  d   \        RV  R24      h\        P
                  P                  V 4       R# )a•  Set memory fraction for limiting process's memory allocation on MPS device.
The allowed value equals the fraction multiplied by recommended maximum device memory
(obtained from Metal API device.recommendedMaxWorkingSetSize).
If trying to allocate more than the allowed value in a process, it will raise an out of
memory error in allocator.

Args:
    fraction(float): Range: 0~2. Allowed memory equals total_memory * fraction.

.. note::
   Passing 0 to fraction means unlimited allocations
   (may cause system failure if out of memory).
   Passing fraction greater than 1.0 allows limits beyond the value
   returned from device.recommendedMaxWorkingSetSize.
z3Invalid type for fraction argument, must be `float`zInvalid fraction value: z. Allowed range: 0~2N)Ú
isinstanceÚfloatÚ	TypeErrorÚ
ValueErrorr   r   Ú_mps_setMemoryFraction)Úfractions   &r   Úset_per_process_memory_fractionrC   U   sR   € ô" �h¤×&Ò&ÜÐMÓNÐNØ�!„|�x !”|ÜÐ3°H°:Ð=QÐRÓSÐSä	‡H�H×#Ñ# HÖ-r   c                ó$   € V ^8„  d   QhR\         /# r
   r   )r   s   "r   r   r   n   s   € ÷ 2ñ 2¤#ñ 2r   c                 ó>   € \         P                  P                  4       # )z¥Returns the current GPU memory occupied by tensors in bytes.

.. note::
   The returned size does not include cached allocations in
   memory pools of MPSAllocator.
)r   r   Ú_mps_currentAllocatedMemoryr   r   r   Úcurrent_allocated_memoryrG   n   s   € ô �8‰8×/Ñ/Ó1Ð1r   c                ó$   € V ^8„  d   QhR\         /# r
   r   )r   s   "r   r   r   x   s   € ÷ 1ñ 1¤ñ 1r   c                 ó>   € \         P                  P                  4       # )z×Returns total GPU memory allocated by Metal driver for the process in bytes.

.. note::
   The returned size includes cached allocations in MPSAllocator pools
   as well as allocations from MPS/MPSGraph frameworks.
)r   r   Ú_mps_driverAllocatedMemoryr   r   r   Údriver_allocated_memoryrK   x   s   € ô �8‰8×.Ñ.Ó0Ð0r   c                ó$   € V ^8„  d   QhR\         /# r
   r   )r   s   "r   r   r   ‚   s   € ÷ 0ñ 0¤ñ 0r   c                 ó>   € \         P                  P                  4       # )z²Returns recommended max Working set size for GPU memory in bytes.

.. note::
   Recommended max working set size for Metal.
   returned from device.recommendedMaxWorkingSetSize.
)r   r   Ú_mps_recommendedMaxMemoryr   r   r   Úrecommended_max_memoryrO   ‚   s   € ô �8‰8×-Ñ-Ó/Ð/r   c                ó$   € V ^8„  d   QhR\         /# )r   Úsource)r$   )r   s   "r   r   r   Œ   s   € ÷ /ñ /œ3ñ /r   c                ór  € ^ RI Hp ^ RIHp \	        \
        P                  R4      '       g   \        R4      hT! V P                  R4       Uu. uF  q3R,           NK  	  upV! \        4      P                  P                  R,          .\        4       4      p \
        P                  P                  V 4      # u upi )aª  Compiles compute shader from source and allows one to invoke kernels
defined there from the comfort of Python runtime
Example::

    >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_MPS)
    >>> lib = torch.mps.compile_shader(
    ... "kernel void full(device float* out, constant float& val, uint idx [[thread_position_in_grid]]) { out[idx] = val; }"
    ...  )
    >>> x = torch.zeros(16, device="mps")
    >>> lib.full(x, 3.14)
)ÚPath)Ú_embed_headersÚ_mps_compileShaderúMPS is not availableÚ
Úinclude)ÚpathlibrS   Útorch.utils._cpp_embed_headersrT   Úhasattrr   r   ÚRuntimeErrorÚsplitÚ__file__ÚparentÚsetrU   )rQ   rS   rT   Úls   &   r   Úcompile_shaderrb   Œ   s�   € õ å=ä”5—8‘8Ð1×2Ò2ÜÐ1Ó2Ð2ÙØ!Ÿ<™<¨Ô-Ó.Ñ-�aˆT�ˆÑ-Ñ.Ù	Œh‹×	Ñ	×	%Ñ	%¨	Õ	1Ð2Ü‹ó€Fô
 �8‰8×&Ñ& vÓ.Ð.ùò	 	/s   ÁB4c                ó  € ^ RI p\        V \        \        34      '       dT   \	        \
        P                  R4      '       g   \        R4      h\
        P                  P                  \        V 4      4      # \        V \        VP                  34      '       dT   \	        \
        P                  R4      '       g   \        R4      h\
        P                  P                  \        V 4      4      # \        R\        V 4      P                   24      h)aS  Loads a precompiled Metal library (.metallib) and returns a shader
library object that allows invoking kernels defined in it.

Args:
    source: Either raw metallib bytes (``bytes``/``bytearray``) or a
        filesystem path (``str``/``os.PathLike``) to a ``.metallib`` file.

This is useful for loading Metal libraries compiled ahead of time or
generated by external tools (e.g. Triton, MetalASM).

Example::

    >>> # xdoctest: +SKIP("requires external .metallib file")
    >>> lib = torch.mps.load_metallib("kernels.metallib")
    >>> x = torch.ones(16, device="mps")
    >>> lib.square(x)
NÚ_mps_loadMetalllibrV   Ú_mps_loadMetallibFromPathzexpected bytes or path, got )Úosr=   ÚbytesÚ	bytearrayr[   r   r   r\   rd   r$   ÚPathLikere   r?   ÚtypeÚ__name__)rQ   rf   s   & r   Úload_metallibrl   ¦   s»   € ó$ ä�&œ5¤)Ð,×-Ò-Ü”u—x‘xÐ!5×6Ò6ÜÐ5Ó6Ð6Ü�x‰x×*Ñ*¬5°«=Ó9Ð9Ü	�FœS "§+¡+Ð.×	/Ò	/Ü”u—x‘xÐ!<×=Ò=ÜÐ5Ó6Ð6Ü�x‰x×1Ñ1´#°f³+Ó>Ð>äÐ6´t¸F³|×7LÑ7LÐ6MÐNÓOÐOr   c                ó$   € V ^8„  d   QhR\         /# r
   )Úbool)r   s   "r   r   r   Æ   s   € ÷ ñ ”dñ r   c                  ó   € \        4       ^ 8„  # )é    )r   r   r   r   Úis_availablerq   Æ   s   € Ü‹>˜AÑÐr   c                ó    € V ^8„  d   QhRRRR/# )r   Ústorageztorch.UntypedStorager   r   )r   s   "r   r   r   Ê   s   € ÷ 5ñ 5Ð!7ð 5Ð<Rñ 5r   c                ó@   € \         P                  P                  V 4      # )aD  Returns a CPU :class:`torch.UntypedStorage` that aliases the
host-visible contents of the MTLBuffer backing ``storage``.

The returned storage shares memory with ``storage``: writes through the
CPU alias land directly in the MPS-allocated MTLBuffer, avoiding a
CPU->MPS staging copy. This is intended for advanced interop with bulk
loaders (e.g. safetensors) that already know how to write into CPU
memory.

The alias storage retains a reference to the source MPS storage, so the
host pointer remains valid for the alias's lifetime even if the original
tensor is freed.

Raises an exception if ``storage`` is not backed by a shared-storage
``id<MTLBuffer>`` allocated by the MPS allocator.

.. warning::
    Use with caution. This bypasses the cache-coherence guarantees that
    the higher-level PyTorch APIs (:meth:`torch.Tensor.cpu`,
    :meth:`torch.Tensor.to`, ``copy_``) provide for you, and makes the
    caller responsible for ordering CPU and GPU accesses to the same
    memory. You should **always** call :func:`torch.mps.synchronize`
    both **before** issuing host reads/writes through the alias (to
    drain any in-flight GPU work that may still be touching the
    buffer) and **after** (before launching GPU work that depends on
    the host writes). Failure to do so can produce stale reads,
    torn writes, or data corruption.
)r   r   Ú_mps_host_alias_storage)rs   s   &r   Ú_host_alias_storagerv   Ê   s   € ô: �8‰8×+Ñ+¨GÓ4Ð4r   )Úprofiler)ÚEventc                óh   € V ^8„  d   Qh/ ^ \         9   d   \        P                  P                  ;R&   # )r   r   )Ú__conditional_annotations__r   r   r   )r   s   "r   r   r      s(   € ÷ ñ ÷ 2Ò 1œŸ™×*Ñ*Ñ 1òr   )Úmps)rb   rl   r   r'   r4   r2   r0   r!   r:   rC   rG   rK   rx   rw   rO   rq   )rz   Ú__doc__r   r   Úgetattrr   Ú_is_in_bad_forkr   r   r   r!   r'   r0   r4   r2   r:   rC   rG   rK   rO   rb   rl   rq   rv   Ú rw   Úeventrx   Ú__all__r   )rz   s   @r   Ú<module>r‚      s”   øðöó Ý ñ ˜%Ÿ(™(Ð$9¹=ÓI€Ø-1Ð Ó 1õ"õCõ
-÷
4÷	;õ3õ (õ
õ.õ22õ1õ0õ/ò4Põ@õ5õ@ Ý ò‚r   