cupyx.profiler.time_range#

class cupyx.profiler.time_range(message=None, color_id=None, argb_color=None, sync=False)[source]#

使用 NVTX/rocTX 标记函数调用的时间范围。此对象可以用作装饰器或上下文管理器。

用作装饰器时,被装饰的函数调用被标记为范围

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

用作上下文管理器时,它将包含的代码块描述为嵌套范围

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

标记的范围在性能分析器(如 nvvp、nsys-ui 等)的时间轴中可见。

参数:
  • message (str) – 范围名称。用作装饰器时,默认为 func.__name__

  • color_id – 范围颜色 ID

  • argb_color – ARGB 格式的范围颜色 (例如,绿色为 0xFF00FF00)

  • sync (bool) – 如果为 True,则在调用 cupy.cuda.nvtx.RangePush()cupy.cuda.nvtx.RangePop() 之前,等待 GPU 上所有未完成的处理完成。

方法

__call__(func)[source]#

将自身作为函数调用。

__enter__()[source]#
__exit__(exc_type, exc_value, traceback)[source]#
__eq__(value, /)#

返回 self==value。

__ne__(value, /)#

返回 self!=value。

__lt__(value, /)#

返回 self<value。

__le__(value, /)#

返回 self<=value。

__gt__(value, /)#

返回 self>value。

__ge__(value, /)#

返回 self>=value。