Ë
    ÏÍ:jê  ã                   óÄ  — 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	m
Z
 ddlmZmZmZ d dlmZ dZd	efd
„Zded	efd„Zded	dfd„Z	 ddddddœdee   dee   dee   dee   dee   f
d„Zddee   d	dfd„Zddee   d	dfd„Zddee   ded	dfd„Z	 	 	 	 	 d dee   dee   dee   dee   dee   f
d„Z	 dddddddœdee   dee   dee   dee   dee   f
d„Zy)!é    N)Úknobs)Úprotoné   )Úregister_triton_hookÚunregister_triton_hook)Úset_profiling_offÚset_profiling_onÚis_command_line)ÚOptionalr   Úreturnc                  ó¨   — t         j                  j                  j                  j	                  «       j
                  } | dk(  ry| dk(  ryt        d«      ‚)NÚcudaÚcuptiÚhipÚ	roctracerz/No backend is available for the current target.)ÚtritonÚruntimeÚdriverÚactiveÚget_current_targetÚbackendÚ
ValueError)r   s    úl/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/triton/profiler/profile.pyÚ_select_backendr      sH   € Ü�n‰n×#Ñ#×*Ñ*×=Ñ=Ó?×GÑG€GØ�&ÒØØ	�EÒ	ØäÐJÓKÐKó    r   c                 óì   — d}| dk(  rlt         j                  j                  }|€Pt        t	        j
                  t        «      j                  j                  j                  «       dz  dz  dz  dz  «      }|S )NÚ r   ÚbackendsÚnvidiaÚlib)	r   r   Ú	cupti_dirÚstrÚpathlibÚPathÚ__file__ÚparentÚabsolute)r   Úlib_paths     r   Ú_get_backend_default_pathr)      sj   € Ø€HØ�'Òä—<‘<×)Ñ)ˆØÐô œ7Ÿ<™<¬Ó1×8Ñ8×?Ñ?×HÑHÓJÈZÑWÐZbÑbÐejÑjÐmtÑtÓuˆHØ€Or   c                 óp   — | dk(  r1ddg}|D ]'  }t        j                  |d «      €Œt        d|› d�«      ‚ y y )Nr   ÚHIP_VISIBLE_DEVICESÚCUDA_VISIBLE_DEVICESz3Proton does not work when the environment variable zK is set on AMD GPUs. Please unset it and use `ROCR_VISIBLE_DEVICES` instead)ÚosÚgetenvr   )r   Úhip_device_envsÚenvs      r   Ú
