U
    ©Ê¹j‚  ã                   @   sr   d dl Z d dlZd dlZddlmZmZ ddddgZdd	d
ddddg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ÚprofileZgpustarttimestampZgpuendtimestampZ
gridsize3dZthreadblocksizeZstreamidzenableonstart 0ZconckerneltraceÚ	key_valuec              	   C   sà   t ƒ }t|dƒstdƒ‚ttjdƒrRtjjd k	rRttjj d¡d ƒdkrRtdƒ‚|d kr^tn|}|dkrt|j	j
}n|d	kr†|j	j}ntd
ƒ‚tjdd��<}| d dd„ |D ƒ¡¡ | ¡  t| |j| |¡ƒ W 5 Q R X 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                 s   s   | ]}|  d ¡V  qdS )ÚasciiN)Úencode)Ú.0Úf© r   úR/var/www/html/bwave/python/venv/lib/python3.8/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,    

ÿ
þý

ÿc                   C   s   t tƒ  ¡ ƒ d S ©N)r   r   ZcudaProfilerStartr   r   r   r   r   /   s    c                   C   s   t tƒ  ¡ ƒ d S r(   )r   r   ZcudaProfilerStopr   r   r   r   r   3   s    c                   c   s   ztƒ  d V  W 5 t ƒ  X d S r(   )r   r   r   r   r   r   r   7   s    
)Nr	   )Ú
contextlibr    r   Ú r   r   Ú__all__r   r   r   r   Úcontextmanagerr   r   r   r   r   Ú<module>   s"   ù
