
    
9j                    D    S SK Jr  S SKrS SKJr  S SKJr   " S S5      rg)    )annotationsN)cuda)runtimec                  <    \ rS rSrSr S
S jrS rS rS rS r	S	r
g)
time_range   aO  Mark function calls with ranges using NVTX/rocTX. This object can be
used either as a decorator or a context manager.

When used as a decorator, the decorated function calls are marked as
ranges:

>>> from cupyx.profiler import time_range
>>> @time_range()
... def function_to_profile():
...     pass

When used as a context manager, it describes the enclosed block as a nested
range:

>>> from cupyx.profiler import time_range
>>> with time_range('some range in green', color_id=0):
...    # do something you want to measure
...    pass

The marked ranges are visible in the profiler (such as nvvp, nsys-ui, etc)
timeline.

Args:
    message (str): Name of a range. When used as a decorator, the default
        is ``func.__name__``.
    color_id: range color ID
    argb_color: range color in ARGB (e.g. 0xFF00FF00 for green)
    sync (bool): If ``True``, waits for completion of all outstanding
        processing on GPU before calling :func:`cupy.cuda.nvtx.RangePush()`
        or :func:`cupy.cuda.nvtx.RangePop()`

.. seealso:: :func:`cupy.cuda.nvtx.RangePush`,
    :func:`cupy.cuda.nvtx.RangePop`
Nc                    [         R                  R                  (       d  [        S5      eUb  Ub  [	        S5      eXl        Ub  UOSU l        X0l        X@l        g )Nznvtx is not installedz3Only either color_id or argb_color can be specified)	r   nvtx	availableRuntimeError
ValueErrormessagecolor_id
argb_colorsync)selfr   r   r   r   s        T/home/wildlama/miniconda3/lib/python3.13/site-packages/cupyx/profiler/_time_range.py__init__time_range.__init__1   sU    yy""677J$:E  $,$8b$	    c                p   U R                   c  [        S5      eU R                  (       a  [        R                  " 5         U R
                  b6  [        R                  R                  U R                   U R
                  5        U $ [        R                  R                  U R                   U R                  5        U $ )NzCwhen used as a context manager, the message argument cannot be None)r   r   r   r   deviceSynchronizer   r   r   
RangePushC	RangePushr   )r   s    r   	__enter__time_range.__enter__?   s    <<  99%%'??&II  t?  IIdmm<r   c                    U R                   (       a  [        R                  " 5         [        R                  R                  5         g N)r   r   r   r   r   RangePop)r   exc_type	exc_value	tracebacks       r   __exit__time_range.__exit__L   s%    99%%'		r   c                ,    U R                   c  Xl         U $ r   )r   )r   r   s     r   _recreate_cmtime_range._recreate_cmQ   s    <<"Lr   c                J   ^ ^ [         R                  " T5      UU 4S j5       nU$ )Nc                    > TR                  TR                  5         T" U 0 UD6sS S S 5        $ ! , (       d  f       g = fr   )r'   __name__)argskwargsfuncr   s     r   inner"time_range.__call__.<locals>.innerW   s.    ""4==1T,V, 211s   /
=)	functoolswraps)r   r.   r/   s   `` r   __call__time_range.__call__V   s%    			- 
	- r   )r   r   r   r   )NNNF)r+   
__module____qualname____firstlineno____doc__r   r   r$   r'   r3   __static_attributes__ r   r   r   r      s(    !H FK

r   r   )
__future__r   r1   cupyr   cupy_backends.cuda.apir   r   r:   r   r   <module>r>      s    "   *N Nr   