a
    –§»a'Z  ã                   @   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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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'yò   Y n0 dZ%ddgZ(d\Z)Z*Z+dZ,dZ-d\Z.Z/d\Z0Z1dZ2d\Z3Z4dZ5d\Z6Z7d\Z8Z9d\Z:Z;dZ<dZ=dZ>dZ?dZ@d ZAd!ZBd"ZCd#ZDd$ZEd%ZFd&\ZGZHd'\ZIZJd(ZKd)ZLd*\ZMZNd+\ZOZPd,ZQd-\ZRZSd.ZTd/\ZUZVd0\ZWZXd1ZYd2ZZd3Z[d4Z\d5Z]g Z^g Z_d6d7„ Z`d8d„ Zad<d:d„Zbecd;k�rebƒ  dS )=é    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 Version)zCUDA Detect OutputzCUDA Lib Test)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 ¡�r
zft|	d dƒ�B}
|
 ¡ }|�r d |	d |d f¡|d< | |¡ W d   ƒ n1 �s¶0    Y  W nD t�y } z*t d|› �¡ W Y d }~�q8W Y d }~n
d }~0 0 nt d  |	d ¡¡ �q8n”zt|	td!�}W nH tt f�y| } z*t d"|› �¡ W Y d }~�q8W Y d }~n
d }~0 0 t|	d#ƒ�r¦d$ d%d„ | !¡ D ƒ¡d& }| | "¡  !¡ ¡ �q8ˆ d'i ¡}|D ]\}| #¡ | $¡ @ }|�r
t|ƒdk�r
|| %¡  }|ˆ |< nt|ƒdk�rÌt&d(|› �ƒ �qÌ‡ fd)d*„}‡ ‡fd+d,„}z|ƒ  t�sX|ƒ  W n6 t'�y� } zt d-|› �¡ W Y d }~n
d }~0 0 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$   úR/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/numba/misc/numba_sysinfo.pyÚCmdBufferOutf   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%   ÚCmdReadFilei   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)r.   r/   r0   ÚFreeVirtualMemory)r1   r2   ))Zsysctlz
hw.memsizeZvm_stat)zhw.memsize:zfree:é   i   )r+   r,   r-   Úunits)ÚLinuxÚWindowsÚDarwinr+   Úcpu_affinityú c                 s   s   | ]}t |ƒV  qd S ©N©Ústr)Ú.0Únr$   r$   r%   Ú	<genexpr>¬   ó    z#get_os_spec_info.<locals>.<genexpr>zWWarning (psutil): psutil cannot be imported. For more accuracy, consider installing it.r,   r'   r   ÚrzError (file read): zWarning (no file): {})ÚstderrzError (subprocess): r#   ó    c                 s   s   | ]
}|V  qd S r:   r$   )r=   Úliner$   r$   r%   r?   Ñ   r@   ó   
r-   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Ú éÿÿÿÿ)r0   Ú
_cfs_quotaÚsplitÚfloatÚ_cfs_periodÚ_cfs_restrict)rI   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|p–dd	ƒƒƒ 
d
¡ˆ t< ˆ  td¡ ¡ }|rÊ|d ˆ t< d S )Ni   r4   rF   c                 s   s   | ]}|  ¡ r|V  qd S r:   )Úisdigit)r=   Údr$   r$   r%   r?   ò   r@   z<get_os_spec_info.<locals>.format_optional.<locals>.<genexpr>r   rG   ú,é   Ú1)Ú
_mem_totalÚ_mem_availableÚupdater0   ÚjoinÚintÚ_cpus_allowedrI   r<   ÚbinÚcountÚ
_cpus_list)r4   ÚkÚdigitsrI   r>   ©rM   Úparamsr$   r%   Úformat_optionalí   s     z)get_os_spec_info.<locals>.format_optionalzError (format shell output): c                   S   s   d  t ¡ ¡S )Nr9   )rW   ÚplatformÚlibc_verr$   r$   r$   r%   Ú<lambda>  r@   z"get_os_spec_info.<locals>.<lambda>c                   S   s   d  dd„ t ¡ D ƒ¡S )Nr9   c                 s   s   | ]
}|V  qd S r:   r$   )r=   Úsr$   r$   r%   r?     s   ú5get_os_spec_info.<locals>.<lambda>.<locals>.<genexpr>)rW   rb   Ú	win32_verr$   r$   r$   r%   rd     s   
ÿc                   S   s   d  dd„ tt ¡ ƒD ƒ¡S )NrF   c                 s   s    | ]}|D ]}|pd V  q
qdS )r9   Nr$   )r=   re   Úir$   r$   r%   r?     s   rf   )rW   Útuplerb   Úmac_verr$   r$   r$   r%   rd     s   

