a
    öDfC                     @   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   `/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/triton/common/build.pyis_hip   s    r   c                  C   s   t d} | r| gS tddg }dd | D }dd |D }t d}|rl|sldd |d	D }d
}|r|dt| 7 }|d7 }n|d7 }|d7 }tdd |D sJ ||S )NZTRITON_LIBCUDA_PATHz/sbin/ldconfigz-pc                 S   s    g | ]}d |v r|  d qS )
libcuda.so)split).0liner   r   r   
<listcomp>       z libcuda_dirs.<locals>.<listcomp>c                 S   s   g | ]}t j|qS r   )ospathdirname)r
   locr   r   r   r      r   ZLD_LIBRARY_PATHc                 S   s&   g | ]}t jt j|d r|qS )r   r   r   existsjoinr
   dirr   r   r   r       r   :zlibcuda.so cannot found!
z!Possible files are located at %s.z9Please create a symlink of libcuda.so to any of the file.z;Please make sure GPU is setup and then run "/sbin/ldconfig"z- (requires sudo) to refresh the linker cache.c                 s   s$   | ]}t jt j|d V  qdS )r   Nr   )r
   r   r   r   r   	<genexpr>(   r   zlibcuda_dirs.<locals>.<genexpr>)	r   getenv
subprocesscheck_outputdecode
splitlinesr	   strany)Zenv_libcuda_pathZlibsZlocsdirsZenv_ld_library_pathmsgr   r   r   libcuda_dirs   s"    


r"   c                   C   s   t jdddS )NZ	ROCM_PATHz	/opt/rocm)default)r   r   r   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 _n| | t _t _0 d S )N)sysstdoutstderrioStringIO)Z
old_stdoutZ
old_stderrr   r   r   quiet1   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_dir;   s    r0   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 rtd}
td}|d ur|n|
}	|	d u 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 i | W d    n1 s0    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_schemeZposix_localposix_prefix)schemez-Iz-sharedz-fPIC-Lz
-lamdhip64z-oz-O3z-lcudac                 S   s   g | ]}d | qS )r;   r   r   r   r   r   r   i   r   z_build.<locals>.<listcomp>r   r+   c)r3   languagesourcesinclude_dirsextra_compile_argsextra_link_argslibrary_dirs	libraries	build_extz--build-temp=z--build-lib=z-q)r3   ext_modulesscript_args)r   r   r   r   r$   r"   r0   	sysconfigget_config_varformatenvirongetshutilwhichRuntimeErrorhasattrr8   _get_default_scheme	get_pathsr   
check_call
setuptools	Extensionappenddictr*   setup)r3   srcsrcdirZhip_lib_dirZhip_include_dirZcuda_lib_dirsZcu_include_dirr4   soccr6   r7   r:   Zpy_include_dirretcc_cmdr@   rB   r?   rC   rA   extargsr   r   r   _buildB   sv    




 $


0r`   )
contextlib	functoolsr(   r   rL   r   r%   rG   rS   r   	lru_cacher"   r$   contextmanagerr*   r0   r`   r   r   r   r   <module>   s$   


	
