U
    9%e                     @   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/Darija-Ai-API/env/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rtd}
td}|d k	r|n|
}	|	d krtd	ttd
rt }nt }|dkrd}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$   


	
