
    iU                     $   U d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZmZ ddlZeeegef      ed<   ej$                  j'                         rddlmZ ndZi Zeee
f   ed	<   i Zeeef   ed
<    G d d      Z G d d      Z G d de      Zeeegef      ed<   ej<                  j'                         rddlmZ  ndZ  G d de      Z!eeegef      ed<   ejD                  j'                         rddlm#Z$ ndZ$ G d de      Z%e G d d             Z& G d de      Z' G d de      Z(i Z)eee*e   f   ed<   d a+d!eeejX                  f   d"e*e   d#dfd$Z-d!eeejX                  f   d#e*e   fd%Z.d#ee/ee*e   f      fd&Z0d(d'Z1y))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            	          e Zd ZdZ G d d      Z G d d      Z G d d      Z G d d	      Zed
e	fd       Z
edej                  j                  d
dfd       Zede	d
e	fd       Zede	d
e	fd       Zed
e	fd       Zed
efd       Zedej                  d
efd       Zed
ej                  fd       Zedej                  d
dfd       Zede	de	de	d
dfd       Zede	d
e	fd       Zed&dej                  j                  d
dfd       Zed&dej                  j                  d
efd       Zed&dej                  j                  d
efd       Zed'ded
efd        Ze	 d'd!ej>                  ded
efd"       Z ed&dej                  j                  d
e	fd#       Z!ed&dej                  j                  d
efd$       Z"ed&dej                  j                  d
dfd%       Z#y)(DeviceInterfacez
    This is a simple device runtime interface for Inductor. It enables custom
    backends to be integrated with Inductor in a device-agnostic semantic.
    c                   D    e Zd Zdej                  j
                  defdZy)DeviceInterface.devicedevicereturnc                     t         NNotImplementedErrorclsr   s     X/var/www/html/engine/venv/lib/python3.12/site-packages/torch/_dynamo/device_interface.py__new__zDeviceInterface.device.__new__.   s    %%    N)__name__
__module____qualname__torchtypesDevicer   r    r   r   r   r   -   s    	&!3!3 	& 	&r   r   c                        e Zd ZdededefdZy)DeviceInterface.Eventargskwargsr   c                     t        d      )NzYEvent should be inherited from torch.Event, otherwise, it couldn't be captured by dynamo.r   r   r'   r(   s      r   r   zDeviceInterface.Event.__new__2   s    %k r   Nr   r   r    r   r   r$   r   r   Eventr&   1       	 	s 	s 	r   r,   c                        e Zd ZdededefdZy)DeviceInterface.Streamr'   r(   r   c                     t        d      )Nz[Stream should be inherited from torch.Stream, otherwise, it couldn't be captured by dynamo.r   r*   s      r   r   zDeviceInterface.Stream.__new__8   s    %m r   Nr+   r$   r   r   Streamr/   7   r-   r   r1   c                       e Zd ZdZededdfd       Zedefd       Zeddej                  j                  defd       Zy)	DeviceInterface.Workera  
        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                     t         r   r   r   s    r   
set_devicez!DeviceInterface.Worker.set_deviceE       %%r   c                      t         r   r   r$   r   r   current_devicez%DeviceInterface.Worker.current_deviceI   r7   r   c                     t         r   r   r5   s    r   get_device_propertiesz,DeviceInterface.Worker.get_device_propertiesM   r7   r   r   )r   r   r    __doc__staticmethodintr6   r9   r!   r"   r#   r   r;   r$   r   r   Workerr3   =   sp    	 
	&s 	&t 	& 
	& 
	& 	& 
	& 
	&%++*<*< 	& 	& 
	&r   r?   r   c                      t         r   r   r$   r   r   r9   zDeviceInterface.current_deviceQ       !!r   Nc                     t         r   r   r5   s    r   r6   zDeviceInterface.set_deviceU   rA   r   c                     t         r   r   r5   s    r   maybe_exchange_devicez%DeviceInterface.maybe_exchange_deviceY   rA   r   c                     t         r   r   r5   s    r   exchange_devicezDeviceInterface.exchange_device]   rA   r   c                      t         r   r   r$   r   r   device_countzDeviceInterface.device_counta   rA   r   c                      t         r   r   r$   r   r   is_availablezDeviceInterface.is_availablee   rA   r   streamc                     t         r   r   rK   s    r   rK   zDeviceInterface.streami   rA   r   c                      t         r   r   r$   r   r   current_streamzDeviceInterface.current_streamm   rA   r   c                     t         r   r   rM   s    r   
