U
    ,dd                     @   s&  d dl 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d dlmZ d dl	m	Z	 d dl
mZ d dlmZmZmZ d dlZd dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ  d d
l!m"Z# d dl$m%Z% dZ&zd dl'Z'W n e(k
r   Y nX dZ&ddgZ)d\Z*Z+Z,dZ-dZ.d\Z/Z0d\Z1Z2dZ3d\Z4Z5dZ6d\Z7Z8d\Z9Z:d\Z;Z<dZ=dZ>dZ?dZ@dZAd ZBd!ZCd"ZDd#ZEd$ZFd%ZGd&ZHd'ZId(\ZJZKd)ZLd*ZMd+ZNd,ZOd-ZPd.\ZQZRd/ZSd0ZTd1\ZUZVd2\ZWZXd3ZYd4\ZZZ[d5Z\d6\Z]Z^d7\Z_Z`d8Zad9Zbd:Zcd;Zdd<Zeg Zfg Zgd=d> Zhd?d ZidCdAdZjekdBkr"ej  dS )D    N)redirect_stdout)datetime)StringIO)check_outputPIPECalledProcessError)__version__)cudar   )cudadrv)driver)runtime)configFTget_sysinfodisplay_sysinfo)ZStartz	Start UTCZRuntimeNumba VersionMachine)CPU Name	CPU Count)zCPUs AllowedzList CPUs AllowedCPU Features)z	CFS Quotaz
CFS PeriodzCFS Restriction)z	Mem TotalzMem Available)Platform NamePlatform Release)OS Name
OS VersionOS Specific VersionLibc VersionzPython CompilerzPython ImplementationzPython VersionzPython Localellvmlite VersionLLVM VersionzCUDA Device InitCUDA Driver VersionCUDA Runtime VersionzNVIDIA CUDA BindingszNVIDIA CUDA Bindings In Use)zCUDA Detect OutputzCUDA Lib TestNumPy VersionNumPy Supported SIMD featuresNumPy Supported SIMD dispatchNumPy Supported SIMD baselinezNumPy AVX512_SKX detected)z
SVML StatezSVML Lib LoadedzLLVM SVML PatchedSVML Operational)zTBB ThreadingzTBB Threading Error)zOpenMP ThreadingzOpenMP Threading ErrorzOpenMP vendor)zWorkqueue ThreadingzWorkqueue Threading ErrorzNumba Env Vars)zConda Buildz	Conda Env)zConda PlatformzConda Python VersionzConda Root WritablezInstalled PackageszPsutil AvailableZErrorsZWarningsc                    s  G dd dt }G dd dt }|d|df|d|dfttttttd	d
d|d|dfttdd
ddttdtdtdidd}i  || i dd}trt	
 } t|jt|ji t	 }t|dr| ng }|r0t| t< ddd |D  t< ntd |dd7 }g }|D ]^}	t|	drtj|	d rzPt|	d d8}
|
 }|rd|	d |d f|d< || W 5 Q R X W n> tk
