Comments (2)
I think it's worth clarifying here that "thread" or "scoped" range objects are trivial RAII wrappers for nvtxRangePush/nvtxRangePop in the NVTX C API, and "process" or "unique" range objects are trivial RAII wrappers for nvtxRangeStart/nvtxRangeEnd.
Note that the choice of "process_range" and "thread_range" was originally based on the behavior of developer tools with hierarchical organization placing the former on a row under a Process node, and the latter under a Thread node. However, the NVTX C API docs don't directly make this distinction that RangeStart/End == process, while they do clarify RangePush/Pop is inherently specific to a CPU thread. Tools no longer make this relationship as stark as they used to -- Nsight Systems detects when both the Start/End calls for a range occur on the same thread, and show it under a Thread node, in addition to ranges that only Start or only End on that thread with visual indication of which end is related.
Ideally there would have just been one kind of range... RangeStart gives you a handle, and you pass that handle to RangeEnd. But since passing things from the beginning of a range to the end can be difficult or inefficient (consider a tool getting a "before" callback and an "after" callback around something), the Push/Pop type was added as an optimization for the case where tools could infer the relationship between the calls. There are measurable perf benefits of using Push/Pop instead of Start/End wherever possible.
The expectation for a modern C++ RAII wrapper around a handle-based kind of range would be that it is movable. So it makes sense to name it something that C++ programmers would recognize as a move-only handle class to an object that needs to be destructed when that one reference to it is dropped. So "nvtx3::unique_range" is a fairly obvious choice, given that it is implemented using std::unique_ptr, and has the same semantics as unique_ptr, unique_lock, unique_resource, etc. Also, while C++20 adds a whole API for "Ranges", these are pairs of iterators in a structure, not really confusable with NVTX ranges of code execution in a program. Even https://en.cppreference.com/w/cpp/algorithm/ranges/unique would be hard to confuse with an nvtx3::unique_range, given that it's an algorithm that rearranges a container to have repeats of values at the end.
The wrapper for Push/Pop ranges doesn't have as clear a choice, but scoped_range is the most familiar to anyone who uses scoped lock objects to manage mutexes. Boost had a scoped_lock for years, and now it's in C++17. Our "scoped" is a bit different in that it prevent usage anywhere but in stack variables, and is not movable. But since it's effectively hard-locked to a lexical scope, which must stay on one CPU thread, that does imply it uses the NVTX functions documented to be specific to a CPU thread. And since lexical scopes nest like a stack, it's easy to connect that to the Push/Pop C API names. The only other name I thought could make sense for these was "stack_range" since it's an even more direct implication, but the familiarity of "scoped_range" being like the tried and true "scoped_lock" gives that one a big advantage.
So I agree with Jake that "scoped_range" is sensible name for the thing you'd normally use, and if you get our polite compiler error message for trying to move it or use it in heap objects, "unique_range" is a sensible name for the thing you'd use instead.
from nvtx.
closed by #42
from nvtx.
Related Issues (20)
- NVTX can't annotate backward process of AI model training
- Missing include on windows for using `_wgetenv` HOT 2
- Failed to build nvtx HOT 3
- scoped_range does not work with domain::global HOT 1
- `nvToolsExt.h` defines min/max macros on Windows HOT 2
- NvToolExt_LIBRARIES-NOTFOUND
- how can i get nvToolsExt64_1.dll and nvToolsExt64_1.lib HOT 1
- Python 3.11 support HOT 3
- PyPi README missing
- pip install nvtx on macOs HOT 3
- Wheels for Mac OS and Windows HOT 1
- How to use NVTX in device code. HOT 2
- [python] Automatic annotation with function name HOT 1
- Payloads in python events? HOT 11
- __sync_val_compare_and_swap used incorrect parameter order
- `NVTX3_CPP_REQUIRE_EXPLICIT_VERSION` is problematic in header-only libraries HOT 1
- Simplify the process of using NVTX in another CMake project HOT 1
- Seeking for some explanations on the meaning of terminology in nvtx.h and nvToolsExtPayload.h
- Will NVTX3 ship the C++ V1 API for eternity?
- Meet cmake error when building nvtx3 on Jetson Orin
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvtx.