+
    ړLj)&                     2   ^ RI t ^ RIt^ RIHt ^ RIHt ^RIHt ^RIH	t	H
t
Ht ^RIHt ^RIHt ^ RIHtHt R	tR
 R ltR R ltR R ltR$RRRRRRRRRR/R R llltR$R R lltR%R R lltR&R R lltR'R R  lltR$R!RRRRRRRRRRR/R" R# llltR# )(    N)proton)getenv)flags)HookManager
LaunchHookInstrumentationHook)Hook)BaseMode)OptionalUnionr   c                $    V ^8  d   QhR\         /# )   returnstr)formats   "C/app/.local/lib/python3.14/site-packages/triton/profiler/profile.py__annotate__r      s     L L L    c                      \         P                  P                  P                  P	                  4       P
                  p V R 8X  d   R# V R8X  d   R# \        R4      h)cudacuptihip	roctracerz/No backend is available for the current target.)tritonruntimedriveractiveget_current_targetbackend
ValueError)r    s    r   _select_backendr"      sH    nn##**==?GGG&	E	JKKr   c                t    V ^8  d   QhR\         R\        \        \         \        3,          ,          R\         /# )r   r    moder   )r   r   r   r
   )r   s   "r   r   r      s/     % %3 %huS(]/C&D % %r   c                     V R 8X  dN   \         P                  P                  P                  P	                  4       P
                  pV'       d   V RV 2# T# V'       d   \        V4      # R# )instrumentation: )r   r   r   r   r   r    r   )r    r$   prefixs   && r   _get_mode_strr*      sX    ##&&--@@BJJ%)&4&!5v53t9$"$r   c                (    V ^8  d   QhR\         RR/# )r   r    r   Nr   )r   s   "r   r   r       s     9 9 9 9r   c                    V R 8X  d+   RR.pV F   p\        VR4      f   K  \        RV R24      h	  \        P                  P                  P
                  P                  4        F  w  r4VP                  p\        VR4      e   K!  \        \        P                  P                  V4      pVf   KK  \        P                  P                  V4      ;p'       g   Kt  \        P                  P                  WW^ ,          4       K  	  R# )r   HIP_VISIBLE_DEVICESCUDA_VISIBLE_DEVICESNz3Proton does not work when the environment variable zK is set on AMD GPUs. Please unset it and use `ROCR_VISIBLE_DEVICES` instead)r   r!   r   knobsr   knob_descriptorsitemskeygetattrtoenvsetenv)r    hip_device_envsenvattrdescr2   valenv_vals   &       r   
_check_envr<       s    +02HI"Cc4 , I#  OZ  [  # ll))::@@B
hh#t$&,,--t4C$ll0055755LL''QZ8 Cr   contextshadowdatatreer    r$   hookc                J   V ^8  d   QhR\         \        ,          R\         \        ,          R\         \        ,          R\         \        ,          R\         \        \        \        3,          ,          R\         \        \        \        3,          ,          R\         \
        ,          /# )r   namer=   r?   r    r$   rA   r   )r   r   r   r
   r	   int)r   s   "r   r   r   3   s     K K
3-K c]K 3-	K
 c]K 5h'
(K 5d#
$K c]Kr   c               P   \         P                  '       g+   \        P                  P                  P
                  '       d   R# R\         n        V f   \        MT p Vf   \        4       MTp\        W44      p\        V4       \        P                  ! WW#V4      p\        V\        4      '       d   \        P                   ! WW4       M:VR8X  d!   \        P                   ! \#        4       V4       MVe   \%        RV: 24      hVR8X  d!   \        P                   ! \'        V4      V4       V# )a
  
Start profiling with the given name and backend.

Usage:

    ```python
    proton.start("my_profile")
    # do something
    proton.finalize()
    ```

Args:
    name (str, optional): The name (with path) of the profiling session.
                          If not provided, the default name is "~/proton.<suffix>", where suffix is the default
                          format according to the data type. For example, if data is "tree", the default name is "~/proton.hatchet".
    context (str, optional): The context to use for profiling.
                             Available options are ["shadow", "python"].
                             Defaults to "shadow".
    data (str, optional): The data structure to use for profiling.
                          Available options are ["tree", "trace"].
                          Defaults to "tree".
    backend (str, optional): The backend to use for profiling.
                             Available options are [None, "cupti", "roctracer", "instrumentation"].
                             Defaults to None, which automatically selects the backend matching the current active runtime.
    mode (Union[str, BaseMode], optional): The "mode" to use for profiling, which is specific to the backend.
                                           Can be a string or an instance of BaseMode (or any subclass thereof).
                                           Defaults to None.
                                           For "cupti", available options are [None, "pcsampling", "periodic_flushing"].
                                           For "roctracer", available options are ["periodic_flushing"].
                                           For "instrumentation", available options are [None].
                                           Each mode has a set of control knobs following with the mode name.
                                           For example, "periodic_flushing" mode has a knob:
                                           - format: The output format of the profiling results. Available options are ["hatchet", "hatchet_msgpack", "chrome_trace"]. Default is "hatchet".
                                           The can be set via `mode="periodic_flushing:format=chrome_trace"`.
    hook (Union[str, Hook], optional): The hook to use for profiling.
                                       You may pass either:
                                       - a string hook name, e.g. "triton" (kernel launch metadata), or
                                       - a custom Hook instance.
                                       Defaults to None.
Returns:
    session (Optional[int]): The session ID of the profiling session, or None if profiling is disabled.
