ó
    …~iüO  ã                   ó  • S SK r S SKr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	J
r
Jr  SSKJr  SSKJr  S rS rS	 rSS
 jrSS jrSS jr " S S5      r " S S5      rS rSS jrSS jrS r\SS j5       rSS jrg)é    N)Úcontextmanager)ÚAnyÚDictÚListé   )Úlanguage)Úruntimec                 ó  • SR                  U 5      n SSSSU -   S/n[        R                  " U5      nUR                  [        R
                  R                  5      R                  S5      nU Vs/ s H  n[        U5      PM     nnU$ s  snf )NÚ,ú
nvidia-smiú-iÚ0z--query-gpu=z--format=csv,noheader,nounits)	ÚjoinÚ
subprocessÚcheck_outputÚdecodeÚsysÚstdoutÚencodingÚsplitÚint)ÚattrsÚcmdÚoutÚretÚxs        ÚK/home/mande/repo/quber/.venv/lib/python3.13/site-packages/triton/testing.pyÚnvsmir      sz   € Ø�H‰H�U‹O€EØ˜˜s N°UÑ$:Ð<[Ð
\€CÜ
×
!Ò
! #Ó
&€CØ
�*‰*”S—Z‘Z×(Ñ(Ó
)×
/Ñ
/°Ó
4€CÙÓ
š3�aŒ3ˆqŽ6™3€CÐ
Ø€Jùò  s   Á.Bc                 óz   ^ ^• [        T 5      m[        T 5      m U U4S jnU Vs/ s H
  o" U5      PM     sn$ s  snf )Nc                 óÐ   >• SU s=::  a  S::  d  O  [        S5      eU TS-
  -  n[        R                  " U5      n[        R                  " U5      nX-
  nSU-
  TU   -  UTU   -  -   $ )Nr   r   z%Quantiles must be in the range [0, 1])Ú
ValueErrorÚmathÚfloorÚceil)ÚqÚpointÚlowerÚupperÚtÚaÚns        €€r   Úget_quantileÚ_quantile.<locals>.get_quantile   sj   ø€ Ø�Q•˜!•ÜÐDÓEÐEØ�Q˜‘U‘ˆÜ—
’
˜5Ó!ˆÜ—	’	˜%Ó ˆØ‰MˆØ�A‘˜˜5™Ñ! A¨¨%©¡LÑ0Ð0ó    )ÚlenÚsorted)r*   r%   r,   r+   s   `  @r   Ú	_quantiler1      s8   ù€ ÜˆA‹€AÜˆq‹	€Aö1ñ &'Ó'¢Q ˆL˜ŽO¡QÑ'Ð'ùÒ's   ¤8c                 ó  • Ub!  [        X5      n[        U5      S:X  a  US   nU$ US:X  a  U $ US:X  a  [        U 5      $ US:X  a  [        U 5      $ US:X  a  [        R
                  " U 5      $ US:X  a  [        R                  " U 5      $ g )Nr   r   ÚallÚminÚmaxÚmeanÚmedian)r1   r/   r4   r5   Ú
statisticsr6   r7   )ÚtimesÚ	quantilesÚreturn_moder   s       r   Ú_summarize_statisticsr<   *   s‘   € ØÑÜ˜Ó)ˆÜˆs‹8�q‹=Ø�a‘&ˆCØˆ
Ø�eÓØˆØ	˜Ó	Ü�5‹zÐØ	˜Ó	Ü�5‹zÐØ	˜Ó	Ü�Š˜uÓ%Ð%Ø	˜Ó	 Ü× Ò  Ó'Ð'ð 
!r.   c                 ó2  • SSK nUS;   d   eUR                  R                  UR                  R                  5       5         U " 5         Ub1  U H+  nUR	                  5         UR                  S5        SUl        M-     UR                  R                  SS9nUR                  R                  SS9nUR                  5         [        S5       H
  n	U " 5         M     UR                  5         UR                  R                  5         UR                  U5      S-  n
U
S:X  a  SnO[        S[        X-  5      5      nUR                  R                  5       nUR                  R                  U5         [        U5       H  n	Ub  U H
  nSUl        M     U " 5         M     SSS5        UR                  R                  5         / nS	n[        U5       H–  n	UR                  R                  SS9nUR                  R                  SS9nUR                  5         UR!                  5         UR                  5         UR                  R                  5         X×R                  U5      U-  /-  nM˜     [#        XÓU5      sSSS5        $ ! , (       d  f       Næ= f! , (       d  f       g= f)
a¢  
Benchmark the runtime of the provided function.

:param fn: Function to benchmark
:type fn: Callable
:param rep: Repetition time (in ms)
:type rep: int
:param grad_to_none: Reset the gradient of the provided tensor to None
:type grad_to_none: torch.tensor, optional
:param return_mode: The statistical measure to return. Options are "min", "max", "mean", "median", or "all". Default is "mean".
:type return_mode: str
r   N©r4   r5   r6   r7   r3   T©Úenable_timingé   iè  r   é
   )ÚtorchÚcudaÚstreamÚStreamÚdetach_Úrequires_grad_ÚgradÚEventÚrecordÚrangeÚsynchronizeÚelapsed_timer5   r   Ú	CUDAGraphÚgraphÚreplayr<   )ÚfnÚrepÚgrad_to_noner:   r;   rC   r   Ústart_eventÚ	end_eventÚ_Úestimate_msÚn_repeatÚgr   Ú	n_retriess                  r   Údo_bench_cudagraphr\   <   s*  € ó ØÐAÓAÐAÐAà	�‰×	Ñ	˜5Ÿ:™:×,Ñ,Ó.Õ	/á
ŒØÑ#Û!�Ø—	‘	”Ø× Ñ  Ô&Ø�–ñ "ð —j‘j×&Ñ&°TÐ&Ð:ˆØ—J‘J×$Ñ$°4Ð$Ð8ˆ	Ø×ÑÔÜ�q–ˆAÙŽDñ à×ÑÔØ�
‰
×ÑÔ Ø!×.Ñ.¨yÓ9¸AÑ=ˆà˜!ÓØ‰Hä˜1œc #Ñ"3Ó4Ó5ˆHð �J‰J× Ñ Ó"ˆØ�Z‰Z×Ñ˜aÕ Ü˜8–_�ØÑ+Û)˜Ø!%˜žñ *á–ñ	 %÷ !ð 	�
‰
×ÑÔ àˆØˆ	Ü�yÖ!ˆAØŸ*™*×*Ñ*¸Ð*Ð>ˆKØŸ
™
×(Ñ(°tÐ(Ð<ˆIØ×ÑÔ Ø�H‰HŒJØ×ÑÔØ�J‰J×"Ñ"Ô$Ø×,Ñ,¨YÓ7¸(ÑBÐCÑCŠCñ "ô % S°[ÓA÷a 
0Ñ	/÷< !Õ ú÷= 
0Õ	/ús&   Á D*JÅ*-I7ÆCJÉ7
J	ÊJÊ
Jc                 óú  • US;   d   e[         R                  R                  R                  5       nU " 5         UR	                  5         [         R                  R                  R                  5       nUR                  SS9nUR                  SS9n	UR                  5         [        S5       H3  n
[         R                  R                  R                  U5        U " 5         M5     U	R                  5         UR	                  5         UR                  U	5      S-  n[        S[        X-  5      5      n[        S[        X+-  5      5      n[        U5       Vs/ s H  oæR                  SS9PM     nn[        U5       Vs/ s H  oæR                  SS9PM     n	n[        U5       H
  n
U " 5         M     [        U5       Hj  nUb  U H
  nSUl        M     [         R                  R                  R                  U5        XŽ   R                  5         U " 5         Xž   R                  5         Ml     UR	                  5         [        X‰5       VVs/ s H  u  nnUR                  U5      PM     nnn[        UXE5      $ s  snf s  snf s  snnf )a·  
Benchmark the runtime of the provided function. By default, return the median runtime of :code:`fn` along with
the 20-th and 80-th performance percentile.

:param fn: Function to benchmark
:type fn: Callable
:param warmup: Warmup time (in ms)
:type warmup: int
:param rep: Repetition time (in ms)
:type rep: int
:param grad_to_none: Reset the gradient of the provided tensor to None
:type grad_to_none: torch.tensor, optional
:param quantiles: Performance percentile to return in addition to the median.
:type quantiles: list[float], optional
:param return_mode: The statistical measure to return. Options are "min", "max", "mean", "median", or "all". Default is "mean".
:type return_mode: str
r>   Tr?   rA   r   N)r	   ÚdriverÚactiveÚget_device_interfacerM   Úget_empty_cache_for_benchmarkrJ   rK   rL   Úclear_cacherN   r5   r   rI   Úzipr<   )rR   ÚwarmuprS   rT   r:   r;   ÚdiÚcacherU   rV   rW   rX   Ún_warmuprY   Úir   ÚsÚer9   s                      r   Údo_benchrk      s  € ð$ ÐAÓAÐAÐAä	�‰×	Ñ	×	3Ñ	3Ó	5€Bá„DØ‡N�NÔä�N‰N×!Ñ!×?Ñ?ÓA€Eð —(‘(¨�(Ð.€KØ—‘ t�Ð,€IØ×ÑÔÜ�1ŽXˆÜ�‰×Ñ×)Ñ)¨%Ô0Ù
Žñ ð ×ÑÔØ‡N�NÔØ×*Ñ*¨9Ó5¸Ñ9€Kô �1”c˜&Ñ.Ó/Ó0€HÜ�1”c˜#Ñ+Ó,Ó-€HÜ9>¸x¼ÓIº°A—8‘8¨$�8Ó/¹€KÐIÜ7<¸X´ÓG²°!—‘¨�Ó-±€IÐGä�8Ž_ˆÙ
Žñ ô �8Ž_ˆð Ñ#Û!�Ø�–ñ "ô 	�‰×Ñ×)Ñ)¨%Ô0à‰×ÑÔÙ
ŒØ‰×ÑÖñ ð ‡N�NÔÜ+.¨{Ô+FÔGÒ+F¡4 1 aˆQ�^‰^˜AÖÑ+F€EÑGÜ  ¨	Ó?Ð?ùò- JùÚGùó( Hs   ÅI-Å6I2É I7c                 óú  • SSK nSSKn[        XR                  5      (       d  UR	                  U 5      n [        XR                  5      (       d  UR	                  U5      nUc  Sn[        U5      (       a  U" U R                  5      OUnUc  Sn[        U5      (       a  U" U R                  5      OUn[        XR                  5      (       aV  U R                  UR                  :X  a  U R                  5       n U R                  5       R                  5       R                  5       n [        XR                  5      (       aV  UR                  UR                  :X  a  UR                  5       nUR                  5       R                  5       R                  5       nU R                  S:”  d  UR                  S:”  a  UR                  R                  XX#SS9  gUR                  XX#S9(       d  [        U S	U  S
U SU SU S3
5      eg)aâ  
Asserts that two inputs are close within a certain tolerance.

:param x: The first input.
:type x: scala, list, numpy.ndarray, or torch.Tensor
:param y: The second input.
:type y: scala, list, numpy.ndarray, or torch.Tensor
:param atol: The absolute tolerance. Default value is 1e-2.
:type atol: float, optional
:param rtol: The relative tolerance. Default value is 0.
:type rtol: float, optional
:param err_msg: The error message to use if the assertion fails.
:type err_msg: str
r   Ng{®Gáz„?g        r   T)ÚatolÚrtolÚ	equal_nan)rm   rn   Ú z is not close to z (atol=z, rtol=Ú))ÚnumpyrC   Ú
isinstanceÚTensorÚtensorÚcallableÚdtypeÚbfloat16ÚfloatÚcpuÚdetachÚsizeÚtestingÚassert_allcloseÚallcloseÚAssertionError)r   Úyrm   rn   Úerr_msgÚnprC   s          r   Úassert_closer„   Á   sˆ  € ó Ûô �aŸ™×&Ñ&Ø�L‰L˜‹OˆÜ�aŸ™×&Ñ&Ø�L‰L˜‹Oˆà�|ØˆÜ$ TŸN™N‰4�—‘Œ=°€Dà�|ØˆÜ$ TŸN™N‰4�—‘Œ=°€Dô �!—\‘\×"Ñ"Ø�7‰7�e—n‘nÓ$Ø—‘“	ˆAØ�E‰E‹G�N‰NÓ×"Ñ"Ó$ˆÜ�!—\‘\×"Ñ"Ø�7‰7�e—n‘nÓ$Ø—‘“	ˆAØ�E‰E‹G�N‰NÓ×"Ñ"Ó$ˆð 	‡v�v�ƒz�Q—V‘V˜a“ZØ
�
‰
×"Ñ" 1¨dÈÐ"ÑNØØ�;‰;�q $ˆ;Ö2Ü ˜y¨¨!¨Ð,=¸a¸SÀÈÀvÈWÐUYÐTZÐZ[Ð\Ó]Ð]ð 3r.   c                   ó~   • \ rS rSrSr     SS\\   S\\   S\S\\   S\\   S	\S
\\\4   S\S\S\	S\	4S jjr
Srg)Ú	Benchmarkéô   zc
This class is used by the :code:`perf_report` function to generate line plots with a concise API.
NÚx_namesÚx_valsÚline_argÚ	line_valsÚ
line_namesÚ	plot_nameÚargsÚxlabelÚylabelÚx_logÚy_logc                 ó”   • Xl         X l        X l        X0l        X@l        XPl        X°l        XÀl        X€l        X�l	        X`l
        Xpl        g)a�  
