o
    i                     @   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versionZhip)r    r   b/var/www/html/eduruby.in/lip-sync/lip-sync-env/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 )NZ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)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   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)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 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 )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	librariesZ	build_extz--build-temp=z--build-lib=z-q)r.   Zext_modulesZscript_argsr   )r   r   r   r   r   r   r+   	sysconfigget_config_varformatenvirongetshutilwhichRuntimeErrorhasattrr3   Z_get_default_scheme	get_pathsr   
check_call
setuptoolsZ	Extensionappenddictr%   setup)r.   srcsrcdirZhip_lib_dirZhip_include_dirZcuda_lib_dirsZcu_include_dirr/   soccr1   r2   r6   Zpy_include_dirretZcc_cmdr=   r?   r<   r@   r>   extargsr   r   r   _build8   sr   




:,


rW   )
contextlib	functoolsr#   r   rF   r   r    rA   rL   r   	lru_cacher   r   contextmanagerr%   r+   rW   r   r   r   r   <module>   s&    


	