NTr   zUnsupported hook: r&   )r   command_liner   r/   r   disableprofiling_onDEFAULT_PROFILE_NAMEr"   r*   r<   	libprotonstart
isinstancer	   r   registerr   r!   r   )rC   r=   r?   r    r$   rA   mode_strsessions   &$$$$$  r   rK   rK   3   s    f V\\00888E#'<TD#*?oGW+HwoodTHEG$T+		Z\73		-dX677##06@Nr   c                >    V ^8  d   QhR\         \        ,          RR/# )r   rO   r   N)r   rD   )r   s   "r   r   r      s     $ $hsm $t $r   c                    \         P                  '       d   V ^ 8w  d   \        R4      h\        P                  ! V 4       V f   \
        P                  ! 4        R# \
        P                  ! V 4       R# )z
Activate the specified session.
The profiling session will be active and data will be recorded.

Args:
    session (int): The session ID of the profiling session. Defaults to None (all sessions)

Returns:
    None
zEOnly one session can be activated when running from the command line.N)r   rF   r!   r   activaterJ   activate_all)rO   s   &r   rR   rR      sO     gl`aa! 7#r   c                J    V ^8  d   QhR\         \        ,          R\        RR/# )r   rO   flushingr   N)r   rD   bool)r   s   "r   r   r      s%     0 0 0 0 0r   c                    \         P                  '       d   V ^ 8w  d   \        R4      h\        P                  ! V 4       V f   \
        P                  ! V4       R# \
        P                  ! W4       R# )aP  
Stop the specified session.
The profiling session's data will still be in the memory, but no more data will be recorded.

Args:
    session (int): The session ID of the profiling session. Defaults to None (all sessions)
    flushing (bool): Whether to flush the profiling data before deactivating. Defaults to True.

Returns:
    None
zGOnly one session can be deactivated when running from the command line.N)r   rF   r!   r   
deactivaterJ   deactivate_all)rO   rU   s   &&r   rX   rX      sQ     glbcc7#  *W/r   c                `    V ^8  d   QhR\         \        ,          R\         \        ,          RR/# )r   rO   output_formatr   N)r   rD   r   )r   s   "r   r   r      s*     3 3hsm 38C= 3RV 3r   c                    \         P                  ! V 4       V f$   R\        n        \        P
                  ! V4       R# \        P                  '       d   V ^ 8w  d   \        R4      h\        P                  ! W4       R# )a  
Finalizes a profiling session.
Flush and write the profiling data to the file specified by the session name.

Args:
    session (int, optional): The session ID to finalize. If None, all sessions are finalized. Defaults to None.
    output_format (str, optional): The output format for the profiling results.
                                   Available options are ["hatchet", "hatchet_msgpack", "chrome_trace"].

Returns:
    None
NFzEOnly one session can be finalized when running from the command line.)	r   
unregisterr   rH   rJ   finalize_allrF   r!   finalize)rO   r[   s   &&r   r_   r_      sY     7#"}-'Q,dee72r   c                   V ^8  d   QhR\         \        ,          R\         \        ,          R\         \        ,          R\         \        ,          R\         \        ,          R\         \        \        \        3,          ,          /# r   rC   r=   r?   r    r$   rA   r   r   r   r	   )r   s   "r   r   r      sh      
3- c] 3-	
 c] 3- 5d#
$r   c                ^   a aaaaaa \         P                  ! S 4      VVVV VVV3R l4       pV# )z
Context manager for profiling. Internally use only.

Args:
    See start() for the arguments.

Returns:
    wrapper (function): The wrapped function.
c            	      P   < \        S
SSSS	SR 7      pS! V / VB p\        V4       V# ))r=   r?   r    r$   rA   )rK   rX   )argskwargsrO   retr    r=   r?   funcrA   r$   rC   s   *,  r   wrapper_profiling.<locals>.wrapper   s5    gD'PT[_`D#F#7
r   )	functoolswraps)rh   rC   r=   r?   r    r$   rA   ri   s   fffffff r   
_profilingrm      s,    & __T   Nr   rC   c                   V ^8  d   QhR\         \        ,          R\         \        ,          R\         \        ,          R\         \        ,          R\         \        ,          R\         \        \        \        3,          ,          /# ra   rb   )r   s   "r   r   r      sr     #n #n 3-#n c]	#n
 3-#n c]#n 3-#n 5d#
$#nr   c          
     T   aaaaaa V f   VVVVVV3R lpV# \        V SSSSSSR7      # )z
Decorator for profiling.

Usage:

```python
@proton.profile
def foo():
    pass
```

Args:
    See start() for the arguments.

Returns:
    decorator (function): The decorator function.
c           
      (   < \        V SSSSSSR 7      # )rC   r=   r?   r    r$   rA   rm   )fr    r=   r?   rA   r$   rC   s   &r   	decoratorprofile.<locals>.decorator   s    adG$PW^bimnnr   rq   rr   )rh   rC   r=   r?   r    r$   rA   rt   s   &dddddd r   profilerv      s9    6 |	o 	o  $T7w]ahlmmr   )N)NF)Nr(   )Nr>   r@   NNN)rk   r   triton._C.libprotonr   rJ   triton._C.libtritonr   r   hooksr   r   r   
hooks.hookr	   r$   r
   typingr   r   rI   r"   r*   r<   rK   rR   rX   r_   rm   rv    r   r   <module>r}      s      3 &  ? ?   " L%9&K &K !	K
 "K ,0K (,K K\$,0.30:#n #n &	#n
 !#n "#n #n (,#n #nr   