NVTX C++ API Reference 1.0
C++ convenience wrappers for NVTX v3 C API
Loading...
Searching...
No Matches
nvtx3.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Licensed under the Apache License v2.0 with LLVM Exceptions.
18 * See https://nvidia.github.io/NVTX/LICENSE.txt for license information.
19 */
20
21#if defined(NVTX_AS_SYSTEM_HEADER)
22#if defined(__clang__)
23#pragma clang system_header
24#elif defined(__GNUC__) || defined(__NVCOMPILER)
25#pragma GCC system_header
26#elif defined(_MSC_VER)
27#pragma system_header
28#endif
29#endif
30
31/* Temporary helper #defines, #undef'ed at end of header */
32#define NVTX3_CPP_VERSION_MAJOR 1
33#define NVTX3_CPP_VERSION_MINOR 1
34
35/*
36 * NVTX C++ header versioning
37 *
38 * Goals
39 * 1) Allow limited coexistence of different versions of NVTX headers in a
40 * single translation unit (TU)
41 * 2) Support linking objects built with different header versions of NVTX
42 *
43 * Namespaces
44 *
45 * Symbols live in nested major/minor namespaces, e.g.,
46 * `nvtx3::v1::mv1::domain`. The minor namespace is always inlined into the
47 * major namespace. This prevents ODR issues when linking code built against
48 * different minor versions. Do not use minor-version names directly; headers
49 * ship only the latest minor.
50 *
51 * Unversioned vs versioned names
52 *
53 * By default the major namespace is also inlined into `nvtx3`, so both
54 * `nvtx3::v1::domain` and `nvtx3::domain` exist. Defining
55 * `NVTX3_CPP_REQUIRE_EXPLICIT_VERSION` disables this inlining; unversioned
56 * names are omitted. When set, you must use explicit major-version names
57 * (e.g., `nvtx3::v1::scoped_range`).
58 * With default inlining, including two different major headers in one TU is an
59 * error. With `NVTX3_CPP_REQUIRE_EXPLICIT_VERSION` defined, it is technically
60 * possible to mix major versions. However, this typically means all NVTX usage
61 * in the TU must be versioned, unless exactly one major version is included
62 * without the macro (providing unversioned symbols).
63 *
64 * Minor-version policy
65 *
66 * Minor versions are API-backward compatible. Include the highest minor
67 * version first, or just don't mix them at all. Bump the minor version for any
68 * implementation change to avoid ODR conflicts (`NVTX3_CPP_VERSION_MINOR` and
69 * `NVTX3_CPP_INLINED_VERSION_MINOR`). Do not bump
70 * `NVTX3_CPP_DEFINITIONS_V1_0`, this mechanism is no longer applied.
71 *
72 * Macros follow the same scheme, e.g., `NVTX3_V1_FUNC_RANGE`. Unversioned
73 * aliases (e.g., `NVTX3_FUNC_RANGE`) exist unless
74 * `NVTX3_CPP_REQUIRE_EXPLICIT_VERSION` is defined.
75 *
76 * The C++ version numbering described here is strictly about API compatibility
77 * and is unrelated to NVTX release version numbers.
78 *
79 * Recommendations
80 * - Prefer a single specific version of the NVTX headers per TU.
81 * - Use the latest minor version.
82 * - For maximal compatibility in complex builds or header-only code, use
83 * versioned symbols, e.g., `nvtx3::v1::domain`.
84 * - Only define `NVTX3_CPP_REQUIRE_EXPLICIT_VERSION` when you need to mix
85 * multiple major versions in the same TU and thus suppress unversioned
86 * names.
87 */
88/* clang-format off */
89#if !defined(NVTX3_CPP_REQUIRE_EXPLICIT_VERSION)
90 /* Define macro used by all definitions in this header to indicate the
91 * unversioned symbols should be defined in addition to the versioned ones.
92 */
93 #define NVTX3_INLINE_THIS_VERSION
94
95 #if !defined(NVTX3_CPP_INLINED_VERSION_MAJOR)
96 /* First occurrence of this header in the translation unit. Define macros
97 * indicating which version shall be used for unversioned symbols.
98 */
99
110 #define NVTX3_CPP_INLINED_VERSION_MAJOR 1 // NVTX3_CPP_VERSION_MAJOR
111
122 #define NVTX3_CPP_INLINED_VERSION_MINOR 1 // NVTX3_CPP_VERSION_MINOR
123 #elif NVTX3_CPP_INLINED_VERSION_MAJOR != NVTX3_CPP_VERSION_MAJOR
124 /* Unsupported case -- cannot define unversioned symbols for different major versions
125 * in the same translation unit.
126 */
127 #error \
128 "Two different major versions of the NVTX C++ Wrappers are being included in a single .cpp file, with unversioned symbols enabled in both. Only one major version can enable unversioned symbols in a .cpp file. To disable unversioned symbols, #define NVTX3_CPP_REQUIRE_EXPLICIT_VERSION before #including nvtx3.hpp, and use the versioned symbols instead."
129 #elif (NVTX3_CPP_INLINED_VERSION_MAJOR == NVTX3_CPP_VERSION_MAJOR) && \
130 (NVTX3_CPP_INLINED_VERSION_MINOR < NVTX3_CPP_VERSION_MINOR)
131 /* An older minor version of the same major version already defined unversioned
132 * symbols. The new features provided in this header will be inlined
133 * redefine the minor version macro to this header's version.
134 */
135 #undef NVTX3_CPP_INLINED_VERSION_MINOR
136 #define NVTX3_CPP_INLINED_VERSION_MINOR 1 // NVTX3_CPP_VERSION_MINOR
137 // else, already have this version or newer, nothing to do
138 #endif
139#endif
140/* clang-format on */
141
652/* Temporary helper #defines, removed with #undef at end of header */
653
654/* Some compilers do not correctly support SFINAE, which is used in this API
655 * to detect common usage errors and provide clearer error messages (by using
656 * static_assert) than the compiler would produce otherwise. These compilers
657 * will generate errors while compiling this file such as:
658 *
659 * error: 'name' is not a member of 'nvtx3::v1::domain::global'
660 *
661 * The following compiler versions are known to have this problem, and so are
662 * set by default to disable the SFINAE-based checks:
663 *
664 * - All MSVC versions prior to VS2017 Update 7 (15.7)
665 * - GCC 8.1-8.3 (the problem was fixed in GCC 8.4)
666 *
667 * If you find your compiler hits this problem, you can work around it by
668 * defining NVTX3_USE_CHECKED_OVERLOADS_FOR_GET to 0 before including this
669 * header, or you can add a check for your compiler version to this #if.
670 * Also, please report the issue on the NVTX GitHub page.
671 */
672#if !defined(NVTX3_USE_CHECKED_OVERLOADS_FOR_GET)
673#if defined(_MSC_VER) && _MSC_VER < 1914 \
674 || defined(__GNUC__) && __GNUC__ == 8 && __GNUC_MINOR__ < 4
675#define NVTX3_USE_CHECKED_OVERLOADS_FOR_GET 0
676#else
677#define NVTX3_USE_CHECKED_OVERLOADS_FOR_GET 1
678#endif
679#define NVTX3_USE_CHECKED_OVERLOADS_FOR_GET_DEFINED_HERE
680#endif
681
682/* Within this header, nvtx3::NVTX3_VERSION_NAMESPACE resolves to nvtx3::vX,
683 * where "X" is the major version number. */
684#define NVTX3_CONCAT(A, B) A##B
685#define NVTX3_NAMESPACE_FOR(VERSION) NVTX3_CONCAT(v, VERSION)
686#define NVTX3_VERSION_NAMESPACE NVTX3_NAMESPACE_FOR(NVTX3_CPP_VERSION_MAJOR)
687/* We use a different prefix to avoid ambiguity with the version namespace */
688#define NVTX3_MINOR_NAMESPACE_FOR(VERSION) NVTX3_CONCAT(mv, VERSION)
689#define NVTX3_MINOR_VERSION_NAMESPACE NVTX3_MINOR_NAMESPACE_FOR(NVTX3_CPP_VERSION_MINOR)
690
691/* Avoid duplicating #if defined(NVTX3_INLINE_THIS_VERSION) for namespaces
692 * in each minor version by making a macro to use unconditionally, which
693 * resolves to "inline" or nothing as appropriate. */
694#if defined(NVTX3_INLINE_THIS_VERSION)
695#define NVTX3_INLINE_IF_REQUESTED inline
696#else
697#define NVTX3_INLINE_IF_REQUESTED
698#endif
699
700/* Enables the use of constexpr when support for C++14 constexpr is present.
701 *
702 * Initialization of a class member that is a union to a specific union member
703 * can only be done in the body of a constructor, not in a member initializer
704 * list. A constexpr constructor must have an empty body until C++14, so there
705 * is no way to make an initializer of a member union constexpr in C++11. This
706 * macro allows making functions constexpr in C++14 or newer, but non-constexpr
707 * in C++11 compilation. It is used here on constructors that initialize their
708 * member unions.
709 */
710#if __cpp_constexpr >= 201304L
711#define NVTX3_CONSTEXPR_IF_CPP14 constexpr
712#else
713#define NVTX3_CONSTEXPR_IF_CPP14
714#endif
715
716/* Enables the use of constexpr when support for C++20 constexpr is present.
717 */
718#if __cplusplus >= 202002L
719#define NVTX3_CONSTEXPR_IF_CPP20 constexpr
720#else
721#define NVTX3_CONSTEXPR_IF_CPP20
722#endif
723
724// Macro wrappers for C++ attributes
725#if !defined(__has_cpp_attribute)
726#define __has_cpp_attribute(x) 0
727#endif
728#if __has_cpp_attribute(maybe_unused)
729#define NVTX3_MAYBE_UNUSED [[maybe_unused]]
730#else
731#define NVTX3_MAYBE_UNUSED
732#endif
733#if __has_cpp_attribute(nodiscard)
734#define NVTX3_NO_DISCARD [[nodiscard]]
735#else
736#define NVTX3_NO_DISCARD
737#endif
738
739 /* Use a macro for static asserts, which defaults to static_assert, but that
740 * testing tools can replace with a logging function. For example:
741 * #define NVTX3_STATIC_ASSERT(c, m) \
742 * do { if (!(c)) printf("static_assert would fail: %s\n", m); } while (0)
743 */
744#if !defined(NVTX3_STATIC_ASSERT)
745#define NVTX3_STATIC_ASSERT(condition, message) static_assert(condition, message)
746#define NVTX3_STATIC_ASSERT_DEFINED_HERE
747#endif
748
749/* The original idea here was to have separate implementation sections, enclosed
750 * in guard macros for each minor version. However, this approach was very
751 * limited in practice. Specifically, it is not possible to add constructors to
752 * `event_attributes`, which was needed for version 1.1 and is API compatible.
753 * So we stick with `NVTX3_CPP_DEFINITIONS_V1_0` as guard macro for now, even
754 * with bumped minor versions.
755 */
756#ifndef NVTX3_CPP_DEFINITIONS_V1_0
757#define NVTX3_CPP_DEFINITIONS_V1_0
758
759#include "nvToolsExt.h"
760#include "nvToolsExtPayload.h"
761#include "nvToolsExtPayloadHelper.h"
762
763#include <memory>
764#include <string>
765#include <type_traits>
766#include <utility>
767#include <cstddef>
768#include <cstdint>
769
770namespace nvtx3 {
771
772NVTX3_INLINE_IF_REQUESTED namespace NVTX3_VERSION_NAMESPACE
773{
774inline namespace NVTX3_MINOR_VERSION_NAMESPACE
775{
776
777namespace detail {
778
779template <typename Unused>
780struct always_false : std::false_type {};
781
782template <typename T, typename = void>
783struct has_name : std::false_type {};
784template <typename T>
785struct has_name<T, decltype((void)T::name, void())> : std::true_type {};
786
787template <typename T, typename = void>
788struct has_id : std::false_type {};
789template <typename T>
790struct has_id<T, decltype((void)T::id, void())> : std::true_type {};
791
792template <typename T, typename = void>
793struct has_message : std::false_type {};
794template <typename T>
795struct has_message<T, decltype((void)T::message, void())> : std::true_type {};
796
797template <typename T, typename = void>
798struct is_c_string : std::false_type {};
799template <typename T>
800struct is_c_string<T, typename std::enable_if<
801 std::is_convertible<T, char const* >::value ||
802 std::is_convertible<T, wchar_t const*>::value
803>::type> : std::true_type {};
804
805template <typename T>
806using is_uint32 = std::is_same<typename std::decay<T>::type, uint32_t>;
807
808template <typename... Args>
809static inline void silence_unused(Args const&...) noexcept {}
810
811// Type trait to check for a .data() member returning T* or const T*
812// Some day, we can just use std::span
813template <typename T, typename TD>
814struct has_data_member
815{
816private:
817 template <typename U>
818 static auto test_data(int) -> decltype(std::declval<const U>().data());
819 template <typename>
820 static auto test_data(...) -> void;
821 using return_type = decltype(test_data<T>(0));
822
823public:
824 static constexpr bool value =
825 std::is_same<return_type, TD*>::value || std::is_same<return_type, TD const*>::value;
826};
827
828// Type trait to check for a .size() member returning something convertible to size_t
829template <typename T>
830struct has_size_member
831{
832private:
833 template <typename U>
834 static auto test_size(int) -> decltype(std::declval<const U>().size());
835 template <typename>
836 static auto test_size(...) -> void;
837 using return_type = decltype(test_size<T>(0));
838
839public:
840 static constexpr bool value = !std::is_same<return_type, void>::value &&
841 std::is_convertible<return_type, size_t>::value;
842};
843
854template <typename W, typename U, typename = void>
855struct is_safe_wrapper_of : std::false_type
856{
857};
858
859template <typename W, typename U>
860struct is_safe_wrapper_of<
861 W,
862 U,
863 typename std::enable_if<
864 std::is_standard_layout<W>::value && std::is_standard_layout<U>::value &&
865 std::is_trivially_copyable<W>::value && std::is_trivially_copyable<U>::value &&
866 sizeof(W) == sizeof(U)>::type> : std::true_type
867{
868};
869} // namespace detail
870
924class domain {
925 public:
926 domain(domain const&) = delete;
927 domain& operator=(domain const&) = delete;
928 domain(domain&&) = delete;
929 domain& operator=(domain&&) = delete;
930
942 struct global {
943 };
944
945#if NVTX3_USE_CHECKED_OVERLOADS_FOR_GET
990 template <typename D = global,
991 typename std::enable_if<
992 detail::is_c_string<decltype(D::name)>::value
993 , int>::type = 0>
994 NVTX3_NO_DISCARD static domain const& get() noexcept
995 {
996 static domain const d(D::name);
997 return d;
998 }
999
1005 template <typename D = global,
1006 typename std::enable_if<
1007 !detail::is_c_string<decltype(D::name)>::value
1008 , int>::type = 0>
1009 NVTX3_NO_DISCARD static domain const& get() noexcept
1010 {
1011 NVTX3_STATIC_ASSERT(detail::always_false<D>::value,
1012 "Type used to identify an NVTX domain must contain a static constexpr member "
1013 "called 'name' of type const char* or const wchar_t* -- 'name' member is not "
1014 "convertible to either of those types");
1015 static domain const unused;
1016 return unused; // Function must compile for static_assert to be triggered
1017 }
1018
1023 template <typename D = global,
1024 typename std::enable_if<
1025 !detail::has_name<D>::value
1026 , int>::type = 0>
1027 NVTX3_NO_DISCARD static domain const& get() noexcept
1028 {
1029 NVTX3_STATIC_ASSERT(detail::always_false<D>::value,
1030 "Type used to identify an NVTX domain must contain a static constexpr member "
1031 "called 'name' of type const char* or const wchar_t* -- 'name' member is missing");
1032 static domain const unused;
1033 return unused; // Function must compile for static_assert to be triggered
1034 }
1035#else
1036 template <typename D = global>
1037 NVTX3_NO_DISCARD static domain const& get() noexcept
1038 {
1039 static domain const d(D::name);
1040 return d;
1041 }
1042#endif
1043
1050 operator nvtxDomainHandle_t() const noexcept { return _domain; }
1051
1052 private:
1061 explicit domain(char const* name) noexcept : _domain{nvtxDomainCreateA(name)} {}
1062
1071 explicit domain(wchar_t const* name) noexcept : _domain{nvtxDomainCreateW(name)} {}
1072
1081 explicit domain(std::string const& name) noexcept : domain{name.c_str()} {}
1082
1091 explicit domain(std::wstring const& name) noexcept : domain{name.c_str()} {}
1092
1101 constexpr domain() noexcept {}
1102
1117 ~domain() = default;
1118
1119 private:
1120 nvtxDomainHandle_t const _domain{};
1121};
1122
1136template <>
1137NVTX3_NO_DISCARD inline domain const& domain::get<domain::global>() noexcept
1138{
1139 static domain const d{};
1140 return d;
1141}
1142
1148struct rgb {
1150 using component_type = uint8_t;
1151
1162 constexpr rgb(
1163 component_type red_,
1164 component_type green_,
1165 component_type blue_) noexcept
1166 : red{red_}, green{green_}, blue{blue_}
1167 {
1168 }
1169
1173};
1174
1180struct argb final : rgb {
1193 constexpr argb(
1194 component_type alpha_,
1195 component_type red_,
1196 component_type green_,
1197 component_type blue_) noexcept
1198 : rgb{red_, green_, blue_}, alpha{alpha_}
1199 {
1200 }
1201
1203};
1204
1214class color {
1215 public:
1217 using value_type = uint32_t;
1218
1236 constexpr explicit color(value_type hex_code) noexcept : _value{hex_code} {}
1237
1244 constexpr color(argb argb_) noexcept
1245 : color{from_bytes_msb_to_lsb(argb_.alpha, argb_.red, argb_.green, argb_.blue)}
1246 {
1247 }
1248
1257 constexpr color(rgb rgb_) noexcept
1258 : color{from_bytes_msb_to_lsb(0xFF, rgb_.red, rgb_.green, rgb_.blue)}
1259 {
1260 }
1261
1266 constexpr value_type get_value() const noexcept { return _value; }
1267
1272 constexpr nvtxColorType_t get_type() const noexcept { return _type; }
1273
1274 color() = delete;
1275 ~color() = default;
1276 color(color const&) = default;
1277 color& operator=(color const&) = default;
1278 color(color&&) = default;
1279 color& operator=(color&&) = default;
1280
1281 private:
1287 constexpr static value_type from_bytes_msb_to_lsb(
1288 uint8_t byte3,
1289 uint8_t byte2,
1290 uint8_t byte1,
1291 uint8_t byte0) noexcept
1292 {
1293 return uint32_t{byte3} << 24 | uint32_t{byte2} << 16 | uint32_t{byte1} << 8 | uint32_t{byte0};
1294 }
1295
1296 value_type _value{};
1297 nvtxColorType_t _type{NVTX_COLOR_ARGB};
1298};
1299
1322 public:
1324 using id_type = uint32_t;
1325
1335 constexpr explicit category(id_type id) noexcept : id_{id} {}
1336
1341 constexpr id_type get_id() const noexcept { return id_; }
1342
1343 category() = delete;
1344 ~category() = default;
1345 category(category const&) = default;
1346 category& operator=(category const&) = default;
1347 category(category&&) = default;
1348 category& operator=(category&&) = default;
1349
1350 private:
1351 id_type id_{};
1352};
1353
1403template <typename D = domain::global>
1404class named_category_in final : public category {
1405 public:
1406#if NVTX3_USE_CHECKED_OVERLOADS_FOR_GET
1441 template <typename C,
1442 typename std::enable_if<
1443 detail::is_c_string<decltype(C::name)>::value &&
1444 detail::is_uint32<decltype(C::id)>::value
1445 , int>::type = 0>
1446 static named_category_in const& get() noexcept
1447 {
1448 static named_category_in const cat(C::id, C::name);
1449 return cat;
1450 }
1451
1458 template <typename C,
1459 typename std::enable_if<
1460 !detail::is_c_string<decltype(C::name)>::value ||
1461 !detail::is_uint32<decltype(C::id)>::value
1462 , int>::type = 0>
1463 NVTX3_NO_DISCARD static named_category_in const& get() noexcept
1464 {
1465 NVTX3_STATIC_ASSERT(detail::is_c_string<decltype(C::name)>::value,
1466 "Type used to name an NVTX category must contain a static constexpr member "
1467 "called 'name' of type const char* or const wchar_t* -- 'name' member is not "
1468 "convertible to either of those types");
1469 NVTX3_STATIC_ASSERT(detail::is_uint32<decltype(C::id)>::value,
1470 "Type used to name an NVTX category must contain a static constexpr member "
1471 "called 'id' of type uint32_t -- 'id' member is the wrong type");
1472 static named_category_in const unused;
1473 return unused; // Function must compile for static_assert to be triggered
1474 }
1475
1480 template <typename C,
1481 typename std::enable_if<
1482 !detail::has_name<C>::value ||
1483 !detail::has_id<C>::value
1484 , int>::type = 0>
1485 NVTX3_NO_DISCARD static named_category_in const& get() noexcept
1486 {
1487 NVTX3_STATIC_ASSERT(detail::has_name<C>::value,
1488 "Type used to name an NVTX category must contain a static constexpr member "
1489 "called 'name' of type const char* or const wchar_t* -- 'name' member is missing");
1490 NVTX3_STATIC_ASSERT(detail::has_id<C>::value,
1491 "Type used to name an NVTX category must contain a static constexpr member "
1492 "called 'id' of type uint32_t -- 'id' member is missing");
1493 static named_category_in const unused;
1494 return unused; // Function must compile for static_assert to be triggered
1495 }
1496#else
1497 template <typename C>
1498 NVTX3_NO_DISCARD static named_category_in const& get() noexcept
1499 {
1500 static named_category_in const cat(C::id, C::name);
1501 return cat;
1502 }
1503#endif
1504
1505 private:
1506 // Default constructor is only used internally for static_assert(false) cases.
1507 named_category_in() noexcept : category{0} {}
1508
1509 public:
1520 named_category_in(id_type id, char const* name) noexcept : category{id}
1521 {
1522#ifndef NVTX_DISABLE
1523 nvtxDomainNameCategoryA(domain::get<D>(), get_id(), name);
1524#else
1525 (void)id;
1526 (void)name;
1527#endif
1528 }
1529
1540 named_category_in(id_type id, wchar_t const* name) noexcept : category{id}
1541 {
1542#ifndef NVTX_DISABLE
1543 nvtxDomainNameCategoryW(domain::get<D>(), get_id(), name);
1544#else
1545 (void)id;
1546 (void)name;
1547#endif
1548 }
1549};
1550
1556
1603template <typename D = domain::global>
1605 public:
1606#if NVTX3_USE_CHECKED_OVERLOADS_FOR_GET
1640 template <typename M,
1641 typename std::enable_if<
1642 detail::is_c_string<decltype(M::message)>::value
1643 , int>::type = 0>
1644 NVTX3_NO_DISCARD static registered_string_in const& get() noexcept
1645 {
1646 static registered_string_in const regstr(M::message);
1647 return regstr;
1648 }
1649
1655 template <typename M,
1656 typename std::enable_if<
1657 !detail::is_c_string<decltype(M::message)>::value
1658 , int>::type = 0>
1659 NVTX3_NO_DISCARD static registered_string_in const& get() noexcept
1660 {
1661 NVTX3_STATIC_ASSERT(detail::always_false<M>::value,
1662 "Type used to register an NVTX string must contain a static constexpr member "
1663 "called 'message' of type const char* or const wchar_t* -- 'message' member is "
1664 "not convertible to either of those types");
1665 static registered_string_in const unused;
1666 return unused; // Function must compile for static_assert to be triggered
1667 }
1668
1673 template <typename M,
1674 typename std::enable_if<
1675 !detail::has_message<M>::value
1676 , int>::type = 0>
1677 NVTX3_NO_DISCARD static registered_string_in const& get() noexcept
1678 {
1679 NVTX3_STATIC_ASSERT(detail::always_false<M>::value,
1680 "Type used to register an NVTX string must contain a static constexpr member "
1681 "called 'message' of type const char* or const wchar_t* -- 'message' member "
1682 "is missing");
1683 static registered_string_in const unused;
1684 return unused; // Function must compile for static_assert to be triggered
1685 }
1686#else
1687 template <typename M>
1688 NVTX3_NO_DISCARD static registered_string_in const& get() noexcept
1689 {
1690 static registered_string_in const regstr(M::message);
1691 return regstr;
1692 }
1693#endif
1694
1706 explicit registered_string_in(char const* msg) noexcept
1707 : handle_{nvtxDomainRegisterStringA(domain::get<D>(), msg)}
1708 {
1709 }
1710
1722 explicit registered_string_in(std::string const& msg) noexcept
1723 : registered_string_in{msg.c_str()} {}
1724
1736 explicit registered_string_in(wchar_t const* msg) noexcept
1737 : handle_{nvtxDomainRegisterStringW(domain::get<D>(), msg)}
1738 {
1739 }
1740
1752 explicit registered_string_in(std::wstring const& msg) noexcept
1753 : registered_string_in{msg.c_str()} {}
1754
1759 nvtxStringHandle_t get_handle() const noexcept
1760 {
1761 // We want to ensure that we can use the registered_string in place of a handle
1762 // in a payload data struct.
1763 NVTX3_STATIC_ASSERT(
1764 (detail::is_safe_wrapper_of<registered_string_in<D>, nvtxStringHandle_t>::value),
1765 "Internal error! registered_string_in is potentially unsafe.");
1766 return handle_;
1767 }
1768
1769private:
1770 // Default constructor is only used internally for static_assert(false) cases.
1771 registered_string_in() noexcept {}
1772public:
1773 ~registered_string_in() = default;
1775 registered_string_in& operator=(registered_string_in const&) = default;
1777 registered_string_in& operator=(registered_string_in&&) = default;
1778
1779 private:
1780 nvtxStringHandle_t handle_{};
1782};
1783
1789
1827class message {
1828 public:
1829 using value_type = nvtxMessageValue_t;
1830
1836 NVTX3_CONSTEXPR_IF_CPP14 message(char const* msg) noexcept : type_{NVTX_MESSAGE_TYPE_ASCII}
1837 {
1838 value_.ascii = msg;
1839 }
1840
1846 message(std::string const& msg) noexcept : message{msg.c_str()} {}
1847
1856#ifndef NVTX3_ALLOW_RVALUE_CONSTRUCTORS
1857 message(std::string&&) = delete;
1858#endif
1859
1865 NVTX3_CONSTEXPR_IF_CPP14 message(wchar_t const* msg) noexcept : type_{NVTX_MESSAGE_TYPE_UNICODE}
1866 {
1867 value_.unicode = msg;
1868 }
1869
1875 message(std::wstring const& msg) noexcept : message{msg.c_str()} {}
1876
1885#ifndef NVTX3_ALLOW_RVALUE_CONSTRUCTORS
1886 message(std::wstring&&) = delete;
1887#endif
1888
1897 template <typename D>
1898 NVTX3_CONSTEXPR_IF_CPP14 message(registered_string_in<D> const& msg) noexcept
1899 : type_{NVTX_MESSAGE_TYPE_REGISTERED}
1900 {
1901 value_.registered = msg.get_handle();
1902 }
1903
1910 constexpr message(
1911 nvtxMessageType_t const& type,
1912 nvtxMessageValue_t const& value) noexcept
1913 : type_{type}, value_(value)
1914 {
1915 }
1916
1922 NVTX3_CONSTEXPR_IF_CPP14 message(nvtxStringHandle_t handle) noexcept
1923 : type_{NVTX_MESSAGE_TYPE_REGISTERED}
1924 {
1925 value_.registered = handle;
1926 }
1927
1932 constexpr value_type get_value() const noexcept { return value_; }
1933
1938 constexpr nvtxMessageType_t get_type() const noexcept { return type_; }
1939
1940 private:
1941 nvtxMessageType_t type_{};
1942 nvtxMessageValue_t value_{};
1943};
1944
1961class payload {
1962 public:
1963 using value_type = typename nvtxEventAttributes_v2::payload_t;
1964
1970 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(int64_t value) noexcept
1971 : type_{NVTX_PAYLOAD_TYPE_INT64}, value_{}
1972 {
1973 value_.llValue = value;
1974 }
1975
1981 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(int32_t value) noexcept
1982 : type_{NVTX_PAYLOAD_TYPE_INT32}, value_{}
1983 {
1984 value_.iValue = value;
1985 }
1986
1992 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(uint64_t value) noexcept
1993 : type_{NVTX_PAYLOAD_TYPE_UNSIGNED_INT64}, value_{}
1994 {
1995 value_.ullValue = value;
1996 }
1997
2003 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(uint32_t value) noexcept
2004 : type_{NVTX_PAYLOAD_TYPE_UNSIGNED_INT32}, value_{}
2005 {
2006 value_.uiValue = value;
2007 }
2008
2015 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(float value) noexcept
2016 : type_{NVTX_PAYLOAD_TYPE_FLOAT}, value_{}
2017 {
2018 value_.fValue = value;
2019 }
2020
2027 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(double value) noexcept
2028 : type_{NVTX_PAYLOAD_TYPE_DOUBLE}, value_{}
2029 {
2030 value_.dValue = value;
2031 }
2032
2039 constexpr payload(
2040 nvtxPayloadType_t const& type,
2041 value_type const& value) noexcept
2042 : type_{type}, value_(value)
2043 {
2044 }
2045
2050 constexpr value_type get_value() const noexcept { return value_; }
2051
2056 constexpr nvtxPayloadType_t get_type() const noexcept { return type_; }
2057
2058 private:
2059 nvtxPayloadType_t type_;
2060 value_type value_;
2061};
2062
2075{
2076private:
2082 schema()
2083 : _schema_id{0}
2084 {}
2085
2086 public:
2087 schema(schema const&) = delete;
2088 schema& operator=(schema const&) = delete;
2089 schema(schema&&) = delete;
2090 schema& operator=(schema&&) = delete;
2091
2100 explicit schema(uint64_t id)
2101 : _schema_id{id}
2102 {}
2103
2114 template <typename T>
2115 NVTX3_NO_DISCARD static schema const& get() noexcept
2116 {
2117 NVTX3_STATIC_ASSERT(
2118 detail::always_false<T>::value,
2119 "payload_data schema deduction requires a template specialization. Use the macro "
2120 "NVTX3_DEFINE_SCHEMA_GET to generate this specialization.");
2121 static schema unused;
2122 return unused;
2123 }
2124
2128 uint64_t get_handle() const noexcept
2129 {
2130 return _schema_id;
2131 }
2132
2133private:
2134 uint64_t const _schema_id;
2135};
2136
2145{
2146public:
2154 explicit payload_data(nvtxPayloadData_t const& pd)
2155 : data_(pd)
2156 {}
2157
2171 // We cannot simply delete the rvalue constructor here because with a template
2172 // parameter that would be a forwarding reference. Thus, we have this one
2173 // ctor with a forwarding reference and use a static assert for the rvalue check.
2174 // Disable this for the C-style nvtxPayloadData_t to prefer above ctor for non-const.
2175 template <
2176 typename R,
2177 typename T = typename std::remove_cv<typename std::remove_reference<R>::type>::type,
2178 typename = typename std::enable_if<!std::is_same<T, nvtxPayloadData_t>::value>::type>
2179 explicit payload_data(R&& t)
2180 : data_{schema::get<T>().get_handle(), sizeof(T), &t}
2181 {
2182#ifndef NVTX3_ALLOW_RVALUE_CONSTRUCTORS
2183 NVTX3_STATIC_ASSERT(
2184 std::is_lvalue_reference<R>::value,
2185 "payload_data requires an lvalue reference to the underlying data. Constructing "
2186 "from an rvalue is potentially unsafe and therefore forbidden.");
2187#endif
2188 NVTX3_STATIC_ASSERT(
2189 std::is_standard_layout<T>::value && std::is_trivially_copyable<T>::value,
2190 "structs used for NVTX3 payload schema must be standard layout and trivially copyable");
2191 }
2192
2205 template <typename T>
2206 explicit payload_data(T const& t, schema s)
2207 : data_{s.get_handle(), sizeof(T), &t}
2208 {
2209 NVTX3_STATIC_ASSERT(
2210 std::is_standard_layout<T>::value && std::is_trivially_copyable<T>::value,
2211 "structs used for NVTX3 payload schema must be standard layout and trivially copyable");
2212 }
2213
2218 uint64_t as_ull_value() const noexcept
2219 {
2220 NVTX3_STATIC_ASSERT(
2221 (detail::is_safe_wrapper_of<payload_data, nvtxPayloadData_t>::value),
2222 "Internal error! payload_data is potentially unsafe.");
2223 return NVTX_POINTER_AS_PAYLOAD_ULLVALUE(&data_);
2224 }
2225
2226private:
2227 nvtxPayloadData_t data_;
2228};
2229
2289 public:
2290 using value_type = nvtxEventAttributes_t;
2291
2296 constexpr event_attributes() noexcept
2297 : attributes_{
2298 NVTX_VERSION, // version
2299 sizeof(nvtxEventAttributes_t), // size
2300 0, // category
2301 NVTX_COLOR_UNKNOWN, // color type
2302 0, // color value
2303 NVTX_PAYLOAD_UNKNOWN, // payload type
2304 0, // reserved 4B
2305 {0}, // payload value (union)
2306 NVTX_MESSAGE_UNKNOWN, // message type
2307 {nullptr} // message value (union)
2308 }
2309 {
2310 }
2311
2319 template <typename... Args>
2320 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(category const& c, Args const&... args) noexcept
2321 : event_attributes(args...)
2322 {
2323 attributes_.category = c.get_id();
2324 }
2325
2333 template <typename... Args>
2334 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(color const& c, Args const&... args) noexcept
2335 : event_attributes(args...)
2336 {
2337 attributes_.color = c.get_value();
2338 attributes_.colorType = c.get_type();
2339 }
2340
2348 template <typename... Args>
2349 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(payload const& p, Args const&... args) noexcept
2350 : event_attributes(args...)
2351 {
2352 attributes_.payload = p.get_value();
2353 attributes_.payloadType = p.get_type();
2354 }
2355
2363 template <typename... Args>
2364 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(payload_data const& pd, Args const&... args) noexcept
2365 : event_attributes(args...)
2366 {
2367 attributes_.payloadType = NVTX_PAYLOAD_TYPE_EXT;
2368 attributes_.reserved0 = 1;
2369 attributes_.payload.ullValue = pd.as_ull_value();
2370 }
2371
2379#ifndef NVTX3_ALLOW_RVALUE_CONSTRUCTORS
2380 template <typename... Args>
2381 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(payload_data&& pd, Args const&... args) = delete;
2382#endif
2383
2393 template <
2394 typename T,
2395 typename... Args,
2396 typename = typename std::enable_if<
2397 detail::has_data_member<T, payload_data>::value && detail::has_size_member<T>::value>::type>
2398 NVTX3_CONSTEXPR_IF_CPP20 explicit event_attributes(T&& pdc, Args const&... args) noexcept
2399 : event_attributes(args...)
2400 {
2401 NVTX3_STATIC_ASSERT(
2402 std::is_lvalue_reference<T>::value,
2403 "event_attributes requires an lvalue reference to the underlying data. "
2404 "Constructing from an rvalue is potentially unsafe and therefore forbidden.");
2405 attributes_.payloadType = NVTX_PAYLOAD_TYPE_EXT;
2406 attributes_.reserved0 = static_cast<int32_t>(pdc.size()); // Cast size to int32_t
2407 attributes_.payload.ullValue = pdc.data()->as_ull_value();
2408 }
2409
2417 template <typename... Args>
2418 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(message const& m, Args const&... args) noexcept
2419 : event_attributes(args...)
2420 {
2421 attributes_.message = m.get_value();
2422 attributes_.messageType = m.get_type();
2423 }
2424
2425 ~event_attributes() = default;
2426 event_attributes(event_attributes const&) = default;
2427 event_attributes& operator=(event_attributes const&) = default;
2429 event_attributes& operator=(event_attributes&&) = default;
2430
2435 constexpr value_type const* get() const noexcept { return &attributes_; }
2436
2437 private:
2438 value_type attributes_{};
2439};
2440
2488template <class D = domain::global>
2489class NVTX3_MAYBE_UNUSED scoped_range_in {
2490 public:
2505 explicit scoped_range_in(event_attributes const& attr) noexcept
2506 {
2507#ifndef NVTX_DISABLE
2508 nvtxDomainRangePushEx(domain::get<D>(), attr.get());
2509#else
2510 (void)attr;
2511#endif
2512 }
2513
2534 template <typename... Args>
2535 explicit scoped_range_in(Args const&... args) noexcept
2537 {
2538 }
2539
2546
2553 void* operator new(std::size_t) = delete;
2554
2555 scoped_range_in(scoped_range_in const&) = delete;
2556 scoped_range_in& operator=(scoped_range_in const&) = delete;
2557 scoped_range_in(scoped_range_in&&) = delete;
2558 scoped_range_in& operator=(scoped_range_in&&) = delete;
2559
2564 {
2565#ifndef NVTX_DISABLE
2566 nvtxDomainRangePop(domain::get<D>());
2567#endif
2568 }
2569};
2570
2576
2577namespace detail {
2578
2580template <typename D = domain::global>
2581class NVTX3_MAYBE_UNUSED optional_scoped_range_in
2582{
2583public:
2584 optional_scoped_range_in() = default;
2585
2586 void begin(event_attributes const& attr) noexcept
2587 {
2588#ifndef NVTX_DISABLE
2589 // This class is not meant to be part of the public NVTX C++ API and should
2590 // only be used in the `NVTX3_FUNC_RANGE_IF` and `NVTX3_FUNC_RANGE_IF_IN`
2591 // macros. However, to prevent developers from misusing this class, make
2592 // sure to not start multiple ranges.
2593 if (initialized) { return; }
2594
2595 nvtxDomainRangePushEx(domain::get<D>(), attr.get());
2596 initialized = true;
2597#else
2598 (void)attr;
2599#endif
2600 }
2601
2602 ~optional_scoped_range_in() noexcept
2603 {
2604#ifndef NVTX_DISABLE
2605 if (initialized) { nvtxDomainRangePop(domain::get<D>()); }
2606#endif
2607 }
2608
2609 void* operator new(std::size_t) = delete;
2610 optional_scoped_range_in(optional_scoped_range_in const&) = delete;
2611 optional_scoped_range_in& operator=(optional_scoped_range_in const&) = delete;
2612 optional_scoped_range_in(optional_scoped_range_in&&) = delete;
2613 optional_scoped_range_in& operator=(optional_scoped_range_in&&) = delete;
2614
2615private:
2616#ifndef NVTX_DISABLE
2617 bool initialized = false;
2618#endif
2619};
2621
2622} // namespace detail
2623
2632 using value_type = nvtxRangeId_t;
2633
2634
2639 constexpr explicit range_handle(value_type id) noexcept : _range_id{id} {}
2640
2648 constexpr range_handle() noexcept = default;
2649
2661 constexpr explicit operator bool() const noexcept { return get_value() != null_range_id; }
2662
2669 constexpr range_handle(std::nullptr_t) noexcept {}
2670
2676 constexpr value_type get_value() const noexcept { return _range_id; }
2677
2678 private:
2680 static constexpr value_type null_range_id = nvtxRangeId_t{0};
2681
2682 value_type _range_id{null_range_id};
2683};
2684
2691inline constexpr bool operator==(range_handle lhs, range_handle rhs) noexcept
2692{
2693 return lhs.get_value() == rhs.get_value();
2694}
2695
2702inline constexpr bool operator!=(range_handle lhs, range_handle rhs) noexcept { return !(lhs == rhs); }
2703
2733template <typename D = domain::global>
2734NVTX3_NO_DISCARD inline range_handle start_range_in(event_attributes const& attr) noexcept
2735{
2736#ifndef NVTX_DISABLE
2737 return range_handle{nvtxDomainRangeStartEx(domain::get<D>(), attr.get())};
2738#else
2739 (void)attr;
2740 return {};
2741#endif
2742}
2743
2774template <typename D = domain::global, typename... Args>
2775NVTX3_NO_DISCARD inline range_handle start_range_in(Args const&... args) noexcept
2776{
2777#ifndef NVTX_DISABLE
2778 return start_range_in<D>(event_attributes{args...});
2779#else
2780 detail::silence_unused(args...);
2781 return {};
2782#endif
2783}
2784
2811NVTX3_NO_DISCARD inline range_handle start_range(event_attributes const& attr) noexcept
2812{
2813#ifndef NVTX_DISABLE
2814 return start_range_in<domain::global>(attr);
2815#else
2816 (void)attr;
2817 return {};
2818#endif
2819}
2820
2848template <typename... Args>
2849NVTX3_NO_DISCARD inline range_handle start_range(Args const&... args) noexcept
2850{
2851#ifndef NVTX_DISABLE
2852 return start_range_in<domain::global>(args...);
2853#else
2854 detail::silence_unused(args...);
2855 return {};
2856#endif
2857}
2858
2874template <typename D = domain::global>
2875inline void end_range_in(range_handle r) noexcept
2876{
2877#ifndef NVTX_DISABLE
2878 nvtxDomainRangeEnd(domain::get<D>(), r.get_value());
2879#else
2880 (void)r;
2881#endif
2882}
2883
2897inline void end_range(range_handle r) noexcept
2898{
2899#ifndef NVTX_DISABLE
2900 end_range_in<domain::global>(r);
2901#else
2902 (void)r;
2903#endif
2904}
2905
2927template <typename D = domain::global>
2928class NVTX3_MAYBE_UNUSED unique_range_in {
2929 public:
2943 explicit unique_range_in(event_attributes const& attr) noexcept
2944 : handle_{start_range_in<D>(attr)}
2945 {
2946 }
2947
2967 template <typename... Args>
2968 explicit unique_range_in(Args const&... args) noexcept
2970 {
2971 }
2972
2979
2984 ~unique_range_in() noexcept = default;
2985
2992 unique_range_in(unique_range_in&& other) noexcept = default;
2993
3000 unique_range_in& operator=(unique_range_in&& other) noexcept = default;
3001
3005
3008 unique_range_in& operator=(unique_range_in const&) = delete;
3009
3010 private:
3011
3012 struct end_range_handle {
3013 using pointer = range_handle;
3014 void operator()(range_handle h) const noexcept { end_range_in<D>(h); }
3015 };
3016
3018 std::unique_ptr<range_handle, end_range_handle> handle_;
3019};
3020
3026
3050template <typename D = domain::global>
3051inline void mark_in(event_attributes const& attr) noexcept
3052{
3053#ifndef NVTX_DISABLE
3054 nvtxDomainMarkEx(domain::get<D>(), attr.get());
3055#else
3056 (void)(attr);
3057#endif
3058}
3059
3087template <typename D = domain::global, typename... Args>
3088inline void mark_in(Args const&... args) noexcept
3089{
3090#ifndef NVTX_DISABLE
3091 mark_in<D>(event_attributes{args...});
3092#else
3093 detail::silence_unused(args...);
3094#endif
3095}
3096
3117inline void mark(event_attributes const& attr) noexcept
3118{
3119#ifndef NVTX_DISABLE
3120 mark_in<domain::global>(attr);
3121#else
3122 (void)attr;
3123#endif
3124}
3125
3150template <typename... Args>
3151inline void mark(Args const&... args) noexcept
3152{
3153#ifndef NVTX_DISABLE
3154 mark_in<domain::global>(args...);
3155#else
3156 detail::silence_unused(args...);
3157#endif
3158}
3159
3160} // namespace NVTX3_MINOR_VERSION_NAMESPACE
3161} // namespace NVTX3_VERSION_NAMESPACE
3162} // namespace nvtx3
3163
3164#ifndef NVTX_DISABLE
3193#define NVTX3_V1_FUNC_RANGE_IN(D) \
3194 static ::nvtx3::v1::registered_string_in<D> const nvtx3_func_name__{__func__}; \
3195 static ::nvtx3::v1::event_attributes const nvtx3_func_attr__{nvtx3_func_name__}; \
3196 ::nvtx3::v1::scoped_range_in<D> const nvtx3_range__{nvtx3_func_attr__}
3197
3214#define NVTX3_V1_FUNC_RANGE_IF_IN(D, C) \
3215 ::nvtx3::v1::detail::optional_scoped_range_in<D> optional_nvtx3_range__; \
3216 if (C) { \
3217 static ::nvtx3::v1::registered_string_in<D> const nvtx3_func_name__{__func__}; \
3218 static ::nvtx3::v1::event_attributes const nvtx3_func_attr__{nvtx3_func_name__}; \
3219 optional_nvtx3_range__.begin(nvtx3_func_attr__); \
3220 } (void)0
3221#else /* NVTX_DISABLE */
3222#define NVTX3_V1_FUNC_RANGE_IN(D) (void)0
3223#define NVTX3_V1_FUNC_RANGE_IF_IN(D, C) (void)(C)
3224#endif /* NVTX_DISABLE */
3225
3248#define NVTX3_V1_FUNC_RANGE() NVTX3_V1_FUNC_RANGE_IN(::nvtx3::v1::domain::global)
3249
3261#define NVTX3_V1_FUNC_RANGE_IF(C) NVTX3_V1_FUNC_RANGE_IF_IN(::nvtx3::v1::domain::global, C)
3262
3263// We need another helper macro because the other one will get undefined
3264#if __has_cpp_attribute(nodiscard)
3265#define NVTX3_V1_NO_DISCARD [[nodiscard]]
3266#else
3267#define NVTX3_V1_NO_DISCARD
3268#endif
3301#define NVTX3_V1_DEFINE_SCHEMA_GET(dom, struct_id, schema_name, entries) \
3302 template <> \
3303 NVTX3_V1_NO_DISCARD inline nvtx3::v1::schema const& nvtx3::v1::schema::get<struct_id>() noexcept \
3304 { \
3305 static_assert( \
3306 std::is_standard_layout<struct_id>::value, \
3307 "structs used for NVTX3 payload schema must be standard layout"); \
3308 static_assert( \
3309 std::is_trivially_copyable<struct_id>::value, \
3310 "structs used for NVTX3 payload schema must be trivially copyable"); \
3311 using nvtx_struct_id = struct_id; /* avoids issues with namespaced struct_id */ \
3312 _NVTX_DEFINE_SCHEMA_FOR_STRUCT(nvtx_struct_id, schema_name, static constexpr, entries) \
3313 static const schema s{ \
3314 nvtxPayloadSchemaRegister(nvtx3::v1::domain::get<dom>(), &nvtx_struct_id##Attr)}; \
3315 return s; \
3316 }
3317
3318/* When inlining this version, versioned macros must have unversioned aliases.
3319 * For each NVTX3_Vx_ #define, make an NVTX3_ alias of it here.*/
3320#if defined(NVTX3_INLINE_THIS_VERSION)
3321/* clang format off */
3322#define NVTX3_FUNC_RANGE NVTX3_V1_FUNC_RANGE
3323#define NVTX3_FUNC_RANGE_IF NVTX3_V1_FUNC_RANGE_IF
3324#define NVTX3_FUNC_RANGE_IN NVTX3_V1_FUNC_RANGE_IN
3325#define NVTX3_FUNC_RANGE_IF_IN NVTX3_V1_FUNC_RANGE_IF_IN
3326#define NVTX3_DEFINE_SCHEMA_GET NVTX3_V1_DEFINE_SCHEMA_GET
3327/* clang format on */
3328#endif
3329
3330#endif // NVTX3_CPP_DEFINITIONS_V1_0
3331
3332/* Undefine all temporarily-defined unversioned macros, which would conflict with
3333 * subsequent includes of different versions of this header. */
3334#undef NVTX3_CPP_VERSION_MAJOR
3335#undef NVTX3_CPP_VERSION_MINOR
3336#undef NVTX3_CONCAT
3337#undef NVTX3_NAMESPACE_FOR
3338#undef NVTX3_VERSION_NAMESPACE
3339#undef NVTX3_MINOR_NAMESPACE_FOR
3340#undef NVTX3_MINOR_VERSION_NAMESPACE
3341#undef NVTX3_INLINE_IF_REQUESTED
3342#undef NVTX3_CONSTEXPR_IF_CPP14
3343#undef NVTX3_MAYBE_UNUSED
3344#undef NVTX3_NO_DISCARD
3345
3346#if defined(NVTX3_INLINE_THIS_VERSION)
3347#undef NVTX3_INLINE_THIS_VERSION
3348#endif
3349
3350#if defined(NVTX3_USE_CHECKED_OVERLOADS_FOR_GET_DEFINED_HERE)
3351#undef NVTX3_USE_CHECKED_OVERLOADS_FOR_GET_DEFINED_HERE
3352#undef NVTX3_USE_CHECKED_OVERLOADS_FOR_GET
3353#endif
3354
3355#if defined(NVTX3_STATIC_ASSERT_DEFINED_HERE)
3356#undef NVTX3_STATIC_ASSERT_DEFINED_HERE
3357#undef NVTX3_STATIC_ASSERT
3358#endif
Object for intra-domain grouping of NVTX events.
Definition nvtx3.hpp:1321
constexpr category(id_type id) noexcept
Construct a category with the specified id.
Definition nvtx3.hpp:1335
constexpr id_type get_id() const noexcept
Returns the id of the category.
Definition nvtx3.hpp:1341
uint32_t id_type
Type used for categorys integer id.
Definition nvtx3.hpp:1324
Represents a custom color that can be associated with an NVTX event via its event_attributes.
Definition nvtx3.hpp:1214
uint32_t value_type
Type used for the color's value.
Definition nvtx3.hpp:1217
constexpr nvtxColorType_t get_type() const noexcept
Return the NVTX color type of the color.
Definition nvtx3.hpp:1272
constexpr color(argb argb_) noexcept
Construct a color using the alpha, red, green, blue components in argb.
Definition nvtx3.hpp:1244
constexpr color(rgb rgb_) noexcept
Construct a color using the red, green, blue components in rgb.
Definition nvtx3.hpp:1257
constexpr color(value_type hex_code) noexcept
Constructs a color using the value provided by hex_code.
Definition nvtx3.hpp:1236
constexpr value_type get_value() const noexcept
Returns the colors argb hex code.
Definition nvtx3.hpp:1266
domains allow for grouping NVTX events into a single scope to differentiate them from events in other...
Definition nvtx3.hpp:924
static domain const & get() noexcept
Returns reference to an instance of a function local static domain object.
Definition nvtx3.hpp:994
Describes the attributes of a NVTX event.
Definition nvtx3.hpp:2288
constexpr event_attributes() noexcept
Default constructor creates an event_attributes with no category, color, payload, nor message.
Definition nvtx3.hpp:2296
constexpr value_type const * get() const noexcept
Get raw pointer to underlying NVTX attributes object.
Definition nvtx3.hpp:2435
event_attributes(payload_data &&pd, Args const &... args)=delete
Deleted constructor for payload_data rvalue references.
event_attributes(message const &m, Args const &... args) noexcept
Variadic constructor where the first argument is a message.
Definition nvtx3.hpp:2418
event_attributes(T &&pdc, Args const &... args) noexcept
Variadic constructor template for containers of payload_data.
Definition nvtx3.hpp:2398
event_attributes(payload const &p, Args const &... args) noexcept
Variadic constructor where the first argument is a payload.
Definition nvtx3.hpp:2349
event_attributes(color const &c, Args const &... args) noexcept
Variadic constructor where the first argument is a color.
Definition nvtx3.hpp:2334
event_attributes(category const &c, Args const &... args) noexcept
Variadic constructor where the first argument is a category.
Definition nvtx3.hpp:2320
event_attributes(payload_data const &pd, Args const &... args) noexcept
Variadic constructor where the first argument is a single payload_data.
Definition nvtx3.hpp:2364
Allows associating a message string with an NVTX event via its EventAttributes.
Definition nvtx3.hpp:1827
message(nvtxStringHandle_t handle) noexcept
Construct a message from NVTX C API registered string handle.
Definition nvtx3.hpp:1922
constexpr nvtxMessageType_t get_type() const noexcept
Return the type information about the value the union holds.
Definition nvtx3.hpp:1938
message(std::string const &msg) noexcept
Construct a message whose contents are specified by msg.
Definition nvtx3.hpp:1846
message(std::wstring const &msg) noexcept
Construct a message whose contents are specified by msg.
Definition nvtx3.hpp:1875
message(registered_string_in< D > const &msg) noexcept
Construct a message from a registered_string_in.
Definition nvtx3.hpp:1898
constexpr value_type get_value() const noexcept
Return the union holding the value of the message.
Definition nvtx3.hpp:1932
message(wchar_t const *msg) noexcept
Construct a message whose contents are specified by msg.
Definition nvtx3.hpp:1865
message(std::string &&)=delete
Disallow construction for std::string r-value.
message(char const *msg) noexcept
Construct a message whose contents are specified by msg.
Definition nvtx3.hpp:1836
constexpr message(nvtxMessageType_t const &type, nvtxMessageValue_t const &value) noexcept
Construct a message from NVTX C API type and value.
Definition nvtx3.hpp:1910
message(std::wstring &&)=delete
Disallow construction for std::wstring r-value.
A category with an associated name string.
Definition nvtx3.hpp:1404
named_category_in(id_type id, wchar_t const *name) noexcept
Construct a named_category_in with the specified id and name.
Definition nvtx3.hpp:1540
static named_category_in const & get() noexcept
Returns a global instance of a named_category_in as a function-local static.
Definition nvtx3.hpp:1446
named_category_in(id_type id, char const *name) noexcept
Construct a named_category_in with the specified id and name.
Definition nvtx3.hpp:1520
Wrapper around the NVTX C API nvtxPayloadData_t struct.
Definition nvtx3.hpp:2145
payload_data(T const &t, schema s)
Constructs payload_data for a payload instance with a given schema.
Definition nvtx3.hpp:2206
payload_data(nvtxPayloadData_t const &pd)
Constructs payload_data from an existing NVTX C API struct.
Definition nvtx3.hpp:2154
uint64_t as_ull_value() const noexcept
Definition nvtx3.hpp:2218
payload_data(R &&t)
Constructs payload_data for a specific payload struct instance.
Definition nvtx3.hpp:2179
A numerical value that can be associated with an NVTX event via its event_attributes.
Definition nvtx3.hpp:1961
payload(uint32_t value) noexcept
Construct a payload from an unsigned, 4 byte integer.
Definition nvtx3.hpp:2003
payload(double value) noexcept
Construct a payload from a double-precision floating point value.
Definition nvtx3.hpp:2027
payload(uint64_t value) noexcept
Construct a payload from an unsigned, 8 byte integer.
Definition nvtx3.hpp:1992
payload(int64_t value) noexcept
Construct a payload from a signed, 8 byte integer.
Definition nvtx3.hpp:1970
constexpr payload(nvtxPayloadType_t const &type, value_type const &value) noexcept
Construct a payload from NVTX C API type and value.
Definition nvtx3.hpp:2039
constexpr value_type get_value() const noexcept
Return the union holding the value of the payload.
Definition nvtx3.hpp:2050
constexpr nvtxPayloadType_t get_type() const noexcept
Return the information about the type the union holds.
Definition nvtx3.hpp:2056
payload(float value) noexcept
Construct a payload from a single-precision floating point value.
Definition nvtx3.hpp:2015
payload(int32_t value) noexcept
Construct a payload from a signed, 4 byte integer.
Definition nvtx3.hpp:1981
A message registered with NVTX.
Definition nvtx3.hpp:1604
static registered_string_in const & get() noexcept
Returns a global instance of a registered_string_in as a function local static.
Definition nvtx3.hpp:1644
nvtxStringHandle_t get_handle() const noexcept
Returns the registered string's handle.
Definition nvtx3.hpp:1759
registered_string_in(std::wstring const &msg) noexcept
Constructs a registered_string_in from the specified msg string.
Definition nvtx3.hpp:1752
registered_string_in(char const *msg) noexcept
Constructs a registered_string_in from the specified msg string.
Definition nvtx3.hpp:1706
registered_string_in(std::string const &msg) noexcept
Constructs a registered_string_in from the specified msg string.
Definition nvtx3.hpp:1722
registered_string_in(wchar_t const *msg) noexcept
Constructs a registered_string_in from the specified msg string.
Definition nvtx3.hpp:1736
Represents the registered schema for a payload struct.
Definition nvtx3.hpp:2075
static schema const & get() noexcept
Gets the schema instance for a specific payload struct type.
Definition nvtx3.hpp:2115
uint64_t get_handle() const noexcept
Return the underlying C handle of the schema.
Definition nvtx3.hpp:2128
schema(uint64_t id)
Constructs a schema object directly from a schema ID.
Definition nvtx3.hpp:2100
A RAII object for creating a NVTX range local to a thread within a domain.
Definition nvtx3.hpp:2489
scoped_range_in(Args const &... args) noexcept
Constructs a scoped_range_in from the constructor arguments of an event_attributes.
Definition nvtx3.hpp:2535
~scoped_range_in() noexcept
Destroy the scoped_range_in, ending the NVTX range event.
Definition nvtx3.hpp:2563
scoped_range_in(event_attributes const &attr) noexcept
Construct a scoped_range_in with the specified event_attributes
Definition nvtx3.hpp:2505
scoped_range_in() noexcept
Default constructor creates a scoped_range_in with no message, color, payload, nor category.
Definition nvtx3.hpp:2545
A RAII object for creating a NVTX range within a domain that can be created and destroyed on differen...
Definition nvtx3.hpp:2928
unique_range_in(event_attributes const &attr) noexcept
Construct a new unique_range_in object with the specified event attributes.
Definition nvtx3.hpp:2943
~unique_range_in() noexcept=default
Destroy the unique_range_in ending the range.
unique_range_in(Args const &... args) noexcept
Constructs a unique_range_in from the constructor arguments of an event_attributes.
Definition nvtx3.hpp:2968
constexpr unique_range_in() noexcept
Default constructor creates a unique_range_in with no message, color, payload, nor category.
Definition nvtx3.hpp:2978
void mark_in(event_attributes const &attr) noexcept
Annotates an instantaneous point in time with a "marker", using the attributes specified by attr.
Definition nvtx3.hpp:3051
constexpr bool operator!=(range_handle lhs, range_handle rhs) noexcept
Compares two range_handles for inequality.
Definition nvtx3.hpp:2702
constexpr bool operator==(range_handle lhs, range_handle rhs) noexcept
Compares two range_handles for equality.
Definition nvtx3.hpp:2691
void mark(event_attributes const &attr) noexcept
Annotates an instantaneous point in time with a "marker", using the attributes specified by attr,...
Definition nvtx3.hpp:3117
range_handle start_range_in(event_attributes const &attr) noexcept
Manually begin an NVTX range.
Definition nvtx3.hpp:2734
void end_range(range_handle r) noexcept
Manually end the range associated with the handle r in the global domain.
Definition nvtx3.hpp:2897
range_handle start_range(event_attributes const &attr) noexcept
Manually begin an NVTX range in the global domain.
Definition nvtx3.hpp:2811
void end_range_in(range_handle r) noexcept
Manually end the range associated with the handle r in domain D.
Definition nvtx3.hpp:2875
Indicates the value of the alpha, red, green, and blue color channels for an ARGB color to use as an ...
Definition nvtx3.hpp:1180
constexpr argb(component_type alpha_, component_type red_, component_type green_, component_type blue_) noexcept
Construct an argb with alpha, red, green, and blue channels specified by alpha_, red_,...
Definition nvtx3.hpp:1193
Tag type for the "global" NVTX domain.
Definition nvtx3.hpp:942
Handle used for correlating explicit range start and end events.
Definition nvtx3.hpp:2630
nvtxRangeId_t value_type
Type used for the handle's value.
Definition nvtx3.hpp:2632
constexpr range_handle(value_type id) noexcept
Construct a range_handle from the given id.
Definition nvtx3.hpp:2639
constexpr value_type get_value() const noexcept
Returns the range_handle's value.
Definition nvtx3.hpp:2676
constexpr range_handle() noexcept=default
Constructs a null range handle.
constexpr range_handle(std::nullptr_t) noexcept
Implicit conversion from nullptr constructs a null handle.
Definition nvtx3.hpp:2669
Indicates the values of the red, green, and blue color channels for an RGB color to use as an event a...
Definition nvtx3.hpp:1148
constexpr rgb(component_type red_, component_type green_, component_type blue_) noexcept
Construct a rgb with red, green, and blue channels specified by red_, green_, and blue_,...
Definition nvtx3.hpp:1162
uint8_t component_type
Type used for component values.
Definition nvtx3.hpp:1150