a
    –¥»aÅ  ã                   @   sT   d dl Z d dlZddlmZmZ g d¢Zddd„Zdd	„ Zd
d„ Zej	dd„ ƒZ
dS )é    Né   )ÚcudartÚcheck_error)ZgpustarttimestampZgpuendtimestampZ
gridsize3dZthreadblocksizeZstreamidzenableonstart 0ZconckerneltraceÚ	key_valuec                 C   sº   t ƒ }t|dƒstdƒ‚|d u r$tn|}|dkr:|jj}n|dkrL|jj}ntdƒ‚tj	dd��F}| 
d d	d
„ |D ƒ¡¡ | ¡  t| |j| |¡ƒ W d   ƒ n1 s¬0    Y  d S )NÚcudaOutputModez-HIP does not support profiler initialization!r   Úcsvz;supported CUDA profiler output modes are: key_value and csvT)Údeleteó   
c                 s   s   | ]}|  d ¡V  qdS )ÚasciiN)Úencode)Ú.0Úf© r   úM/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/torch/cuda/profiler.pyÚ	<genexpr>   ó    zinit.<locals>.<genexpr>)r   ÚhasattrÚAssertionErrorÚDEFAULT_FLAGSr   ZKeyValuePairZCSVÚRuntimeErrorÚtempfileÚNamedTemporaryFileÚwriteÚjoinÚflushr   ZcudaProfilerInitializeÚname)Zoutput_fileÚflagsZoutput_modeÚrtZoutput_mode_enumr   r   r   r   Úinit   s    


r   c                   C   s   t tƒ  ¡ ƒ d S ©N)r   r   ZcudaProfilerStartr   r   r   r   Ústart"   s    r    c                   C   s   t tƒ  ¡ ƒ d S r   )r   r   ZcudaProfilerStopr   r   r   r   Ústop&   s    r!   c                   c   s$   zt ƒ  d V  W tƒ  ntƒ  0 d S r   )r    r!   r   r   r   r   Úprofile*   s    r"   )Nr   )r   Ú
contextlibÚ r   r   r   r   r    r!   Úcontextmanagerr"   r   r   r   r   Ú<module>   s   