set_streamzDeviceInterface.set_streamq   rA   r   	stream_iddevice_indexdevice_typec                     t         r   r   )rR   rS   rT   s      r   _set_stream_by_idz!DeviceInterface._set_stream_by_idu   rA   r   
device_idxc                     t         r   r   rW   s    r   get_raw_streamzDeviceInterface.get_raw_streamy   rA   r   c                     t         r   r   r5   s    r   synchronizezDeviceInterface.synchronize}   rA   r   c                 8    | j                   j                  |      S r   )r?   r;   r   s     r   r;   z%DeviceInterface.get_device_properties   s    zz//77r   c                     t         r   r   r5   s    r   get_compute_capabilityz&DeviceInterface.get_compute_capability   rA   r   including_emulationc                     t         r   r   r`   s    r   is_bf16_supportedz!DeviceInterface.is_bf16_supported   rA   r   dtypec                 N    |t         j                  k7  xs | j                  |      S r   )r!   bfloat16rc   r   rd   r`   s      r   is_dtype_supportedz"DeviceInterface.is_dtype_supported   s$     &T#*?*?@S*TTr   c                     t         r   r   r5   s    r   memory_allocatedz DeviceInterface.memory_allocated   rA   r   c                      y)z
        Returns True if the device has Triton support, False otherwise, even if
        the appropriate Triton backend is not available.
        Fr$   r5   s    r   is_triton_capablez!DeviceInterface.is_triton_capable   s     r   c                 :    | j                         st        d      y)aH  
        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)rl   RuntimeErrorr   s     r   raise_if_triton_unavailablez+DeviceInterface.raise_if_triton_unavailable   s!     $$&PQQ 'r   r   F)$r   r   r    r<   r   r,   r1   r?   r=   r>   r9   r!   r"   r#   r6   rD   rF   rH   boolrJ   r   rK   rO   rQ   rV   rZ   r\   classmethodr;   r_   rc   rd   rh   rj   rl   ro   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            	       V    e Zd ZdZdee   dee   ddfdZddZ	de
