
    (Th                        S SK r S SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
  S SKrS SKrS SKJr  Sr\S:X  Ga  \" \S9r\R%                  S	S
S9  \R%                  SS\SSSS9  \R%                  SS\SSS9  \R%                  SS\SSS9  \R%                  SS\SSS9  \R%                  SS\SS S9  \R%                  S!S"\S#SS$9  \R%                  S%S&\S'SS$9  \R+                  5       r\R.                  (       a  \R.                  O\R0                  r\R2                  (       a  \R2                  O\" \5      r\" \R4                  5      r\R4                  R9                  S \" \R:                  5      5        \R<                  R?                  \R@                  \5      r!\R<                  RE                  \!5      r#\!RH                  RK                  \#5        \&" \#\R0                  5      r'\RP                  RS                  S(5      r(\*" \(5      S:X  d   e\+" \," S) \RZ                  RS                  S(5      5      5      r-S*\
\   4S+ jr.S,\R^                   S-\R`                   3r1\." \-\1/-   5      r2S. r3\4" \-5       V Vs0 s H)  u  pS/U;   d  M  U 4\3" URS                  S/5      S   5      _M+     snn r5\5Rm                  5        VVs0 s H  u  p#Uc  M
  X#_M     snnr5\4" \-5       V Vs0 s H  u  p\'Rn                  U    \3" U5      _M     snn r8\8Rm                  5        VVs0 s H  u  p#Uc  M
  X#_M     snnr8\5Rm                  5        H#  u  r9r:\:S:X  d  M  \:\8\'Rn                  \9S       '   M%     \4" \-5       V Vs0 s H'  u  p\'Rn                  U    URS                  S/5      S    _M)     snn r-\8 H  r9S0\-\9'   M
     S1Rw                  \8Ry                  5        Vs/ s H  n\" U5      PM     sn5      r=\8Rm                  5        VVs/ s H  u  p#U S2U 3PM     snnr>\>S3\R^                   3S4\R`                   3/-  r>\5Ry                  5        H  r?\?S5;   a  M   S6\? 35       e   \5Rm                  5        VVs0 s H  u  p#US7:X  d  M  US8S7//_M     snnr@\R                  R                  \'\8\-\@S99rC\R^                  \R`                  S:.rD\R                  " \C\DS;9rF\FR                  R                  S :  a  \I" S<5      e/ r7/ rJ/ rK/ rL\4" \'Rn                  5       H  u  rMrN\N\8;  aL  \7R                  \N5        \JR                  \-\N   5        \KR                  \N5        \LR                  \-\N   5        MX  \5R                  \M4S5      S:X  d  Mq  \7R                  \N5        \JR                  S=5        M     SrQ\4" \-Ry                  5       5       HK  u  rMrR\Q\" \M5      -  rQ\5R                  \M4S5      S:X  a  \QS>-  rQ\5R                  \M4S5      S7:X  d  MF  \QS?-  rQMM     S@Rw                  \\2\Q/5      rS\FR                  SA   rT\" \ R                  " \T5      5      SBSC rV0 SD\S_SE\R0                  _SF\*" \T5      _SGSHRw                  \W" \VSSSB2   \VSSSB2   5       VVs/ s H  u  pESIU U 3PM     snn5      _S*SHRw                  \W" \K\L5       VVs/ s H  u  pg\" U5       SJU 3PM     snn5      _SKSHRw                  \W" \7\J5       VVs/ s H  u  pg\" U5       SJU 3PM     snn5      _SLSHRw                  \K Vs/ s H  nSMU 3PM
     snSN/-   5      _SO\*" \K5      S-   _SP\>_SQ\FR                  R                  _SR\R^                  _SSS@Rw                  \=\1/5      _ST\(S    _SU\(S   _SV\(SB   _SWS_rYSX H  rZ\" \[5      R:                  SY-  SZ-  S[\Z 3-  r\\R                  S\\2 S@\Q S\\Z 35      R                  S]5       r_\_R                  \" \\5      R                  5       R                  " S^0 \YD65        SSS5        M     ggs  snn f s  snnf s  snn f s  snnf s  snn f s  snf s  snnf s  snnf s  snnf s  snnf s  snnf s  snf ! , (       d  f       M  = f)_    N)ArgumentParser)Path)List)	ty_to_cppa  
Triton ahead-of-time compiler:

This program compiles the kernel with name `kernel-name` in the file at the
provided `path` into self-contained C source-code that embeds the `cubin`
data along with utilities to load, unload and launch the kernel.

signature is provided as a list of (optionally divisibility-hinted) types
or constexpr values, e.g.

`compile.py --kernel-name kernel --signature "*fp32:16, i32:16, 1024, i32" --out-name kernel /path/to/kernel.py`

will compile triton.JITFunction of name `kernel` inside the file `/path/to/kernel.py`.
Said kernel will be specialized such that argument 0, 1 are assumed to be multiple of 16,
and argument 2 is assumed to be a compile-time constant of value 1024, i.e. it won't be part of the generated prototype.

The resulting entry point will have signature

