
    IЦi1                        % S SK r S SKJr  S SKJrJrJr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\\R(                  \\S4   r0 r\\\4   \S'   0 r\\\4   \S'    " S S	5      r " S
 S5      r " S S\5      r\\\/\4      \S'   \R8                  R!                  5       (       a  S SKJr  OSr " S S\5      r\ " S S5      5       r  " S S\5      r!0 r"\\\
\   4   \S'   Sq#S\\\R(                  4   S\
\   4S jr$S\\\R(                  4   S\
\   4S jr%S\\	\\
\   4      4S jr&S r'g)    N)	dataclass)AnyCallableDictIterableOptionalTupleType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 5       r
\	S\4S j5       r\	S\S\4S j5       r\	S\S\4S j5       r\	S 5       r\	S\4S j5       r\	S\R                  4S j5       r\	S 5       r\	S\R                  4S j5       r\	S\S\S\4S j5       r\	S\S\4S j5       r\	S$S\4S jj5       r\S$S\4S jj5       r\	S$S\4S jj5       r\	S%S \4S! jj5       r\	S$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                   "    \ rS rSrS\4S jrSrg)DeviceInterface.device   devicec                     [         eNNotImplementedErrorclsr   s     ]/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torch/_dynamo/device_interface.py__new__DeviceInterface.device.__new__   s    %%     N)__name__
__module____qualname____firstlineno__	_device_tr   __static_attributes__r!   r    r   r   r      s    	& 	&r    r   c                       \ rS rSrS rSrg)DeviceInterface.Event    c                     [        S5      e)NzYEvent should be inherited from torch.Event, otherwise, it couldn't be captured by dynamo.r   r   argskwargss      r   r   DeviceInterface.Event.__new__!   s    %k r    r!   Nr"   r#   r$   r%   r   r'   r!   r    r   Eventr)           	r    r1   c                       \ rS rSrS rSrg)DeviceInterface.Stream&   c                     [        S5      e)Nz[Stream should be inherited from torch.Stream, otherwise, it couldn't be captured by dynamo.r   r,   s      r   r   DeviceInterface.Stream.__new__'   s    %m r    r!   Nr0   r!   r    r   Streamr4   &   r2   r    r8   c                   d    \ rS rSrSr\S\4S j5       r\S\4S j5       r\S
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   c                     [         er   r   r   s    r   
set_device!DeviceInterface.Worker.set_device4       %%r    returnc                      [         er   r   r!   r    r   current_device%DeviceInterface.Worker.current_device8   r@   r    Nc                     [         er   r   r=   s    r   get_device_properties,DeviceInterface.Worker.get_device_properties<   r@   r    r!   r   )r"   r#   r$   r%   __doc__staticmethodintr>   rC   r&   rF   r'   r!   r    r   Workerr:   ,   sX    	 
	&s 	& 
	& 
	& 	& 
	& 
	&) 	& 
	&r    rK   c                      [         er   r   r!   r    r   rC   DeviceInterface.current_device@       !!r    c                     [         er   r   r=   s    r   r>   DeviceInterface.set_deviceD   rN   r    rA   c                     [         er   r   r=   s    r   maybe_exchange_device%DeviceInterface.maybe_exchange_deviceH   rN   r    c                     [         er   r   r=   s    r   exchange_deviceDeviceInterface.exchange_deviceL   rN   r    c                      [         er   r   r!   r    r   device_countDeviceInterface.device_countP   rN   r    c                      [         er   r   r!   r    r   is_availableDeviceInterface.is_availableT   rN   r    streamc                     [         er   r   r]   s    r   r]   DeviceInterface.streamX   rN   r    c                      [         er   r   r!   r    r   current_streamDeviceInterface.current_stream\   rN   r    c                     [         er   r   r_   s    r   
set_streamDeviceInterface.set_stream`   rN   r    	stream_iddevice_indexdevice_typec                     [         er   r   )rg   rh   ri   s      r   _set_stream_by_id!DeviceInterface._set_stream_by_idd   rN   r    
device_idxc                     [         er   r   rm   s    r   get_raw_streamDeviceInterface.get_raw_streamh   rN   r    Nc                     [         er   r   r=   s    r   synchronizeDeviceInterface.synchronizel   rN   r    c                 8    U R                   R                  U5      $ r   )rK   rF   r   s     r   rF   %DeviceInterface.get_device_propertiesp   s    zz//77r    c                     [         er   r   r=   s    r   get_compute_capability&DeviceInterface.get_compute_capabilityt   rN   r    including_emulationc                     [         er   r   rz   s    r   is_bf16_supported!DeviceInterface.is_bf16_supportedx   rN   r    c                     [         er   r   r=   s    r   memory_allocated DeviceInterface.memory_allocated|   rN   r    r!   r   F) r"   r#   r$   r%   rH   r   r1   r8   rK   rI   rC   r&   r>   rJ   rR   rU   rX   boolr[   torchr]   rb   re   rk   rp   rs   classmethodrF   rx   r}   r   r'   r!   r    r   r   r      s   
& &  & &( " " "9 " " "c "c " " " " " " " " "$ " " "u|| " " " " "5<< " " "S " "# " " "3 "3 " " "I " " 89 8 8 "y " " "t " " " "c " "r    r   c                   V    \ rS rSrSrS\\   S\\   SS4S jr	S r
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indexrA   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   rU   r   )r   s    r   	__enter__DeviceGuard.__enter__   s-    88 11AA$((KDM  r    typevalue	tracebackc                 r    U R                   b*  U R                  R                  U R                  5      U l         g)NF)r   r   rR   r   )r   r   r   r   s       r   __exit__DeviceGuard.__exit__   s+    88,,BB4==QDHr    r   )r"   r#   r$   r%   rH   r
   r   r   rJ   r   r   r   r   r'   r!   r    r   r   r      sM     $_ 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\4S jj5       rS	r g)CudaInterface   c                   `    \ rS rSr\S\4S j5       r\S\4S j5       r\S	S\4S jj5       r	Sr
g)
CudaInterface.Worker   r   c                     U [         S'   g Ncudar   r=   s    r   r>   CudaInterface.Worker.set_device   s    5;*62r    rA   c                  d    S[         ;   a	  [         S   $ [        R                  R                  5       $ r   )r   r   r   rC   r!   r    r   rC   #CudaInterface.Worker.current_device   s)    775f==::,,..r    Nc                 
   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   rK   rC   r   ranger   rX   rF   r   idevice_props      r   rF   *CudaInterface.Worker.get_device_properties   s    !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%   rI   rJ   r>   rC   r&   rF   r'   r!   r    r   rK   r      sT    		<s 	< 
	< 
	/ 	/ 
	/
 
	D) 	D 
	Dr    rK   rA   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_capabilityrF   gcnArchNamesplit)r   majormins      r   rx   $CudaInterface.get_compute_capability   sf    ==$99&AJE2:##::33F;GGMMcSTUVWXXr    r!   r   )!r"   r#   r$   r%   r   r   r   r1   r8   rK   rI   rC   r>   rX   r]   rb   re   rk   rs   rF   r   rp   _exchange_devicerU   _maybe_exchange_devicerR   r   r}   r   r[   r&   rx   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y Y Yr    r   get_xpu_stream)_xpu_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\
S\4S j5       r\
SS\4S jj5       r\
SS	\S\4S
 jj5       rSr g)XpuInterface   c                   `    \ rS rSr\S\4S j5       r\S\4S j5       r\S	S\4S jj5       r	Sr
g)
XpuInterface.Worker   r   c                     U [         S'   g Nxpur   r=   s    r   r>   XpuInterface.Worker.set_device   s    4:*51r    rA   c                  d    S[         ;   a	  [         S   $ [        R                  R                  5       $ r   )r   r   r   rC   r!   r    r   rC   "XpuInterface.Worker.current_device   s)    665e<<99++--r    Nc                 
   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   rK   rC   r   r   r   rX   rF   r   s      r   rF   )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   rK   r      sT    		;s 	; 
	; 
	. 	. 
	.
 
	C) 	C 
	Cr    rK   rA   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   ccs     r   rx   #XpuInterface.get_compute_capability  s    YY,,V4	r    rz   c                 >    [         R                  R                  5       $ r   )r   r   r}   r|   s    r   r}   XpuInterface.is_bf16_supported#  s    yy**,,r    r!   r   r   )!r"   r#   r$   r%   r   r   r   r1   r8   rK   rI   rC   r>   rX   r]   rb   re   rk   rs   rF   r   rp   r   rU   r   rR   r   r   r[   r&   rx   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$>$>? ($ ( ( y   -t - - -r    r   c                        \ rS rSr% \\S'   Srg)CpuDevicePropertiesi(  multi_processor_countr!   N)r"   r#   r$   r%   rJ   __annotations__r'   r!   r    r   r   r   (  s    r    r   c                       \ rS rSr " S S\R
                  5      r\S\4S j5       r\SS\	S\
4S jj5       r\S\4S	 j5       r\S
 5       r\SS\	4S jj5       r " S S5      rSrg)CpuInterfacei-  c                   6    \ rS rSrSS jrS\4S jrS	S jrSrg)
CpuInterface.Eventi.  c                     SU l         g )Ng        time)r   enable_timings     r   r   CpuInterface.Event.__init__/  s	    DIr    rA   c                 :    UR                   U R                   -
  S-  $ )Ni  r   )r   	end_events     r   elapsed_timeCpuInterface.Event.elapsed_time2  s    NNTYY.$66r    Nc                 8    [         R                  " 5       U l         g r   )r   perf_counter)r   r]   s     r   recordCpuInterface.Event.record5  s    ))+DIr    r   )Tr   )	r"   r#   r$   r%   r   floatr   r   r'   r!   r    r   r1   r   .  s    		7U 	7	,r    r1   rA   c                      g)NTr!   r!   r    r   r[   CpuInterface.is_available8  s    r    Nr   c                     g)N r!   r=   s    r   rx   #CpuInterface.get_compute_capability<  s    r    c                     gNr   r!   ro   s    r   rp   CpuInterface.get_raw_stream@      r    c                      gr   r!   r!   r    r   rC   CpuInterface.current_deviceD  r   r    c                     g r   r!   r=   s    r   rs   CpuInterface.synchronizeH  s    r    c                   0    \ rS rSr\SS\4S jj5       rSrg)CpuInterface.WorkeriL  Nr   c                 @    SS K nUR                  5       n[        U5      $ r   )multiprocessing	cpu_countr   )r   r   r  s      r   rF   )CpuInterface.Worker.get_device_propertiesM  s    "'113I&y11r    r!   r   )r"   r#   r$   r%   rI   r&   rF   r'   r!   r    r   rK   r   L  s    		2) 	2 
	2r    rK   r!   r   )r"   r#   r$   r%   r   r1   rI   r   r[   r&   r   rx   rJ   rp   rC   rs   rK   r'   r!   r    r   r   r   -  s    , , $   y C   c     I  2 2r    r   device_interfacesFr   r   c                 l    [        U [        R                  5      (       a  U R                  n U[        U '   g r   )r   r   r   r   r  )r   r   s     r   register_interface_for_devicer  Y  s)     &%,,'' 0fr    rA   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_regr  r   r=   s    r   get_interface_for_devicer	  a  sO    &%,,''"" ((
 8A
BBr    c                  T    [         (       d
  [        5         [        R                  5       $ r   )r  r  r  itemsr!   r    r    get_registered_device_interfacesr  k  s    ""$$r    c                  l   [        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q	g )Nr   zcuda:r   zxpu:cpuT)
r  r   r   r   r   rX   r   r   r   r  )r   s    r   r  r  q  s    !&-85::**,-%aSk=A . "%6599))+,%QCj,? - "%6r    )(r   dataclassesr   typingr   r   r   r   r   r	   r
   r   r   rJ   r   r   _is_compiledtorch._Cr   r   r   r   r&   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r	  r  r  r!   r    r   <module>r     s    ! N N N  (C5#:./ /::EO%,,S$./	 46  $sCx. 513 S#X 3h" h"V 6AYO AYH 3%*-. .99CN>-? >-B   %2? %2P 79 4T/223 8 1#u||#$18<_8M1CU3+<%= C$BW C%(5d?>S9S3T*U %r    