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mZmZ d dlm	Z	 d dl
mZ d dlmZ e	dddZeeZe jeZe jed	ZG d
d deZdd Zdd Zdd Zdd ZdS )    N)	ASTSourcemake_backend)	GPUTarget)GluonASTSource)ircudad       Z	FileCheckc                       s(   e Zd Z fddZ fddZ  ZS )
MatchErrorc                    s   t  | || _d S N)super__init__
module_str)selfmessager   	__class__ W/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/triton/_filecheck.pyr      s   
zMatchError.__init__c                    s   t    d| j S )N
)r   __str__r   )r   r   r   r   r      s   zMatchError.__str__)__name__
__module____qualname__r   r   __classcell__r   r   r   r   r
      s    r
   c           	      C   s   t  q}tj|d}t|d}|| W d    n1 s!w   Y  tj|d}t|d}|| W d    n1 sBw   Y  ztjt	|d|gtj
d W n tjyl } z
|jd}t|d }~ww W d    d S 1 sxw   Y  d S )Nmodulewexpectedz--input-file)stderrunicode_escape)tempfileTemporaryDirectoryospathjoinopenwrite
subprocesscheck_outputfilecheck_pathSTDOUTCalledProcessErroroutputdecode
ValueError)	namer   check_templatetempdirZtemp_moduletempZtemp_expectederrordecodedr   r   r   run_filecheck"   s(   

"r5   c                 C   s   dd | j D }dd tt|D }dd t||D }|  r#tnt}|| |d}t }t	| t
	| | }t
tdi |}t
|}	t
 }
|||	|
|}| s^J |S )Nc                 S   s   g | ]}|j qS r   )r/   ).0xr   r   r   
<listcomp>5   s    zrun_parser.<locals>.<listcomp>c                 S   s   g | ]}d | qS )argr   )r6   ir   r   r   r8   6       c                 S   s   i | ]\}}||qS r   r   )r6   kvr   r   r   
<dictcomp>7   r;   zrun_parser.<locals>.<dictcomp>)fn	signaturer   )paramsrangelenzipZis_gluonr   r   r   contextZload_dialectsstub_backendZparse_optionsdictZget_codegen_implementationZget_module_mapZmake_irverify)	kernel_fnZsigkeysZsigvalsr@   Z
source_clssrcrE   Zextra_optionsoptionsZcodegen_fnsZ
module_mapr   r   r   r   
run_parser4   s   


rL   c                 C   sJ   t | tjjs	J t| j}|d u rtdt| }t	d|
 | d S )Nz=kernel function must have a docstring with FileCheck templateplaceholder)
isinstancetritonZruntimeZJITFunctioninspect	getsourcer?   r.   rL   r5   Zstr_nodebug)rI   r0   Zmlir_moduler   r   r   run_filecheck_testH   s   rR   c                    s    fdd}|S )Nc                      s   t   d S r   )rR   r   r?   r   r   test_fnT   s   zfilecheck_test.<locals>.test_fnr   )r?   rT   r   rS   r   filecheck_testR   s   rU   )r"   rP   r'   r    rO   Ztriton.compilerr   r   Ztriton.backends.compilerr   Z"triton.experimental.gluon._runtimer   Ztriton._C.libtritonr   Zstub_targetrF   r#   dirname__file__Z
triton_dirr$   r)   r.   r
   r5   rL   rR   rU   r   r   r   r   <module>   s$    