r } ztd|  W Y q8W 5 d }~X Y nX ntd |	d  q8nzt|	td!}W nB tt fk
rZ } ztd"|  W Y q8W 5 d }~X Y nX t|	d#rd$d%d |! D d& }||" !  q8d'i }|D ]\}|# |$ @ }|rt|dkr||%  }| |< nt|dkrt&d(|  q fd)d*} fd+d,}z|  ts6|  W n4 t'k
rl } ztd-|  W 5 d }~X Y nX t(d.d/ it)d0d/ it)d1d/ id}|| i } d2d3 |* D   S )4Nc                   @   s   e Zd ZdZdS )z&get_os_spec_info.<locals>.CmdBufferOutTN)__name__
__module____qualname__buffer_output_flag r(   r(   </tmp/pip-unpacked-wheel-eu7e0c37/numba/misc/numba_sysinfo.pyCmdBufferOutn   s   r*   c                   @   s   e Zd ZdZdS )z%get_os_spec_info.<locals>.CmdReadFileTN)r$   r%   r&   read_file_flagr(   r(   r(   r)   CmdReadFileq   s   r,   )'/sys/fs/cgroup/cpuacct/cpu.cfs_quota_us)(/sys/fs/cgroup/cpuacct/cpu.cfs_period_us)z/proc/meminfo)z/proc/self/status)z	MemTotal:zMemAvailable:zCpus_allowed:zCpus_allowed_list:r-   r.   )cmdcmd_optionalkwdsr(   )wmicOSgetTotalVirtualMemorySize)r2   r3   r4   FreeVirtualMemory)r5   r6   ))Zsysctlz
hw.memsizeZvm_stat)zhw.memsize:zfree:   i   )r/   r0   r1   units)LinuxWindowsDarwinr/   cpu_affinity c                 s   s   | ]}t |V  qd S Nstr).0nr(   r(   r)   	<genexpr>   s     z#get_os_spec_info.<locals>.<genexpr>zWWarning (psutil): psutil cannot be imported. For more accuracy, consider installing it.r0   r+   r   rzError (file read): zWarning (no file): {})stderrzError (subprocess): r'       c                 s   s   | ]
}|V  qd S r>   r(   )rA   liner(   r(   r)   rC      s        
r1   zAmbiguous output: c                     s     td } | r$t| d  t<   td } | rHt| d  t<   tddkr  td}  td}|| }| t< d S )N )r4   
_cfs_quotasplitfloat_cfs_period_cfs_restrict)rL   Z	cfs_quotaZ
cfs_periodZruntime_amount)os_spec_infor(   r)   format   s    z get_os_spec_info.<locals>.formatc                     s   t dtdi} | di  t tfD ]8}ddd  |dD }t|pNd| |   |< q& td }|r|d }|dd }tt	t|pdd	
d
 t<  td }|r|d  t< d S )Ni   r8   rI   c                 s   s   | ]}|  r|V  qd S r>   )isdigit)rA   dr(   r(   r)   rC      s      z<get_os_spec_info.<locals>.format_optional.<locals>.<genexpr>r   rJ   ,   1)
_mem_total_mem_availableupdater4   joinint_cpus_allowedrL   r@   bincount
_cpus_list)r8   kdigitsrL   rB   rP   paramsr(   r)   format_optional   s     z)get_os_spec_info.<locals>.format_optionalzError (format shell output): c                   S   s   d t S )Nr=   )rZ   platformlibc_verr(   r(   r(   r)   <lambda>      z"get_os_spec_info.<locals>.<lambda>c                   S   s   d dd t D S )Nr=   c                 s   s   | ]
}|V  qd S r>   r(   )rA   sr(   r(   r)   rC     s    5get_os_spec_info.<locals>.<lambda>.<locals>.<genexpr>)rZ   re   	win32_verr(   r(   r(   r)   rg     s   
c                   S   s   d dd tt D S )NrI   c                 s   s    | ]}|D ]}|pd V  q
qdS )r=   Nr(   )rA   ri   ir(   r(   r)   rC     s      rj   )rZ   tuplere   mac_verr(   r(   r(   r)   rg     s   

c                 S   s   i | ]\}}|| qS r(   r(   )rA   r`   fr(   r(   r)   
<dictcomp>  s      z$get_os_spec_info.<locals>.<dictcomp>)+rm   rW   rX   r\   r_   rK   rN   r4   _psutil_importpsutilZvirtual_memoryrY   total	availableProcesshasattrr<   lenrZ   _warning_logappendospathexistsopen	readlinesextendOSError
_error_logrQ   r   r   r   
splitlinesdecodekeysrL   popprint	Exception_libc_version_os_spec_versionitems)os_namer*   r,   Zshell_paramsZcmd_selectedZvmpZcpus_allowedoutputr/   ro   outer1   rG   matchr`   rQ   rd   Zos_specific_funcsZkey_funcr(   rb   r)   get_os_spec_infob   s      2  


"   r   c            !   "   C   s>  t t tt tt tt	
 tt ttjddtt tt tt tt tt tt tdd tj D tt t!d"dd t	j#D t$t%t&t'i} zt	( }W n2 t)k
r } zt*+d|  W 5 d }~X Y n&X t,d	d
 | D }d"|| t-< z d"dd
 t./ D | t0< W n4 t1k
