o
    h                     @   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)gpustarttimestampgpuendtimestamp
gridsize3dthreadblocksizestreamidzenableonstart 0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   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   I/var/www/html/ai/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   KeyValuePairCSVRuntimeErrortempfileNamedTemporaryFilewritejoinflushr   cudaProfilerInitializename)output_fileflagsoutput_modertoutput_mode_enumr   r   r   r   r      s*   



"r   c                   C      t t   d S N)r   r   cudaProfilerStartr   r   r   r   r   /      r   c                   C   r4   r5   )r   r   cudaProfilerStopr   r   r   r   r   3   r7   r   c                   c   s$    zt   d V  W t  d S t  w r5   )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    