_check_envr1   %   s[   € Ø�+ÒØ0Ð2HÐIˆØ"ò 	ˆCÜ�y‰y˜˜dÓ#Ñ/Ü ØIÈ#Èð  OZð  [óð ñ	ð r   ÚshadowÚtree©ÚcontextÚdatar   ÚhookÚnamer5   r6   r7   c                óÔ   — t        «       ry| €t        } |€
t        «       }t        |«       t	        |«      }t        «        |r|dk(  r
t        «        t        j                  | ||||«      S )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.hatchet".
        backend (str, optional): The backend to use for profiling.
                                 Available options are [None, "cupti", "cupti_pcsampling", "roctracer"].
                                 Defaults to None, which automatically selects the backend matching the current active runtime.
        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"].
                              Defaults to "tree".
        hook (str, optional): The hook to use for profiling.
                              Available options are [None, "triton"].
                              Defaults to None.
    Returns:
        session (int): The session ID of the profiling session.
    Nr   )	r
   ÚDEFAULT_PROFILE_NAMEr   r1   r)   r	   r   Ú	libprotonÚstart)r8   r5   r6   r   r7   Úbackend_paths         r   r<   r<   /   sd   € ôJ Ôàà€|Ü#ˆà€Ü!Ó#ˆäˆwÔä,¨WÓ5€LäÔÙ�˜Ò ÜÔÜ�?‰?˜4 ¨$°¸ÓFÐFr   Úsessionc                 ó�   — t        «       r| dk7  rt        d«      ‚| €t        j                  «        yt        j                  | «       y)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
    r   zEOnly one session can be activated when running from the command line.N)r
   r   r;   Úactivate_allÚactivate©r>   s    r   rA   rA   h   s;   € ô Ô˜W¨š\ÜÐ`ÓaÐaØ€Ü×ÑÕ ä×Ñ˜7Õ#r   c                 ó�   — t        «       r| dk7  rt        d«      ‚| €t        j                  «        yt        j                  | «       y)a  
    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)

    Returns:
        None
    r   zGOnly one session can be deactivated when running from the command line.N)r
   r   r;   Údeactivate_allÚ
deactivaterB   s    r   rE   rE   {   s;   € ô Ô˜W¨š\ÜÐbÓcÐcØ€Ü× Ñ Õ"ä×Ñ˜WÕ%r   Úoutput_formatc                 ó¼   — | €*t        «        t        j                  |«       t        «        yt	        «       r| dk7  rt        d«      ‚t        j                  | |«       y)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.
                                       Aavailable options are ["hatchet"].

    Returns:
        None
    Nr   zEOnly one session can be finalized when running from the command line.)r   r;   Úfinalize_allr   r
   r   Úfinalize)r>   rF   s     r   rI   rI   Ž   sK   € ð €ÜÔÜ×Ñ˜}Ô-ÜÕ äÔ ¨A¢ÜÐdÓeÐeÜ×Ñ˜7 MÕ2r   c                 óV   ‡ ‡‡‡‡‡— t        j                  ‰ «      ˆˆˆˆ ˆˆfd„«       }|S )z¯
    Context manager for profiling. Internally use only.

    Args:
        See start() for the arguments.

    Returns:
        wrapper (function): The wrapped function.
    c                  óN   •— t        ‰	‰‰‰‰¬«      } ‰| i |¤Ž}t        |«       |S )Nr4   )r<   rE   )
ÚargsÚkwargsr>   Úretr   r5   r6   Úfuncr7   r8   s
       €€€€€€r   Úwrapperz_profiling.<locals>.wrapper·   s2   ø€ ä˜ g°DÀ'ÐPTÔUˆÙ�DÐ#˜FÑ#ˆÜ�7ÔØˆ
r   )Ú	functoolsÚwraps)rO   r8   r5   r6   r   r7   rP   s   `````` r   Ú
_profilingrS   ¥   s,   ý€ ô$ ‡_�_�TÓ÷ð ó ðð €Nr   ©r8   r5   r6   r   r7   c                óH   ‡‡‡‡‡— | €ˆˆˆˆˆfd„}|S t        | ‰‰‰‰‰¬«      S )zë
    Decorator for profiling.

    Usage:

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

    Args:
        See start() for the arguments.

    Returns:
        decorator (function): The decorator function.
    c                 ó&   •— t        | ‰‰‰‰‰¬«      S )NrT   ©rS   )Úfr   r5   r6   r7   r8   s    €€€€€r   Ú	decoratorzprofile.<locals>.decoratorÝ   s   ø€ Ü˜a d°GÀ$ÐPWÐ^bÔcÐcr   rT   rW   )rO   r8   r5   r6   r   r7   rY   s    ````` r   ÚprofilerZ   Á   s6   ü€ ð4 €|÷	dð 	dð Ðô ˜$ T°7ÀÈwÐ]aÔbÐbr   )N)NÚhatchet)Nr2   r3   NN)rQ   r   r-   r#   r   Útriton._C.libprotonr   r;   r7   r   r   Úflagsr   r	   r
   Útypingr   r:   r"   r   r)   r1   r<   ÚintrA   rE   rI   rS   rZ   © r   r   ú<module>ra      sÙ  ðÛ Û Û 	Û å Ý 3ß >ß GÑ GÝ àÐ ðL˜ó Lð	 sð 	¨só 	ð˜ð  ó ð ð6Gð &Ø Ø!Øò6GØ
�3‰-ð6Gð �c‰]ð6Gð �3‰-ð	6Gð
 �c‰]ð6Gð �3‰-ó6Gñr$�h˜s‘mð $¨tó $ñ&&˜ ™ð &°ó &ñ&3�h˜s‘mð 3¸3ð 3Ètó 3ð2 Ø%Ø Ø!Øñà
�3‰-ðð �c‰]ðð �3‰-ð	ð
 �c‰]ðð �3‰-óð: 
ð"cð Ø%Ø Ø!Øò"cð �3‰-ð"cð �c‰]ð	"cð
 �3‰-ð"cð �c‰]ð"cð �3‰-ô"cr   