NVIDIA NVTX (NVIDIA Tools Extension Library)

13.2.20 · active · verified Thu Apr 09

NVIDIA Tools Extension (NVTX) is a C-based API for annotating events, code ranges, and resources within applications, allowing developers to visualize and analyze performance using NVIDIA profiling tools like Nsight Systems. While `nvidia-nvtx` (version 13.2.20) provides the core C API, Python users typically interact with NVTX through the separate `nvtx` Python package (current version 0.2.15), which offers native Python wrappers for a subset of the C API. It enables profiling Python code, including CPU and GPU activities, and visualizing these on a timeline.

Warnings

Install

Imports

Quickstart

This example demonstrates how to annotate Python code using the `nvtx` package. The `@nvtx.annotate` decorator and `with nvtx.annotate` context manager create profiled ranges. To collect and visualize this data, you need to run your script with an NVIDIA profiling tool, such as NVIDIA Nsight Systems (e.g., `nsys profile -t nvtx python your_script.py`).

import time
import nvtx

@nvtx.annotate(color="blue", message="my_function_range")
def my_function():
    for i in range(3):
        with nvtx.annotate(f"my_loop_iteration_{i}", color="red"):
            time.sleep(0.01 * i)

if __name__ == "__main__":
    print("Running annotated function...")
    my_function()
    print("Function complete. Use NVIDIA Nsight Systems to view profile (e.g., nsys profile -t nvtx python your_script.py)")

view raw JSON →