Constructor.
x_vals can be a list of scalars or a list of tuples/lists. If x_vals is a list
of scalars and there are multiple x_names, all arguments will have the same value.
If x_vals is a list of tuples/lists, each element should have the same length as
x_names.

:param x_names: Name of the arguments that should appear on the x axis of the plot.
:type x_names: List[str]
:param x_vals: List of values to use for the arguments in :code:`x_names`.
:type x_vals: List[Any]
:param line_arg: Argument name for which different values correspond to different lines in the plot.
:type line_arg: str
:param line_vals: List of values to use for the arguments in :code:`line_arg`.
:type line_vals: List[Any]
:param line_names: Label names for the different lines.
:type line_names: List[str]
:param plot_name: Name of the plot.
:type plot_name: str
:param args: Dictionary of keyword arguments to remain fixed throughout the benchmark.
:type args: Dict[str, Any]
:param xlabel: Label for the x axis of the plot.
:type xlabel: str, optional
:param ylabel: Label for the y axis of the plot.
:type ylabel: str, optional
:param x_log: Whether the x axis should be log scale.
:type x_log: bool, optional
:param y_log: Whether the y axis should be log scale.
:type y_log: bool, optional
:param styles: A list of tuples, where each tuple contains two elements: a color and a linestyle.
:type styles: list[tuple[str, str]]
N)rˆ   r‰   r‘   rŠ   r‹   rŒ   r’   Ústylesr�   r�   r�   rŽ   )Úselfrˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r”   s                r   Ú__init__ÚBenchmark.__init__ù   sA   € ð^ ŒØŒØŒ
Ø ŒØ"ŒØ$ŒØŒ
ØŒàŒØŒØ"ŒØ�	r.   )rŽ   rŠ   rŒ   r‹   r�   r”   r‘   rˆ   r‰   r�   r’   r�   )Ú r˜   FFN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ústrr   r   Úboolr–   Ú__static_attributes__© r.   r   r†   r†   ô   s¦   † ñð ØØØØñ;à�c‘ð;ð �S‘	ð;ð ð	;ð
 ˜‘9ð;ð ˜‘Ið;ð ð;ð �3˜�8‰nð;ð ð;ð ð;ð ð;ð ÷;ð ;r.   r†   c            	       óF   • \ rS rSrS r  SS\S\S\S\4S jjrSS jr	S	r
