+
    ғLjP                        ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	H
t
Ht ^RIHt ^RIHt R tR tR tRR	 ltRR
 ltRR lt ! R R4      t ! R R4      tR tRR ltRR ltR t]RR l4       tRR ltR# )    N)contextmanager)AnyDictList)language)runtimec                    R P                  V 4      p RRRRV ,           R.p\        P                  ! V4      pVP                  \        P
                  P                  4      P                  R 4      pV Uu. uF  p\        V4      NK  	  ppV# u upi ),
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   &    :/app/.local/lib/python3.14/site-packages/triton/testing.pynvsmir      sz    HHUOEsNU$:<[
\C

!
!#
&C
**SZZ((
)
/
/
4C
3a3q63C
J  s   2B
c                 x   a a \        S 4      o\        S 4      o V V3R  lpV Uu. uF
  q! V4      NK  	  up# u upi )c                   < ^ T u;8:  d   ^8:  g   M \        R4      hV S^,
          ,          p\        P                  ! V4      p\        P                  ! V4      pW,
          p^V,
          SV,          ,          VSV,          ,          ,           # )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   f& @r   	_quantiler0      s8    AAq	A1 &''QLOQ'''s   7c                 (   Ve'   \        W4      p\        V4      ^8X  d
   V^ ,          pV# VR8X  d   V # VR8X  d   \        V 4      # VR8X  d   \        V 4      # VR8X  d   \        P
                  ! V 4      # VR8X  d   \        P                  ! V 4      # R # )Nallminmaxmeanmedian)r0   r.   r3   r4   
statisticsr5   r6   )times	quantilesreturn_moder   s   &&& r   _summarize_statisticsr;   *   s    )s8q=a&C
e		5z		5z		u%%		   '' 
!r-   c           	        ^ RI pVR9   g   Q hVP                  P                  VP                  P                  4       4      ;_uu_ 4        V ! 4        Ve2   V F+  pVP	                  4        VP                  R4       RVn        K-  	  VP                  P                  RR7      pVP                  P                  RR7      pVP                  4        \        ^4       F
  p	V ! 4        K  	  VP                  4        VP                  P                  4        VP                  V4      ^,          p
V
^ 8X  d   RpM\        ^\        W,          4      4      pVP                  P                  4       pVP                  P                  V4      ;_uu_ 4        \        V4       F  p	Ve   V F
  pRVn        K  	  V ! 4        K   	  RRR4       VP                  P                  4        . p^
p\        V4       F  p	VP                  P                  RR7      pVP                  P                  RR7      pVP                  4        VP!                  4        VP                  4        VP                  P                  4        WP                  V4      V,          .,          pK  	  \#        WV4      uuRRR4       #   + '       g   i     L; i  + '       g   i     R# ; i)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
NTenable_timingi  r3   r4   r5   r6   r2   )torchcudastreamStreamdetach_requires_grad_gradEventrecordrangesynchronizeelapsed_timer4   r   	CUDAGraphgraphreplayr;   )fnrepgrad_to_noner9   r:   r@   r   start_event	end_event_estimate_msn_repeatgr   	n_retriess   &&&&&          r   do_bench_cudagraphrY   <   s3    AAAA			5::,,.	/	/
#!		  & " jj&&T&:JJ$$4$8	qAD 

 !..y9A=!H1c#"345H JJ  "ZZa  8_+)!% *	 % ! 	

 	y!A*****>K

