+
    –°³jÿ  ã                  ó4  a € 0 t $ ^ RIH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 ^ RIHt ^ RIt^ RIHtHt ]'       d	   ^ RIHtHt ]! R4      tR	 R
 lsRR R lltR R ltR R ltR R ltR R ltR R lt. sR]R&   R R ltRR R llt R# )é    )ÚannotationsN)ÚAbstractContextManager)ÚAnyÚTYPE_CHECKING)ÚTypeVar)ÚprofileÚProfilerActivity)ÚCallableÚSequenceÚ_Rc               ó   € V ^8„  d   QhRR/# )é   ÚreturnÚNone© )Úformats   "Úa/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/_functorch/benchmark_utils.pyÚ__annotate__r      s   € ÷ 	ñ 	�Tñ 	ó    c                 ó   € R # )Nr   r   r   r   Úsynchronizer      s   € Ùr   c               ó@   € V ^8„  d   QhRRRRRRRRR	R
RRRRRRRRRR/
# )r   ÚfúCallable[[tuple[Any, ...]], _R]Úinput_útuple[Any, ...]Útrace_filenameÚstrÚoptimize_ctxzAbstractContextManager[Any]Ú
activitieszSequence[ProfilerActivity]Únum_runsÚintÚdeviceszlist[str] | NoneÚkwargs_for_fzdict[str, Any] | NoneÚkwargs_for_profilerr   Úfloatr   )r   s   "r   r   r      sl   € ÷ 7ñ 7Ø&ð7àð7ð ð7ð .ð	7ð
 +ð7ð ð7ð ð7ð (ð7ð /ð7ð ñ7r   c	           
     ó°  € Vf   R.pVR.8w  d?   \         P                  P                  4       '       d   \         P                  P                  sVf   / pVf   / pT;_uu_ 4        \         P                  ! R4       \        ^4       F  p	V ! V3/ VB  \        4        K  	  \         P                  ! R4       \        P                  ! 4       p
\        V4       F  p	V ! V3/ VB  \        4        K  	  \        P                  ! 4       pRRR4       XX
,
          p\        RRV/VB ;_uu_ 4       pT;_uu_ 4        \        4        \         P                  ! R4       \        V4       F  p	V ! V3/ VB  \        4        K  	  RRR4       RRR4       XP                  V4       V#   + '       g   i     L¢; i  + '       g   i     L>; i  + '       g   i     LI; i)a  
Output the chrome trace of running f(input_, **kwargs_for_f) with [optimize_ctx]
[num_runs] times to [trace_filename].

[activities] are the activities that the profiler will record, e.g. ProfilerActivity.CUDA.
Return total runtime without the profiler

Outputs to trace_filename
NÚcudaÚcpui9  r    r   )
ÚtorchÚacceleratorÚis_availabler   Úmanual_seedÚrangeÚtimeÚperf_counterr   Úexport_chrome_trace)r   r   r   r   r    r!   r#   r$   r%   Ú_Út0Út1ÚtimingÚprofs   &&&&&&&&&     r   Údump_chrome_tracer7      so  € ð* ‚Ø�(ˆð �5�'Ôœe×/Ñ/×<Ñ<×>Ò>Ü×'Ñ'×3Ñ3ˆàÒØˆØÒ"Ø Ðç	ŠÜ×Ò˜$ÔÜ�q–ˆAÙˆfÑ%˜Ò%ÜŽMñ ô 	×Ò˜$ÔÜ×ÒÓ ˆÜ�x–ˆAÙˆfÑ%˜Ò%ÜŽMñ !ô ×ÒÓ ˆ÷ 
ð �"�W€Fä	Ñ	>˜JÐ	>Ð*=×	>Ò	>À$ßŠ\ÜŒMÜ×Ò˜dÔ#Ü˜8–_�Ù�&Ñ)˜LÒ)Ü–ñ %÷ ÷ 
?ð 	×Ñ˜^Ô,à€M÷- 
�ú÷ �\ú÷ 
?×	>ús2   Á$B!FÄ+GÄ6AF2	Å<GÆF/	Æ2GÆ=GÇG	c               ó    € V ^8„  d   QhRRRR/# )r   Úfilenamer   r   úlist[dict[str, Any]]r   )r   s   "r   r   r   U   s   € ÷ ñ  cð Ð.Bñ r   c                ó¢   € \        V 4      ;_uu_ 4       p\        P                  ! V4      pR R R 4       XR,          pV#   + '       g   i     L; i)NÚtraceEvents)ÚopenÚjsonÚload)r9   r   ÚdataÚeventss   &   r   Úget_chrome_trace_eventsrB   U   s6   € Ü	ˆh�Œ˜1Ü�yŠy˜‹|ˆ÷ 
à�-Õ €FØ€M÷ 
�ús	   ”>¾A	c               ó    € V ^8„  d   QhRRRR/# ©r   Úeventzdict[str, Any]r   Úboolr   )r   s   "r   r   r   \   s   € ÷ ñ  ð °4ñ r   c                ó~   € R V 9   ;'       d2    V R ,          \         9   ;'       d    RV 9   ;'       d    V R,          R8H  # )ÚpidÚphÚX)Úgpu_pids©rE   s   &r   Úis_gpu_compute_eventrM   \   sO   € ð 	�‰÷ 	ð 	Ø�%�LœHÑ$÷	ð 	à�E‰M÷	ð 	ð �$�K˜3Ñð	r   c               ó    € V ^8„  d   QhRRRR/# ©r   rA   r:   r   r   )r   s   "r   r   r   f   s    € ÷ Dñ DÐ"6ð DÐ;Oñ Dr   c                ó¢   € . pV  F'  p\        V4      '       g   K  VP                  V4       K)  	  \        V\        P                  ! R 4      R7      # )Úts)Úkey)rM   ÚappendÚsortedÚoperatorÚ
itemgetter)rA   Úsorted_gpu_eventsrE   s   &  r   Úget_sorted_gpu_eventsrX   f   sI   € Ø.0ÐÛˆÜ# E×*Ò*ÙØ× Ñ  Ö'ñ ô Ð#¬×)<Ò)<¸TÓ)BÔCÐCr   c               ó    € V ^8„  d   QhRRRR/# )r   rW   r:   r   r"   r   )r   s   "r   r   r   o   s   € ÷ ñ Ð$8ð ¸Sñ r   c                ó8  € \        V 4      ^ 8X  d   ^ # V ^ ,          pVR,          VR,          ,           pVR,          pV R,           FQ  p\        VR,          V4      pVR,          VR,          ,           pV\        WT,
          ^ 4      ,           p\        W%4      pKS  	  V# )r   rQ   Údur:é   NN)ÚlenÚmax)rW   rE   Úcurrent_end_timeÚtotal_durationÚ