rV } zt*+d|  W 5 d }~X Y nX zt23 d  W n t1k
r } zd| t4< d}d}d}d}t5|dd }|d k	r||kr|| }	n ||kr|| }	n|d | }	n|d t6| }	t7+d|	t6t8|f  W 5 d }~X Y n0X zd| t4< t9 }
t:|
 t2;  W 5 Q R X |
< | t=< |
>  dt?@  | tA< dtB@  | tC< t9 }
t:|
 tDjEjFtGjdd W 5 Q R X |
< | tH< |
>  zddlImI} d}W n tJk
r   d}Y nX || tK< tLtDjMjN}|| tO< W n> t1k
rJ } zt7+dt8| d|  W 5 d }~X Y nX tPjjQ| tR< zddlSmT}mU}mV} W n tJk
r   d| tW< Y n<X dd
 | D }|| tX< || tY< || tZ< |[dd| tW< d}zVtGj\drt	]d  n8tGj\d!rt	]d" ntGj\d#rt	]d$ nd}W n t1k
r>   d}Y nX t5t	j^d%d }|rZ| nd| t_< t`ja| tb< || tc< td| tb | tc | t_ f| te< d&d' }z*dd(lfmg} dd)lhmi} |  d| tj< W n: tJk
r } zd| tj< ||d*| tk< W 5 d }~X Y nX z"dd+lfml} d| tm< |jn| to< W n: tJk
r\ } zd| tm< ||d,| tp< W 5 d }~X Y nX zdd-lfmq} d| tr< W n: tJk
r } zd| tr< ||d.| ts< W 5 d }~X Y nX d/}ztt|}W n t1k
rX } zvt7+d0| d1 tGjud2d3d4f}ztt|}W n4 t1k
r6 } zt*+d5|  W 5 d }~X Y nX |v w | tx< W 5 d }~X Y nX tyz|v }t{t|t}t~td6}| D ]\}}|[|d7| |< qd8}ztt|}W n4 tk
r } zt*+d9|  W 5 d }~X Y n X |v w } d:d
 | D | tx< | t| t  t*| t< t7| t< t | t    | t< | S );NT)aliasedc                 S   s    i | ]\}}| d r||qS )ZNUMBA_
startswithrA   r`   vr(   r(   r)   rp   0  s    
 zget_sysinfo.<locals>.<dictcomp>.c                 s   s   | ]}t |V  qd S r>   r?   rA   rl   r(   r(   r)   rC   3  s     zget_sysinfo.<locals>.<genexpr>zError (CPU features): c                 S   s   g | ]\}}|r|qS r(   r(   )rA   keyvaluer(   r(   r)   
<listcomp>>  s      zget_sysinfo.<locals>.<listcomp>r=   c                 S   s   g | ]}t |qS r(   r?   r   r(   r(   r)   r   F  s     zError (locale): r   Fz#CUDA driver library cannot be foundzCUDA is disabledz( or no CUDA enabled devices are present.z#CUDA device initialisation problem.msgz	 Message:z&Warning (cuda): %s
Exception class: %sz%s.%s)Zprint_paths)r	   zYWarning (cuda): Probing CUDA failed (device and driver present, runtime problem?)
(cuda) z: )__cpu_features____cpu_dispatch____cpu_baseline__c                 S   s   g | ]\}}|r|qS r(   r(   r   r(   r(   r)   r     s      Z
AVX512_SKXlinuxz
libsvml.sodarwinzlibsvml.dylibwinZsvml_dispmdZhas_svmlc                 S   s`   zFdd | j dD \}}}tj|d }||krDd||f W S W n tk
rZ   Y nX dS )Nc                 S   s   g | ]}|  qS r(   )strip)rA   xr(   r(   r)   r     s     z4get_sysinfo.<locals>.parse_error.<locals>.<listcomp>:r7   z%s: %szUnknown import problem.)r   rL   rz   r{   r   )r   backendr{   ZproblemsymbolZextn_dsor(   r(   r)   parse_error  s    z get_sysinfo.<locals>.parse_error)tbbpool)_check_tbb_version_compatibler   )omppoolr   )	workqueuer   )condainfoz--jsonz)Warning: Conda not available.
 Error was 
z-mpiplistzError (pip): )Zconda_build_versionZconda_env_versionre   python_versionZroot_writablezN/A)r   r   zError (conda): c                 S   s   g | ]}| d s|qS )#r   )rA   lr(   r(   r)   r     s     
 )_startr   now
_start_utcutcnow_machinere   machine	_cpu_namellvmbindZget_host_cpu_name
_cpu_countmultiprocessing	cpu_count_platform_name_platform_releaserelease_os_namesystem_os_versionversion_python_comppython_compiler_python_implpython_implementation_python_versionr   _numba_env_varsrz   environr   _numba_versionversion_number_llvm_versionrZ   Zllvm_version_info_llvmlite_versionllvmlite_version_psutilrq   Zget_host_cpu_featuresRuntimeErrorr   ry   sorted_cpu_featureslocalegetdefaultlocale_python_localer   cuZlist_devices_cu_dev_initgetattrr@   rx   typer   r   detectgetvalue_cu_detect_outclosecudriverget_version_cu_drv_ver	curuntime
_cu_rt_verr
   Zlibstestsys_cu_lib_testr	   ImportError_cu_nvidia_bindingsboolr   ZUSE_NV_BINDING_cu_nvidia_bindings_usednpZfull_version_numpy_versionZnumpy.core._multiarray_umathr   r   r   _numpy_AVX512_SKX_detected_numpy_supported_simd_features_numpy_supported_simd_dispatch_numpy_supported_simd_baseliner4   r   Zload_library_permanentlytargets_llvm_svml_patchedr   Z
USING_SVML_svml_state_svml_loadedall_svml_operationalZnumba.np.ufuncr   Znumba.np.ufunc.parallelr   _tbb_thread
_tbb_errorr   _openmp_threadZopenmp_vendor_openmp_vendor_openmp_errorr   _wkq_thread
_wkq_errorr   
executabler   r   	_inst_pkgjsonloads_conda_build_ver_conda_env_ver_conda_platform_conda_python_ver_conda_root_writabler   rY   r   _errors	_warningstotal_seconds_runtime)!Zsys_infoZfeature_mapr   featuresZmsg_not_foundZmsg_disabled_by_userZmsg_endZmsg_generic_problemr   err_msgr   r	   Znvidia_bindings_availableZnv_binding_usedr   r   r   Zfeat_filteredZsvml_lib_loadedfuncr   r   r   r   r   r/   Z	conda_outreqsZjsondr   Zconda_kZ	sysinfo_kdatar(   r(   r)   r      sb         
           "
"











   """-   c           	   W      s  G dd dt }G dd dt}G dd dt}| d kr>t } d d d	}d
dd| tdfd| tdfd| tdfddd| tdfd| tdfd| t	dfd| t
dfd| tdfd| tdfdddfddttj| tdd dD fdd| td | p"df| td!d"ksD| td#rHd$nd%| td | p^dfdd&d'| tdfd(| tdfd)| tdfd*| tdfd+| tdfd,| tdfdd-|d.d/ |  D dd0d1| tdfd2| tdfdd3d4| tdfdd5d6| tdfd7| t dfd8| t!dfd9| t"dfd:| t#dfd;| t$dfd<| t%dfdd=d>| t&dfd?|| t'g pd@fdA|| t(g pd@fdB|| t)g pd@fdC| t*dfddDdE| t+dfdF| t,dfdG| t-dfdH| t.dfddIdJ| t/df| t/dr0dKndL| t0d fdM| t1df| t1d#rpdN| t2d ndL| t3d fdO| t4df| t4d#rdPndL| t5d fddQ|| t6i pd@ddR|dSd/ |  D pdTddU|| t7dVd| t8g rdWndXf|| t8g d| t9g r6dYndZf|| t9g d
d[fU}|D ]}t:|d\rtt;|d]di nt:|d^rt;t fd_d| D d]di ndt:|d`r|D ],}t;t fdad| D dddb qn$t<|dckrt; |  nt;|  qTd S )dNc                   @   s   e Zd ZdZdS )z#display_sysinfo.<locals>.DisplayMapTN)r$   r%   r&   display_map_flagr(   r(   r(   r)   
DisplayMap  s   r  c                   @   s   e Zd ZdZdS )z#display_sysinfo.<locals>.DisplaySeqTN)r$   r%   r&   display_seq_flagr(   r(   r(   r)   
DisplaySeq  s   r  c                   @   s   e Zd ZdZdS )z'display_sysinfo.<locals>.DisplaySeqMapsTN)r$   r%   r&   display_seqmaps_flagr(   r(   r(   r)   DisplaySeqMaps  s   r  z%-zs : %-si   )zP--------------------------------------------------------------------------------)z__Time Stamp__zReport started (local time)?zUTC start timezRunning time (s))rI   )z__Hardware Information__r   r   r   zNumber of accessible CPUszList of accessible CPUs coresz(CFS Restrictions (CPUs worth of runtime)Noner   r   c                 3   s*   | ]"\}}|rd  d  | n|V  qdS )r=      Nr(   )rA   rl   r   )sep_posr(   r)   rC   #  s   z"display_sysinfo.<locals>.<genexpr>O   )widthzMemory Total (MB)r   rI   r;   FzMemory Available (MB)zFree Memory (MB))z__OS Information__r   r   r   r   r   r   )z__Python Information__c                 S   s    i | ]\}}| d r||qS )Pythonr   r   r(   r(   r)   rp   ;  s     
  z#display_sysinfo.<locals>.<dictcomp>)z__Numba Toolchain Versions__r   r   )z__LLVM Information__r   )z__CUDA Information__zCUDA Device Initializedr   r   zCUDA NVIDIA Bindings AvailablezCUDA NVIDIA Bindings In Use)zCUDA Detect Output:)zCUDA Libraries Test Output:)z__NumPy Information__r   r    )zNone found.r!   r"   z!NumPy AVX512_SKX support detected)z__SVML Information__zSVML State, config.USING_SVMLzSVML Library Loadedz llvmlite Using SVML Patched LLVMr#   )z__Threading Layer Information__zTBB Threading Layer Availablez+-->TBB imported successfully.z+--> Disabled due to z OpenMP Threading Layer Availablez+-->Vendor: z#Workqueue Threading Layer Availablez$+-->Workqueue imported successfully.)z*__Numba Environment Variable Information__)z__Conda Information__c                 S   s    i | ]\}}| d r||qS )ZCondar   r   r(   r(   r)   rp   t  s    
 )zConda not available.)z__Installed Packages__)z Couldn't retrieve packages info.z__Error log__zNo errors reported.z__Warning log__zNo warnings reported.)a  If requested, please copy and paste the information between
