
    |rh                         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                   j#                  e      Ze j                   j)                  ed	      Z G d
 de      Zd Zd Zd Zd Zy)    N)	ASTSourcemake_backend)	GPUTarget)GluonASTSource)ircudad       	FileCheckc                   (     e Zd Z fdZ fdZ xZS )
MatchErrorc                 2    t         |   |       || _        y N)super__init__
module_str)selfmessager   	__class__s      d/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/triton/_filecheck.pyr   zMatchError.__init__   s    !$    c                 >    t         |           d| j                   S )N
)r   __str__r   )r   r   s    r   r   zMatchError.__str__   s!    '/#$Bt&788r   )__name__
__module____qualname__r   r   __classcell__)r   s   @r   r   r      s    %9 9r   r   c                 ~   t        j                         5 }t        j                  j	                  |d      }t        |d      5 }|j                  |       d d d        t        j                  j	                  |d      }t        |d      5 }|j                  |       d d d        	 t        j                  t        |d|gt        j                         	 d d d        y # 1 sw Y   xY w# 1 sw Y   MxY w# t        j                  $ r+}|j                  j                  d      }t        |      d }~ww xY w# 1 sw Y   y xY w)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decodeds	            r   run_filecheckr<   "   s   		$	$	& &'ggll7H5+s# 	#tJJz"	# Wj9-% 	'JJ~&	'	&##^]NT_$`+5+<+<>& &	# 	#	' 	' ,, 	&ll))*:;GW%%	&& &sY   -D3C4D3C&D3#-C2C#	D3&C/	+D32D0&D++D00D33D<c                    | j                   D cg c]  }|j                   }}t        t        |            D cg c]  }d| 	 }}t	        ||      D ci c]  \  }}||
 }}}| j                         rt        nt        } || |      }	t        j                         }
t        j                  |
       t        j                  |
       |	j                         }t        j                  t        di |      }t        j                  |      }t        j                         }|	j!                  ||||
      }|j#                         sJ |S c c}w c c}w c c}}w )Narg)fn	signature )paramsr4   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xsigkeysisigvalskvr@   
source_clssrcrG   extra_optionsoptionscodegen_fns
module_mapr    s                   r   
run_parserr]   4   s   (//0!qvv0G0"'G"56QQCy6G6$'$9:&1aA:I:#,#5#5#7YJ
	Y
7CjjlGWw'%%'M(()>)>?G99'BK,,.J[[+z7CF==??M! 16:s   E
EEc                     t        | t        j                  j                        sJ t	        j
                  | j                        }|t        d      t        |       }t        d|j                         |       y )Nz=kernel function must have a docstring with FileCheck templateplaceholder)
isinstancetritonruntimeJITFunctioninspect	getsourcer?   r3   r]   r<   str_nodebug)rP   r5   mlir_modules      r   run_filecheck_testrh   H   sa    i!;!;<<<&&y||4NXYYY'K-!8!8!:NKr   c                       fd}|S )Nc                      t                y r   )rh   )r?   s   r   test_fnzfilecheck_test.<locals>.test_fnT   s    2r   rA   )r?   rk   s   ` r   filecheck_testrl   R   s     Nr   )r'   rd   r,   r%   ra   triton.compilerr   r   triton.backends.compilerr   "triton.experimental.gluon._runtimer   triton._C.libtritonr   stub_targetrI   r(   dirname__file__
triton_dirr)   r.   r3   r   r<   r]   rh   rl   rA   r   r   <module>ru      s    	     3 . = " R(K(WW__X&
j+69 9&$(Lr   