CUresult kernel_{specialization_suffix}(CUstream stream, unsigned gX, unsigned gY, unsigned gZ, float* arg0, int32_t arg1, int32_t arg2)

Different such specialized entry points can be combined using the `linker.py` script.

NOTE: when resolving the scope of /path/to/kernel.py, the file will be executed from within its parent directory with the python interpreter
used to run this `compile.py` script
__main__)descriptionpathzTPath to Python source containing desired kernel in its scope. File will be executed.)helpz--kernel-namez-n zName of the kernel to compileT)typedefaultr
   requiredz--num-warpsz-w   z$Number of warps to launch the kernel)r   r   r
   z--num-stagesz-ns   z/Number of stages (meta-parameter of the kernel)z
--out-namez-onz Out name for the compiled kernelz
--out-pathz-ozOut filenamez--signaturez-szSignature of the kernel)r   r
   r   z--gridz-gzLaunch grid of the kernel,c                 $    U R                  S5      $ )N )strip)ss    L/var/www/auris/envauris/lib/python3.13/site-packages/triton/tools/compile.py<lambda>r   F   s    1773<    	signaturec                     [         R                  " 5       nUR                  SR                  U 5      R	                  5       5        UR                  5       S S $ )Nr      )hashlibsha256updatejoinencode	hexdigest)r   ms     r   hash_signaturer#   H   s?    NN	)$++-.{{}Ra  r   warpsxstagesc                 z     [        U 5      nU$ ! [         a     Of = f [        U 5      nU$ ! [         a     g f = f)N)int
ValueErrorfloat)r   rets     r   	constexprr+   P   sO    	a&CJ 			(CJ 		s    
- 
:::r+   x=z
num_warps=znum_stages=)r      z#Only 1 and 16 are valid hints, got r/   ztt.divisibility)fn
constexprsr   attrs)	num_warps
num_stages)optionszMAOT compiling kernels with global scratch requirements is not yet implementedi32cd_cubin   kernel_nametriton_kernel_namebin_sizebin_dataz, 0xr   full_signaturearg_pointers&z&global_scratchnum_argskernel_docstringsharedr3   	algo_infogridXgridYgridZ_placeholder)hr7   extracudazcompile..w )cbinasciir   importlib.util	importlibsysargparser   pathlibr   typingr   tritontriton.backendstriton.backends.nvidia.driverr   desc__name__parseradd_argumentstrr'   
parse_argsargsout_namer=   out_pathr	   arg_pathinsertparentutilspec_from_file_locationstemspecmodule_from_specmodloaderexec_modulegetattrkernelgridsplitlenlistmapr   r#   r3   r4   meta_sigsig_hashr+   	enumeratehintsitems	arg_names	constantskeyvaluer   values	const_sig
doc_stringrM   r2   compiler	ASTSourcesrcoptscompileccinfometadataglobal_scratch_sizeRuntimeError	arg_typesarg_names_not_1arg_types_not_1iarg_nameappendgetsuffixty	func_nameasmhexlifyhex_ziprG   paramsext__file__template_pathwith_suffixopenfpwrite	read_textformat)	r   r   kvr-   ynamer   args	   000000000r   <module>r      s      
 #     34 z -F
s  u
CJi!%  '
t#qGmn
CN  P
e#tJlm
dt.Y
t#<U`de
$S7R]abD $t}}43C3CH $t}}4>H DIIHHHOOAs8??+,>>11(--JD
..
)
)$
/CKKC S$**+F99??3Dt9>> S/1E1Ec1JKLI!$s) !
 t~~&gdoo->?Hi8*45H <EY;O\;O41SVZ[S[.aUIaggcl1o..;O\E#kkm=mdaqTQTm=E?H?ST?Stq!!!$il2?STI"+//"3E"3$!q"3EIkkm
UA:27If&&s1v./ $ CLIBVWBV$!!!!$aggcl1o5BVWI$	# )*:*:*<=*<Q#a&*<=>I)2):;):QCq*):;JZ/0K?P2QRRJ\\^G|FB1#FF| 6;kkmOmdaqBw)Q#R())mOE
//
#
#v)y`e
#
fCtGD^^C.F**Q.jkkIIOO !1!1289$X&Yx01""8,""9X#67YYud#q(X&U# 3 F9++-.2#a&99aUD!Q&cMF99aUD!R'cMF / (Hf56I
**W
Cx$%a+Dyd.. 	CH 	DIIs4!9d14a4j7QR7QtqA3qc{7QRS	
 	TYY#o_nJopJohd9R=/4& 9Jopq 	$))sS\^gOh$iOh84	"av%>Oh$ij 			"HQse9"HL]K^"^_ 	C(1, 	J 	&//(( 	T^^ 	SXXy(34 	a 	a 	a  	!F$ X--7&@XcUCSS!!AhZq#"?@EEcJbHHT-(224;;EfEF KJ q l ]=TE X >;
 PH Sp$i"H KJsl   3`' `':	`-`-"`3	`9"`9..`?a7a
)a9
aa6a/a" a(#6a--
a<	