d	e
d
e
ded   fdZy)DeviceGuarda_  
    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                 .    || _         || _        d| _        y )N)ru   idxprev_idx)selfru   rv   s      r   __init__zDeviceGuard.__init__   s     !1r   c                 r    | j                   +| j                  j                  | j                         | _        y y r   )ry   ru   rF   rz   )r{   s    r   	__enter__zDeviceGuard.__enter__   s-    88 11AA$((KDM  r   typevalue	tracebackFc                 p    | j                   *| j                  j                  | j                        | _         yNF)ry   ru   rD   rz   )r{   r   r   r   s       r   __exit__zDeviceGuard.__exit__   s+    88,,BB4==QDHr   r   N)r   r   r    r<   r   r   r	   r>   r|   r~   r   r   r   r$   r   r   rt   rt      sX     $_ 5>Fsm	LS    r   rt   c                   x   e Zd Zej                  j
                  Zej                  j                  Zej                  j                  Z G d d      Z e	ej                  j                        Z
 e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                         Z e	ej                  j"                        Z e	ej                  j$                        Z e	e      Z e	ej                  j*                        Z e	ej                  j.                        Z e	ej                  j2                        Z e	ej                  j4                        Ze	defd       Ze	d
dej:                  j<                  dee e!f   fd       Z"e	d
dej:                  j<                  defd       Z#e	d
dej:                  j<                  ddfd	       Z$y)CudaInterfacec                       e Zd Zededdfd       Zedefd       Zeddej                  j                  de
fd       Zy)CudaInterface.Workerr   r   Nc                     | t         d<   y Ncudar   r5   s    r   r6   zCudaInterface.Worker.set_device       5;*62r   c                  `    dt         v r	t         d   S t        j                  j                         S r   )r   r!   r   r9   r$   r   r   r9   z#CudaInterface.Worker.current_device   )    775f==::,,..r   c                    | \t        | t              r&t        j                  |       } | j                  dk(  sJ t        | t        j                        r| j
                  } | t        j                  j                         } dt        vrZt        t        j                  j                               D cg c]!  }t        j                  j                  |      # }}|t        d<   t        d   |    S c c}w r   )
isinstancestrr!   r   r   rv   r   r?   r9   r   ranger   rH   r;   r   idevice_props      r   r;   z*CudaInterface.Worker.get_device_properties       !fc*"\\&1F!;;&000fell3#\\F~&--<<>== #5::#:#:#<= JJ44Q7  <G083F;FCC   0&C-r   r   r   r    r=   r>   r6   r9   r!   r"   r#   r   r;   r$   r   r   r?   r      m    		<s 	<t 	< 
	< 
	/ 	/ 
	/
 
	D%++*<*< 	D 	D 
	Dr   r?   r   c                  >    t         j                  j                         S r   )r!   r   rJ   r$   r   r   rJ   zCudaInterface.is_available   s    zz&&((r   Nr   c                    t         j                  j                  *t         j                  j	                  |       \  }}|dz  |z   S t         j                  j                  |       j                  j                  dd      d   S )N
   :   r   )r!   versionhipr   get_device_capabilityr;   gcnArchNamesplit)r   majormins      r   r_   z$CudaInterface.get_compute_capability  sh    ==$99&AJE32:##::33F;GGMMcSTUVWXXr   c                     t         j                  j                  d uxs, t         j                  j	                  |       j
                  dk\  S )N   )r!   r   r   r   r;   r   r5   s    r   rl   zCudaInterface.is_triton_capable  s>     MMT) Czz//7==B	
r   c                 x   ddl m} t        j                  |       s:t        j
                  j                  |       } ||t        j                               dd l	}t        j                  j                  $d|j                  j                  vrt        d      y d|j                  j                  vrt        d      y )Nr   )GPUTooOldForTritonamdz'triton not built with the 'amd' backendnvidiaz*triton not built with the 'nvidia' backend)torch._inductor.excr   r   rl   r!   r   r;   inspectcurrentframetriton.backendsr   r   backendsrn   )r   r   device_propstritons       r   ro   z)CudaInterface.raise_if_triton_unavailable  s    :..v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,   r1   r?   r=   r9   r6   rH   rK   rO   rQ   rV   r\   r;   r   rZ   _exchange_devicerF   _maybe_exchange_devicerD   rj   rc   rq   rJ   r"   r#   r
   r>   r   r_   rl   ro   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                   n   e Zd Zej                  j
                  Zej                  j                  Zej                  j                  Z G d d      Z e	ej                  j                        Z
 e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                         Z e	ej                  j"                        Z e	ej                  j$                        Z e	e      Z e	ej                  j*                        Z e	ej                  j.                        Z e	ej                  j2                        Z e	ej                  j4                        Ze	defd       Ze	ddej:                  j<                  defd       Z e	ddej:                  j<                  defd       Z!e	dd	ej:                  j<                  ddfd
       Z"y)MtiaInterfacec                       e Zd Zededdfd       Zedefd       Zeddej                  j                  de
fd       Zy)MtiaInterface.Workerr   r   Nc                     | t         d<   y Nmtiar   r5   s    r   r6   zMtiaInterface.Worker.set_device0  r   r   c                  `    dt         v r	t         d   S t        j                  j                         S r   )r   r!   r   r9   r$   r   r   r9   z#MtiaInterface.Worker.current_device4  r   r   c                    | \t        | t              r&t        j                  |       } | j                  dk(  sJ t        | t        j                        r| j
                  } | t        j                  j                         } dt        vrZt        t        j                  j                               D cg c]!  }t        j                  j                  |      # }}|t        d<   t        d   |    S c c}w r   )r   r   r!   r   r   rv   r   r?   r9   r   r   r   rH   r;   r   s      r   r;   z*MtiaInterface.Worker.get_device_properties:  r   r   r   r   r$   r   r   r?   r   /  r   r   r?   r   c                  B    t         j                  j                         } | S r   )r!   r   rJ   )rets    r   rJ   zMtiaInterface.is_available^  s    jj%%'
r   Nr   c                 D    t         j                  j                  |       }|S r   )r!   r   r   r   ccs     r   r_   z$MtiaInterface.get_compute_capabilityc  s    ZZ--f5	r   c                      yNTr$   r5   s    r   rl   zMtiaInterface.is_triton_capableh      r   evicec                 R    dd l }d|j                  j                  vrt        d      y )Nr   r   z(triton not built with the 'mtia' backendr   r   rn   )r   r   s     r   ro   z)MtiaInterface.raise_if_triton_unavailablel  s(    111IJJ 2r   r   )#r   r   r    r!   r   r   r,   r1   r?   r=   r9   r6   rH   rK   rO   rQ   rV   r\   r;   r   rZ   r   rF   r   rD   rj   rc   rq   rJ   r"   r#   r   r_   rl   ro   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                   R   e Zd Zej                  j
                  Zej                  j                  Zej                  j                  Z G d d      Z e	ej                  j                        Z
 e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                        Z e	ej                  j                         Z e	ej                  j"                        Z e	ej                  j$                        Z e	e      Z e	ej                  j*                        Z e	ej                  j.                        Z e	ej                  j2                        Ze	defd       Ze	ddej8                  j:                  defd       Ze	ddedefd	       Z e	ddej8                  j:                  defd
       Z!e	ddej8                  j:                  ddfd       Z"y)XpuInterfacec                       e Zd Zededdfd       Zedefd       Zeddej                  j                  de
