
    9iU                     J   % S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r
JrJrJrJr  SSKr\\\/\4      \S'   \R$                  R'                  5       (       a  SSKJr  OSr0 r\\\
4   \S	'   0 r\\\4   \S
'    " S S5      r " S S5      r " S S\5      r\\\/\4      \S'   \R<                  R'                  5       (       a  SSKJr   OSr  " S S\5      r!\\\/\4      \S'   \RD                  R'                  5       (       a  SSKJ#r$  OSr$ " S S\5      r%\ " S S5      5       r& " S S\5      r' " S S\5      r(0 r)\\\*\   4   \S'   S q+S!\\\RX                  4   S"\*\   S#S4S$ jr-S!\\\RX                  4   S#\*\   4S% jr.S#\\/\\*\   4      4S& jr0S(S' jr1g))a  
Device abstraction layer for TorchDynamo and Inductor backends.

This module provides a unified interface for different hardware backends (CUDA, XPU,
CPU, MPS, MTIA) through a common device interface. Key components include:

- DeviceInterface: Base class defining the common API for all device types
- Device-specific implementations: CudaInterface, XpuInterface, CpuInterface, MpsInterface, MtiaInterface
- Device registration system for managing available backends
- Worker APIs for multi-processing scenarios
- Stream and event management across different devices
- Device property caching for worker processes

The abstraction layer enables device-agnostic code in TorchDynamo while allowing
specialized implementations for each hardware backend's unique features.
    N)
