o
    h                     @   s   d Z ddlmZ zddlmZ W n ey#   G dd dZe ZY nw g dZdd Zd	d
 Z	de
fddZdddZddede
defddZddede
ddfddZdd Zedd ZdS )zNThis package adds support for NVIDIA Tools Extension (NVTX) used in profiling.    )contextmanager)_nvtxc                   @   s$   e Zd Zedd ZeZeZeZdS )	_NVTXStubc                  O   s   t d)NzANVTX functions not installed. Are you sure you have a CUDA build?)RuntimeError)argskwargs r   c/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torch/cuda/nvtx.py_fail   s   z_NVTXStub._failN)__name__
__module____qualname__staticmethodr
   
rangePushArangePopmarkAr   r   r   r	   r      s    
r   )
range_push	range_poprange_start	range_endmarkrangec                 C   
   t | S )z
    Push a range onto a stack of nested range span.  Returns zero-based depth of the range that is started.

    Args:
        msg (str): ASCII message to associate with range
    )r   r   msgr   r   r	   r         
r   c                   C   s   t  S )zlPop a range off of a stack of nested range spans.  Returns the  zero-based depth of the range that is ended.)r   r   r   r   r   r	   r   %   s   r   returnc                 C   r   )a  
    Mark the start of a range with string message. It returns an unique handle
    for this range to pass to the corresponding call to rangeEnd().

    A key difference between this and range_push/range_pop is that the
    range_start/range_end version supports range across threads (start on one
    thread and end on another thread).

    Returns: A range handle (uint64_t) that can be passed to range_end().

    Args:
        msg (str): ASCII message to associate with the range.
    )r   rangeStartAr   r   r   r	   r   *   s   
r   Nc                 C   s   t |  dS )z
    Mark the end of a range for a given range_id.

    Args:
        range_id (int): an unique handle for the start range.
    N)r   rangeEnd)range_idr   r   r	   r   ;   s   r   r   streamc                 C   s   t | |S )ad  
    Marks the start of a range with string message.
    It returns an opaque heap-allocated handle for this range
    to pass to the corresponding call to device_range_end().

    A key difference between this and range_start is that the
    range_start marks the range right away, while _device_range_start
    marks the start of the range as soon as all the tasks on the
    CUDA stream are completed.

    Returns: An opaque heap-allocated handle that should be passed to _device_range_end().

    Args:
        msg (str): ASCII message to associate with the range.
        stream (int): CUDA stream id.
    )r   deviceRangeStart)r   r    r   r   r	   _device_range_startE   s   r"   range_handlec                 C   s   t | | dS )z
    Mark the end of a range for a given range_handle as soon as all the tasks
    on the CUDA stream are completed.

    Args:
        range_handle: an unique handle for the start range.
        stream (int): CUDA stream id.
    N)r   deviceRangeEnd)r#   r    r   r   r	   _device_range_endY   s   	r%   c                 C   r   )z
    Describe an instantaneous event that occurred at some point.

    Args:
        msg (str): ASCII message to associate with the event.
    )r   r   r   r   r   r	   r   e   r   r   c                 o   s2    t | j|i | z	dV  W t  dS t  w )a  
    Context manager / decorator that pushes an NVTX range at the beginning
    of its scope, and pops it at the end. If extra arguments are given,
    they are passed as arguments to msg.format().

    Args:
        msg (str): message to associate with the range
    N)r   formatr   )r   r   r   r   r   r	   r   o   s
   
r   )r   N)r   )__doc__
contextlibr   torch._Cr   ImportErrorr   __all__r   r   intr   r   strobjectr"   r%   r   r   r   r   r   r	   <module>   s$   




