§
    Ë²Åj)-  ã                   ó*  — U d Z ddlZddlZddlmZmZmZmZmZm	Z	m
Z
 ddlZddlmZmZ ddlmZmZmZ ddlmZ ddlmZ e
eeef         Zej        Zej        Zd	ag aee	eg df         ee         f                  ed
<    ej        ¦   «         Z  ej!        ¦   «         Z" e¦   «         Z#d„ Z$d„ Z%de&fd„Z'd*d„Z( G d„ de)¦  «        Z*de&fd„Z+de&fd„Z,d+dee         ddfd„Z-defd„Z.defd„Z/d+dee         defd„Z0d+dee         defd„Z1d+dee         de	eef         fd„Z2d*d„Z3defd„Z4deddfd„Z5 G d„ d¦  «        Z G d „ d!¦  «        Z6ded"         de6fd#„Z7d,de
eeej        f         defd%„Z8	 d,d&ede
eeej        f         ddfd'„Z9dd(l:T g d)¢Z;dS )-zH
This package enables an interface for accessing MTIA backend in python
é    N)ÚAnyÚCallableÚDictÚListÚOptionalÚTupleÚUnion)ÚdeviceÚTensor)Ú_dummy_typeÚ_LazySeedTrackerÚclassproperty)ÚDeviceé   )Ú_get_device_indexFÚ_queued_callsc                  ó"   — t          ¦   «          d S ©N)Ú
_lazy_init© ó    úDC:\Projects\Historical\venv\Lib\site-packages\torch/mtia/__init__.pyÚinitr   !   s   € Ý�L„L€L€L€Lr   c                  ó.   — t           ot          ¦   «          S )z9Return whether PyTorch's MTIA state has been initialized.)Ú_initializedÚ_is_in_bad_forkr   r   r   Úis_initializedr   %   s   € åÐ1¥Ñ 1Ô 1Ð1Ð1r   Úreturnc                  ó>   — t           j                             ¦   «         S r   )ÚtorchÚ_CÚ_mtia_isInBadForkr   r   r   r   r   *   s   € ÝŒ8×%Ò%Ñ'Ô'Ð'r   c            	      ó2  — t          ¦   «         st          t          d¦  «        rd S t          5  t          ¦   «         r	 d d d ¦  «         d S t	          ¦   «         rt          d¦  «        ‚t          ¦   «         st          d¦  «        ‚t          j	         
                    ¦   «          dt          _        t                               d„ t                               ¦   «         D ¦   «         ¦  «         	 t          D ]Z\  } }	  | ¦   «          Œ# t           $ r=}dt#          |¦  «        › dd                     |¦  «        › �}t'          |¦  «        |‚d }~ww xY w	 t)          t          d¦  «         n# t)          t          d¦  «         w xY wdad d d ¦  «         d S # 1 swxY w Y   d S )	NÚis_initializingzwCannot re-initialize MTIA in forked subprocess. To use MTIA with multiprocessing, you must use the 'spawn' start methodzÆTorch not compiled with MTIA enabled. Ensure you have `import mtia.host_runtime.torch_mtia` in your python src file and include `//mtia/host_runtime/torch_mtia:torch_mtia` as your target dependency!Tc              3   ó   K  — | ]}|¯|V — Œ	d S r   r   )Ú.0Úcallss     r   ú	<genexpr>z_lazy_init.<locals>.<genexpr>P   s(   è è € ÐXÐX uÐRWÐX˜UÐXÐXÐXÐXÐXÐXr   z6MTIA call failed lazily at initialization with error: z(

MTIA call was originally invoked at:

