
    VpfK+                       U d dl mZ d dlZd dlZd dlZd dlZd dlZ	 d dlZn# e	$ r dZY nw xY wd dl
mZ d dl
mZ d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZ  ej        e          Zdad
ed<   daded<   daded<   daded<    ej                    Z e             Z!ded<   d<dZ"d=dZ#d>dZ$d>dZ%d?dZ&d@d Z'd>d!Z(d@d"Z)dAd#Z*dBd&Z+dBd'Z,dCd)Z-dDd+Z.dEd/Z/dFd4Z0d@d5Z1d>d6Z2dGd8Z3dHd;Z4dS )I    )annotationsN)	cache_key)config)
monitoring)CacheInterface)
xla_client)ir)LRUCacheCacheInterface | None_cacheFbool_cache_initialized_cache_checked_cache_usedzset[str]_UNSUPPORTED_RUNTIMESbackendxla_client.Clientreturnc                   t           5  t          rt          cddd           S 	 ddd           n# 1 swxY w Y   t           5  t          sldag d}t                      st	          j        d           n0| j        |v r't          | dd          rt	          j        d           dat          cddd           S 	 ddd           dS # 1 swxY w Y   dS )zCheck if cache is used and report adoption metrics one-time per task.
  The cache may be initialized during the first call to this function.
  NT)tpugpucpuz*/jax/compilation_cache/task_disabled_cache!supports_executable_serializationz(/jax/compilation_cache/tasks_using_cache)_cache_initialized_mutexr   r   _is_cache_enabledr   record_eventplatformgetattr)r   supported_platformss     Z/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/compilation_cache.pyis_cache_usedr!   6   s                                  n 211    LMMMM

1
1
1gBDII 2 	 JKKK%                        s   044A'CCCpathstr!tuple[CacheInterface, str] | Nonec                J    t           j        j        }t          | |          | fS )z1Returns the file cache and the path to the cache.)max_size)r   compilation_cache_max_sizevaluer
   )r"   r&   s     r    get_file_cacher)   X   s%    .4(	$	*	*	*D	00    Nonec                F    t           j                             d|            dS )a  
  Sets the persistent compilation cache directory.

  After calling this, jit-compiled functions are saved to `path`, so they
  do not need be recompiled if the process is restarted or otherwise run again.
  This also tells Jax where to look for compiled functions before compiling.
  jax_compilation_cache_dirN)r   updater"   s    r    set_cache_dirr0   ^   s#     	-2D99999r*   c                ~    t          j        dt          d           t          j                            d|            dS )z
  This API is deprecated; use set_cache_dir instead.

  Set the path. To take effect, should be called prior to any calls to
  get_executable_and_time() and put_executable_and_time().
  z9initialize_cache is deprecated; use set_cache_dir instead   
stacklevelr-   N)warningswarnDeprecationWarningr   r.   r/   s    r    initialize_cacher8   i   sD     -K"q2 2 2 2-2D99999r*   intc                     dS )zDReturns the minimum size below which the entry should not be cached.r    r;   r*   r    default_min_cache_entry_sizer<   u   s    	
r*   c                 $    t           j        j        S N)r   enable_compilation_cacher(   r;   r*   r    r   r   z   s    		(	..r*   c                 ^   t           5  t          r	 d d d            d S dat                      s(t                              d           	 d d d            d S t
          j        j        dk    r,t
          j                            dt                                 t          
J d            t
          j        j        } | s	 d d d            d S t          |           }|t                              d           n |\  a
} t                              d|            d d d            d S # 1 swxY w Y   d S )NTz%_initialize_cache: cache is disabled!r   )jax_persistent_cache_min_entry_size_bytesz'The cache has already been initialized!z/_initialize_cache: cache initialization failed!z.Initialized persistent compilation cache at %s)r   r   r   loggerdebugr   %persistent_cache_min_entry_size_bytesr(   r.   r<   r   compilation_cache_dirr)   )r"   cache_and_paths     r    _initialize_cacherG   ~   s      K K K K K K K K K K   ll:;;;K K K K K K K K 39Q>>mF799; ; ; >>D>>>39D +K K K K K K K K. $D))NllDEEEE#lfdllCTJJJ9K K K K K K K K K K K K K K K K K Ks$   	D"+D"A&D"	AD""D&)D&c                 J    t           j        j        d uot           j        j        S r>   )r   rE   r(   r?   r;   r*   r    is_persistent_cache_enabledrI      s#    

&
,D
8 4-35r*   c                    | j         t          v rIt                      rt          j        nt          j        }t                              |d| j                    d S t          t                       t          S )Nz#_get_cache: Unsupported runtime: %s)
runtime_typer   rI   loggingWARNINGDEBUGrB   logr   rG   )r   log_prioritys     r    
_get_cacherQ      sm     222'B'D'D 'GOO  
JJ|B#% % %4^	-r*   
executablebytesc                    t           r(t          j                    }|                    |           S t          j        |           S r>   )	zstandardZstdCompressorcompresszlib)rR   
compressors     r    compress_executablerZ      s<     %)++Jz***=$$$r*   c                    t           r(t          j                    }|                    |           S t          j        |           S r>   )rU   ZstdDecompressor
decompressrX   )rR   decompressors     r    decompress_executabler_      s<     '-//L"":...?:&&&r*   r   c                Z    t          |           }|dS |                    |          }|duS )z)Checks if the executable is in the cache.NF)rQ   get)r   r   cacheexecutable_and_times       r    is_executable_in_cacherd      s8    
W