ÿc                 S   s   i | ]\}}||ƒ “qS r$   r$   )r=   r]   Úfr$   r$   r%   Ú
<dictcomp>  r@   z$get_os_spec_info.<locals>.<dictcomp>)+ri   rT   rU   rY   r\   rH   rK   r0   Ú_psutil_importÚpsutilZvirtual_memoryrV   ÚtotalÚ	availableÚProcessÚhasattrr8   ÚlenrW   Ú_warning_logÚappendÚosÚpathÚexistsÚopenÚ	readlinesÚextendÚOSErrorÚ
_error_logrN   r   r   r   Ú
splitlinesÚdecodeÚkeysrI   ÚpopÚprintÚ	ExceptionÚ_libc_versionÚ_os_spec_versionÚitems)Úos_namer&   r(   Zshell_paramsZcmd_selectedZvmÚpZcpus_allowedÚoutputr+   rk   ÚoutÚer-   rD   Úmatchr]   rN   ra   Zos_specific_funcsZkey_funcr$   r_   r%   Úget_os_spec_infoZ   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 n4 t)yÞ } zt* +d|› �¡ W Y d }~n.d }~0 0 t,d	d
„ | ¡ D ƒƒ}d "|¡| t-< z d "dd
„ t. /¡ D ƒ¡| t0< W n6 t1�yZ } zt* +d|› �¡ W Y d }~n
d }~0 0 zt2 3¡ d  W n¶ t1�y" } zœd| t4< d}d}d}d}t5|dd ƒ}|d u�râ||v �rÀ|| }	n ||v �rÔ|| }	n|d | }	n|d t6|ƒ }	t7 +d|	t6t8|ƒƒf ¡ W Y d }~�nBd }~0 0 zöd| t4< t9ƒ }
t:|
ƒ� t2 ;¡  W d   ƒ n1 �s\0    Y  |
 <¡ | t=< |
 >¡  t? @d¡}tA Bt? C|¡¡ |jD| tE< t? @d¡}tF Gt? C|¡¡ |jD| tH< t9ƒ }
t:|
ƒ�" tIjJjKtLjdd� W d   ƒ n1 �sú0    Y  |
 <¡ | tM< |
 >¡  W n@ t1�yZ } z&t7 +dt8|ƒ› d|› �¡ W Y d }~n