namedtuple)Iterable)	dataclass)AnyCallableLiteralOptionalUnionget_cuda_stream)_cuda_getCurrentRawStream caching_worker_device_propertiescaching_worker_current_devicesc            	          \ rS rSrSr " S S5      r " S S5      r " S S5      r " S	 S
5      r\	S\
4S j5       r\	S\R                  R                  SS4S j5       r\	S\
S\
4S j5       r\	S\
S\
4S j5       r\	S\
4S j5       r\	S\4S j5       r\	S\R                  S\4S j5       r\	S\R                  4S j5       r\	S\R                  SS4S j5       r\	S\
S\
S\
SS4S j5       r\	S\
S\
4S j5       r\	S(S\R                  R                  SS4S jj5       r\S(S\R                  R                  S\4S jj5       r\	S(S\R                  R                  S\4S jj5       r\	S)S \S\4S! jj5       r\ S)S"\R@                  S \S\4S# jj5       r!\	S(S\R                  R                  S\
4S$ jj5       r"\	S(S\R                  R                  S\4S% jj5       r#\S(S\R                  R                  SS4S& jj5       r$S'r%g)*DeviceInterface'   z
This is a simple device runtime interface for Inductor. It enables custom
backends to be integrated with Inductor in a device-agnostic semantic.
c                   N    \ rS rSrS\R
                  R                  S\4S jrSr	g)DeviceInterface.device-   devicereturnc                     [         eNNotImplementedErrorclsr   s     ^/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torch/_dynamo/device_interface.py__new__DeviceInterface.device.__new__.   s    %%     N)
__name__
__module____qualname____firstlineno__torchtypesDevicer   r   __static_attributes__r!   r    r   r   r   -   s    	&!3!3 	& 	&r    r   c                   *    \ rS rSrS\S\S\4S jrSrg)DeviceInterface.Event1   argskwargsr   c                     [        S5      e)NzYEvent should be inherited from torch.Event, otherwise, it couldn't be captured by dynamo.r   r   r-   r.   s      r   r   DeviceInterface.Event.__new__2   s    %k r    r!   Nr"   r#   r$   r%   r   r   r)   r!   r    r   Eventr+   1       	 	s 	s 	r    r3   c                   *    \ rS rSrS\S\S\4S jrSrg)DeviceInterface.Stream7   r-   r.   r   c                     [        S5      e)Nz[Stream should be inherited from torch.Stream, otherwise, it couldn't be captured by dynamo.r   r0   s      r   r   DeviceInterface.Stream.__new__8   s    %m r    r!   Nr2   r!   r    r   Streamr6   7   r4   r    r:   c                       \ rS rSrSr\S\SS4S j5       r\S\4S j5       r\S
S\	R                  R                  S\4S jj5       rS	rg)DeviceInterface.Worker=   z
Worker API to query device properties that will work in multi processing
workers that cannot use the GPU APIs (due to processing fork() and
initialization time issues). Properties are recorded in the main process
before we fork the workers.
r   r   Nc                     [         er   r   r   s    r   
set_device!DeviceInterface.Worker.set_deviceE       %%r    c                      [         er   r   r!   r    r   current_device%DeviceInterface.Worker.current_deviceI   rB   r    c                     [         er   r   r?   s    r   get_device_properties,DeviceInterface.Worker.get_device_propertiesM   rB   r    r!   r   )r"   r#   r$   r%   __doc__staticmethodintr@   rD   r&   r'   r(   r   rG   r)   r!   r    r   Workerr<   =   sp    	 
	&s 	&t 	& 
	& 
	& 	& 
	& 
	&%++*<*< 	& 	& 
	&r    rL   r   c                      [         er   r   r!   r    r   rD   DeviceInterface.current_deviceQ       !!r    Nc                     [         er   r   r?   s    r   r@   DeviceInterface.set_deviceU   rO   r    c                     [         er   r   r?   s    r   maybe_exchange_device%DeviceInterface.maybe_exchange_deviceY   rO   r    c                     [         er   r   r?   s    r   exchange_deviceDeviceInterface.exchange_device]   rO   r    c                      [         er   r   r!   r    r   device_countDeviceInterface.device_counta   rO   r    c                      [         er   r   r!   r    r   is_availableDeviceInterface.is_availablee   rO   r    streamc                     [         er   r   r^   s    r   r^   DeviceInterface.streami   rO   r    c                      [         er   r   r!   r    r   current_streamDeviceInterface.current_streamm   rO   r    c                     [         er   r   r`   s    r   
set_streamDeviceInterface.set_streamq   rO   r    	stream_iddevice_indexdevice_typec                     [         er   r   )rh   ri   rj   s      r   _set_stream_by_id!DeviceInterface._set_stream_by_idu   rO   r    
device_idxc                     [         er   r   rn   s    r   get_raw_streamDeviceInterface.get_raw_streamy   rO   r    c                     [         er   r   r?   s    r   synchronizeDeviceInterface.synchronize}   rO   r    c                 8    U R                   R                  U5      $ r   )rL   rG   r   s     r   rG   %DeviceInterface.get_device_properties   s    zz//77r    c                     [         er   r   r?   s    r   get_compute_capability&DeviceInterface.get_compute_capability   rO   r    including_emulationc                     [         er   r   r{   s    r   is_bf16_supported!DeviceInterface.is_bf16_supported   rO   r    dtypec                 X    U[         R                  :g  =(       d    U R                  U5      $ r   )r&   bfloat16r~   r   r   r{   s      r   is_dtype_supported"DeviceInterface.is_dtype_supported   s$     &T#*?*?@S*TTr    c                     [         er   r   r?   s    r   memory_allocated DeviceInterface.memory_allocated   rO   r    c                     g)zz
Returns True if the device has Triton support, False otherwise, even if
the appropriate Triton backend is not available.
Fr!   r?   s    r   is_triton_capable!DeviceInterface.is_triton_capable   s     r    c                 D    U R                  5       (       d  [        S5      eg)a  
Raises a `RuntimeError` with the appropriate human-readable instructions
to resolve the issue if Triton is not available for the given device, or
the default device if `device` is `None`.

The caller should ensure the presence of the 'triton' package before
calling this method.
z/This device is not capable of supporting TritonN)r   RuntimeErrorr   s     r   raise_if_triton_unavailable+DeviceInterface.raise_if_triton_unavailable   s$     $$&&PQQ 'r    r!   r   F)&r"   r#   r$   r%   rI   r   r3   r:   rL   rJ   rK   rD   r&   r'   r(   r@   rS   rV   rY   boolr\   r   r^   rc   rf   rl   rq   rt   classmethodrG   ry   r~   r   r   r   r   r   r)   r!   r    r   r   r   '   s   
& &  & &( "C " " "5;;-- "$ " " "c "c " " " " " " "# " " "$ " " "u|| " " " "ELL " " "5<< "D " " "S " "# "RV " " "3 "3 " " "EKK.. "$ " " 85;;+=+= 8 8 8 "u{{'9'9 "S " " "t " " " =BUKKU6:U	U U
 "!3!3 "s " " %++"4"4    
R1C1C 
Rt 
R 
Rr    r   c            	       d    \ rS rSrSrS\\   S\\   SS4S jr	SS jr
S	\S
\S\S\S   4S jrSrg)DeviceGuard   aG  
This class provides a context manager for device switching. This is a stripped
down version of torch.{device_name}.device.

The context manager changes the current device to the given device index
on entering the context and restores the original device on exiting.
The device is switched using the provided device interface.
device_interfaceindexr   Nc                 *    Xl         X l        SU l        g )Nr   idxprev_idx)selfr   r   s      r   __init__DeviceGuard.__init__   s     !1r    c                 t    U R                   b+  U R                  R                  U R                   5      U l        g g r   )r   r   rV   r   )r   s    r   	__enter__DeviceGuard.__enter__   s-    88 11AA$((KDM  r    typevalue	tracebackFc                 r    U R                   b*  U R                  R                  U R                  5      U l         gNF)r   r   rS   r   )r   r   r   r   s       r   __exit__DeviceGuard.__exit__   s+    88,,BB4==QDHr    r   r   N)r"   r#   r$   r%   rI   r   r   r	   rK   r   r   r   r   r   r)   r!   r    r   r   r      sX     $_ 5>Fsm	LS    r    r   c                      \ rS rSr\R
                  R                  r\R
                  R                  r\R
                  R                  r " S S5      r	\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                   5      r\
" \R
                  R"                  5      r\
" \R
                  R$                  5      r\
" \R
                  R&                  5      r\
" \5      r\
" \R
                  R,                  5      r\
" \R
                  R0                  5      r\
" \R
                  R4                  5      r\
" \R
                  R6                  5      r\
S\4S j5       r\
SS\R<                  R>                  S\ \!\"4   4S jj5       r#\
SS\R<                  R>                  S\4S	 jj5       r$\
SS\R<                  R>                  SS4S
 jj5       r%Sr&g)CudaInterface   c                       \ rS rSr\S\SS4S j5       r\S\4S j5       r\S	S\R                  R                  S\4S jj5       rSrg)
CudaInterface.Worker   r   r   Nc                     U [         S'   g Ncudar   r?   s    r   r@   CudaInterface.Worker.set_device       5;*62r    c                  d    S[         ;   a	  [         S   $ [        R                  R                  5       $ r   )r   r&   r   rD   r!   r    r   rD   #CudaInterface.Worker.current_device   )    775f==::,,..r    c                 
   U bh  [        U [        5      (       a(  [        R                  " U 5      n U R                  S:X  d   e[        U [        R                  5      (       a  U R
                  n U c  [        R                  R                  5       n S[        ;  a]  [        [        R                  R                  5       5       Vs/ s H"  n[        R                  R                  U5      PM$     nnU[        S'   [        S   U    $ s  snf r   )
isinstancestrr&   r   r   r   r   rL   rD   r   ranger   rY   rG   r   idevice_props      r   rG   *CudaInterface.Worker.get_device_properties       !fc**"\\&1F!;;&000fell33#\\F~&--<<>== #5::#:#:#<== JJ44Q7=   <G083F;FCC    )D r!   r   r"   r#   r$   r%   rJ   rK   r@   rD   r&   r'   r(   r   rG   r)   r!   r    r   rL   r      m    		<s 	<t 	< 
	< 
	/ 	/ 
	/
 
	D%++*<*< 	D 	D 
	Dr    rL   r   c                  >    [         R                  R                  5       $ r   )r&   r   r\   r!   r    r   r\   CudaInterface.is_available   s    zz&&((r    Nr   c                    [         R                  R                  c)  [         R                  R	                  U 5      u  pUS-  U-   $ [         R                  R                  U 5      R                  R                  SS5      S   $ )N
   :   r   )r&   versionhipr   get_device_capabilityrG   gcnArchNamesplit)r   majormins      r   ry   $CudaInterface.get_compute_capability  sf    ==$99&AJE2:##::33F;GGMMcSTUVWXXr    c                     [         R                  R                  S L=(       d,    [         R                  R	                  U 5      R
                  S:  $ )N   )r&   r   r   r   rG   r   r?   s    r   r   CudaInterface.is_triton_capable  s>     MMT) Czz//7==B	
r    c                    SSK Jn  [        R                  U 5      (       d;  [        R
                  R                  U 5      nU" U[        R                  " 5       5      eSS K	n[        R                  R                  b&  SUR                  R                  ;  a  [        S5      eg SUR                  R                  ;  a  [        S5      eg )Nr   )GPUTooOldForTritonamdz'triton not built with the 'amd' backendnvidiaz*triton not built with the 'nvidia' backend)torch._inductor.excr   r   r   r&   r   rG   inspectcurrentframetriton.backendsr   r   backendsr   )r   r   device_propstritons       r   r   )CudaInterface.raise_if_triton_unavailable  s    :..v66 ::;;FCL$\73G3G3IJJ==(FOO444"#LMM 5V__555KLL 6r    r!   r   )'r"   r#   r$   r%   r&   r   r   r3   r:   rL   rJ   rD   r@   rY   r^   rc   rf   rl   rt   rG   r   rq   _exchange_devicerV   _maybe_exchange_devicerS   r   r~   r   r\   r'   r(   r
   rK   r   ry   r   r   r)   r!   r    r   r   r      s   ZZF JJEZZFD D> "%**";";<Nejj334J

 7 78L%**++,F!%**";";<Nejj334J$UZZ%A%ABuzz556K()I)IJ!/2N"5::#>#>?O()J)JK#EJJ$?$?@$UZZ%A%AB )$ ) ) Yu{{'9'9 YU3PS8_ Y Y 
%++"4"4 
 
 
 MEKK,>,> M$ M Mr    r   get_mtia_stream)_mtia_getCurrentRawStreamc                      \ rS rSr\R
                  R                  r\R
                  R                  r\R
                  R                  r " S S5      r	\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                   5      r\
" \R
                  R"                  5      r\
" \R
                  R$                  5      r\
" \R
                  R&                  5      r\
" \5      r\
" \R
                  R,                  5      r\
" \R
                  R0                  5      r\
" \R
                  R4                  5      r\
" \R
                  R6                  5      r\
S\4S j5       r\
SS\R<                  R>                  S\ 4S jj5       r!\
SS\R<                  R>                  S\4S	 jj5       r"\
SS
\R<                  R>                  SS4S jj5       r#Sr$g)MtiaInterfacei*  c                       \ rS rSr\S\SS4S j5       r\S\4S j5       r\S	S\R                  R                  S\4S jj5       rSrg)
MtiaInterface.Workeri/  r   r   Nc                     U [         S'   g Nmtiar   r?   s    r   r@   MtiaInterface.Worker.set_device0  r   r    c                  d    S[         ;   a	  [         S   $ [        R                  R                  5       $ r   )r   r&   r   rD   r!   r    r   rD   #MtiaInterface.Worker.current_device4  r   r    c                 
   U bh  [        U [        5      (       a(  [        R                  " U 5      n U R                  S:X  d   e[        U [        R                  5      (       a  U R
                  n U c  [        R                  R                  5       n S[        ;  a]  [        [        R                  R                  5       5       Vs/ s H"  n[        R                  R                  U5      PM$     nnU[        S'   [        S   U    $ s  snf r   )r   r   r&   r   r   r   r   rL   rD   r   r   r   rY   rG   r   s      r   rG   *MtiaInterface.Worker.get_device_properties:  r   r   r!   r   r   r!   r    r   rL   r   /  r   r    rL   r   c                  B    [         R                  R                  5       n U $ r   )r&   r   r\   )rets    r   r\   MtiaInterface.is_available^  s    jj%%'
r    Nr   c                 D    [         R                  R                  U 5      nU$ r   )r&   r   r   r   ccs     r   ry   $MtiaInterface.get_compute_capabilityc  s    ZZ--f5	r    c                     gNTr!   r?   s    r   r   MtiaInterface.is_triton_capableh      r    evicec                 V    SS K nSUR                  R                  ;  a  [        S5      eg )Nr   r   z(triton not built with the 'mtia' backendr   r   r   )r   r   s     r   r   )MtiaInterface.raise_if_triton_unavailablel  s(    111IJJ 2r    r!   r   )%r"   r#   r$   r%   r&   r   r   r3   r:   rL   rJ   rD   r@   rY   r^   rc   rf   rl   rt   rG   r   rq   r   rV   r   rS   r   r~   r   r\   r'   r(   r   ry   r   r   r)   r!   r    r   r   r   *  s   ZZFJJEZZFD D> "%**";";<Nejj334J

 7 78L%**++,F!%**";";<Nejj334J$UZZ%A%ABuzz556K()I)IJ!/2N"5::#>#>?O()J)JK#EJJ$?$?@$UZZ%A%AB $   u{{'9'9 S   %++"4"4    K5;;+=+= K K Kr    r   get_xpu_stream)_xpu_getCurrentRawStreamc                   l   \ rS rSr\R
                  R                  r\R
                  R                  r\R
                  R                  r " S S5      r	\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                  5      r\
" \R
                  R                   5      r\
" \R
                  R"                  5      r\
" \R
                  R$                  5      r\
" \R
                  R&                  5      r\
" \5      r\
" \R
                  R,                  5      r\
" \R
                  R0                  5      r\
" \R
                  R4                  5      r\
S\4S j5       r\
SS\R:                  R<                  S\4S jj5       r \
SS	\S\4S
 jj5       r!\
SS\R:                  R<                  S\4S jj5       r"\
SS\R:                  R<                  SS4S jj5       r#Sr$g)XpuInterfacei{  c                       \ rS rSr\S\SS4S j5       r\S\4S j5       r\S	S\R                  R                  S\4S jj5       rSrg)
XpuInterface.Workeri  r   r   Nc                     U [         S'   g Nxpur   r?   s    r   r@   XpuInterface.Worker.set_device  s    4:*51r    c                  d    S[         ;   a	  [         S   $ [        R                  R                  5       $ r	  )r   r&   r
  rD   r!   r    r   rD   "XpuInterface.Worker.current_device  s)    665e<<99++--r    c                 
   U bh  [        U [        5      (       a(  [        R                  " U 5      n U R                  S:X  d   e[        U [        R                  5      (       a  U R
                  n U c  [        R                  R                  5       n S[        ;  a]  [        [        R                  R                  5       5       Vs/ s H"  n[        R                  R                  U5      PM$     nnU[        S'   [        S   U    $ s  snf r	  )r   r   r&   r   r   r   r  rL   rD   r   r   r
  rY   rG   r   s      r   rG   )XpuInterface.Worker.get_device_properties  s    !fc**"\\&1F!;;%///fell33#\\F~%,,;;=<< #599#9#9#;<< II33A6<   ;F073E:6BBr   r!   r   r   r!   r    r   rL   r    sm    		;s 	;t 	; 
	; 
	. 	. 
	.
 
	C%++*<*< 	C 	C 
	Cr    rL   r   c                  >    [         R                  R                  5       $ r   )r&   r
  r\   r!   r    r   r\   XpuInterface.is_available  s    yy%%''r    Nr   c                 D    [         R                  R                  U 5      nU$ r   )r&   r
  r   r   s     r   ry   #XpuInterface.get_compute_capability  s    YY,,V4	r    r{   c                 >    [         R                  R                  5       $ r   )r&   r
  r~   r}   s    r   r~   XpuInterface.is_bf16_supported  s    yy**,,r    c                     gr   r!   r?   s    r   r   XpuInterface.is_triton_capable  r   r    c                 V    SS K nSUR                  R                  ;  a  [        S5      eg )Nr   intelz)triton not built with the 'intel' backendr   r   r   s     r   r   (XpuInterface.raise_if_triton_unavailable  s(    &//222JKK 3r    r!   r   r   )%r"   r#   r$   r%   r&   r
  r   r3   r:   rL   rJ   rD   r@   rY   r^   rc   rf   rl   rt   rG   r  rq   r   rV   r   rS   r   r   r\   r'   r(   r   ry   r~   r   r   r)   r!   r    r   r  r  {  s   YYFIIOOEYYFC C> "%))":":;Neii223J		 6 67L%))**+F!%))":":;Neii223J$UYY%@%@Auyy445K()H)HI!.1N"599#=#=>O()I)IJ#EII$>$>? ($ ( ( u{{'9'9 S   -t - - - %++"4"4    LEKK,>,> L$ L Lr    r  c                        \ rS rSr% \\S'   Srg)CpuDevicePropertiesi  multi_processor_countr!   N)r"   r#   r$   r%   rK   __annotations__r)   r!   r    r   r  r    s    r    r  c                      \ rS rSr " S S\R
                  5      r " S S5      r\S\4S j5       r	\SS\S\4S	 jj5       r
\SS\R                  R                  S\4S jj5       r\S\S\4S j5       r\S\4S j5       r\SS\R                  R                  SS
4S jj5       r\SS\R                  R                  S\4S jj5       r\SS\R                  R                  SS
4S jj5       rSrg
)CpuInterfacei  c                   R    \ rS rSrSS\SS4S jjrS\S\4S jrSS\SS4S	 jjr	S
r
g)CpuInterface.Eventi  enable_timingr   Nc                     SU l         g )Ng        time)r   r$  s     r   r   CpuInterface.Event.__init__  s	    DIr    	end_eventc                 :    UR                   U R                   -
  S-  $ )Ni  r&  )r   r)  s     r   elapsed_timeCpuInterface.Event.elapsed_time  s    NNTYY.$66r    r^   c                 8    [         R                  " 5       U l         g r   )r'  perf_counter)r   r^   s     r   recordCpuInterface.Event.record  s    ))+DIr    r&  )Tr   )r"   r#   r$   r%   r   r   r   floatr+  r/  r)   r!   r    r   r3   r#    s@    	$ 	$ 		7# 	7% 	7	, 	, 	, 	,r    r3   c                   ^    \ rS rSr\ SS\R                  R                  S\4S jj5       r	Sr
g)CpuInterface.Workeri  Nr   r   c                 @    SS K nUR                  5       n[        U5      $ Nr   )multiprocessing	cpu_countr  )r   r6  r7  s      r   rG   )CpuInterface.Worker.get_device_properties  s      #'113I&y11r    r!   r   )r"   r#   r$   r%   rJ   r&   r'   r(   r  rG   r)   r!   r    r   rL   r3    s1    	)-	2KK&&	2 	2 
	2r    rL   r   c                      gr   r!   r!   r    r   r\   CpuInterface.is_available  r   r    r{   c                     gr   r!   r}   s    r   r~   CpuInterface.is_bf16_supported  r   r    Nr   c                     gN r!   r?   s    r   ry   #CpuInterface.get_compute_capability      r    rn   c                     gr5  r!   rp   s    r   rq   CpuInterface.get_raw_stream      r    c                      gr5  r!   r!   r    r   rD   CpuInterface.current_device  rD  r    c                     g r   r!   r?   s    r   rt   CpuInterface.synchronize  s    r    c                     gr   r!   r?   s    r   r   CpuInterface.is_triton_capable  r   r    c                 V    SS K nSUR                  R                  ;  a  [        S5      eg )Nr   cpuz'triton not built with the 'cpu' backendr   r  s     r   r   (CpuInterface.raise_if_triton_unavailable  s(    000HII 1r    r!   r   r   )r"   r#   r$   r%   r&   r3   rL   rJ   r   r\   r~   r'   r(   r   ry   r   rK   rq   rD   rt   r   r   r)   r!   r    r   r!  r!    sJ   , ,2 2 $   t    u{{'9'9 S   3 3   C   EKK.. $   %++"4"4    JEKK,>,> J$ J Jr    r!  c                   B   \ rS rSr\SS\S\4S jj5       r\ SS\R                  S\S\4S jj5       r
\S\4S j5       r\S\4S j5       r\SS
\R                  R                  S\4S jj5       r\SS
\R                  R                  SS	4S jj5       r " S S5      rSrg	)MpsInterfacei  r{   r   c                 V    [         R                  R                  R                  SS5      $ )N   r   )r&   r   mpsis_macos_or_newerr}   s    r   r~   MpsInterface.is_bf16_supported  s    ~~!!33B::r    r   c                     U[         R                  [         R                  4;   a  gU[         R                  :g  =(       d    U R	                  U5      $ r   )r&   float64
complex128r   r~   r   s      r   r   MpsInterface.is_dtype_supported
  s>     U]]E$4$455&T#*?*?@S*TTr    c                  R    [         R                  R                  R                  5       $ r   )r&   r   rR  r\   r!   r    r   r\   MpsInterface.is_available  s    ~~!!..00r    c                      gr5  r!   r!   r    r   rD   MpsInterface.current_device  rD  r    Nr   c                     gr>  r!   r?   s    r   ry   #MpsInterface.get_compute_capability  rA  r    c                 @    [         R                  R                  5         g r   )r&   rR  rt   r?   s    r   rt   MpsInterface.synchronize  s    		r    c                   t    \ rS rSr\SS\R                  R                  S\4S jj5       r	\S\
4S j5       rSrg)	MpsInterface.Workeri"  Nr   r   c                 t    [        SS/5      " [        R                  R                  R	                  5       5      $ )NMPSPropertiesr  )r   r&   r   rR  get_core_countr?   s    r   rG   )MpsInterface.Worker.get_device_properties#  s0    o0G/HI""113 r    c                      gr5  r!   r!   r    r   rD   "MpsInterface.Worker.current_device)  s    r    r!   r   )r"   r#   r$   r%   rJ   r&   r'   r(   r   rG   rK   rD   r)   r!   r    r   rL   rb  "  sG    		%++*<*< 	 	 
	
 
	 	 
	r    rL   r!   r   r   )r"   r#   r$   r%   rJ   r   r~   r   r&   r   r   r\   rK   rD   r'   r(   r   ry   rt   rL   r)   r!   r    r   rO  rO    s    ;t ; ; ; =BUKKU6:U	U U 1$ 1 1 C   u{{'9'9 S    EKK..  $    	 	r    rO  device_interfacesFr   r   r   c                 l    [        U [        R                  5      (       a  U R                  n U[        U '   g r   )r   r&   r   r   ri  )r   r   s     r   register_interface_for_devicerk  2  s)     &%,,'' 0fr    c                     [        U [        R                  5      (       a  U R                  n [        (       d
  [        5         U [        ;   a	  [        U    $ [        SU  35      e)NzNo interface for device )r   r&   r   r   _device_initializedinit_device_regri  r   r?   s    r   get_interface_for_devicero  :  sO    &%,,''"" ((
 8A
BBr    c                  T    [         (       d
  [        5         [        R                  5       $ r   )rm  rn  ri  itemsr!   r    r    get_registered_device_interfacesrr  D  s    ""$$r    c                  .   [        S[        5        [        [        R                  R                  5       5       H  n [        SU  3[        5        M     [        S[        5        [        [        R                  R                  5       5       H  n [        SU  3[        5        M     [        S[        5        [        [        R                  R                  5       5       H  n [        SU  3[        5        M     [        S[        5        [        S[        5        S	qg )
Nr   zcuda:r
  zxpu:r   zmtia:rL  rR  T)rk  r   r   r&   r   rY   r  r
  r   r   r!  rO  rm  )r   s    r   rn  rn  J  s    !&-85::**,-%aSk=A . "%6599))+,%QCj,? - "&-85::**,-%aSk=A . "%6!%6r    r   )2rI   r   r'  collectionsr   collections.abcr   dataclassesr   typingr   r   r   r	   r
   r&   rK   r  r   _is_compiledtorch._Cr   r   r   dictr   r   r   r   r   r   r   r   r   r
  r  r  r  r  r!  rO  ri  r   rm  r   rk  ro  tuplerr  rn  r!   r    r   <module>r|     s  "   " $ ! : :  (C5#:./ /::EO 46  $sCx. 513 S#X 3CR CRL 6XMO XMv (C5#:./ /::EOGKO GKT 3%*-. .99CNIL? ILX   6J? 6Jr&? &R 79 4T/223 8 1#u||#$18<_8M1	1CU3+<%= C$BW C%(5d?>S9S3T*U %r    