§
    Ÿ²Åj·	  ã                   ór   — d dl Z d dlZd dlZddlmZmZ g d¢Zg d¢Zdd„Zd„ Z	d	„ Z
e j        d
„ ¦   «         ZdS )é    Né   )Úcheck_errorÚcudart)ÚinitÚstartÚstopÚprofile)ÚgpustarttimestampÚgpuendtimestampÚ
gridsize3dÚthreadblocksizeÚstreamidzenableonstart 0ÚconckerneltraceÚ	key_valuec                 ó  — t          ¦   «         }t          |d¦  «        st          d¦  «        ‚t          t          j        d¦  «        r[t          j        j        �Jt          t          j        j                             d¦  «        d         ¦  «        dk    rt          d¦  «        ‚|€t          n|}|dk    r|j	        j
        }n"|d	k    r|j	        j        }nt          d
¦  «        ‚t          j        d¬¦  «        5 }|                     d                     d„ |D ¦   «         ¦  «        ¦  «         |                     ¦   «          t%          |                     |j        | |¦  «        ¦  «         d d d ¦  «         d S # 1 swxY w Y   d S )NÚcudaOutputModez-HIP does not support profiler initialization!Úcudaú.r   é   z.CUDA12+ does not need profiler initialization!r   Úcsvz;supported CUDA profiler output modes are: key_value and csvT)Údeleteó   
c              3   ó@   K  — | ]}|                      d ¦  «        V — ŒdS )ÚasciiN)Úencode)Ú.0Úfs     úDC:\Projects\Historical\venv\Lib\site-packages\torch/cuda/profiler.pyú	<genexpr>zinit.<locals>.<genexpr>-   s.   è è € Ð<Ð<°˜1Ÿ8š8 GÑ,Ô,Ð<Ð<Ð<Ð<Ð<Ð<ó    )r   ÚhasattrÚAssertionErrorÚtorchÚversionr   ÚintÚsplitÚDEFAULT_FLAGSr   ÚKeyValuePairÚCSVÚRuntimeErrorÚtempfileÚNamedTemporaryFileÚwriteÚjoinÚflushr   ÚcudaProfilerInitializeÚname)Úoutput_fileÚflagsÚoutput_modeÚrtÚoutput_mode_enumr   s         r   r   r      sÇ  € Ý	‰Œ€BÝ�2Ð'Ñ(Ô(ð NÝÐLÑMÔMÐMå•”˜vÑ&Ô&ðOåŒMÔÐ*Ý•”Ô"×(Ò(¨Ñ-Ô-¨aÔ0Ñ1Ô1°RÒ7Ð7õ ÐMÑNÔNÐNØ"˜]�MˆM°€EØ�kÒ!Ð!ØÔ,Ô9ÐÐØ	˜Ò	Ð	ØÔ,Ô0ÐÐåØIñ
ô 
ð 	
õ 
Ô	$¨DÐ	1Ñ	1Ô	1ð V°QØ	�Š�—
’
Ð<Ð<°eÐ<Ñ<Ô<Ñ<Ô<Ñ=Ô=Ð=Ø	�Š‰	Œ	ˆ	Ý�B×-Ò-¨a¬f°kÐCSÑTÔTÑUÔUÐUðVð Vð Vñ Vô Vð Vð Vð Vð Vð Vð Vð Vøøøð Vð Vð Vð Vð Vð Vs   Ã8A0E5Å5E9Å<E9c                  ó`   — t          t          ¦   «                              ¦   «         ¦  «         dS )z„Starts cuda profiler data collection.

    .. warning::
        Raises CudaError in case of it is unable to start the profiler.
    N)r   r   ÚcudaProfilerStart© r    r   r   r   2   s(   € õ •‘”×*Ò*Ñ,Ô,Ñ-Ô-Ð-Ð-Ð-r    c                  ó`   — t          t          ¦   «                              ¦   «         ¦  «         dS )z‚Stops cuda profiler data collection.

    .. warning::
        Raises CudaError in case of it is unable to stop the profiler.
    N)r   r   ÚcudaProfilerStopr9   r    r   r   r   ;   s(   € õ •‘”×)Ò)Ñ+Ô+Ñ,Ô,Ð,Ð,Ð,r    c               #   ór   K  — 	 t          ¦   «          dV — t          ¦   «          dS # t          ¦   «          w xY w)a™  
    Enable profiling.

    Context Manager to enabling profile collection by the active profiling tool from CUDA backend.
    Example:
        >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
        >>> import torch
        >>> model = torch.nn.Linear(20, 30).cuda()
        >>> inputs = torch.randn(128, 20).cuda()
        >>> with torch.cuda.profiler.profile() as prof:
        ...     model(inputs)
    N)r   r   r9   r    r   r	   r	   D   s8   è è € ðÝ‰ŒˆØˆˆˆå‰Œˆˆˆø�‰Œˆˆøøøs   „& ¦6)Nr   )Ú
contextlibr+   r#   Ú r   r   Ú__all__r'   r   r   r   Úcontextmanagerr	   r9   r    r   ú<module>rA      s¸   ðà Ð Ð Ð Ø €€€à €€€à !Ð !Ð !Ð !Ð !Ð !Ð !Ð !ð /Ð
.Ð
.€ðð ð €ðVð Vð Vð Vð6.ð .ð .ð-ð -ð -ð Ôðð ñ Ôðð ð r    