d }~0 0 d}zVtLj Nd¡�r|t	 Od¡ n8tLj Nd¡�r–t	 Od¡ ntLj Nd¡�r°t	 Od¡ nd}W n t1�yÎ   d}Y n0 t5t	jPd d ƒ}|�rê|ƒ nd| tQ< tRjS| tT< || tU< tV| tT | tU | tQ fƒ| tW< d!d"„ }zdd#lXmY} d| tZ< W n< t[�y~ } z"d| tZ< ||d$ƒ| t\< W Y d }~n
d }~0 0 z"dd%lXm]} d| t^< |j_| t`< W n< t[�yÞ } z"d| t^< ||d&ƒ| ta< W Y d }~n
d }~0 0 zdd'lXmb} d| tc< W n< t[�y4 } z"d| tc< ||d(ƒ| td< W Y d }~n
d }~0 0 d)}zte|ƒ}W nš t1�yà } z€t7 +d*|› d+�¡ tLjfd,d-d.f}zte|ƒ}W n6 t1�yº } zt* +d/|› �¡ W Y d }~nd }~0 0 | g¡  h¡ | ti< W Y d }~n²d }~0 0 tj k| g¡ ¡}tltmtntotpd0œ}| ¡ D ]\}}| q|d1¡| |< �qd2}zte|ƒ}W n6 tr�yj } zt* +d3|› �¡ W Y d }~n(d }~0 0 | g¡  h¡ }d4d
„ |D ƒ| ti< |  stt| t ƒ¡ t*| tu< t7| tv< t ¡ | t    w¡ | tx< | S )5NT)Úaliasedc                 S   s    i | ]\}}|  d ¡r||“qS )ZNUMBA_©Ú
startswith©r=   r]   Úvr$   r$   r%   rl   (  s   
ÿzget_sysinfo.<locals>.<dictcomp>Ú.c                 s   s   | ]}t |ƒV  qd S r:   r;   ©r=   rh   r$   r$   r%   r?   +  r@   zget_sysinfo.<locals>.<genexpr>zError (CPU features): c                 S   s   g | ]\}}|r|‘qS r$   r$   )r=   ÚkeyÚvaluer$   r$   r%   Ú
<listcomp>6  r@   zget_sysinfo.<locals>.<listcomp>r9   c                 S   s   g | ]}t |ƒ‘qS r$   r;   r”   r$   r$   r%   r—   >  r@   zError (locale): r   Fz#CUDA driver library cannot be foundzCUDA is disabledz( or no CUDA enabled devices are present.z"CUDA device intialisation problem.Úmsgz	 Message:z&Warning (cuda): %s
Exception class: %s)Zprint_pathszYWarning (cuda): Probing CUDA failed (device and driver present, runtime problem?)
(cuda) z: Úlinuxz
libsvml.soÚdarwinzlibsvml.dylibÚwinZsvml_dispmdZhas_svmlc                 S   s^   zFdd„ | j  d¡D ƒ\}}}tj |¡d }||v rDd||f W S W n tyX   Y n0 dS )Nc                 S   s   g | ]}|  ¡ ‘qS r$   )Ústrip)r=   Úxr$   r$   r%   r—   •  r@   z4get_sysinfo.<locals>.parse_error.<locals>.<listcomp>ú:r3   z%s: %szUnknown import problem.)r˜   rI   rv   rw   rƒ   )r‹   Úbackendrw   ÚproblemÚsymbolZextn_dsor$   r$   r%   Úparse_error‘  s    z get_sysinfo.<locals>.parse_error)Útbbpoolr£   )Úomppoolr¤   )Ú	workqueuer¥   )ÚcondaÚinfoz--jsonz)Warning: Conda not available.
 Error was Ú
z-mÚpipÚlistzError (pip): )Zconda_build_versionZconda_env_versionrb   Úpython_versionZroot_writablezN/A)r¦   rª   zError (conda): c                 S   s   g | ]}|  d ¡s|‘qS )ú#r�   )r=   Úlr$   r$   r%   r—   ×  r@   )yÚ_startr   ÚnowÚ
_start_utcÚutcnowÚ_machinerb   Ú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_varsrv   Úenvironr†   Ú_numba_versionÚversion_numberÚ_llvm_versionrW   Zllvm_version_infoÚ_llvmlite_versionÚllvmlite_versionÚ_psutilrm   Zget_host_cpu_featuresÚRuntimeErrorr}   ru   ÚsortedÚ_cpu_featuresÚlocaleÚgetdefaultlocaleÚ_python_localerƒ   ÚcuZlist_devicesÚ_cu_dev_initÚgetattrr<   rt   Útyper   r   ÚdetectÚgetvalueÚ_cu_detect_outÚcloseÚctypesÚc_intÚcudriverZcuDriverGetVersionÚbyrefr–   Ú_cu_drv_verÚ	curuntimeZcudaRuntimeGetVersionÚ
_cu_rt_verr
   ZlibsÚtestÚsysÚ_cu_lib_testr�   Zload_library_permanentlyÚtargetsÚ_llvm_svml_patchedr   Z