Ú )r   ÚhasattrÚ_tlsÚ_initialization_lockr   ÚRuntimeErrorÚ_is_compiledÚAssertionErrorr    r!   Ú
_mtia_initr$   r   ÚextendÚ_lazy_seed_trackerÚ	get_callsÚ	ExceptionÚstrÚjoinÚDeferredMtiaCallErrorÚdelattrr   )Úqueued_callÚorig_tracebackÚeÚmsgs       r   r   r   .   s;  € åÑÔð �7¥4Ð):Ñ;Ô;ð ØˆÝ	ð ,ð ,õ ÑÔð 	Øð,ð ,ð ,ñ ,ô ,ð ,ð ,ð ,õ ÑÔð 	ÝðIñô ð õ ‰~Œ~ð 	Ý ð*ñô ð õ 	Œ×ÒÑÔÐð  $�Ôå×ÒÐXÐXÕ0B×0LÒ0LÑ0NÔ0NÐXÑXÔXÑXÔXÐXð	-Ý/<ð <ð <Ñ+�˜^ð<Ø�K‘M”M�M�MøÝ ð <ð <ð <ð]ÕQTÐUVÑQWÔQWð ]ð ]ØCEÇ7Â7È>ÑCZÔCZð]ð ]ð õ 0°Ñ4Ô4¸!Ð;øøøøð<øøøð<õ •DÐ+Ñ,Ô,Ð,Ð,ø�G•DÐ+Ñ,Ô,Ð,Ð,øøøØˆðY,ð ,ð ,ñ ,ô ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,øøøð ,ð ,ð ,ð ,ð ,ð ,sT   ­FÁ
BFÃ*E#Ã7
DÄE#Ä
E	Ä8EÅE	Å	E#ÅFÅ#E:Å:FÆFÆFc                   ó   — e Zd ZdS )r7   N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r7   r7   a   s   € € € € € Ø€Dr   r7   c                  ó>   — t           j                             ¦   «         S )z*Return true if compiled with MTIA support.)r    r!   Ú_mtia_isBuiltr   r   r   r.   r.   e   s   € åŒ8×!Ò!Ñ#Ô#Ð#r   c                  óF   — t          ¦   «         sdS t          ¦   «         dk    S )z'Return true if MTIA device is availableFr   )r.   Údevice_countr   r   r   Úis_availablerE   j   s"   € å‰>Œ>ð Øˆuå‰>Œ>˜AÒÐr   r
   c                 ó°   — t           j                             | ¦  «        5  t           j                             ¦   «         cddd¦  «         S # 1 swxY w Y   dS )z?Waits for all jobs in all streams on a MTIA device to complete.N)r    Úmtiar
   r!   Ú_mtia_deviceSynchronize©r
   s    r   ÚsynchronizerJ   r   s�   € å	Œ×	Ò	˜6Ñ	"Ô	"ð 2ð 2ÝŒx×/Ò/Ñ1Ô1ð2ð 2ð 2ð 2ñ 2ô 2ð 2ð 2ð 2ð 2ð 2ð 2øøøð 2ð 2ð 2ð 2ð 2ð 2s    AÁAÁAc                  ó>   — t           j                             ¦   «         S )z,Return the number of MTIA devices available.)r    r!   Ú_accelerator_hooks_device_countr   r   r   rD   rD   x   s   € åŒ8×3Ò3Ñ5Ô5Ð5r   c                  ó>   — t           j                             ¦   «         S )z0Return the index of a currently selected device.)r    r!   Ú%_accelerator_hooks_get_current_devicer   r   r   Úcurrent_devicerO   }   s   € åŒ8×9Ò9Ñ;Ô;Ð;r   c                 ó^   — t           j                             t          | d¬¦  «        ¦  «        S )aS  Return the currently selected :class:`Stream` for a given device.

    Args:
        device (torch.device or int, optional): selected device. Returns
            the currently selected :class:`Stream` for the current device, given
            by :func:`~torch.mtia.current_device`, if :attr:`device` is ``None``
            (default).
    T©Úoptional)r    r!   Ú_mtia_getCurrentStreamr   rI   s    r   Úcurrent_streamrT   ‚   ó(   € õ Œ8×*Ò*Õ+<¸VÈdÐ+SÑ+SÔ+SÑTÔTÐTr   c                 ó^   — t           j                             t          | d¬¦  «        ¦  «        S )a=  Return the default :class:`Stream` for a given device.

    Args:
        device (torch.device or int, optional): selected device. Returns
            the default :class:`Stream` for the current device, given by
            :func:`~torch.mtia.current_device`, if :attr:`device` is ``None``
            (default).
    TrQ   )r    r!   Ú_mtia_getDefaultStreamr   rI   s    r   Údefault_streamrX   Ž   rU   r   c                 ó^   — t           j                             t          | d¬¦  «        ¦  «        S )a  Return capability of a given device as a tuple of (major version, minor version).

    Args:
        device (torch.device or int, optional) selected device. Returns
            statistics for the current device, given by current_device(),
            if device is None (default).
    TrQ   )r    r!   Ú_mtia_getDeviceCapabilityr   rI   s    r   Úget_device_capabilityr[   š   s)   € õ Œ8×-Ò-Õ.?ÀÐQUÐ.VÑ.VÔ.VÑWÔWÐWr   c                  ó>   — t           j                             ¦   «         S )zEmpty the MTIA device cache.)r    r!   Ú_mtia_emptyCacher   r   r   Úempty_cacher^   ¥   s   € åŒ8×$Ò$Ñ&Ô&Ð&r   Ústreamc                 óL   — | €dS t           j                             | ¦  «         dS )a  Set the current stream.This is a wrapper API to set the stream.
        Usage of this function is discouraged in favor of the ``stream``
        context manager.

    Args:
        stream (Stream): selected stream. This function is a no-op
            if this argument is ``None``.
    N)r    r!   Ú_mtia_setCurrentStream©r_   s    r   Ú