the dashed (----) lines, or from a given specific section as
appropriate.

=============================================================
IMPORTANT: Please ensure that you are happy with sharing the
contents of the information present, any information that you
wish to keep private you should remove before sharing.
=============================================================
r  sepr  c                 3   s   | ]\}} ||f V  qd S r>   r(   r   fmtr(   r)   rC     s     r  c                 3   s"   | ]\}} d | |f V  qdS )	Nr(   r   r"  r(   r)   rC     s     )r!  end   )=dictrm   r   r4   r   r   r  r   r   r   r\   r_   rO   rZ   	enumeratetextwrapwrapr   rW   r   r   rX   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  rv   r   rw   )	r   r  r  r  r  ZMBtemplatetrS   r(   )r#  r  r)   r     s,   

	
 


x& __main__)Nr  )lr  r   r   rz   re   r)  r   
contextlibr   r   ior   
subprocessr   r   r   Znumpyr   Zllvmlite.bindingZbindingr   Zllvmliter   r   Znumbar	   r   r   Z
numba.cudar
   Znumba.cuda.cudadrv.driverr   r   Znumba.cuda.cudadrv.runtimer   r   Z
numba.corer   rq   rr   r   __all__r   r   r  r   r   r   r   r\   r_   r   rK   rN   rO   rW   rX   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   rx   r   r   r   r$   r(   r(   r(   r)   <module>   s   
 ? e
 
