§
    zniÙ  ã                   ó
  — d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlZd dlmZ d dlmZ dZedk    �rÏ ee¬	¦  «        Ze                     d
d¬¦  «         e                     ddeddd¬¦  «         e                     ddedd¬¦  «         e                     ddedd¬¦  «         e                     ddedd¬¦  «         e                     dded d¬!¦  «         e                     ¦   «         Zej        rej        nej        Zej        rej        neZ eej        ¦  «        Zej                             d  eej        ¦  «        ¦  «         ej                              ej!        e¦  «        Z"ej         #                    e"¦  «        Z$e"j%         &                    e$¦  «          e'e$ej        ¦  «        Z( e) e*d"„ ej+         ,                    d#¦  «        ¦  «        ¦  «        Z+d$e
e         fd%„Z- e-e+¦  «        Z.d&„ Z/d'„  e0e+¦  «        D ¦   «         Z1d(„ e1 2                    ¦   «         D ¦   «         Z1d)„  e0e+¦  «        D ¦   «         Z3d*„ e3 2                    ¦   «         D ¦   «         Z3d+„  e0e+¦  «        D ¦   «         Z+e1 4                    ¦   «         D ]Z5e5d,v sJ d-e5› �¦   «         ‚Œd.„ e1 2                    ¦   «         D ¦   «         Z6d/„ e1 2                    ¦   «         D ¦   «         Z7ej8         9                    e6e7¬0¦  «        Z: ej;        e(e+e3e:gej<        ¬1¦  «        Z=d2„ e+ >                    ¦   «         D ¦   «         Z? ee+ 4                    ¦   «         e:¦  «        Z@d3 A                    ee.e@g¦  «        ZBd3 A                    ej        e@g¦  «        ZC e e jD        e=jE        d4         ¦  «        ¦  «        d5d6…         ZFeBeC eGeF¦  «        d7 A                    d8„  eHeFddd5…         eFddd5…         ¦  «        D ¦   «         ¦  «        d7 A                    d9„  eHe?e+ 4                    ¦   «         ¦  «        D ¦   «         ¦  «        d7 A                    d:„ e?D ¦   «         ¦  «         eGe?¦  «        de=jI        ej<        dd;œZJd<D ]žZK eeL¦  «        j        d=eK› �z  ZMe N                    d>e.› d3e@› d>eK› �¦  «         O                    d?¦  «        5 ZPeP Q                      eeM¦  «         R                    ¦   «         jS        d@i eJ¤Ž¦  «         ddd¦  «         n# 1 swxY w Y   Œ�dS dS )Aé    N)ÚArgumentParser)ÚPath)ÚList)Úkernel_suffix©Ú	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 "*f32: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
--out-namez-onz Out name for the compiled kernelz
--out-pathz-ozOut filenamez--signaturez-szSignature of the kernel)r   r   r   c                 ó,   — |                       d¦  «        S )Nú )Ústrip)Úss    út/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/triton/tools/compile.pyú<lambda>r   ?   s   €  1§7¢7¨3¡<¤<€ ó    ú,Ú	signaturec                 óÔ   — t          j        ¦   «         }|                     d                     | ¦  «                             ¦   «         ¦  «         |                     ¦   «         d d…         S )Nr   é   )ÚhashlibÚsha256ÚupdateÚjoinÚencodeÚ	hexdigest)r   Úms     r   Úhash_signaturer$   A   sP   € ÝŒNÑÔˆØ	�Š�—’˜)Ñ$Ô$×+Ò+Ñ-Ô-Ñ.Ô.Ð.Ø�{Š{‰}Œ}˜R˜a˜RÔ Ð r   c                 óŽ   — 	 t          | ¦  «        }|S # t          $ r Y nw xY w	 t          | ¦  «        }|S # t          $ r Y nw xY wd S ©N)ÚintÚ
ValueErrorÚfloat)r   Úrets     r   Ú	constexprr+   H   sq   € ð	Ý�a‘&”&ˆCØˆJøÝð 	ð 	ð 	ØˆDð	øøøð	Ý˜‘(”(ˆCØˆJøÝð 	ð 	ð 	ØˆDð	øøøàˆts   ‚ “
 Ÿ ¤5 µ
AÁAc                 ón   — i | ]2\  }}d |v ¯	|t          |                     d ¦  «        d         ¦  «        “Œ3S )ú:r   )r+   Úsplit©Ú.0Úir   s      r   ú
<dictcomp>r2   U   s:   € ÐXÐXÐX©t¨q°!ÈsÐVWÈxÈxˆQ•	˜!Ÿ'š' #™,œ, qœ/Ñ*Ô*ÈxÈxÈxr   c                 ó   — i | ]
\  }}|®||“ŒS r&   © ©r0   ÚkÚvs      r   r2   r2   V   s   € Ð=Ð=Ð=‘d�a˜¨q¨}ˆQ�¨}¨}¨}r   c                 ó4   — i | ]\  }}|t          |¦  «        “ŒS r4   )r+   r/   s      r   r2   r2   W   s$   € ÐCÐCÐC¡d a¨�!•Y˜q‘\”\ÐCÐCÐCr   c                 ó   — i | ]
\  }}|®||“ŒS r&   r4   r5   s      r   r2   r2   X   s   € ÐGÐGÐG™4˜1˜a¸¸�!�Q¸¸¸r   c                 ó^   — i | ]*\  }}|t           v¯||                     d ¦  «        d         “Œ+S )r-   r   )Ú
constexprsr.   r/   s      r   r2   r2   Y   s7   € Ð\Ð\Ð\©¨¨1ÈÕQ[ÐH[ÐH[��A—G’G˜C‘L”L ”OÐH[ÐH[ÐH[r   )r   é   z#Only 1 and 16 are valid hints, got c                 ó$   — g | ]\  }}|d k    ¯|‘ŒS )r<   r4   ©r0   r1   Úhs      r   ú
<listcomp>r@   ^   s!   € Ð>Ð>Ð>™T˜Q °a¸2²g°g�q°g°g°gr   c                 ó$   — g | ]\  }}|d k    ¯|‘ŒS )r   r4   r>   s      r   r@   r@   _   s!   € Ð8Ð8Ð8™˜˜1°°a²°�!°°°r   )Údivisible_by_16Ú
equal_to_1)r   Ú	constantsÚconfigsÚ	num_warpsc                 ó2   — g | ]}t           j        |         ‘ŒS r4   )ÚkernelÚ	arg_names)r0   r1   s     r   r@   r@   b   s    € Ð?Ð?Ð?¨•Ô! !Ô$Ð?Ð?Ð?r   Ú_Úcubiné   éÿÿÿÿz, c                 ó"   — g | ]\  }}d |› |› �‘ŒS )Ú0xr4   )r0   ÚxÚys      r   r@   r@   m   s&   € ÐRÐRÐR©t¨q°!˜{ A˜{ q˜{˜{ÐRÐRÐRr   c                 ó<   — g | ]\  }}t          |¦  «        › d |› �‘ŒS )r   r   )r0   ÚnameÚtys      r   r@   r@   n   s0   € ÐmÐmÐm¹h¸dÀB¥9¨R¡=¤=Ð 9Ð 9°4Ð 9Ð 9ÐmÐmÐmr   c                 ó   — g | ]}d |› �‘ŒS )ú&r4   )r0   Úargs     r   r@   r@   o   s   € Ð"BÐ"BÐ"B° 9 s 9 9Ð"BÐ"BÐ"Br   )Úkernel_nameÚtriton_kernel_nameÚbin_sizeÚbin_datar   Úarg_pointersÚnum_argsÚkernel_docstringÚsharedrF   Ú_placeholder)r?   Úczcompile.ú.Úwr4   )TÚbinasciir   Úimportlib.utilÚ	importlibÚsysÚargparser   Úpathlibr   Útypingr   ÚtritonÚtriton.compiler.code_generatorr   Útriton.compiler.make_launcherr   ÚdescÚ__name__ÚparserÚadd_argumentÚstrr'   Ú
parse_argsÚargsÚout_namerX   Úout_pathr   Úarg_pathÚinsertÚparentÚutilÚspec_from_file_locationÚstemÚspecÚmodule_from_specÚmodÚloaderÚexec_moduleÚgetattrrH   ÚlistÚmapr   r.   r$   Úsig_hashr+   Ú	enumerateÚhintsÚitemsr;   Úvaluesr?   rB   rC   ÚcompilerÚinstance_descriptorÚconfigÚcompilerF   ÚccinfoÚkeysrI   Úsuffixr    Ú	func_namerY   ÚhexlifyÚasmÚhex_ÚlenÚzipr_   ÚparamsÚextÚ__file__Útemplate_pathÚwith_suffixÚopenÚfpÚwriteÚ	read_textÚformatr4   r   r   ú<module>r¡      sp  ðØ €€€Ø €€€Ø Ð Ð Ð Ø 
€
€
€
Ø #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à €€€Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3ð€ð4 ˆzÒÑð ˆ^¨Ð-Ñ-Ô-€FØ
×Ò˜Ð%{ÐÑ|Ô|Ð|Ø
×Ò˜¨°CÀÐJiÐtxÐÑyÔyÐyØ
×Ò˜ t°#¸qÐGmÐÑnÔnÐnØ
×Ò˜ e°#¸tÐJlÐÑmÔmÐmØ
×Ò˜ d°¸tÈ.ÐÑYÔYÐYØ
×Ò˜ t°#Ð<UÐ`dÐÑeÔeÐeØ×ÒÑÔ€Dà $¤ÐCˆtŒ}ˆ}°4Ô3C€HØ $¤Ð;ˆtŒ}ˆ}°8€Hð ˆt�D”I‰Œ€HØ„H‡O‚O�A�s�s˜8œ?Ñ+Ô+Ñ,Ô,Ð,ØŒ>×1Ò1°(´-ÀÑJÔJ€DØ
Œ.×
)Ò
)¨$Ñ
/Ô
/€CØ„K×Ò˜CÑ Ô Ð ØˆW�S˜$Ô*Ñ+Ô+€Fð ��S�SÐ/Ð/°´×1EÒ1EÀcÑ1JÔ1JÑKÔKÑLÔL€Ið! $ s¤)ð !ð !ð !ð !ð
 ˆ~˜iÑ(Ô(€Hðð ð ð YÐX°y°yÀÑ7KÔ7KÐXÑXÔX€EØ=Ð=˜eŸkšk™mœmÐ=Ñ=Ô=€EØCÐC¨i¨i¸	Ñ.BÔ.BÐCÑCÔC€JØGÐG :×#3Ò#3Ñ#5Ô#5ÐGÑGÔG€JØ\Ð\°	°	¸)Ñ0DÔ0DÐ\Ñ\Ô\€Ið �\Š\‰^Œ^ð Gð GˆØ�Gˆ|ˆ|ˆ|ÐFÀ1ÐFÐF‰|Œ|ˆ|ˆ|Ø>Ð> U§[¢[¡]¤]Ð>Ñ>Ô>€OØ8Ð8 §¢¡¤Ð8Ñ8Ô8€JØŒ_×0Ò0ÀÐ]gÐ0ÑhÔh€FØˆVŒ^˜F¨iÀ:ÐX^ÐW_ÐkoÔkyÐzÑzÔz€FØ?Ð?¨i¯nªnÑ.>Ô.>Ð?Ñ?Ô?€Ið ˆ]˜9×+Ò+Ñ-Ô-¨vÑ6Ô6€FØ—’˜( H¨fÐ5Ñ6Ô6€IØŸš 4Ô#3°VÐ"<Ñ=Ô=ÐØˆ3ÐˆxÔ ¤
¨7Ô 3Ñ4Ô4Ñ5Ô5°a¸°dÔ;€Dà Ø0Ø�C˜‘I”IØ—I’IÐRÐR°s°s¸4ÀÀÀ!À¼9ÀdÈ1È4ÈaÈ4ÄjÑ7QÔ7QÐRÑRÔRÑSÔSØ—Y’YÐmÐmÈ#È#ÈiÐYb×YiÒYiÑYkÔYkÑJlÔJlÐmÑmÔmÑnÔnØŸ	š	Ð"BÐ"B¸	Ð"BÑ"BÔ"BÑCÔCØ�C˜	‘N”NØØ”-Ø”^Øðð €Fð ð Gð GˆØ˜˜X™œÔ-Ð0@¸3Ð0@Ð0@Ñ@ˆØ×!Ò!Ð"? hÐ"?Ð"?°Ð"?Ð"?¸#Ð"?Ð"?Ñ@Ô@×EÒEÀcÑJÔJð 	GÈbØ�HŠHÐ;�T�T˜-Ñ(Ô(×2Ò2Ñ4Ô4Ô;ÐEÐE¸fÐEÐEÑFÔFÐFð	Gð 	Gð 	Gñ 	Gô 	Gð 	Gð 	Gð 	Gð 	Gð 	Gð 	Gøøøð 	Gð 	Gð 	Gð 	Gøðc Ðð^Gð Gs   Ò7<S?Ó?T	ÔT	