set_streamrc   ª   s*   € ð €~ØˆÝ	„H×#Ò# FÑ+Ô+Ð+Ð+Ð+r   c                 ór   — t          | ¦  «        } | dk    r!t          j                             | ¦  «         dS dS )z¡Set the current device.

    Args:
        device (torch.device or int): selected device. This function is a no-op
            if this argument is negative.
    r   N)r   r    r!   Ú%_accelerator_hooks_set_current_devicerI   s    r   Ú
set_devicerf   ¸   s=   € õ ˜vÑ&Ô&€FØ�‚{€{ÝŒ×6Ò6°vÑ>Ô>Ð>Ð>Ð>ð €{r   c                   ó8   — e Zd ZdZd efd„Zd„ Zdededefd„ZdS )	r
   zÌContext-manager that changes the selected device.

    Args:
        device (torch.device or int): device index to select. It's a no-op if
            this argument is a negative integer or ``None``.
    c                 ó@   — t          |d¬¦  «        | _        d| _        d S )NTrQ   éÿÿÿÿ)r   ÚidxÚprev_idx)Úselfr
   s     r   Ú__init__zdevice.__init__Ì   s!   € Ý$ V°dÐ;Ñ;Ô;ˆŒØˆŒˆˆr   c                 óX   — t           j                             | j        ¦  «        | _        d S r   )r    r!   Ú(_accelerator_hooks_maybe_exchange_devicerj   rk   )rl   s    r   Ú	__enter__zdevice.__enter__Ð   s   € Ýœ×IÒIÈ$Ì(ÑSÔSˆŒˆˆr   ÚtypeÚvalueÚ	tracebackc                 óX   — t           j                             | j        ¦  «        | _        dS )NF)r    r!   ro   rk   rj   )rl   rq   rr   rs   s       r   Ú__exit__zdevice.__exit__Ó   s    € Ý”8×DÒDÀTÄ]ÑSÔSˆŒØˆur   N)r>   r?   r@   Ú__doc__r   rm   rp   ru   r   r   r   r
   r
   Ä   st   € € € € € ðð ð˜sð ð ð ð ðTð Tð Tð˜Sð ¨ð ¸ð ð ð ð ð ð r   c                   ó\   — e Zd ZU dZed         ed<   ded         fd„Zd„ Zdeded	efd