%
]5 		),,	D	((r*   5tuple[xla_client.LoadedExecutable | None, int | None]c                   t          |          }|t                              d           dS |                    |           }|dS t	          |          }t          |          \  }}|                    ||          }||fS )zZReturns the cached executable and its compilation time if present, or None
  otherwise.
  Nz:get_executable_and_time: cache is disabled/not initialized)NN)rQ   rB   rC   ra   r_   extract_executable_and_timedeserialize_executable)r   compile_optionsr   rb   rc   serialized_executablecompile_timexla_executable_deserializeds           r    get_executable_and_timerm      s     W

%
]
LLMNNN:		),, :-.ABB(C) )% ' > >_!. !.	$l	22r*   module_namexla_client.LoadedExecutablerk   c                T   t           j        j        rt                      rt          j        nt          j        }t          |          }|t          	                    |d|            dS |
                    |          }t          ||          }t          |          }t           j        j        }	t          |          }
|
|	k     r t          	                    |d| |
|	           dS t          	                    |d||            t          j        d           |                    | |           dS )zbAdds the 'executable' and its compilation time to the cache, possibly
  evicting older entries.
  NzVNot writing persistent cache entry with key %r since cache is disabled/not initializedzjNot writing persistent cache entry with key %r since its size (%d bytes) is less than threshold (%d bytes)z6Writing %s to persistent compilation cache with key %rz#/jax/compilation_cache/cache_misses)r   explain_cache_missesr(   rI   rL   rM   rN   rQ   rB   rO   serialize_executablecombine_executable_and_timerZ   rD   lenr   r   put)r   rn   rR   r   rk   rP   rb   rj   rc   min_entry_size
entry_sizes              r    put_executable_and_timerx      sL    06%133%'// }  W

%
]
JJ|:;DF F F F!66zBB3\+ ++,?@@?E.&''*.  
JJ|	89BJ    
 JJ|GI' ' ' ABBB	IIi,-----r*   module	ir.Moduledevices
np.ndarrayc                D    t          j        | |||t          dnd          S )NrU   rX   )r   ra   rU   )ry   r{   ri   r   s       r    get_cache_keyr~     s-    	vw&/&;{{
I 
I Ir*   c                 V    t          j        dt          d           t                      S )z
  Deprecated.

  Return whether the cache is enabled. Initialization can be deferred, so
  initialized status is not checked. The name is retained for backwards
  compatibility.
  z(is_initialized is deprecated; do not user2   r3   )r5   r6   r7   r   r;   r*   r    is_initializedr     s1     -:"q2 2 2 2			r*   c                     t                               dt          t          j        nd           dat          5  dadadaddd           dS # 1 swxY w Y   dS )z*Get back to pristine, uninitialized state.zResetting cache at %s.Nz<empty>F)rB   infor   _pathr   r   r   r   r;   r*   r    reset_cacher     s     	++&%1v||yB B B&  NK                 s   AAArj   c                P    t          |                              dd          | z   S )a  Given the serialized executable and the compilation time, produce a cache
  entry in the format shown below.

  The cache entry is of the form:
  Byte:     0    1    2    3    4 ...
  Content:  compilation time    serialized executable
            (big-endian int)
     big	byteorder)r9   to_bytes)rj   rk   s     r    rs   rs   .  s+     
\			#	#A	#	7	7:O	OOr*   exectuable_and_timetuple[bytes, int]c                ^    | dd         t                               | dd         d          fS )a#  Given the cache entry in the format shown below, extract the serialized
  executable and the compilation time.

  The cache entry 'executable_and_time' is of the form:
  Byte:     0    1    2    3    4 ...
  Content:  compilation time    serialized executable
            (big-endian int)
  r   Nr   r   )r9   
from_bytes)r   s    r    rg   rg   <  s=     
QRR	 #.."1" #1 #0 #0 
0 0r*   )r   r   r   r   )r"   r#   r   r$   )r   r+   )r   r9   )r   r   )r   r   )rR   rS   r   rS   )r   r#   r   r   )r   r#   r   re   )
r   r#   rn   r#   rR   ro   rk   r9   r   r+   )ry   rz   r{   r|   r   r#   )rj   rS   rk   r9   r   rS   )r   rS   r   r   )5
__future__r   rL   	threadingr5   rX   numpynprU   ImportErrorjax._srcr   r   r   $jax._src.compilation_cache_interfacer   jax._src.libr   jax._src.lib.mlirr	   jax._src.lru_cacher
   	getLogger__name__rB   r   __annotations__r   r   r   Lockr   setr   r!   r)   r0   r8   r<   r   rG   rI   rQ   rZ   r_   rd   rm   rx   r~   r   r   rs   rg   r;   r*   r    <module>r      s   # " " " " " "              )))                   ? ? ? ? ? ? # # # # # #             ' ' ' ' ' ' 
	8	$	$ $ $ $ $ $                   *9>++ "%#%%  ' ' ' '   D1 1 1 1: : : :	: 	: 	: 	:   
/ / / /K K K KB5 5 5 5
   % % % %' ' ' ') ) ) )3 3 3 3,&. &. &. &.RI I I I
 
 
 
   P P P P0 0 0 0 0 0s   " ,,