fd       Zy)XpuInterface.Workerr   r   Nc                     | t         d<   y Nxpur   r5   s    r   r6   zXpuInterface.Worker.set_device  s    4:*51r   c                  `    dt         v r	t         d   S t        j                  j                         S r   )r   r!   r   r9   r$   r   r   r9   z"XpuInterface.Worker.current_device  s)    665e<<99++--r   c                    | \t        | t              r&t        j                  |       } | j                  dk(  sJ t        | t        j                        r| j
                  } | t        j                  j                         } dt        vrZt        t        j                  j                               D cg c]!  }t        j                  j                  |      # }}|t        d<   t        d   |    S c c}w r   )r   r   r!   r   r   rv   r   r?   r9   r   r   r   rH   r;   r   s      r   r;   z)XpuInterface.Worker.get_device_properties  s    !fc*"\\&1F!;;%///fell3#\\F~%,,;;=<< #599#9#9#;< II33A6  ;F073E:6BBr   r   r   r$   r   r   r?   r     sm    		;s 	;t 	; 
	; 
	. 	. 
	.
 
	C%++*<*< 	C 	C 
	Cr   r?   r   c                  >    t         j                  j                         S r   )r!   r   rJ   r$   r   r   rJ   zXpuInterface.is_available  s    yy%%''r   Nr   c                 D    t         j                  j                  |       }|S r   )r!   r   r   r   s     r   r_   z#XpuInterface.get_compute_capability  s    YY,,V4	r   r`   c                 >    t         j                  j                         S r   )r!   r   rc   rb   s    r   rc   zXpuInterface.is_bf16_supported  s    yy**,,r   c                      yr   r$   r5   s    r   rl   zXpuInterface.is_triton_capable  r   r   c                 R    dd l }d|j                  j                  vrt        d      y )Nr   intelz)triton not built with the 'intel' backendr   r   r   s     r   ro   z(XpuInterface.raise_if_triton_unavailable  s(    &//222JKK 3r   r   rp   )#r   r   r    r!   r   r   r,   r1   r?   r=   r9   r6   rH   rK   rO   rQ   rV   r\   r;   r   rZ   r   rF   r   rD   rj   rq   rJ   r"   r#   r   r_   rc   rl   ro   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                       e Zd ZU eed<   y)CpuDevicePropertiesmulti_processor_countN)r   r   r    r>   __annotations__r$   r   r   r   r     s    r   r   c                      e Zd Z G d dej                        Z G d d      Zedefd       Zeddedefd       Z	edd
ej                  j                  defd       Zededefd       Zedefd       Zedd
ej                  j                  dd	fd       Zedd
ej                  j                  defd       Zedd
ej                  j                  dd	fd       Zy	)CpuInterfacec                   @    e Zd Zd	deddfdZdedefdZd
deddfdZy)CpuInterface.Eventenable_timingr   Nc                     d| _         y )Ng        time)r{   r   s     r   r|   zCpuInterface.Event.__init__  s	    DIr   	end_eventc                 :    |j                   | j                   z
  dz  S )Ni  r   )r{   r   s     r   elapsed_timezCpuInterface.Event.elapsed_time  s    NNTYY.$66r   rK   c                 6    t        j                         | _         y r   )r   perf_counter)r{   rK   s     r   recordzCpuInterface.Event.record  s    ))+DIr   )Tr   )	r   r   r    rq   r|   r   floatr   r   r$   r   r   r,   r     s;    	$ 	$ 		7# 	7% 	7	, 	, 	,r   r,   c                   R    e Zd Ze	 ddej
                  j                  defd       Zy)CpuInterface.WorkerNr   r   c                 @    dd l }|j                         }t        |      S Nr   )multiprocessing	cpu_countr   )r   r   r   s      r   r;   z)CpuInterface.Worker.get_device_properties  s      #'113I&y11r   r   )	r   r   r    r=   r!   r"   r#   r   r;   r$   r   r   r?   r     s1    	)-	2KK&&	2 	2 
	2r   r?   r   c                       yr   r$   r$   r   r   rJ   zCpuInterface.is_available  r   r   r`   c                      yr   r$   rb   s    r   rc   zCpuInterface.is_bf16_supported  r   r   Nr   c                      yN r$   r5   s    r   r_   z#CpuInterface.get_compute_capability      r   rW   c                      yr   r$   rY   s    r   rZ   zCpuInterface.get_raw_stream      r   c                       yr   r$   r$   r   r   r9   zCpuInterface.current_device  r   r   c                      y r   r$   r5   s    r   r\   zCpuInterface.synchronize  s    r   c                      yr   r$   r5   s    r   rl   zCpuInterface.is_triton_capable  r   r   c                 R    dd l }d|j                  j                  vrt        d      y )Nr   cpuz'triton not built with the 'cpu' backendr   r   s     r   ro   z(CpuInterface.raise_if_triton_unavailable  s(    000HII 1r   rp   r   )r   r   r    r!   r,   r?   r=   rq   rJ   rc   r"   r#   r   r_   r   r>   rZ   r9   r\   rl   ro   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                   &   e Zd Zeddedefd       Ze	 ddej                  dedefd       Z	edefd       Z
edefd       Zedd	ej                  j                  defd
       Zedd	ej                  j                  ddfd       Z G d d      Zy)MpsInterfacer`   r   c                 V    t         j                  j                  j                  dd      S )N   r   )r!   r   mpsis_macos_or_newerrb   s    r   rc   zMpsInterface.is_bf16_supported  s    ~~!!33B::r   rd   c                     |t         j                  t         j                  fv ry|t         j                  k7  xs | j	                  |      S r   )r!   float64