„Z	dS )ÚStreamContexta  Context-manager that selects a given stream.

    All MTIA kernels queued within its context will be enqueued on a selected
    stream.

    Args:
        Stream (Stream): selected stream. This manager is a no-op if it's
            ``None``.
    .. note:: Streams are per-device.
    útorch.mtia.StreamÚ
cur_streamr_   c                 ó´  — d | _         || _        t          d d¦  «        | _        t          j                             ¦   «         s| j        €d| _        t          j                             ¦   «         sd nt          j                             d ¦  «        | _	        t          j                             ¦   «         sd nt          j                             d ¦  «        | _
        d S )NTri   )rz   r_   r   rj   r    ÚjitÚis_scriptingrG   rX   Úsrc_prev_streamÚdst_prev_stream)rl   r_   s     r   rm   zStreamContext.__init__æ   s¶   € ØˆŒØˆŒÝ$ T¨4Ñ0Ô0ˆŒÝŒy×%Ò%Ñ'Ô'ð 	ØŒxÐØ�”õ œ	×.Ò.Ñ0Ô0ÐUˆDˆDµe´j×6OÒ6OÐPTÑ6UÔ6Uð 	Ôõ œ	×.Ò.Ñ0Ô0ÐUˆDˆDµe´j×6OÒ6OÐPTÑ6UÔ6Uð 	ÔÐÐr   c                 óŒ  — | j         }|�| j        dk    rd S t          j                             d ¦  «        | _        | j        j        |j        k    rUt          |j        ¦  «        5  t          j                             |j        ¦  «        | _        d d d ¦  «         n# 1 swxY w Y   t          j                             |¦  «         d S ©Nri   )	r_   rj   r    rG   rT   r~   r
   r   rc   )rl   rz   s     r   rp   zStreamContext.__enter__õ   sú   € à”[ˆ
àÐ ¤¨R¢ ØˆFÝ$œz×8Ò8¸Ñ>Ô>ˆÔð ÔÔ&¨*Ô*;Ò;Ð;Ý˜
Ô)Ñ*Ô*ð Tð TÝ',¤z×'@Ò'@ÀÔARÑ'SÔ'S�Ô$ðTð Tð Tñ Tô Tð Tð Tð Tð Tð Tð Tøøøð Tð Tð Tð TåŒ
×Ò˜jÑ)Ô)Ð)Ð)Ð)s   Á$*BÂBÂ!Brq   rr   rs   c                 óì   — | j         }|�| j        dk    rd S | j        j        |j        k    r$t          j                             | j        ¦  «         t          j                             | j        ¦  «         d S r�   )r_   rj   r~   r
   r    rG   rc   r   )rl   rq   rr   rs   rz   s        r   ru   zStreamContext.__exit__  sl   € à”[ˆ
àÐ ¤¨R¢ ØˆFð ÔÔ&¨*Ô*;Ò;Ð;ÝŒJ×!Ò! $Ô"6Ñ7Ô7Ð7ÝŒ
×Ò˜dÔ2Ñ3Ô3Ð3Ð3Ð3r   N)
r>   r?   r@   rv   r   Ú__annotations__rm   rp   r   ru   r   r   r   rx   rx   Ø   s�   € € € € € € ð	ð 	ð Ð,Ô-Ð-Ð-Ñ-ð
˜xÐ(;Ô<ð 
ð 
ð 
ð 
ð*ð *ð *ð4˜Sð 4¨ð 4¸ð 4ð 4ð 4ð 4ð 4ð 4r   rx   ry   c                 ó    — t          | ¦  «        S )a+  Wrap around the Context-manager StreamContext that selects a given stream.

    Arguments:
        stream (Stream): selected stream. This manager is a no-op if it's
            ``None``.
    ..Note:: In eager mode stream is of type Stream class while in JIT it doesn't support torch.mtia.stream
    )rx   rb   s    r   r_   r_     s   € õ ˜Ñ Ô Ð r   rG   c                 ó~   — t          j        dt          d¬¦  «         t          j        dgt          j        | ¬¦  «        S )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: ``'mtia'`` (i.e., ``torch.device('mtia')``, the current mtia device).
    z.get_rng_state is not implemented in torch.mtiaé   ©Ú