start_timeÚend_times   &     r   Úget_durationrc   o   s–   € Ü
ÐÓ Ô"ÙØ˜aÕ €EØ˜T•{ U¨5¥\Õ1ÐØ˜5•\€NØ" 2×&Ð&ˆÜ˜˜t�Ð&6Ó7ˆ
Ø˜•;  u¥Õ-ˆØ'¬#¨hÕ.CÀQÓ*GÕGˆÜÐ/Ó:Òñ	 'ð
 Ðr   c               ó    € V ^8„  d   QhRRRR/# rO   r   )r   s   "r   r   r   }   s   € ÷ ñ Ð*>ð ÐCWñ r   c                ó€   € R  R lp\        V 4      p. pV F$  pV! V4      '       g   K  VP                  V4       K&  	  V# )c               ó    € V ^8„  d   QhRRRR/# rD   r   )r   s   "r   r   Ú3get_sorted_gpu_mm_conv_events.<locals>.__annotate__~   s   € ÷ 
ñ 
 ð 
°4ñ 
r   c                ó¬   € R V 9   ;'       dI    RV R ,          9   ;'       g5    RV R ,          9   ;'       g!    RV R ,          9   ;'       g    RV R ,          9   # )ÚnameÚgemmÚconvÚcutlassÚwgradr   rL   s   &r   Úis_mm_conv_eventÚ7get_sorted_gpu_mm_conv_events.<locals>.is_mm_conv_event~   sh   € Ø˜‰÷ 
ð 
Ø�e˜F•mÑ#÷ (ð (Ø˜˜v�Ñ&÷(ð (à˜E &�MÑ)÷(ð (ð ˜% �-Ñ'ð		
r   )rX   rS   )rA   rn   Ú
gpu_eventsÚsorted_eventsrE   s   &    r   Úget_sorted_gpu_mm_conv_eventsrr   }   sF   € õ
ô ' vÓ.€JØ*,€MÛˆÙ ×&Ò&ÙØ×Ñ˜UÖ#ñ ð Ðr   z	list[Any]rK   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r9   r   Útotal_lengthr&   r   útuple[float, float]r   )r   s   "r   r   r   ’   s"   € ÷ ,ñ , #ð ,°Uð ,Ð?Rñ ,r   c                óR  € \        V 4      p. sV FO  pRV9  d   K  VR,          R8X  g   K  RVR,          R,          9   g   K3  \        P                  VR,          4       KQ  	  VR,          p\        V4      p\	        V4      V,          p\        V4      p\	        V4      V,          pWW3# )a…  
Process the chrome traces outputs by the pytorch profiler to compute GPU Utilization
and percent of times spent on matmul and convolution

