
    קga	                     r    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dS )    N   )check_errorcudart)initstartstopprofile)gpustarttimestampgpuendtimestamp
gridsize3dthreadblocksizestreamidzenableonstart 0conckerneltrace	key_valuec                    t                      }t          |d          st          d          t          t          j        d          r[t          j        j        Jt          t          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 }|                    d                    d |D                                  |                                 t%          |                    |j        | |                     d d d            d S # 1 swxY w 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              3   @   K   | ]}|                     d           V  dS )asciiN)encode).0fs     O/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/cuda/profiler.py	<genexpr>zinit.<locals>.<genexpr>-   s.      <<188G,,<<<<<<    )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'(( NLMMMv&&OM*"((--a011R77 MNNN"]MMEk!!,9			,0I
 
 	
 
	$D	1	1	1 VQ	

<<e<<<<<===				B--afkCSTTUUUV V V V V V V V V V V V V V V V V Vs   8A0E55E9<E9c                  `    t          t                                                                 dS )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   r   2   s(     **,,-----r    c                  `    t          t                                                                 dS )zStops cuda profiler data collection.

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