g
)ÚMarki7  c                 ó   • Xl         X l        g ©N©rR   Ú
benchmarks)r•   rR   r§   s      r   r–   ÚMark.__init__9  s   € ØŒØ$�r.   ÚbenchÚ	save_pathÚ
show_plotsÚ
print_datac           	      ó 
  • SS K nSS KJn	  SS Kn
UR                   Vs/ s H  o» SUR
                   S3PM     nnUR                   Vs/ s H  o» SUR
                   S3PM     nnUR                   Vs/ s H  o» SUR
                   S3PM     nn[        UR                  5      nU
R                  Xü-   U-   U-   S9nUR                   GH  n[        U[        [        45      (       d  U Vs/ s H  nUPM     nn[        U5      [        U5      :w  a  [        S[        U5       SU 35      e[        [        Xû5      5      n/ / / nnnUR                    HJ  nU R"                  " S0 UDUR$                  U0DUR&                  DUD6n Uu  nnnUU/-  nUU/-  nUU/-  nML     [        U5      U-   U-   U-   UR*                  [        U5      '   GM     UR,                  (       Ga-  U	R/                  5         U	R1                  5       nUS   n[3        [        XÍU5      5       GH  u  nu  nnn UU   UU    nnUR4                  (       a  UR4                  U   S   OS n!UR4                  (       a  UR4                  U   S	   OS n"UR7                  UU   UU   UU!U"S
9  UR9                  5       R;                  5       (       a  M�  UR9                  5       R;                  5       (       a  MÂ  UR=                  [>        5      nUR=                  [>        5      nURA                  UU   UUSU!S9  GM     URC                  5         URE                  URF                  =(       d    U5        URI                  UR
                  5        URK                  URL                  (       a  SOS5        URO                  URP                  (       a  SOS5        U(       a  U	RS                  5         U(       a7  U	RU                  URV                  RY                  X!R,                   S35      5        UXü-      nU(       a>  URZ                  S	   S:X  a+  UR\                  R_                  5       u  n#n$UU$   UU#   -
  US'   U(       a1  [a        UR,                  S-   5        [a        URc                  5       5        U(       a;  URe                  URV                  RY                  X!R,                   S35      SU S3SS9  U$ s  snf s  snf s  snf s  snf ! [(         a
    US S nnn GNsf = f)Nr   z (rq   z-min (z-max ()Úcolumnsz	Expected z values, got r   )ÚlabelÚcolorÚlsg333333Ã?)Úalphar°   ÚlogÚlinearz.pngé   ÚDiffÚ:z.csvz%.ÚfF)Úfloat_formatÚindexr¡   )3ÚosÚmatplotlib.pyplotÚpyplotÚpandasrŒ   r�   Úlistrˆ   Ú	DataFramer‰   rs   Útupler/   r!   Údictrc   r‹   rR   rŠ   rŽ   Ú	TypeErrorÚlocr�   ÚfigureÚsubplotÚ	enumerater”   ÚplotÚisnullr3   Úastypery   Úfill_betweenÚlegendÚ
set_xlabelr�   Ú
set_ylabelÚ
set_xscaler‘   Ú
set_yscaler’   ÚshowÚsavefigÚpathr   Úshaper®   ÚtolistÚprintÚ	to_stringÚto_csv)%r•   r©   rª   r«   r¬   Údiff_colÚsave_precisionÚkwragsr»   ÚpltÚpdr   Úy_mean_labelsÚy_min_labelsÚy_max_labelsrˆ   ÚdfrW   Úx_argsÚrow_meanÚrow_minÚrow_maxr�   r   Úy_meanÚy_minÚy_maxÚaxÚfirst_xrh   Ú
mean_labelÚ	min_labelÚ	max_labelÚcolÚstyÚcol0Úcol1s%                                        r   Ú_runÚ	Mark._run=  sJ  € ãå'ÛØ:?×:JÒ:JÓKÒ:J°Q˜3˜b §¡ ¨aÓ0Ñ:JˆÐKØ=B×=MÒ=MÓNÒ=M¸˜#˜V E§L¡L >°Ó3Ñ=MˆÐNØ=B×=MÒ=MÓNÒ=M¸˜#˜V E§L¡L >°Ó3Ñ=MˆÐNÜ�u—}‘}Ó%ˆØ�\‰\ 'Ñ"9¸LÑ"HÈ<Ñ"Wˆ\ÐXˆØ—•ˆAä˜a¤$¬ ×/Ñ/Ù 'Ó(¢˜1“Q¡�Ð(ä�1‹vœ˜W›Ó%Ü  9¬S°«\¨N¸-ÈÀsÐ!KÓLÐLÜœ#˜g›/Ó*ˆFà)+¨R°˜w�gˆHØ—_”_�Ø—g’gÑV ÐV¨5¯>©>¸1Ð*=ÐVÀÇÁÐVÈvÑV�ð;Ø+.Ñ(�F˜E 5ð ˜V˜HÑ$�Ø˜E˜7Ñ"�Ø˜E˜7Ñ"’ñ %ô # 1›g¨Ñ0°7Ñ:¸WÑDˆB�F‰F”3�r“7ŒOñ' ð* �?�?ˆ?Ø�J‰JŒLØ—‘“ˆBà˜a‘jˆGÜ9BÄ3À}ÐdpÓCq×9rÑ5�Ñ5�J 	¨9Ø! )™}¨b°©m�u�Ø,1¯L¯L�e—l‘l 1‘o aÒ(¸d�Ø,1¯L¯L�e—l‘l 1‘o aÒ(¸d�Ø—‘˜˜7™ R¨
¡^¸:ÈSÐUX�ÑYØ—|‘|“~×)Ñ)×+Ó+°E·L±L³N×4FÑ4F×4HÓ4HØ!ŸL™L¬Ó/�EØ!ŸL™L¬Ó/�EØ—O‘O B w¡K°¸ÀTÐQT�OÔUñ :sð �I‰IŒKØ�M‰M˜%Ÿ,™,×1¨'Ô2Ø�M‰M˜%Ÿ,™,Ô'à�M‰M 5§;§;™%°HÔ=Ø�M‰M 5§;§;™%°HÔ=ÞØ—‘”
ÞØ—‘˜BŸG™GŸL™L¨·±Ð6GÀtÐ4LÓMÔNØ�Ñ'Ñ(ˆÞ˜Ÿ™ ™ qÓ(ØŸ™×*Ñ*Ó,‰JˆD�$Ø˜D™ B t¡HÑ,ˆBˆv‰JæÜ�%—/‘/ CÑ'Ô(Ü�"—,‘,“.Ô!ÞØ�I‰I�b—g‘g—l‘l 9·±Ð0AÀÐ.FÓGÐXZÐ[iÐZjÐjkÐVlØ!ð ñ #àˆ	ùò{ LùÚNùÚNùò )øô !ó ;Ø+.°°d 5˜E�F¢5ð;ús)   �SÁSÁ3SÃ+S$ÆS)Ó)S=Ó<S=c           	      óè  • [        U R                  [        5      nU(       a  U R                  /OU R                  n/ n U H&  n	UR                  U R                  " X“X40 UD65        M(     U(       aŸ  [
        R                  " USS9  [        [
        R                  R                  US5      S5       n
U
R                  S5        US [        U5        H"  n	U
R                  SU	R                   S35        M$     U
R                  S5        S S S 5        O U(       a  U(       a  US	   $ U$ g ! , (       d  f       N$= f! U(       a°  [
        R                  " USS9  [        [
        R                  R                  US5      S5       n
U
R                  S5        US [        U5        H"  n	U
R                  SU	R                   S35        M$     U
R                  S5        S S S 5        f ! , (       d  f       f = ff = f)
NT)Úexist_okzresults.htmlÚwz<html><body>
z<image src="z.png"/>
z</body></html>
r   )rs   r§   r†   Úappendrò   r»   ÚmakedirsÚopenrÓ   r   Úwriter/   r�   )r•   r«   r¬   rª   Ú	return_dfÚkwargsÚhas_single_benchr§   Ú
result_dfsr©   Úhtmls              r   ÚrunÚMark.run‚  s�  € Ü% d§o¡o´yÓAÐÞ*:�d—o‘oÑ&ÀÇÁˆ
Øˆ
ð	3Û#�Ø×!Ñ! $§)¢)¨E¸jÑ"_ÐX^Ñ"_Ö`ñ $ö ä—’˜I°Ò5Üœ"Ÿ'™'Ÿ,™, y°.ÓAÀ3ÔGÈ4Ø—J‘JÐ/Ô0Ø!+Ð,<¬S°«_Ó!=˜ØŸ
™
 ]°5·?±?Ð2CÀ:Ð#NÖOñ ">à—J‘JÐ1Ô2÷	 HÐGð ö ÞØ! !‘}Ð$à!Ð!Ø÷ HÕGûö ä—’˜I°Ò5Üœ"Ÿ'™'Ÿ,™, y°.ÓAÀ3ÔGÈ4Ø—J‘JÐ/Ô0Ø!+Ð,<¬S°«_Ó!=˜ØŸ
™
 ]°5·?±?Ð2CÀ:Ð#NÖOñ ">à—J‘JÐ1Ô2÷	 H×GÖGúð ús2   ¾,D8 Â0AD'Ä'
D5Ä8AG1Å?AGÇ	G1Ç
G-Ç)G1)r§   rR   N)Fé   )FFr˜   F)r™   rš   r›   rœ   r–   r†   rž   rŸ   rò   r   r    r¡   r.   r   r£   r£   7  s>   † ò%ð chØñC˜)ð C°ð CÀð CÐSWõ C÷Jr.   r£   c                 ó   ^ • U 4S jnU$ )zÚ
Mark a function for benchmarking. The benchmark can then be executed by using the :code:`.run` method on the return value.

:param benchmarks: Benchmarking configurations.
:type benchmarks: List of :class:`Benchmark`
c                 ó   >• [        U T5      $ r¥   )r£   r¦   s    €r   Ú<lambda>Úperf_report.<locals>.<lambda>¡  s   ø€ œ˜b *Ô-r.   r¡   )r§   Úwrappers   ` r   Úperf_reportr  š  s   ø€ ô .€GØ€Nr.   c                 ó"  • SSK Jn  U c(  UR                  R                  5       R	                  5       n UR                  R
                  R                  U 5      S   nUR                  R
                  R                  U 5      S   nX#-  S-  S-  S-  nU$ )zreturn DRAM bandwidth in GB/s r   ©r^   Úmem_clock_rateÚmem_bus_widthrµ   g    €„.Aé   )r	   r^   r_   r`   Úcurrent_deviceÚutilsÚget_device_properties)Údevicer^   Úmem_clock_khzÚ	bus_widthÚbw_gbpss        r   Úget_dram_gbpsr  ¥  s‚   € õ  Ø�~Ø—‘×3Ñ3Ó5×DÑDÓFˆØ—M‘M×'Ñ'×=Ñ=¸fÓEÐFVÑW€MØ—‘×#Ñ#×9Ñ9¸&ÓAÀ/ÑR€IØÑ'¨!Ñ+¨cÑ1°AÑ5€GØ€Nr.   c                 óZ  • SS K nSSKJn  U(       d  UR                  R	                  5       nUR
                  R                  R                  U5      S   S-  nUR                  R                  U5      nUS   S:  a  XR                  :X  d   eSnO’XR                  UR                  4;   a  SnOtXR                  UR                  UR                  4;   a  SnOKXR                  [        R                   [        R"                  [        R$                  4;   a  S	nO['        S
5      eXQ-  U-  S-  nU$ )Nr   r   r
  Úmultiprocessor_counté   r  é   i   i   údtype not supportedç•Ö&è.>)rC   r	   r^   rD   r  r_   r  r  Úget_device_capabilityÚfloat16Úfloat32Úint32rx   Úint16Úint8ÚtlÚ
float8e4nvÚfloat8e4b15Úfloat8e5ÚRuntimeError©	rw   Ú
clock_rater  rC   r^   Únum_subcoresÚ
capabilityÚops_per_sub_coreÚtflopss	            r   Úget_max_tensorcore_tflopsr-  ±  sú   € ÛåÞØ—‘×*Ñ*Ó,ˆà—=‘=×&Ñ&×<Ñ<¸VÓDÐE[Ñ\Ð_`Ñ`€LØ—‘×1Ñ1°&Ó9€JØ�!�}�qÓØŸ™Ó%Ð%Ð%ØÑà—]‘] E§K¡KÐ0Ó0Ø"ÑØ—}‘} e§n¡n°e·k±kÐBÓBØ"ÑØ—z‘z¤2§=¡=´"·.±.Ä"Ç+Á+ÐNÓNØ#ÑäÐ4Ó5Ð5ØÑ&Ð)9Ñ9¸DÑ@€FØ€Mr.   c                  ó   ^ • U 4S jnU$ )Nc                 óJ   >^ • [         R                  " T 5      UU 4S j5       nU$ )Nc                  ó†  >• SS K nUR                  [        R                  " 5       5      R	                  5       nT
R                  5       UR                  5       :*  nU(       aÚ  US:w  aÔ  [        R                  R                  TR                  S   5      n[        R                  S   SS.nSU;   d   S5       eUS   R                  R                  R                  nU S	TR                   S
U S3n[        R                  " SSSU/SUS9n	U	R                   S:X  d   S5       eS[#        U	R$                  5      ;   d   eg T" U 0 UD6  g )Nr   zcuda-memcheckÚ__file__ÚPATHÚ1)r2  ÚPYTORCH_NO_CUDA_MEMORY_CACHINGÚrequestz@memcheck'ed test must have a (possibly unused) `request` fixturez::Ú[Ú]Úpytestz-vsT)Úcapture_outputÚenvz7cuda-memcheck returned an error: bounds checking failedzERROR SUMMARY: 0 errors)ÚpsutilÚProcessr»   ÚgetppidÚnameÚitemsrÓ   ÚrealpathÚ__globals__ÚenvironÚnodeÚcallspecÚidr™   r   r   Ú
returncoderž   r   )rŽ   rü   r;  Ú	ppid_nameÚrun_cuda_memcheckrÓ   r:  Útest_idr   r   Útarget_kwargsÚtest_fns             €€r   r  Ú1cuda_memcheck.<locals>.decorator.<locals>.wrapperÒ  s!  ø€ ãØŸ™¤r§z¢z£|Ó4×9Ñ9Ó;ˆIØ -× 3Ñ 3Ó 5¸¿¹»Ñ GÐÞ  Y°/Ó%AÜ—w‘w×'Ñ'¨×(;Ñ(;¸JÑ(GÓH�ä!Ÿz™z¨&Ñ1ÐUXÑY�Ø  FÓ*ÐnÐ,nÓnÐ*Ø  Ñ+×0Ñ0×9Ñ9×<Ñ<�Ø˜˜b ×!1Ñ!1Ð 2°!°G°9¸AÐ>�Ü —n’n o°xÀÈÐ%LÐ]aÐgjÑk�Ø—~‘~¨Ó*ÐeÐ,eÓeÐ*Ø0´C¸¿
¹
³OÓCÐCÑCá˜Ð( Ó(r.   )Ú	functoolsÚwraps)rK  r  rJ  s   ` €r   Ú	decoratorÚ cuda_memcheck.<locals>.decoratorÐ  s%   ù€ ä	�Š˜Ó	!õ	)ó 
"ð	)ð" ˆr.   r¡   )rJ  rO  s   ` r   Úcuda_memcheckrQ  Î  s   ø€ õð, Ðr.   c           	   #   ó¸  #   •  [         R                  " / SQ5        [         R                  " SSSSU  SU  3/5        [         R                  " SSSSU SU 3/5        [        S/5      S	   n[        S
/5      S	   n[        X -
  5      S:  d   SU  S35       e[        X1-
  5      S:  d   SU S35       eSU -  nSU-  S-  nXE4v •  [         R                  " / SQ5        [         R                  " / SQ5        [         R                  " / SQ5        g ! [         R                  " / SQ5        [         R                  " / SQ5        [         R                  " / SQ5        f = f7f)N)r   r   r   ú-pmr3  r   r   r   z--lock-gpu-clocks=r   z--lock-memory-clocks=zclocks.current.smr   zclocks.current.memoryrB   zGPU SMs must run at z MHzgÞ 3ßÁOÌ?i   gü©ñÒMbP?)r   r   r   rS  r   )r   r   r   z-rgc)r   r   r   z-rmc)r   r   r   Úabs)Úref_sm_clockÚref_mem_clockÚcur_sm_clockÚcur_mem_clockr,  Úgbpss         r   Úset_gpu_clockrZ  é  sf  é € ðCÜ×ÒÒ EÔFÜ×ÒØØØØ   ¨a°¨~Ð>ð	!
ô 	ô 	×ÒØØØØ# M ?°!°M°?ÐCð	!
ô 	ô Ð1Ð2Ó3°AÑ6ˆÜÐ6Ð7Ó8¸Ñ;ˆÜ�<Ñ.Ó/°"Ó4Ð_Ð8LÈ\ÈNÐZ^Ð6_Ó_Ð4Ü�=Ñ0Ó1°BÓ6ÐbÐ:NÈ}ÈoÐ]aÐ8bÓbÐ6Ø)¨LÑ8ˆØ˜Ñ&¨Ñ-ˆØˆlÒä×ÒÒ EÔFÜ×ÒÒ AÔBÜ×ÒÒ AÕBøô 	×ÒÒ EÔFÜ×ÒÒ AÔBÜ×ÒÒ AÕBüs   ‚E„C D ÃA	EÄA
EÅEc                 óà  • SS K nSSKJn  U(       d  UR                  R	                  5       nUR
                  R                  R                  U5      S   S-  nUR                  R                  5       nUS   S:  a/  XR                  :X  a  SnOXXR                  :X  a  SnOF[        S	5      eXR                  :X  a  SnO)XR                  UR                  4;   a  SnO[        S	5      eXQ-  U-  S
-  nU$ )Nr   r   r
  r  r  r  é    é@   r  r  )rC   r	   r^   rD   r  r_   r  r  r  r  r  r&  rx   r'  s	            r   Úget_max_simd_tflopsr^    sÚ   € ÛåÞØ—‘×*Ñ*Ó,ˆà—=‘=×&Ñ&×<Ñ<¸VÓDÐE[Ñ\Ð_`Ñ`€LØ—‘×1Ñ1Ó3€JØ�!�}�qÓØ—M‘MÓ!Ø!ÑØ—m‘mÓ#Ø!ÑäÐ4Ó5Ð5à—M‘MÓ!Ø!ÑØ—}‘} e§n¡nÐ5Ó5Ø!ÑäÐ4Ó5Ð5ØÑ&Ð)9Ñ9¸DÑ@€FØ€Mr.   )é   NNr6   )é   éd   NNr6   )NNr˜   r¥   )iF  i¿  )rM  r"   r»   r8   r   r   Ú
contextlibr   Útypingr   r   r   r˜   r   r"  r	   r   r1   r<   r\   rk   r„   r†   r£   r  r  r-  rQ  rZ  r^  r¡   r.   r   Ú<module>rd     s”   ðÛ Û Û 	Û Û Û 
Ý %ß "Ñ "Ý Ý òò(ò (ô$@BôF?@ôD0^÷f@ñ @÷F`ñ `òFô	ôò:ð6 óCó ðCõ8r.   