o
     jO                     @   s  d dl Z d dlZd dlZd dlZd dlZdZdZdZe jdkr!dZe j	
e j	eZe j	ee j e d e r<dZz8e jdkrsee j d	 e j d
 Zed e d e jd  e jd< ej	d e ejdd dkrse e W n@ ey Z z'e jdkre j	
e j	ejZede de dee edee dZ[w ey Z zedZ[ww dd Zdd Zdd Zdd Zdd Zdd Z dd  Z!e" # d!kr
e  \Z$Z%e$d"kr
e!e%d#r
zed$ W n ey	 Z zej&'d% W Y dZ[ndZ[ww zd&d'l(m)Z) e r e)* s ej&'d( e)j+e)_,d&d)l)T d&d*l)m-Z-mZm.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZM d&d+l)mNZNmOZOmPZPmQZQmRZR d&d,l)mSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z] d&d-l)m^Z^m_Z_ ejd.krd&d/l)m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZh d&d0l)miZi W n2 ey Z z%erej&'d1e e j d2 e d3  e se)* rej&'d4 edZ[ww d5d6 Zjd7d8 Zkek  d9d: Zld;d< Zmd=d> Zneo eo d?Zpd@dA ZqeqdBgdBgdBgdCZrd&gd&gdDgdEZsdFdG ZtdHdI ZudJdK ZvdLdM ZwdNdO ZxdPdQ ZydRdS ZzdTdU Z{dVdW Z|dXdY Z}dS )Z    NF	libpaddlesontZpyd.T..libs;path   )      z$NOTE: You may need to run "set PATH=z;%PATH%"
        if you encounters "DLL load failed" errors. If you have python
        installed in other directory, replace "z<" with your own
        directory. The original error is: 
 a  NOTE: You may need to run "export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH"
        if you encounters "libmkldnn.so not found" errors. If you have python
        installed in other directory, replace "/usr/local/lib" with your own
        directory. The original error is: 
c               
      s  t   } d}| dkr<ztd}| dk}|  W |S  ty; } ztj	
dt|  W Y d}~|S d}~ww | dkrztd}| dk}|  W n tym } ztj	
d	t|  W Y d}~nd}~ww |sd
dl}|jdd|j|jd}| }|jd
krdnd}|S | dkrd
dld jdf fdd	}d}d}d
}	z||\}
}|
 }	jj|d
  W n ty } ztj	
dt|  W Y d}~nd}~ww |	d|> @ d
kS tj	
d|   dS )zN
    Whether current system(Linux, MacOS, Windows) is supported with AVX.
    Flinuxzcat /proc/cpuinfo | grep -i avx zGCan not get the AVX flag from /proc/cpuinfo.
The original error is: %s
Ndarwinz)sysctl machdep.cpu.features | grep -i avxzNCan not get the AVX flag from machdep.cpu.features.
The original error is: %s
r   z/sysctl machdep.cpu.leaf7_features | grep -i avxT)shellstdoutstderrwindows    c              	      s  j jj}j|_d}d}|d  ||}|s tdjjjjj	}||| t
| dk r=tdd}j jj}	|	| |d}
|
s]tdj jj}j|_| }j j|| }
|
s~tdj|g|R  }||}||fS )	Nr      zFailed to VirtualAllocr   zFailed to memmove   zFailed VirtualProtectzFailed FlushInstructionCache)windllkernel32ZVirtualAllocc_void_prestypec_ulong	Exception	CFUNCTYPEc_size_t_memmove_addrlenZVirtualProtectbyrefZGetCurrentProcessZFlushInstructionCache)code_strr   argtypesZpfnVirtualAllocZ
MEM_COMMITZPAGE_READWRITEaddressmemmoveZPAGE_EXECUTEZpfnVirtualProtectresZpfnGetCurrentProcessZ
prochandleZfunctypefuncZONE_PAGEctypesr   Q/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/base/core.pyasm_funcp   sP   





zavx_supported.<locals>.asm_funcs
         zBFailed getting the AVX flag on Windows.
The original error is: %s
   zDo not get AVX flag on %s
)platformsystemlowerospopenreadcloser   sysr   writestr
subprocessPopenPIPEcommunicate
returncoder*   r   c_uint32r   r   ZVirtualFreer   )ZsysstrZhas_avxpipeer9   _r,   r#   Zavx_bitretvalr(   r%   r   r)   r+   avx_supportedD   s   



