Annotating Code with NVTX
Naming ranges for readable timelines.
Annotating Code with NVTX is a free CUDA Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CUDA Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Timelines Need Labels
A raw timeline is full of anonymous bars. NVTX lets you add your own names so the profiler reads like your code. 🏷️
What NVTX Is
NVTX is NVIDIA's Tools Extension: a tiny library for marking regions and events that Nsight then draws on the timeline.
Including the Header
You start by including one header. After that, the marking calls are available anywhere in your host code.
#include <nvtx3/nvToolsExt.h>Marking a Range
Wrap a section of work in a named range. The push starts it and the pop ends it, drawing one labeled bar.
nvtxRangePush("load data");
// work here
nvtxRangePop();Push and Pop Nest
Ranges nest like brackets. An inner push must pop before its outer one, so labels stack neatly on the timeline.
Instant Markers
For a single moment in time, drop a marker instead of a range. It pins one event, like the start of an epoch.
nvtxMark("epoch start");Color Your Ranges
You can give each range a color so stages stand out at a glance. Loading might be blue, computing might be green.
Readable Timelines
With NVTX, your Nsight view shows phases like preprocess and inference by name. You stop decoding cryptic kernel symbols.
Nearly Free When Off
When no profiler is attached, NVTX calls are almost free. You can leave the annotations in your code with no real cost.
It Is Host-Side
NVTX annotates host code, the CPU side that orchestrates work. It frames the regions where your kernels and copies happen.
RAII Wrappers
In modern C++ you often wrap a range in a small RAII object. It pops automatically when the scope ends, so you never forget.
Quick Check
You want named, labeled regions to appear on your Nsight timeline.
Recap
NVTX turns mystery bars into named ranges and markers. A few push and pop calls make your Nsight timelines instantly readable. 👏
Frequently asked questions
Is the “Annotating Code with NVTX” lesson free?
Yes — the full text of “Annotating Code with NVTX” is free to read here on the web, and the CUDA Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CUDA Academy course, upgrade to CoddyKit PRO.
What will I learn in “Annotating Code with NVTX”?
Naming ranges for readable timelines. You practise CUDA Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CUDA Academy?
No prior experience is required. CUDA Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Annotating Code with NVTX” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CUDA Academy lesson?
Yes. Every CUDA Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Timeline View in Nsight Systems
- Kernel Metrics in Nsight Compute
- Compute-Bound vs Memory-Bound
- Annotating Code with NVTX