((t(<I HHJJJ""$,,Y7(BCCC " %S[Aa 
0	/< ! = 
0	/	/s&   	EJ;.J(	9C$J;(J83J;;K	c                8   VR9   g   Q h\         P                  P                  P                  4       pV ! 4        VP	                  4        \         P                  P                  P                  4       pVP                  RR7      pVP                  RR7      p	VP                  4        \        ^4       F3  p
\         P                  P                  P                  V4       V ! 4        K5  	  V	P                  4        VP	                  4        VP                  V	4      ^,          p\        ^\        W,          4      4      p\        ^\        W+,          4      4      p\        V4       Uu. uF  qP                  RR7      NK  	  pp\        V4       Uu. uF  qP                  RR7      NK  	  p	p\        V4       F
  p
V ! 4        K  	  \        V4       Fs  pVe   V F
  pRVn        K  	  \         P                  P                  P                  V4       W,          P                  4        V ! 4        W,          P                  4        Ku  	  VP	                  4        \        W4       UUu. uF  w  ppVP                  V4      NK  	  ppp\        VWE4      # u upi u upi u uppi )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
Tr=   Nr?   )r   driveractiveget_device_interfacerJ   get_empty_cache_for_benchmarkrG   rH   rI   clear_cacherK   r4   r   rF   zipr;   )rO   warmuprP   rQ   r9   r:   dicacherR   rS   rT   rU   n_warmuprV   ir   ser8   s   &&&&&&             r   do_benchrh      s   $ AAAA				3	3	5BDNNNN!!??AE (((.Kt,I1X))%0
  NN**959K 1c&./0H1c#+,-H9>xIA88$8/KI7<XG!-IG8_
  8_ #! " 	))%0
  NN+.{+FG+F41aQ^^A+FEG 	??- JG( Hs   "JJ Jc                &   ^ RI p^ RIp\        WP                  4      '       g   VP	                  V 4      p \        WP                  4      '       g   VP	                  V4      pVf   Rp\        V4      '       d   V! V P                  4      MTpVf   Rp\        V4      '       d   V! V P                  4      MTp\        WP                  4      '       dX   V P                  VP                  8X  d   V P                  4       p V P                  4       P                  4       P                  4       p \        WP                  4      '       dX   VP                  VP                  8X  d   VP                  4       pVP                  4       P                  4       P                  4       pV P                  ^8  g   VP                  ^8  d"   VP                  P                  WW#RVR7       R# VP                  WW#R7      '       g   \        V RV  RV R	V R
V R2
4      hR# )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
Ng{Gz?g        T)atolrtol	equal_nanerr_msg)rj   rk    z is not close to z (atol=z, rtol=))numpyr@   
isinstanceTensortensorcallabledtypebfloat16floatcpudetachsizetestingassert_allcloseallcloseAssertionError)r   yrj   rk   rm   npr@   s   &&&&&  r   assert_closer      s     a&&LLOa&&LLO|$TNN4=D|$TNN4=D !\\""77enn$	AEEGNN""$!\\""77enn$	AEEGNN""$ 	vvzQVVaZ


""1dW^"_;;q$;22y!,=aSvWUYTZZ[\]] 3r-   c                   :   a  ] tR t^t o RtRV 3R lR lltRtV tR# )	Benchmarkzc
This class is used by the :code:`perf_report` function to generate line plots with a concise API.
Nc                   < V ^8  d   QhRS[ S[,          RS[ S[,          RS[RS[ S[,          RS[ S[,          RS[RS[S[S[3,          RS[R	S[R
S[RS[/# )   x_namesx_valsline_arg	line_vals
line_names	plot_nameargsxlabelylabelx_logy_log)r   strr   r   bool)format__classdict__s   "r   __annotate__Benchmark.__annotate__   s     ; ;c; S	; 	;
 9; I; ; 38n; ; ; ; ;r-   c                    Wn         W n        Wn        W0n        W@n        WPn        Wn        Wn        Wn        Wn	        W`n
        Wpn        R# )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   __static_attributes____classdictcell__r   s   @r   r   r      s     ; ; ;r-   r   c                   F   a  ] tR tRt o R tRV 3R lR lltR	R ltRtV tR# )
Marki7  c                    Wn         W n        R # NrO   
benchmarks)r   rO   r   s   &&&r   r   Mark.__init__9  s    $r-   c                2   < V ^8  d   QhRS[ RS[RS[RS[/# )r   bench	save_path
show_plots
print_data)r   r   r   )r   r   s   "r   r   Mark.__annotate__=  s0     C C) C C CSW Cr-   c           	        ^ RI p^ RIHp	 ^ RIp
VP                   Uu. uF  q RVP
                   R2NK  	  ppVP                   Uu. uF  q RVP
                   R2NK  	  ppVP                   Uu. uF  q RVP
                   R2NK  	  pp\        VP                  4      pV
P                  W,           V,           V,           R7      pVP                   EF  p\        V\        \        34      '       g   V Uu. uF  pVNK  	  pp\        V4      \        V4      8w  d   \        R\        V4       RV 24      h\        \        W4      4      p. . . pppVP                    FV  pV P"                  ! R/ VBVP$                  V/BVP&                  BVB p Vw  pppVV.,          pVV.,          pVV.,          pKX  	  \        V4      V,           V,           V,           VP*                  \        V4      &   EK  	  VP,                  '       Ede   V	P/                  4        V	P1                  4       pV^ ,          p\3        \        WV4      4       EF0  w  pw  ppp VV,          VV ,          ppVP4                  '       d   VP4                  V,          ^ ,          MRp!VP4                  '       d   VP4                  V,          ^,          MRp"VP7                  VV,          VV,          VV!V"R	7       VP9                  4       P;                  4       '       d   K  VP9                  4       P;                  4       '       d   K  VP=                  \>        4      pVP=                  \>        4      pVPA                  VV,          VVR
V!R7       EK3  	  VPC                  4        TPE                  VPF                  ;'       g    T4       VPI                  VP
                  4       TPK                  VPL                  '       d   RMR4       TPO                  VPP                  '       d   RMR4       V'       d   V	PS                  4        V'       d8   V	PU                  VPV                  PY                  W!P,                   R24      4       VW,           ,          pV'       dP   VPZ                  ^,          ^8X  d8   VP\                  P_                  4       w  p#p$VV$,          VV#,          ,
          VR&   V'       d6   \a        VP,                  R,           4       \a        VPc                  4       4       V'       d?   VPe                  VPV                  PY                  W!P,                   R24      RV R2RR7       V# u upi u upi u upi u upi   \(         d    TRRppp ELi ; i)r   Nz (ro   z-min (z-max ()columnsz	Expected z values, got )labelcolorlsg333333?)alphar   loglinearz.pngDiff:z.csvz%.fF)float_formatindex )3osmatplotlib.pyplotpyplotpandasr   r   listr   	DataFramer   rq   tupler.   r    dictr`   r   rO   r   r   	TypeErrorlocr   figuresubplot	enumerater   plotisnullr2   astyperw   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   dfrT   x_argsrow_meanrow_minrow_maxr   r   y_meany_miny_maxaxfirst_xre   
mean_label	min_label	max_labelcolstycol0col1s%   &&&&&&&,                             r   _run	Mark._run=  sU   ':?:J:JK:JQ3ba0:JK=B=M=MN=M#VELL>3=MN=B=M=MN=M#VELL>3=MNu}}%\\'"9L"H<"W\XAa$// '(1Q(1vW% 9S\N-s!KLL#g/*F)+RwgH__ggVV5>>1*=VVvV;+.(FE5 VH$E7"E7" % #1g07:WDBFF3r7O' * ???JJLBajG9B3}dpCq9r55J	9!)}bmu,1LLLell1oa(d,1LLLell1oa(d7R
^:SUXY||~))++ELLN4F4F4H4H!LL/E!LL/EOOBwKTQTOU :s IIKMM%,,11'2MM%,,'MM5;;;%H=MM5;;;%H=
BGGLL6Gt4LMN'(q(**,JD$DBtH,BvJ%//C'(",,.!IIbggll90A.FGXZ[iZjjkVl!  #	{ LNN ) ! ;+.d5EF5;s)   UU1U8U$U))U>=U>c           
     0   \        V P                  \        4      pV'       d   V P                  .MV P                  p. p V F&  p	VP                  V P                  ! WW3/ VB 4       K(  	  V'       d   \
        P                  ! VR R7       \        \
        P                  P                  VR4      R4      ;_uu_ 4       p
V
P                  R4       VR\        V4        F"  p	V
P                  RV	P                   R24       K$  	  V
P                  R4       RRR4       M V'       d   V'       d
   V^ ,          # V# R#   + '       g   i     L-; i  T'       d   \
        P                  ! TR R7       \        \
        P                  P                  TR4      R4      ;_uu_ 4       p
T
P                  R4       TR\        T4        F"  p	T
P                  RT	P                   R24       K$  	  T
P                  R4       RRR4       i   + '       g   i     i ; ii ; i)	T)exist_okzresults.htmlwz<html><body>
Nz<image src="z.png"/>
z</body></html>
)rq   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   %dooyA*:doo&

	3#!!$))Ej"_X^"_` $ I5"'',,y.A3GG4JJ/0!+,<S_!=

]5??2C:#NO ">JJ12	 HG  !!}$!! HG I5"'',,y.A3GG4JJ/0!+,<S_!=

]5??2C:#NO ">JJ12	 HGGG s2   ,E =AD;;E	AH!AH	8	HH	H)r   rO   N)F   )FFr   F)	r   r   r   r   r   r   r  r   r   r   s   @r   r   r   7  s!     %C CJ r-   r   c                   a  V 3R lpV# )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                    < \        V S4      # r   )r   r   s   &r   <lambda>perf_report.<locals>.<lambda>  s    b*-r-   r   )r   wrappers   f r   perf_reportr    s     .GNr-   c                T   ^RI Hp V f)   VP                  P                  4       P	                  4       p VP                  P
                  P                  V 4      R,          pVP                  P
                  P                  V 4      R,          pW#,          ^,          R,          ^,          pV# )zreturn DRAM bandwidth in GB/s r[   mem_clock_ratemem_bus_widthg    .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MM''==fEFVWM##99&A/RI'!+c1A5GNr-   c                    ^ RI p^RIHp V'       g   VP                  P	                  4       pVP
                  P                  P                  V4      R,          ^,          pVP                  P                  V4      pV^ ,          ^8  d   WP                  8X  g   Q hRpMWP                  VP                  39   d   RpMvWP                  VP                  VP                  39   d   RpMLWP                  \        P                   \        P"                  \        P$                  39   d   RpM\'        R4      hWQ,          V,          R,          pV# )	r   Nr  multiprocessor_count   i   i   dtype not supported&.>)r@   r   r[   rA   r  r\   r  r  get_device_capabilityfloat16float32int32rv   int16int8tl
float8e4nvfloat8e4b15float8e5RuntimeError	ru   
clock_rater  r@   r[   num_subcores
capabilityops_per_sub_coretflopss	   &&&      r   get_max_tensorcore_tflopsr0    s    **,==&&<<VDE[\_``L11&9J!}q%%%]]EKK00"}}ennekkBB"zz2==".."++NN#455&)99D@FMr-   c                     a  V 3R  lpV# )c                 J   <a  \         P                  ! S 4      VV 3R  l4       pV# )c                    < ^ RI pVP                  \        P                  ! 4       4      P	                  4       pS
P                  4       VP                  4       8*  pV'       d   VR8w  d   \        P                  P                  SP                  R,          4      pR\        P                  R,          RR/pRV9   g   Q R4       hVR,          P                  P                  P                  pV R	SP                   R
V R2p\        P                  ! RRRV.RVR7      p	V	P                   ^ 8X  g   Q R4       hR\#        V	P$                  4      9   g   Q hR# S! V / VB  R# )r   Nzcuda-memcheck__file__PATHPYTORCH_NO_CUDA_MEMORY_CACHING1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&   rzz|499;I - 3 3 5 G Y/%Aww''(;(;J(GHrzz&13SUXY F*n,nn* +0099<<b!1!1 2!G9A> nnox%L]agjk~~*e,ee*0C

OCCC((r-   )	functoolswraps)rN  r  rM  s   f r   	decorator cuda_memcheck.<locals>.decorator  s%    		!	) 
"	)" r-   r   )rM  rR  s   l r   cuda_memcheckrT    s    , r-   c           	   #     "    \         P                  ! . RO4       \         P                  ! R RRRV  RV  2.4       \         P                  ! R RRRV RV 2.4       \        R.4      ^ ,          p\        R.4      ^ ,          p\        W ,
          4      ^
8  g   Q RV  R	24       h\        W1,
          4      ^
8  g   Q RV R	24       hRV ,          pRV,          R
,          pWE3x  \         P                  ! . RO4       \         P                  ! . RO4       \         P                  ! . RO4       R#   \         P                  ! . RO4       \         P                  ! . RO4       \         P                  ! . RO4       i ; i5i)r   r   r   z--lock-gpu-clocks=r
   z--lock-memory-clocks=zclocks.current.smzclocks.current.memoryzGPU SMs must run at z MHzgMbP?N)r   r   r   -pmr7  g 3O?i   )r   r   r   rV  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_clockr]    sf    C EF a~>	!
 	 	#M?!M?C	!
 	 123A6678;<./"4_8L\NZ^6__4=01B6b:N}o]a8bb6)L8&-l EF AB AB 	 EF AB ABs   E9CD, "A
E9,A
E66E9c                    ^ RI p^RIHp V'       g   VP                  P	                  4       pVP
                  P                  P                  V4      R,          ^,          pVP                  P                  4       pV^ ,          ^8  d2   WP                  8X  d   ^ pM[WP                  8X  d   ^@pMH\        R4      hWP                  8X  d   ^ pM*WP                  VP                  39   d   ^@pM\        R4      hWQ,          V,          R,          pV# )r   Nr  r  r  r  )r@   r   r[   rA   r  r\   r  r  r  r!  r   r)  rv   r*  s	   &&&      r   get_max_simd_tflopsr_    s    **,==&&<<VDE[\_``L113J!}qMM!!mm#!455MM!!}}enn55!455&)99D@FMr-   )   NNr5   )   d   NNr5   )NNr   r   )iF  i  )rP  r!   r   r7   r   r   
contextlibr   typingr   r   r   r   r   r%  r   r   r0   r;   rY   rh   r   r   r   r  r  r0  rT  r]  r_  r   r-   r   <module>re     s      	   
 % " "  ( ($@BF?@D0^f@ @F` `F	:6 C C8r-   