4rC   c                 C   s<   dd l }|j| |j|jdd \}}|rd S |d S )Nr   T)r   r   r   zutf-8)r9   r:   r;   r<   decodestrip)cmdr9   outerrr   r   r+   run_shell_command   s   rI   c                 C   s"   | r|rt d|  d| dS d S )Nzldd z|grep z|awk '{print $3}'rI   )core_sodso_namer   r   r+   get_dso_path   s
   rM   c                 C   sD   | r zddl m} ||  W d S    td|  d Y d S d S )Nr   )cdllzLoad z failed)r*   rN   LoadLibrarywarningswarn)Zdso_absolute_pathrN   r   r   r+   load_dso   s   rR   c                 C   s6   t rttj t d t }nd }t|| }t| d S )Nr   )has_paddle_dy_libcurrent_pathr2   sepdy_lib_namedy_lib_suffixrM   rR   )rL   rK   Zdso_pathr   r   r+   pre_load   s
   
rX   c                  C   s4   t d} | d urd| fS t d}|d urd|fS dS )Nz&ldd --version | awk '/ldd/{print $NF}'glibcz%ldd 2>&1 | awk '/Version/{print $NF}'musl)NNrJ   )Z	ldd_glibcZldd_muslr   r   r+   get_libc_ver   s   r[   c                    sD   | d u s|d u r
dS dd l }dd l  fdd}||| ||S )NFr   c                    s"     dd| } dd | dD S )Nz(\.0+)+$r   c                 S   s   g | ]}t |qS r   )int.0xr   r   r+   
<listcomp>   s    z2less_than_ver.<locals>.to_list.<locals>.<listcomp>r   )subsplit)srer   r+   to_list   s   zless_than_ver.<locals>.to_list)operatorre   lt)abrg   rf   r   rd   r+   less_than_ver   s   rk   r   rY   z2.23Zlibgompz!Error: Can not preload libgomp.sor.   )r   a$  Hint: Your machine support AVX, but the installed paddlepaddle doesn't have avx core. Hence, no-avx core with worse performance will be imported.
If you like, you could reinstall paddlepaddle by 'python -m pip install --force-reinstall paddlepaddle-gpu[==version]' to get better performance.
)*)"__doc____file____name____package____unittest_throw_exception__,_append_python_callable_object_and_return_id_cleanup_create_loaded_parameter_cuda_synchronize_device_synchronize_dygraph_debug_level_get_all_register_op_kernels_get_current_stream_get_eager_deletion_vars_get_phi_kernel_name_get_registered_phi_kernels'_get_use_default_grad_op_desc_maker_ops_is_compiled_with_heterps_is_dygraph_debug_enabled_is_program_version_supported	_Profiler_ProfilerResult _promote_types_if_complex_exists_RecordEvent_Scope#_set_cached_executor_build_strategy_set_current_stream_set_eager_deletion_mode_set_fuse_parameter_group_size_set_fuse_parameter_memory_size_set_paddle_lib_path_switch_tracer_test_enforce_gpu_success_xpu_device_synchronize)CustomDeviceEventCustomDeviceStream!_get_current_custom_device_stream!_set_current_custom_device_stream_synchronize_custom_device)__set_all_prim_enabled__set_bwd_prim_enabled__set_eager_prim_enabled__set_fwd_prim_enabled_add_skip_comp_ops_is_bwd_prim_enabled_is_eager_prim_enabled_is_fwd_prim_enabled_remove_skip_comp_ops_set_bwd_prim_blacklist_set_prim_target_grad_name)need_type_promotionget_promote_dtypewin32)	_array_to_share_memory_tensor_cleanup_mmap_fds_convert_to_tensor_list_erase_process_pids_remove_tensor_list_mmap_fds(_set_max_memory_map_allocation_pool_size_set_process_pids_set_process_signal_handler_throw_error_if_process_failed)is_run_with_cinnz:Error: Can not import paddle core while this file exists: z
libpaddle.
zError: Your machine doesn't support AVX, but the installed PaddlePaddle is avx core, you should reinstall paddlepaddle with no-avx core.
c                 C   sF   t jdd d urd S t j| rt j| t jd< d S dt jd< d S )NZCUSTOM_DEVICE_ROOTr   )r2   environgetr	   existsnormpath)Zlib_pathr   r   r+   !set_paddle_custom_device_lib_path  s
   r   c                  C   s   t tdr	t ndd tjD } | D ]&}tjj|ddg}tj|r9t	| t
