o
    h                     @  s   d dl m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lZd dlmZ ddlmZ ddlmZ dddZejdddZdddZ		dd ddZdS )!    )annotationsN)
ModuleType   )get_cache_manager   )knobsnamestrsrcsrcdirlibrary_dirs	list[str]include_dirs	librariesreturnc                 C  s6  t jj }r|| |||||S td}tj|dj| |d}tj	
d}	|	d u rDtd}
td}|d ur:|n|
}	|	d u rDtdttdrNt }nt }|d	krXd
}tj|dd }t jj}|||g| }|	|ddddd|g}|dd |D 7 }|dd |D 7 }|dd |D 7 }tj|tjd |S )N
EXT_SUFFIXz{name}{suffix})r   suffixCCclanggcczeFailed to find C compiler. Please specify via CC environment variable or set triton.knobs.build.impl.get_default_schemeZposix_localposix_prefix)schemeincludez-O3z-sharedz-fPICz
-Wno-psabiz-oc                 S     g | ]}d | qS )z-l ).0libr   r   Z/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/triton/runtime/build.py
<listcomp>0       z_build.<locals>.<listcomp>c                 S  r   )z-Lr   r   dirr   r   r   r   1   r    c                 S  s   g | ]}|d urd| qS )Nz-Ir   r!   r   r   r   r   2   s    )stdout)r   buildimpl	sysconfigget_config_varospathjoinformatenvirongetshutilwhichRuntimeErrorhasattrr   Z_get_default_scheme	get_pathsZbackend_dirs
subprocess
check_callDEVNULL)r   r
   r   r   r   r   r%   r   soccr   r   r   Zpy_include_dirZcustom_backend_dirsZcc_cmdr   r   r   _build   s6   




r8   c                  C  s,   ddl m} m}m} d|  | g| S )Nr   machinesystemarchitecture,)platformr:   r;   r<   r*   r9   r   r   r   platform_key7   s   r?   r)   r   c                 C  sH   t j| |}|r|jstd|  d| t j|}|j| |S )NzFailed to load newly compiled z from )	importlibutilspec_from_file_locationloaderr0   module_from_specexec_module)r   r)   specmodr   r   r   _load_module_from_path=   s   
rH   list[str] | Nonec              	   C  sb  t | t  d }t|}td}|| | }|d urCzt	||W S  t
tfyB   tt}	|	d| d Y nw t ]}
tj|
|d }t|d}||  W d    n1 sfw   Y  t|||
|prg |pug |pxg }t|d}|j| | | dd	}W d    n1 sw   Y  W d    n1 sw   Y  t	||S )
Nzutf-8r   z$Triton cache error: compiled module z.so could not be loadedz.cwrbT)binary)hashlibsha256r?   encode	hexdigestr   r&   r'   Zget_filerH   r0   ImportErrorlogging	getLogger__name__warningtempfileTemporaryDirectoryr(   r)   r*   openwriter8   putread)r
   r   r   r   r   keycacher   
cache_pathlogZtmpdirZsrc_pathfr6   r   r   r   compile_module_from_srcF   s.   



ra   )r   r	   r
   r	   r   r	   r   r   r   r   r   r   r   r	   )r   r	   )r   r	   r)   r	   r   r   )NNN)r
   r	   r   r	   r   rI   r   rI   r   rI   r   r   )
__future__r   	functoolsrM   importlib.utilr@   rR   r(   r.   r3   r&   rV   typesr   r]   r    r   r8   	lru_cacher?   rH   ra   r   r   r   r   <module>   s(    
$
	