USING_SVMLÚ_svml_stateÚ_svml_loadedÚallÚ_svml_operationalZnumba.np.ufuncr£   Ú_tbb_threadÚImportErrorÚ
_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_writabler0   r   rV   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‰   ZdvZrtverZsvml_lib_loadedÚfuncr¢   r£   r¤   r¥   r+   Z	conda_outÚreqsZjsondr€   Zconda_kZ	sysinfo_kÚdatar$   r$   r%   r     s&   î&
ÿ&




ÿ
(




2þþÿ	

ý
$$$&&û&é-   c           	   N      sŽ  G dd„ dt ƒ}G dd„ dtƒ}G dd„ dtƒ}| d u 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d;d<|  t$d¡fd=|  t%d¡fd>|  t&d¡fd?|  t'd¡fdd@dA|  t(d¡f|  t(d¡�r¬dBndC|  t)d¡› �fdD|  t*d¡f|  t*d#¡�rìdE|  t+d¡› �ndC|  t,d¡› �fdF|  t-d¡f|  t-d#¡�rdGndC|  t.d¡› �fddH||  t/i ¡ƒ�pHdIddJ|dKd/„ |  ¡ D ƒƒ�pfdLddM||  t0dN¡ƒd|  t1g ¡�rŒdOndPf||  t1g ¡ƒd|  t2g ¡�r²dQndRf||  t2g ¡ƒd
dSfL}|D ]¸}t3|dTƒ�rðt4|dUdiŽ n–t3|dVƒ�r"t4t‡ fdWd„| ¡ D ƒƒdUdiŽ ndt3|dXƒ�rb|D ],}t4t‡ fdYd„| ¡ D ƒƒdddZœŽ �q2n$t5|ƒd[k�r~t4ˆ | ƒ nt4|Ž  �qÐd S )\Nc                   @   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))rF   )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 )r9   é   Nr$   )r=   rh   r­   )Úsep_posr$   r%   r?   ÿ  s   ÿz"display_sysinfo.<locals>.<genexpr>éO   )ÚwidthzMemory Total (MB)r   rF   r7   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%   rl     r@   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 Detect Output:)zCUDA Libraries Test Output:)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None found.)z__Conda Information__c                 S   s    i | ]\}}|  d ¡r||“qS )ZCondar�   r‘   r$   r$   r%   rl   ?  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%   r?   Z  r@   r
  c                 3   s"   | ]\}}ˆ d | |f V  qdS )ú	Nr$   r‘   r  r$   r%   r?   ]  r@   )r  Úendé   )6Údictri   r   r0   r®   r°   rÿ   r²   r´   r¶   rY   r\   rL   rW   Ú	enumerateÚtextwrapÚwraprÏ   rT   r¼   rÌ   rU   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ý   rr   r‚   rs   )	r§   r  r  r	  r  ZMBÚtemplateÚtrP   r$   )r  r  r%   r   à  sö    
ÿ
þÿþ	ÿ
ÿþÿ
ÿþÿÿÿ¢g&ÿÚ__main__)Nr  )drÛ   rõ   rÐ   r·   rv   rb   r  rã   Ú
contextlibr   r   Úior   Ú
subprocessr   r   r   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   rm   rn   rì   Ú__all__r®   r°   rÿ   rÇ   r²   r´   r¶   rY   r\   rÏ   rH   rK   rL   rT   rU   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}   rt   r�   r   r   r    r$   r$   r$   r%   Ú<module>   s’   
 ? I
 