tjj|dddg  d S qt tdrctjjtjddg}tj|ret	| t
tjj|dddg d S d S d S )	Ngetsitepackagesc                 S   s   g | ]}d |v r|qS )zsite-packagesr   r]   r   r   r+   r`     s    z'set_paddle_lib_path.<locals>.<listcomp>Zpaddler   r   Zpaddle_custom_device	USER_SITE)hasattrsiter   r6   r	   r2   rU   joinr   r   r   r   )Z	site_dirsZsite_dirlib_dirr   r   r+   set_paddle_lib_path  s,   

r   c                 C   s`  | dkr7t d}|d usJ | }|dkrtd n|dkr%td ntd|  dtdtt  d S | d	krnt d	}|d usFJ | }|dkrStd n|dkr\td ntd|  dtd
tt	  d S | dkrt d}|d us}J | }|dkrt
d n|dkrt
d ntd|  dtdtt ot	  d S td|  d)NFLAGS_prim_forwardfalseFtrueTzflag z should be true or false.forward prim enabled: FLAGS_prim_backwardbackward prim enabled: FLAGS_prim_allall prim enabled: zQWe only support FLAGS_prim_forward/FLAGS_prim_backward/FLAGS_prim_all but we got r   )r2   getenvr1   r   	TypeErrorprintboolr   r   r   r   )flag
flag_valuer   r   r+   __sync_stat_with_flag  sH   









r   c                   C   s   t  ot S N)r   r   r   r   r   r+   _is_all_prim_enabled     r   c                 C   s   t |  d S r   )r   valuer   r   r+   _test_use_sync  r   r   )forward_blacklistZcomposite_ops_recordc                 C   s2   |  do
|  d p|  d}|rg dS dgS )zXSome outputs of batch_norm's replaced composite rule are not needed and will be removed.Zis_testZtrainable_statisticsZuse_global_stats)ReserveSpaceZ	SavedMeanZSavedVariancer   )attr)opZuse_run_statr   r   r+   _get_batch_norm_none_var  s   r   ZXShape)Z
batch_normZflatten_contiguous_rangeZsqueeze2Z
unsqueeze2   )zpd_op.squeezezpd_op.unsqueezezpd_op.batch_normc                   C   s   t ddkr	dS dS )NZFLAGS_prim_skip_dynamic1TF)r2   r   r   r   r   r+   _enable_prim_dynamic_shape  s   r   c                  G   s.   | D ]}t |tstdtd | qd S )Nz/ops set in forward_blacklist must belong to strr   )
isinstancer8   r   prim_configadd)argsitemr   r   r+   _set_prim_forward_blacklist  s
   
r   c                  G   s0   t | }|D ]}t|tstdqt| d S )Nz&all items in set must belong to string)setr   r8   r   r   )r   opsr   r   r   r+   _set_prim_backward_blacklist  s   
r   c                 C   2   t t|  tddkrtdtt  d S d S )NFLAGS_prim_logr   r   )r   r   r2   r   r   r   r   r   r   r+   _set_prim_backward_enabled     r   c                 C   r   )Nr   r   r   )r   r   r2   r   r   r   r   r   r   r+   _set_prim_forward_enabled%  r   r   c                 C   r   )Nr   r   zeager prim enabled: )r   r   r2   r   r   r   r   r   r   r+   set_prim_eager_enabled+  r   r   c                 C   s8   t t|  tddkrtdtt ot  d S d S )Nr   r   r   )r   r   r2   r   r   r   r   r   r   r   r+   _set_prim_all_enabled1  s   r   c                  C   D   t d} | d u rt ddkrtdtt  d S d S td d S )Nr   r   r   r   )r2   r   r   r   r   r   r   r   r   r+   __sync_prim_backward_status:     
r   c                  C   r   )Nr   r   r   r   )r2   r   r   r   r   r   r   r   r   r+   __sync_prim_forward_statusC  r   r   c                  C   s.   t d} | d u rt  t  d S td d S )Nr   )r2   r   r   r   r   r   r   r   r+   check_and_set_prim_all_enabledL  s
   

r   )~r2   r/   r   r6   rP   rS   rV   rW   namer	   abspathdirnamern   rT   r   rU   Zthird_lib_pathr   insertversion_infoZadd_dll_directoryImportErrorr@   
executableZexecutable_pathr8   r   rC   rI   rM   rR   rX   r[   rk   r0   r1   Z	libc_typelibc_verr   r7   r   r   Zis_compiled_with_avxZTensorZ	LoDTensorrm   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zops_contain_noneZ decomp_ops_contain_unused_outputr   r   r   r   r   r   r   r   r   r   r   r   r   r+   <module>   s   



u	
	
(4	,+			