Args:
    filename(str): Name of chrome traces file produced by pytorch profiler

    total_length(float): total length of the process without profiler in second

Return:
    tuple: (GPU Utilization, percent of time spent on matmul and convolution)
ri   Úprocess_labelsÚGPUÚargsÚlabelsrH   g    €„.A)rB   rK   rS   rX   rc   rr   )r9   rt   rA   rE   rW   ÚutilizationÚsorted_gpu_mm_conv_eventsÚmm_conv_utilizations   &&      r   Úcompute_utilizationr~   ’   s£   € ô % XÓ.€Fð €HÛˆØ˜ÔÙØ��=Ð,Ö,°¸%À½-ÈÕ:QÖ1QÜ�O‰O˜E %�LÖ)ñ	 ð   #Õ%€LÜ-¨fÓ5ÐÜÐ0Ó1°LÕ@€Kä =¸fÓ EÐÜ&Ð'@ÓAÀLÕPÐàÐ+Ð+r   c               ó4   € V ^8„  d   QhRRRRRRRRR	RR
RRR/# )r   r   r   r   r   Útrace_folderr   r   z"AbstractContextManager[Any] | NoneÚtrace_file_namer!   r"   r   ru   r   )r   s   "r   r   r   ´   sW   € ÷ A,ñ A,Ø&ðA,àðA,ð ðA,ð 5ð	A,ð
 ðA,ð ðA,ð ñA,r   c           
     ó‚  € \         P                  P                  V4      pV'       g)   \         P                  ! V4       \	        RV,           4       Vf   \
        P                  ! 4       p\         P                  P                  W$R,           4      p\        V VVV\        P                  .VR.R7      p\        Wx4      w  ršWš3# )au  
Benchmark the GPU Utilization and percent of time spent on matmul and convolution operations of
running f(input_, **kwargs_for_f) with [optimize_ctx] [num_runs] times.
It will produce a chrome trace file in trace_folder/trace_file_name.json

Example:

```
def f(a):
    return a.sum()


a = torch.rand(2**20, device="cuda")
utilization, mm_conv_utilization = benchmark_utilization(
    f, a, "tmp", trace_file_name="tmp_chrome_trace"
)
```

Args:
    f: function to benchmark

    input_: input to :attr:`f`

    trace_folder: name of the folder to store the chrome trace

    optimize_ctx: the context in which f will run

    trace_file_name: name of the dumped chrome trace file, default to "tmp_chrome_trace"

    num_runs: number of times to run f, excluding the warm-up runs, default to 1.

Return:
    tuple: (GPU Utilization, percent of time spent on matmul and convolution)

zcreate folder z.jsonr(   )r!   r#   )ÚosÚpathÚexistsÚmakedirsÚprintÚ
contextlibÚnullcontextÚjoinr7   r	   ÚCUDAr~   )r   r   r€   r   r�   r!   ÚisExistÚchrome_trace_file_namert   r{   r}   s   &&&&&&     r   Úbenchmark_utilizationrŽ   ´   s§   € ôV �g‰g�n‰n˜\Ó*€GßÜ
�Š�LÔ!ÜÐ Õ-Ô.àÒÜ!×-Ò-Ó/ˆäŸW™WŸ\™\¨,È'Õ8QÓRÐÜ$Ø	ØØØÜ	×	Ñ	ÐØØ�ô€Lô (;Øó(Ñ$€Kð Ð+Ð+r   )r\   NNN)NÚtmp_chrome_tracer\   )!Ú__conditional_annotations__Ú
__future__r   rˆ   r>   rU   rƒ   r/   r   Útypingr   r   Útyping_extensionsr   r*   Útorch.profilerr   r	   Úcollections.abcr
   r   r   r   r7   rB   rM   rX   rc   rr   rK   Ú__annotations__r~   rŽ   )r�   s   @r   Ú<module>r—      s€   øðß "Ð "ã Û Û Û 	Û Ý -ß %Ý %ã ß 4÷ ß2ñ ˆTƒ]€õ	÷7õtõõDõõð$ €ˆ)Ó õ,÷DA,ñ A,r   