U
    yÊ¹j  ã                   @   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Zdd„ Z	e 
¡ dd„ ƒZe 
¡ dd„ ƒZe jdd	„ ƒZe 
¡ d
d„ ƒZdd„ ZdS )é    Nc                  C   s   dd l } | jjd k	S )Nr   )ÚtorchÚversionZhip)r   © r   úR/var/www/html/bwave/python/venv/lib/python3.8/site-packages/triton/common/build.pyÚis_hip   s    r   c                  C   sp   t  ddg¡ ¡ } dd„ |  ¡ D ƒ}dd„ |D ƒ}d}|rR|dt|ƒ 7 }|d7 }td	d
„ |D ƒƒslt|ƒ‚|S )NZldconfigz-pc                 S   s    g | ]}d |kr|  ¡ d ‘qS )ú
libcuda.soéÿÿÿÿ)Úsplit)Ú.0Úliner   r   r   Ú
<listcomp>   s      z libcuda_dirs.<locals>.<listcomp>c                 S   s   g | ]}t j |¡‘qS r   )ÚosÚpathÚdirname)r
   Úlocr   r   r   r      s     zlibcuda.so cannot found!
z!Possible files are located at %s.z9Please create a symlink of libcuda.so to any of the file.c                 s   s$   | ]}t j t j |d ¡¡V  qdS )r   N)r   r   ÚexistsÚjoin)r
   r   r   r   r   Ú	<genexpr>   s     zlibcuda_dirs.<locals>.<genexpr>)Ú
subprocessÚcheck_outputÚdecodeÚ
splitlinesÚstrÚanyÚAssertionError)ZlibsZlocsÚdirsÚmsgr   r   r   Úlibcuda_dirs   s    r   c                   C   s   t jddd�S )NZ	ROCM_PATHz	/opt/rocm)Údefault)r   Úgetenvr   r   r   r   Úrocm_path_dir"   s    r    c               	   c   sD   t jt j } }t ¡ t ¡  t _t _z
d V  W 5 | | t _t _X d S )N)ÚsysÚstdoutÚstderrÚioÚStringIO)Z
old_stdoutZ
old_stderrr   r   r   Úquiet'   s
    
r&   c                  C   s8   t j t j t¡t jj¡} t j | dd¡}t j |d¡S )NZthird_partyÚcudaÚinclude)r   r   r   r   Ú__file__Úpardir)Úbase_dirZ	cuda_pathr   r   r   Úcuda_include_dir1   s    r,   c                 C   s  t ƒ r(tj tƒ d¡}tj tƒ d¡}ntƒ }tƒ }t d¡}tj |dj	| |d�¡}tj
 d¡}	|	d kržt d¡}
t d¡}|d k	rŠ|n|
}	|	d kržtd	ƒ‚ttd
ƒr²t ¡ }nt ¡ }|dkrÆd}tj|d�d }t ƒ �rt |	|d|› �d|› �d|› �ddd|› �dd|g¡}nH|	|dd|› �d|› �d|› �dddd|g}|dd„ |D ƒ7 }t |¡}|dk�rn|S g }|}||g}dg}g }tj| d|g||dg |||d�}dg}| d| ¡ | d| ¡ | d¡ t| |g|d �}tƒ � tjf |Ž W 5 Q R X |S )!NÚlibr(   Ú
EXT_SUFFIXz{name}{suffix})ÚnameÚsuffixÚCCÚclangÚgcczFFailed to find C compiler. Please specify via CC environment variable.Úget_default_schemeZposix_localÚposix_prefix)Úschemez-Iz-sharedz-fPICú-Lz
-lamdhip64z-oz-O3z-lcudac                 S   s   g | ]}d |› �‘qS )r7   r   )r
   Údirr   r   r   r   Y   s     z_build.<locals>.<listcomp>r   r'   Úc)r/   ÚlanguageÚsourcesÚinclude_dirsÚextra_compile_argsÚextra_link_argsÚlibrary_dirsÚ	librariesÚ	build_extz--build-temp=z--build-lib=z-q)r/   Úext_modulesÚscript_args)r   r   r   r   r    r   r,   Ú	sysconfigÚget_config_varÚformatÚenvironÚgetÚshutilÚwhichÚRuntimeErrorÚhasattrr4   Ú_get_default_schemeÚ	get_pathsr   Ú
check_callÚ
setuptoolsÚ	ExtensionÚappendÚdictr&   Úsetup)r/   ÚsrcÚsrcdirZhip_lib_dirZhip_include_dirZcuda_lib_dirsZcu_include_dirr0   ÚsoÚccr2   r3   r6   Zpy_include_dirÚretÚcc_cmdr=   r?   r<   r@   r>   ÚextÚargsr   r   r   Ú_build8   sl    




:,

ø
ýr]   )Ú
contextlibÚ	functoolsr$   r   rI   r   r!   rD   rP   r   Ú	lru_cacher   r    Úcontextmanagerr&   r,   r]   r   r   r   r   Ú<module>   s$   


	
