
    Ni\                     6   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e          Zd Zdi efdZd Zd ZdS )    N)	ASTSourcemake_backend)	GPUTarget)GluonASTSource)create_function_from_signature)ircudad       	FileCheckc                   (     e Zd Z fdZ fdZ xZS )
MatchErrorc                 X    t                                          |           || _        d S N)super__init__
module_str)selfmessager   	__class__s      i/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/triton/_filecheck.pyr   zMatchError.__init__   s&    !!!$    c                 X    t                                                       d| j         S )N
)r   __str__r   )r   r   s    r   r   zMatchError.__str__   s'    ''//##88t888r   )__name__
__module____qualname__r   r   __classcell__)r   s   @r   r   r      sQ        % % % % %9 9 9 9 9 9 9 9 9r   r   c                    t          j                    5 }t          j                            |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j                            |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   	 t          j        t          |d|dgt          j
                   n@# t          j        $ r.}|j                            d          }t          |          d }~ww xY w	 d d d            d S # 1 swxY w 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decodeds	            r   run_filecheckr=   #   s   		$	&	& &'gll7H55+s## 	#tJJz"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# Wj99-%% 	'JJ~&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'	&#Mfg!(* * * * * , 	& 	& 	&l))*:;;GW%%%	&*& & & & & & & & & & & & & & & & & &s}   1E	A'E	'A+	+E	.A+	/3E	"C8E	C	E	C	E	*C;:E	;D8
)D33D88E		EE c                 f   d|vrt          |          }d|d<   t          |          }t          | j        | j        |          } ||i |\  }}}|                     |||||          \  }}	}
}|                                 rt          nt          } || |	|
|          }t          j
                    }t          j        |           |                    |           |                    |          }|                                }|                    |||||          }|                                sJ |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optionsrB   
constexprsattrs
source_clssrcrF   codegen_fns
module_mapr!   s                     r   
run_parserr[   6   sG   &((f&+"#6""G+ F +1&$*A&*A*A'J,5,@,@&R\^lnu,v,v)GY
E#,#5#5#7#7FYJ
*Y	:u
=
=CjllGW'"""44W==K''))J[[+z7KKF==??Mr   c                     t          | t          j        j                  sJ t	          j        | j                  }|t          d          t          |           }t          d|
                                |           d S )Nz=kernel function must have a docstring with FileCheck templateplaceholder)
isinstancetritonruntimeJITFunctioninspect	getsourcefnr4   r[   r=   str_nodebug)rL   r6   mlir_modules      r   run_filecheck_testrg   Q   su    i!;<<<<<&y|44NXYYYY''K-!8!8!:!:NKKKKKr   c                 F     t          j                    fd            }|S )Nc                  &    t                      d S r   )rg   )rd   s   r   test_fnzfilecheck_test.<locals>.test_fn]   s    2r   )	functoolswraps)rd   rj   s   ` r   filecheck_testrm   [   s8    _R     Nr   )rk   r(   rb   r-   r&   r_   triton.compilerr   r   triton.backends.compilerr   "triton.experimental.gluon._runtimer   triton.runtime.jitr   triton._C.libtritonr   stub_targetr)   dirname__file__
triton_dirr*   r/   r4   r   r=   r[   rg   rm   r>   r   r   <module>rw      s_       				        3 3 3 3 3 3 3 3 . . . . . . = = = = = = = = = = = = " " " " " " iR((W__X&&
j+669 9 9 9 9 9 9 9& & &&  ""[    6L L L    r   