complex128rf   rc   rg   s      r   rh   zMpsInterface.is_dtype_supported
  s>     U]]E$4$455&T#*?*?@S*TTr   c                  R    t         j                  j                  j                         S r   )r!   r   r	  rJ   r$   r   r   rJ   zMpsInterface.is_available  s    ~~!!..00r   c                       yr   r$   r$   r   r   r9   zMpsInterface.current_device  r   r   Nr   c                      yr   r$   r5   s    r   r_   z#MpsInterface.get_compute_capability  r   r   c                 @    t         j                  j                          y r   )r!   r	  r\   r5   s    r   r\   zMpsInterface.synchronize  s    		r   c                   f    e Zd Zeddej
                  j                  defd       Zede	fd       Z
y)MpsInterface.WorkerNr   r   c                 t     t        ddg      t        j                  j                  j	                               S )NMPSPropertiesr   )r   r!   r   r	  get_core_countr5   s    r   r;   z)MpsInterface.Worker.get_device_properties#  s2    I:o0G/HI""113 r   c                       yr   r$   r$   r   r   r9   z"MpsInterface.Worker.current_device)  s    r   r   )r   r   r    r=   r!   r"   r#   r   r;   r>   r9   r$   r   r   r?   r  "  sG    		%++*<*< 	 	 
	
 
	 	 
	r   r?   rp   r   )r   r   r    r=   rq   rc   rr   r!   rd   rh   rJ   r>   r9   r"   r#   r   r_   r\   r?   r$   r   r   r  r    s    ;t ; ; ; =BUKKU6:U	U U 1$ 1 1 C   u{{'9'9 S    EKK..  $    	 	r   r  device_interfacesFr   ru   r   c                 b    t        | t        j                        r| j                  } |t        | <   y r   )r   r!   r   r   r  )r   ru   s     r   register_interface_for_devicer  2  s&     &%,,' 0fr   c                     t        | t        j                        r| j                  } t        s
t                | t        v r	t        |    S t        d|        )NzNo interface for device )r   r!   r   r   _device_initializedinit_device_regr  r   r5   s    r   get_interface_for_devicer  :  sI    &%,,'"" ((
 8A
BBr   c                  J    t         s
t                t        j                         S r   )r  r  r  itemsr$   r   r    get_registered_device_interfacesr!  D  s    ""$$r   c                  "   t        dt               t        t        j                  j                               D ]  } t        d|  t                t        dt               t        t        j                  j                               D ]  } t        d|  t                t        dt               t        t        j                  j                               D ]  } t        d|  t                t        dt               t        dt               d	ay )
Nr   zcuda:r   zxpu:r   zmtia:r  r	  T)r  r   r   r!   r   rH   r   r   r   r   r   r  r  )r   s    r   r  r  J  s    !&-85::**,- B%aSk=AB "%6599))+, @%QCj,?@ "&-85::**,- B%aSk=AB "%6!%6r   r   )2r<   r   r   collectionsr   collections.abcr   dataclassesr   typingr   r   r   r	   r
   r!   r>   r   r   _is_compiledtorch._Cr   r   r   dictr   r   r   rt   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r  r   r  r  tupler!  r  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   