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       	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__ L/var/www/html/scripts/venv/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tempdirtemp_moduletemptemp_expectederrordecodedr   r   r   run_filecheck"   s(   

"r8   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   )r0   ).0xr   r   r   
<listcomp>5   s    zrun_parser.<locals>.<listcomp>c                 S   s   g | ]}d | qS )argr   )r9   ir   r   r   r;   6       c                 S   s   i | ]\}}||qS r   r   )r9   kvr   r   r   
<dictcomp>7   r>   zrun_parser.<locals>.<dictcomp>)fn	signaturer   )paramsrangelenzipis_gluonr   r   r   contextload_dialectsstub_backendparse_optionsdictget_codegen_implementationget_module_mapmake_irverify)	kernel_fnsigkeyssigvalsrC   
source_clssrcrI   extra_optionsoptionscodegen_fns
module_mapr   r   r   r   
run_parser4   s   


r[   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tritonruntimeJITFunctioninspect	getsourcerB   r/   r[   r8   str_nodebug)rR   r1   mlir_moduler   r   r   run_filecheck_testH   s   re   c                    s    fdd}|S )Nc                      s   t   d S r   )re   r   rB   r   r   test_fnT   s   zfilecheck_test.<locals>.test_fnr   )rB   rg   r   rf   r   filecheck_testR   s   rh   )r#   ra   r(   r!   r^   triton.compilerr   r   triton.backends.compilerr   "triton.experimental.gluon._runtimer   triton._C.libtritonr   stub_targetrK   r$   dirname__file__
triton_dirr%   r*   r/   r   r8   r[   re   rh   r   r   r   r   <module>   s$    

