
    Ǆga	                     t    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y)    N   )check_errorcudart)initstartstopprofile)gpustarttimestampgpuendtimestamp
gridsize3dthreadblocksizestreamidzenableonstart 0conckerneltracec                    t               }t        |d      st        d      t        t        j                  d      r]t        j                  j
                  Ct        t        j                  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 }|j                  dj!                  d |D                     |j#                          t%        |j'                  |j(                  | |             d d d        y # 1 sw Y   y xY w)NcudaOutputModez-HIP does not support profiler initialization!cuda.r      z.CUDA12+ does not need profiler initialization!	key_valuecsvz;supported CUDA profiler output modes are: key_value and csvT)delete   
c              3   >   K   | ]  }|j                  d         yw)asciiN)encode).0fs     [/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/torch/cuda/profiler.py	<genexpr>zinit.<locals>.<genexpr>-   s     <188G,<s   )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'(LMMv&MM*""((-a01R7 MNN"]MEk!,,99		,,00I
 	
 
	$	$D	1 VQ	

<e<<=		B--affkCSTUV V Vs   <AE##E,c                  F    t        t               j                                y)zStarts cuda profiler data collection.

    .. warning::
        Raises CudaError in case of it is unable to start the profiler.
    N)r   r   cudaProfilerStart     r   r   r   2   s     **,-r9   c                  F    t        t               j                                y)zStops cuda profiler data collection.

    .. warning::
        Raises CudaError in case of it is unable to stop the profiler.
    N)r   r   cudaProfilerStopr8   r9   r   r   r   ;   s     ))+,r9   c               #   \   K   	 t                d t                y# t                w xY w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   r8   r9   r   r	   r	   D   s     s   , ,),)Nr   )
contextlibr*   r"    r   r   __all__r&   r   r   r   contextmanagerr	   r8   r9   r   <module>rA      sI       ! /V6.-  r9   