stacklevelr   )Údtyper
   )ÚwarningsÚwarnÚUserWarningr    ÚzerosÚuint8rI   s    r   Úget_rng_stater�     sC   € õ „MØ8ÝØðñ ô ð õ
 Œ;˜�s¥%¤+°fÐ=Ñ=Ô=Ð=r   Ú	new_statec                 ó>   — t          j        dt          d¬¦  «         dS )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: ``'mtia'`` (i.e., ``torch.device('mtia')``, the current mtia device).
    z.set_rng_state is not implemented in torch.mtiar†   r‡   N)rŠ   r‹   rŒ   )r�   r
   s     r   Úset_rng_stater’   ,  s0   € õ „MØ8ÝØðñ ô ð ð ð r   )Ú*)r   rE   r   rJ   rD   rO   rT   rX   Úmemory_statsÚmax_memory_allocatedr[   r^   rf   rc   r_   r
   r’   r�   )r   Nr   )rG   )<rv   Ú	threadingrŠ   Útypingr   r   r   r   r   r   r	   r    r
   Ú_devicer   Útorch._utilsr   r   r   Útorch.typesr   Ú_utilsr   r5   ÚintÚ	_device_tÚEventÚStreamr   r   rƒ   Úlocalr+   ÚLockr,   r2   r   r   Úboolr   r   r4   r7   r.   rE   rJ   rD   rO   rT   rX   r[   r^   rc   rf   rx   r_   r�   r’   ÚmemoryÚ__all__r   r   r   ú<module>r¥      so  ððð ð ð Ð Ð Ð Ø €€€Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ Dà €€€Ø +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ø EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EØ Ð Ð Ð Ð Ð à %Ð %Ð %Ð %Ð %Ð %ð �'˜3 Ð#Ô$€	ð 	Œ€Ø	Œ€à€ð ð ˆtØ	ˆ(�2�t�8Ô
˜d 3œiÐ
'Ô(ôð ð ñ ð €y„ÑÔ€Ø%�y”~Ñ'Ô'Ð Ø%Ð%Ñ'Ô'Ð ðð ð ð2ð 2ð 2ð
(˜ð (ð (ð (ð (ð0ð 0ð 0ð 0ðf	ð 	ð 	ð 	ð 	˜Iñ 	ô 	ð 	ð$�dð $ð $ð $ð $ð
�dð ð ð ð ð2ð 2˜ Ô+ð 2°tð 2ð 2ð 2ð 2ð6�cð 6ð 6ð 6ð 6ð
<˜ð <ð <ð <ð <ð
	Uð 	U˜8 IÔ.ð 	U¸&ð 	Uð 	Uð 	Uð 	Uð	Uð 	U˜8 IÔ.ð 	U¸&ð 	Uð 	Uð 	Uð 	UðXð X (¨9Ô"5ð XÀÀsÈCÀxÄð Xð Xð Xð Xð'ð 'ð 'ð 'ð
,�vð ,ð ,ð ,ð ,ð	?�yð 	? Tð 	?ð 	?ð 	?ð 	?ðð ð ð ð ñ ô ð ð(74ð 74ð 74ð 74ð 74ñ 74ô 74ð 74ðt!�8Ð/Ô0ð !°]ð !ð !ð !ð !ð>ð >˜%  S¨%¬,Ð 6Ô7ð >ÀVð >ð >ð >ð >ð  @Fðð ØðØ$ S¨#¨u¬|Ð%;Ô<ðà	ðð ð ð ð" Ð Ð Ð ðð ð €€€r   