Ë
    7^(hã  ã                   ó¸  — 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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)Ú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    úU/var/www/skyplay_api_hub/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(  rht        j                  dd «      }|€Pt        t        j                  t
        «      j                  j                  j                  «       dz  dz  dz  dz  «      }|S )NÚ r   ÚTRITON_CUPTI_LIB_PATHÚbackendsÚnvidiaÚlib)ÚosÚgetenvÚstrÚpathlibÚPathÚ__file__ÚparentÚabsolute)r   Úlib_paths     r   Ú_get_backend_default_pathr*      sl   € Ø€HØ�'Òä—9‘9Ð4°dÓ;ˆØÐô œ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)r!   r"   r   )r   Úhip_device_envsÚenvs      r   Ú
_check_envr0   $   s[   € Ø�+ÒØ0Ð2HÐIˆØ"ò 	ˆCÜ�y‰y˜˜dÓ#Ñ/Ü ØIÈ#Èð  OZð  [óð ñ	ð r   ÚshadowÚtree©ÚcontextÚdatar   ÚhookÚnamer4   r5   r6   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   r0   r*   r   r   Ú	libprotonÚstart)r7   r4   r5   r   r6   Ú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   r@   r@   g   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Ú
deactivaterA   s    r   rD   rD   z   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=   rE   s     r   rH   rH   �   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 )Nr3   )r;   rD   )
ÚargsÚkwargsr=   Úretr   r4   r5   Úfuncr6   r7   s
       €€€€€€r   Úwrapperz_profiling.<locals>.wrapper¶   s2   ø€ ä˜ g°DÀ'ÐPTÔUˆÙ�DÐ#˜FÑ#ˆÜ�7ÔØˆ
r   )Ú	functoolsÚwraps)rN   r7   r4   r5   r   r6   rO   s   `````` r   Ú
_profilingrR   ¤   s,   ý€ ô$ ‡_�_�TÓ÷ð ó ðð €Nr   ©r7   r4   r5   r   r6   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 )NrS   ©rR   )Úfr   r4   r5   r6   r7   s    €€€€€r   Ú	decoratorzprofile.<locals>.decoratorÜ   s   ø€ Ü˜a d°GÀ$ÐPWÐ^bÔcÐcr   rS   rV   )rN   r7   r4   r5   r   r6   rX   s    ````` r   ÚprofilerY   À   s6   ü€ ð4 €|÷	dð 	dð Ðô ˜$ T°7ÀÈwÐ]aÔbÐbr   )N)NÚhatchet)Nr1   r2   NN)rP   r   r!   r$   Útriton._C.libprotonr   r:   r6   r   r   Úflagsr   r   r	   Útypingr
   r9   r#   r   r*   r0   r;   Úintr@   rD   rH   rR   rY   © r   r   ú<module>r`      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   