o
    ^i\                     @   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mZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ e
ddd	ZejeZejed
ZG dd deZdd Zdi efddZdd Zdd ZdS )    N)	ASTSourcemake_backend)	GPUTarget)GluonASTSource)create_function_from_signature)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/RAG/RAG_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  r}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|dgtj
d W n tjym } z
|jd}t|d }~ww W d    d S 1 syw   Y  d S )Nmodulewexpectedz--input-filez--dump-input-context=50)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*   

"r9   r   c                 C   s   d|vrt |}d|d< t|}t| j| j|}||i |\}}}| |||||\}}	}
}|  r5tnt}|| |	|
|}t	
 }t	| || ||}| }||||||}| sdJ |S )Nsanitize_overflowF)dictr   r   	signatureparams
_pack_argsis_gluonr   r   r   contextload_dialectsget_codegen_implementationget_module_mapmake_irverify)	kernel_fnargskwargstargetbackendbinder
bound_argsspecializationoptionsr<   
constexprsattrs
source_clssrcr@   codegen_fns
module_mapr   r   r   r   
run_parser6   s*   


rU   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	getsourcefnr0   rU   r9   str_nodebug)rF   r2   mlir_moduler   r   r   run_filecheck_testQ   s   r`   c                    s   t   fdd}|S )Nc                      s   t   d S r   )r`   r   r]   r   r   test_fn]   s   zfilecheck_test.<locals>.test_fn)	functoolswraps)r]   rb   r   ra   r   filecheck_test[   s   re   )rc   r$   r[   r)   r"   rX   triton.compilerr   r   triton.backends.compilerr   "triton.experimental.gluon._runtimer   triton.runtime.jitr   triton._C.libtritonr   stub_targetr%   dirname__file__
triton_dirr&   r+   r0   r   r9   rU   r`   re   r   r   r   r   <module>   s&    

