Ejemplo n.º 1
0
def time_range(message, color_id=None, argb_color=None):
    """A context manager to describe the enclosed block as a nested range

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

    Args:
        message: Name of a range.
        color_id: range color ID
        argb_color: range color in ARGB (e.g. 0xFF00FF00 for green)

    .. seealso:: :func:`cupy.cuda.nvtx.RangePush`
        :func:`cupy.cuda.nvtx.RangePop`
    """
    if color_id is not None and argb_color is not None:
        raise ValueError('Only either color_id or argb_color can be specified')

    if argb_color is not None:
        nvtx.RangePushC(message, argb_color)
    else:
        if color_id is None:
            color_id = -1
        nvtx.RangePush(message, color_id)
    try:
        yield
    finally:
        nvtx.RangePop()
Ejemplo n.º 2
0
 def __enter__(self):
     if self.argb_color is not None:
         nvtx.RangePushC(self.message, self.argb_color)
     else:
         nvtx.RangePush(self.message, self.color_id)
     return self
Ejemplo n.º 3
0
 def test_RangePushC(self):
     nvtx.RangePushC("test:RangePushC", 0xFF000000)
     nvtx.RangePop()