o
    +ôj‚  ã                   @   sd   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d„Zd	d
„ Z	dd„ Z
e jdd„ ƒZdS )é    Né   )Úcheck_errorÚcudart)ÚinitÚstartÚstopÚprofile)ZgpustarttimestampZgpuendtimestampZ
gridsize3dZthreadblocksizeZstreamidzenableonstart 0ZconckerneltraceÚ	key_valuec                 C   sö   t ƒ }t|dƒstdƒ‚ttjdƒr)tjjd ur)ttjj d¡d ƒdkr)tdƒ‚|d u r/tn|}|dkr:|j	j
}n|d	krC|j	j}ntd
ƒ‚tjdd��$}| d dd„ |D ƒ¡¡ | ¡  t| |j| |¡ƒ W d   ƒ d S 1 stw   Y  d S )NÚcudaOutputModez-HIP does not support profiler initialization!ÚcudaÚ.r   é   z.CUDA12+ does not need profiler initialization!r	   Z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   úf/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torch/cuda/profiler.pyÚ	<genexpr>*   s   € zinit.<locals>.<genexpr>)r   ÚhasattrÚAssertionErrorÚtorchÚversionr   ÚintÚsplitÚ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   r      s*   

ÿ

ÿ"ýr   c                   C   ó   t tƒ  ¡ ƒ d S ©N)r   r   ZcudaProfilerStartr   r   r   r   r   /   ó   r   c                   C   r'   r(   )r   r   ZcudaProfilerStopr   r   r   r   r   3   r)   r   c                   c   s$   � zt ƒ  d V  W tƒ  d S tƒ  w r(   )r   r   r   r   r   r   r   7   s
   €r   )Nr	   )Ú
contextlibr   r   Ú r   r   Ú__all__r   r   r   r   Úcontextmanagerr   r   r   r   r   Ú<module>   s    
