o
    h                     @   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 uS )Nr   )torchversionhip)r    r   I/var/www/html/ai/venv/lib/python3.10/site-packages/triton/common/build.pyis_hip   s   r   c                  C   sp   t ddg } dd |  D }dd |D }d}|r)|dt| 7 }|d7 }td	d
 |D s6J ||S )Nldconfigz-pc                 S   s    g | ]}d |v 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)libslocsdirsmsgr   r   r   libcuda_dirs   s   r    c                   C   s   t jdddS )N	ROCM_PATHz	/opt/rocm)default)r   getenvr   r   r   r   rocm_path_dir"   s   r$   c               	   c   sR    t jt j} }t t t _t _zd V  W | |t _t _d S | |t _t _w )N)sysstdoutstderrioStringIO)
old_stdout
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 )Nthird_partycudainclude)r   r   r   r   __file__pardir)base_dir	cuda_pathr   r   r   cuda_include_dir1   s   r4   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 u rOtd}
td}|d urE|n|
}	|	d u rOtd	ttd
rYt }nt }|dkrcd}tj|dd }t  rt|	|d| d| d| ddd| dd|g}n$|	|dd| d| d| dddd|g}|dd |D 7 }t|}|dkr|S g }|}||g}dg}g }tj| d|g||dg |||d}dg}|d|  |d|  |d t| |g|d }t  tjd!i | W d    |S 1 s	w   Y  |S )"Nlibr/   
EXT_SUFFIXz{name}{suffix})namesuffixCCclanggcczFFailed to find C compiler. Please specify via CC environment variable.get_default_schemeposix_localposix_prefix)schemez-Iz-sharedz-fPIC-Lz
-lamdhip64z-oz-O3z-lcudac                 S   s   g | ]}d | qS )r@   r   )r   dirr   r   r   r   Y   s    z_build.<locals>.<listcomp>r   r.   c)r7   languagesourcesinclude_dirsextra_compile_argsextra_link_argslibrary_dirs	libraries	build_extz--build-temp=z--build-lib=z-q)r7   ext_modulesscript_argsr   )r   r   r   r   r$   r    r4   	sysconfigget_config_varformatenvirongetshutilwhichRuntimeErrorhasattrr<   _get_default_scheme	get_pathsr   
check_call
setuptools	Extensionappenddictr,   setup)r7   srcsrcdirhip_lib_dirhip_include_dircuda_lib_dirscu_include_dirr8   soccr:   r;   r?   py_include_dirretcc_cmdrF   rH   rE   rI   rG   extargsr   r   r   _build8   sr   




:,


rk   )
contextlib	functoolsr(   r   rR   r   r%   rM   rY   r   	lru_cacher    r$   contextmanagerr,   r4   rk   r   r   r   r   <module>   s&    


	
