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-2026 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 2
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 2 // 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 2 // NVTX3_CPP_VERSION_MINOR
137 // else, already have this version or newer, nothing to do
138 #endif
139#endif
140/* clang-format on */
141
677/* Temporary helper #defines, removed with #undef at end of header */
678
679/* Some compilers do not correctly support SFINAE, which is used in this API
680 * to detect common usage errors and provide clearer error messages (by using
681 * static_assert) than the compiler would produce otherwise. These compilers
682 * will generate errors while compiling this file such as:
683 *
684 * error: 'name' is not a member of 'nvtx3::v1::domain::global'
685 *
686 * The following compiler versions are known to have this problem, and so are
687 * set by default to disable the SFINAE-based checks:
688 *
689 * - All MSVC versions prior to VS2017 Update 7 (15.7)
690 * - GCC 8.1-8.3 (the problem was fixed in GCC 8.4)
691 *
692 * If you find your compiler hits this problem, you can work around it by
693 * defining NVTX3_USE_CHECKED_OVERLOADS_FOR_GET to 0 before including this
694 * header, or you can add a check for your compiler version to this #if.
695 * Also, please report the issue on the NVTX GitHub page.
696 */
697#if !defined(NVTX3_USE_CHECKED_OVERLOADS_FOR_GET)
698#if defined(_MSC_VER) && _MSC_VER < 1914 \
699 || defined(__GNUC__) && __GNUC__ == 8 && __GNUC_MINOR__ < 4
700#define NVTX3_USE_CHECKED_OVERLOADS_FOR_GET 0
701#else
702#define NVTX3_USE_CHECKED_OVERLOADS_FOR_GET 1
703#endif
704#define NVTX3_USE_CHECKED_OVERLOADS_FOR_GET_DEFINED_HERE
705#endif
706
707/* Within this header, nvtx3::NVTX3_VERSION_NAMESPACE resolves to nvtx3::vX,
708 * where "X" is the major version number. */
709#define NVTX3_CONCAT(A, B) A##B
710#define NVTX3_NAMESPACE_FOR(VERSION) NVTX3_CONCAT(v, VERSION)
711#define NVTX3_VERSION_NAMESPACE NVTX3_NAMESPACE_FOR(NVTX3_CPP_VERSION_MAJOR)
712/* We use a different prefix to avoid ambiguity with the version namespace */
713#define NVTX3_MINOR_NAMESPACE_FOR(VERSION) NVTX3_CONCAT(mv, VERSION)
714#define NVTX3_MINOR_VERSION_NAMESPACE NVTX3_MINOR_NAMESPACE_FOR(NVTX3_CPP_VERSION_MINOR)
715
716/* Avoid duplicating #if defined(NVTX3_INLINE_THIS_VERSION) for namespaces
717 * in each minor version by making a macro to use unconditionally, which
718 * resolves to "inline" or nothing as appropriate. */
719#if defined(NVTX3_INLINE_THIS_VERSION)
720#define NVTX3_INLINE_IF_REQUESTED inline
721#else
722#define NVTX3_INLINE_IF_REQUESTED
723#endif
724
725/* Enables the use of constexpr when support for C++14 constexpr is present.
726 *
727 * Initialization of a class member that is a union to a specific union member
728 * can only be done in the body of a constructor, not in a member initializer
729 * list. A constexpr constructor must have an empty body until C++14, so there
730 * is no way to make an initializer of a member union constexpr in C++11. This
731 * macro allows making functions constexpr in C++14 or newer, but non-constexpr
732 * in C++11 compilation. It is used here on constructors that initialize their
733 * member unions.
734 */
735#if __cpp_constexpr >= 201304L
736#define NVTX3_CONSTEXPR_IF_CPP14 constexpr
737#else
738#define NVTX3_CONSTEXPR_IF_CPP14
739#endif
740
741/* Enables the use of constexpr when support for C++20 constexpr is present.
742 */
743#if __cplusplus >= 202002L
744#define NVTX3_CONSTEXPR_IF_CPP20 constexpr
745#else
746#define NVTX3_CONSTEXPR_IF_CPP20
747#endif
748
749// Macro wrappers for C++ attributes
750#if !defined(__has_cpp_attribute)
751#define __has_cpp_attribute(x) 0
752#endif
753#if __has_cpp_attribute(maybe_unused)
754#define NVTX3_MAYBE_UNUSED [[maybe_unused]]
755#else
756#define NVTX3_MAYBE_UNUSED
757#endif
758#if __has_cpp_attribute(nodiscard)
759#define NVTX3_NO_DISCARD [[nodiscard]]
760#else
761#define NVTX3_NO_DISCARD
762#endif
763
764 /* Use a macro for static asserts, which defaults to static_assert, but that
765 * testing tools can replace with a logging function. For example:
766 * #define NVTX3_STATIC_ASSERT(c, m) \
767 * do { if (!(c)) printf("static_assert would fail: %s\n", m); } while (0)
768 */
769#if !defined(NVTX3_STATIC_ASSERT)
770#define NVTX3_STATIC_ASSERT(condition, message) static_assert(condition, message)
771#define NVTX3_STATIC_ASSERT_DEFINED_HERE
772#endif
773
774/* The original idea here was to have separate implementation sections, enclosed
775 * in guard macros for each minor version. However, this approach was very
776 * limited in practice. Specifically, it is not possible to add constructors to
777 * `event_attributes`, which was needed for version 1.1 and is API compatible.
778 * So we stick with `NVTX3_CPP_DEFINITIONS_V1_0` as guard macro for now, even
779 * with bumped minor versions.
780 */
781#ifndef NVTX3_CPP_DEFINITIONS_V1_0
782#define NVTX3_CPP_DEFINITIONS_V1_0
783
784#include "nvToolsExt.h"
785#include "nvToolsExtCounters.h"
786#include "nvToolsExtPayload.h"
787#include "nvToolsExtPayloadHelper.h"
788#include "nvToolsExtSemanticsCorrelation.h"
789#include "nvToolsExtSemanticsCounters.h"
790#include "nvToolsExtSemanticsScope.h"
791#include "nvToolsExtSemanticsTime.h"
792
793#include <memory>
794#include <stdexcept>
795#include <string>
796#include <type_traits>
797#include <utility>
798#include <cstddef>
799#include <cstdint>
800
801namespace nvtx3 {
802
803NVTX3_INLINE_IF_REQUESTED namespace NVTX3_VERSION_NAMESPACE
804{
805inline namespace NVTX3_MINOR_VERSION_NAMESPACE
806{
807
808namespace detail {
809
810template <typename Unused>
811struct always_false : std::false_type {};
812
813template <typename T, typename = void>
814struct has_name : std::false_type {};
815template <typename T>
816struct has_name<T, decltype((void)T::name, void())> : std::true_type {};
817
818template <typename T, typename = void>
819struct has_id : std::false_type {};
820template <typename T>
821struct has_id<T, decltype((void)T::id, void())> : std::true_type {};
822
823template <typename T, typename = void>
824struct has_message : std::false_type {};
825template <typename T>
826struct has_message<T, decltype((void)T::message, void())> : std::true_type {};
827
828template <typename T, typename = void>
829struct is_c_string : std::false_type {};
830template <typename T>
831struct is_c_string<T, typename std::enable_if<
832 std::is_convertible<T, char const* >::value ||
833 std::is_convertible<T, wchar_t const*>::value
834>::type> : std::true_type {};
835
836template <typename T>
837using is_uint32 = std::is_same<typename std::decay<T>::type, uint32_t>;
838
839template <typename... Args>
840static inline void silence_unused(Args const&...) noexcept {}
841
842// Type trait to check for a .data() member returning T* or const T*
843// Some day, we can just use std::span
844template <typename T, typename TD>
845struct has_data_member
846{
847private:
848 template <typename U>
849 static auto test_data(int) -> decltype(std::declval<const U>().data());
850 template <typename>
851 static auto test_data(...) -> void;
852 using return_type = decltype(test_data<T>(0));
853
854public:
855 static constexpr bool value =
856 std::is_same<return_type, TD*>::value || std::is_same<return_type, TD const*>::value;
857};
858
859// Type trait to check for a .size() member returning something convertible to size_t
860template <typename T>
861struct has_size_member
862{
863private:
864 template <typename U>
865 static auto test_size(int) -> decltype(std::declval<const U>().size());
866 template <typename>
867 static auto test_size(...) -> void;
868 using return_type = decltype(test_size<T>(0));
869
870public:
871 static constexpr bool value = !std::is_same<return_type, void>::value &&
872 std::is_convertible<return_type, size_t>::value;
873};
874
885template <typename W, typename U, typename = void>
886struct is_safe_wrapper_of : std::false_type
887{
888};
889
890template <typename W, typename U>
891struct is_safe_wrapper_of<
892 W,
893 U,
894 typename std::enable_if<
895 std::is_standard_layout<W>::value && std::is_standard_layout<U>::value &&
896 std::is_trivially_copyable<W>::value && std::is_trivially_copyable<U>::value &&
897 sizeof(W) == sizeof(U)>::type> : std::true_type
898{
899};
910template <typename DataType>
911class semantic_base {
912public:
922 nvtxSemanticsHeader_t const* get() const & noexcept
923 {
924 return reinterpret_cast<nvtxSemanticsHeader_t const*>(&data_);
925 }
926
927protected:
928 explicit semantic_base(DataType const& data) noexcept : data_{data} {}
929
930 void set_next(nvtxSemanticsHeader_t const* next) noexcept
931 {
932 // Raw C-header chaining is non-owning; callers must keep next alive.
933 next_owner_.reset();
934 data_.header.next = next;
935 }
936
937 template <typename OtherDataType>
938 void own_next(semantic_base<OtherDataType> const& next)
939 {
940 // C++ wrapper chaining snapshots next and points the C header at the owned copy.
941 auto owned_next = std::make_shared<semantic_base<OtherDataType>>(next);
942 data_.header.next = owned_next->get();
943 next_owner_ = owned_next;
944 }
945
946 DataType data_;
947
948private:
949 // Type-erased owner for the semantic object addressed by data_.header.next.
950 // Stored here to keep the pointer alive
951 std::shared_ptr<void const> next_owner_;
952};
953
961template <typename T>
962struct counter_limit_traits;
963
964template <>
965struct counter_limit_traits<int64_t>
966{
967 static constexpr int64_t limit_type_value = NVTX_COUNTER_LIMIT_I64;
968 static NVTX3_CONSTEXPR_IF_CPP20 void store(nvtxCounterLimit_t& slot, int64_t v) noexcept
969 {
970 slot.i64 = v;
971 }
972};
973
974template <>
975struct counter_limit_traits<uint64_t>
976{
977 static constexpr int64_t limit_type_value = NVTX_COUNTER_LIMIT_U64;
978 static NVTX3_CONSTEXPR_IF_CPP20 void store(nvtxCounterLimit_t& slot, uint64_t v) noexcept
979 {
980 slot.u64 = v;
981 }
982};
983
984template <>
985struct counter_limit_traits<double>
986{
987 static constexpr int64_t limit_type_value = NVTX_COUNTER_LIMIT_F64;
988 static NVTX3_CONSTEXPR_IF_CPP20 void store(nvtxCounterLimit_t& slot, double v) noexcept
989 {
990 slot.f64 = v;
991 }
992};
993
994} // namespace detail
995
1049class domain {
1050 public:
1051 domain(domain const&) = delete;
1052 domain& operator=(domain const&) = delete;
1053 domain(domain&&) = delete;
1054 domain& operator=(domain&&) = delete;
1055
1067 struct global {
1068 };
1069
1070#if NVTX3_USE_CHECKED_OVERLOADS_FOR_GET
1115 template <typename D = global,
1116 typename std::enable_if<
1117 detail::is_c_string<decltype(D::name)>::value
1118 , int>::type = 0>
1119 NVTX3_NO_DISCARD static domain const& get() noexcept
1120 {
1121 static domain const d(D::name);
1122 return d;
1123 }
1124
1130 template <typename D = global,
1131 typename std::enable_if<
1132 !detail::is_c_string<decltype(D::name)>::value
1133 , int>::type = 0>
1134 NVTX3_NO_DISCARD static domain const& get() noexcept
1135 {
1136 NVTX3_STATIC_ASSERT(detail::always_false<D>::value,
1137 "Type used to identify an NVTX domain must contain a static constexpr member "
1138 "called 'name' of type const char* or const wchar_t* -- 'name' member is not "
1139 "convertible to either of those types");
1140 static domain const unused;
1141 return unused; // Function must compile for static_assert to be triggered
1142 }
1143
1148 template <typename D = global,
1149 typename std::enable_if<
1150 !detail::has_name<D>::value
1151 , int>::type = 0>
1152 NVTX3_NO_DISCARD static domain const& get() noexcept
1153 {
1154 NVTX3_STATIC_ASSERT(detail::always_false<D>::value,
1155 "Type used to identify an NVTX domain must contain a static constexpr member "
1156 "called 'name' of type const char* or const wchar_t* -- 'name' member is missing");
1157 static domain const unused;
1158 return unused; // Function must compile for static_assert to be triggered
1159 }
1160#else
1161 template <typename D = global>
1162 NVTX3_NO_DISCARD static domain const& get() noexcept
1163 {
1164 static domain const d(D::name);
1165 return d;
1166 }
1167#endif
1168
1175 operator nvtxDomainHandle_t() const noexcept { return _domain; }
1176
1177 private:
1186 explicit domain(char const* name) noexcept : _domain{nvtxDomainCreateA(name)} {}
1187
1196 explicit domain(wchar_t const* name) noexcept : _domain{nvtxDomainCreateW(name)} {}
1197
1206 explicit domain(std::string const& name) noexcept : domain{name.c_str()} {}
1207
1216 explicit domain(std::wstring const& name) noexcept : domain{name.c_str()} {}
1217
1226 constexpr domain() noexcept {}
1227
1242 ~domain() = default;
1243
1244 private:
1245 nvtxDomainHandle_t const _domain{};
1246};
1247
1261template <>
1262NVTX3_NO_DISCARD inline domain const& domain::get<domain::global>() noexcept
1263{
1264 static domain const d{};
1265 return d;
1266}
1267
1273struct rgb {
1275 using component_type = uint8_t;
1276
1287 constexpr rgb(
1288 component_type red_,
1289 component_type green_,
1290 component_type blue_) noexcept
1291 : red{red_}, green{green_}, blue{blue_}
1292 {
1293 }
1294
1298};
1299
1305struct argb final : rgb {
1318 constexpr argb(
1319 component_type alpha_,
1320 component_type red_,
1321 component_type green_,
1322 component_type blue_) noexcept
1323 : rgb{red_, green_, blue_}, alpha{alpha_}
1324 {
1325 }
1326
1328};
1329
1339class color {
1340 public:
1342 using value_type = uint32_t;
1343
1361 constexpr explicit color(value_type hex_code) noexcept : _value{hex_code} {}
1362
1369 constexpr color(argb argb_) noexcept
1370 : color{from_bytes_msb_to_lsb(argb_.alpha, argb_.red, argb_.green, argb_.blue)}
1371 {
1372 }
1373
1382 constexpr color(rgb rgb_) noexcept
1383 : color{from_bytes_msb_to_lsb(0xFF, rgb_.red, rgb_.green, rgb_.blue)}
1384 {
1385 }
1386
1391 constexpr value_type get_value() const noexcept { return _value; }
1392
1397 constexpr nvtxColorType_t get_type() const noexcept { return _type; }
1398
1399 color() = delete;
1400 ~color() = default;
1401 color(color const&) = default;
1402 color& operator=(color const&) = default;
1403 color(color&&) = default;
1404 color& operator=(color&&) = default;
1405
1406 private:
1412 constexpr static value_type from_bytes_msb_to_lsb(
1413 uint8_t byte3,
1414 uint8_t byte2,
1415 uint8_t byte1,
1416 uint8_t byte0) noexcept
1417 {
1418 return uint32_t{byte3} << 24 | uint32_t{byte2} << 16 | uint32_t{byte1} << 8 | uint32_t{byte0};
1419 }
1420
1421 value_type _value{};
1422 nvtxColorType_t _type{NVTX_COLOR_ARGB};
1423};
1424
1447 public:
1449 using id_type = uint32_t;
1450
1460 constexpr explicit category(id_type id) noexcept : id_{id} {}
1461
1466 constexpr id_type get_id() const noexcept { return id_; }
1467
1468 category() = delete;
1469 ~category() = default;
1470 category(category const&) = default;
1471 category& operator=(category const&) = default;
1472 category(category&&) = default;
1473 category& operator=(category&&) = default;
1474
1475 private:
1476 id_type id_{};
1477};
1478
1528template <typename D = domain::global>
1529class named_category_in final : public category {
1530 public:
1531#if NVTX3_USE_CHECKED_OVERLOADS_FOR_GET
1566 template <typename C,
1567 typename std::enable_if<
1568 detail::is_c_string<decltype(C::name)>::value &&
1569 detail::is_uint32<decltype(C::id)>::value
1570 , int>::type = 0>
1571 static named_category_in const& get() noexcept
1572 {
1573 static named_category_in const cat(C::id, C::name);
1574 return cat;
1575 }
1576
1583 template <typename C,
1584 typename std::enable_if<
1585 !detail::is_c_string<decltype(C::name)>::value ||
1586 !detail::is_uint32<decltype(C::id)>::value
1587 , int>::type = 0>
1588 NVTX3_NO_DISCARD static named_category_in const& get() noexcept
1589 {
1590 NVTX3_STATIC_ASSERT(detail::is_c_string<decltype(C::name)>::value,
1591 "Type used to name an NVTX category must contain a static constexpr member "
1592 "called 'name' of type const char* or const wchar_t* -- 'name' member is not "
1593 "convertible to either of those types");
1594 NVTX3_STATIC_ASSERT(detail::is_uint32<decltype(C::id)>::value,
1595 "Type used to name an NVTX category must contain a static constexpr member "
1596 "called 'id' of type uint32_t -- 'id' member is the wrong type");
1597 static named_category_in const unused;
1598 return unused; // Function must compile for static_assert to be triggered
1599 }
1600
1605 template <typename C,
1606 typename std::enable_if<
1607 !detail::has_name<C>::value ||
1608 !detail::has_id<C>::value
1609 , int>::type = 0>
1610 NVTX3_NO_DISCARD static named_category_in const& get() noexcept
1611 {
1612 NVTX3_STATIC_ASSERT(detail::has_name<C>::value,
1613 "Type used to name an NVTX category must contain a static constexpr member "
1614 "called 'name' of type const char* or const wchar_t* -- 'name' member is missing");
1615 NVTX3_STATIC_ASSERT(detail::has_id<C>::value,
1616 "Type used to name an NVTX category must contain a static constexpr member "
1617 "called 'id' of type uint32_t -- 'id' member is missing");
1618 static named_category_in const unused;
1619 return unused; // Function must compile for static_assert to be triggered
1620 }
1621#else
1622 template <typename C>
1623 NVTX3_NO_DISCARD static named_category_in const& get() noexcept
1624 {
1625 static named_category_in const cat(C::id, C::name);
1626 return cat;
1627 }
1628#endif
1629
1630 private:
1631 // Default constructor is only used internally for static_assert(false) cases.
1632 named_category_in() noexcept : category{0} {}
1633
1634 public:
1645 named_category_in(id_type id, char const* name) noexcept : category{id}
1646 {
1647#ifndef NVTX_DISABLE
1648 nvtxDomainNameCategoryA(domain::get<D>(), get_id(), name);
1649#else
1650 (void)id;
1651 (void)name;
1652#endif
1653 }
1654
1665 named_category_in(id_type id, std::string const& name) noexcept
1666 : named_category_in{id, name.c_str()} {}
1667
1678 named_category_in(id_type id, wchar_t const* name) noexcept : category{id}
1679 {
1680#ifndef NVTX_DISABLE
1681 nvtxDomainNameCategoryW(domain::get<D>(), get_id(), name);
1682#else
1683 (void)id;
1684 (void)name;
1685#endif
1686 }
1687
1698 named_category_in(id_type id, std::wstring const& name) noexcept
1699 : named_category_in{id, name.c_str()} {}
1700};
1701
1707
1754template <typename D = domain::global>
1756 public:
1757#if NVTX3_USE_CHECKED_OVERLOADS_FOR_GET
1791 template <typename M,
1792 typename std::enable_if<
1793 detail::is_c_string<decltype(M::message)>::value
1794 , int>::type = 0>
1795 NVTX3_NO_DISCARD static registered_string_in const& get() noexcept
1796 {
1797 static registered_string_in const regstr(M::message);
1798 return regstr;
1799 }
1800
1806 template <typename M,
1807 typename std::enable_if<
1808 !detail::is_c_string<decltype(M::message)>::value
1809 , int>::type = 0>
1810 NVTX3_NO_DISCARD static registered_string_in const& get() noexcept
1811 {
1812 NVTX3_STATIC_ASSERT(detail::always_false<M>::value,
1813 "Type used to register an NVTX string must contain a static constexpr member "
1814 "called 'message' of type const char* or const wchar_t* -- 'message' member is "
1815 "not convertible to either of those types");
1816 static registered_string_in const unused;
1817 return unused; // Function must compile for static_assert to be triggered
1818 }
1819
1824 template <typename M,
1825 typename std::enable_if<
1826 !detail::has_message<M>::value
1827 , int>::type = 0>
1828 NVTX3_NO_DISCARD static registered_string_in const& get() noexcept
1829 {
1830 NVTX3_STATIC_ASSERT(detail::always_false<M>::value,
1831 "Type used to register an NVTX string must contain a static constexpr member "
1832 "called 'message' of type const char* or const wchar_t* -- 'message' member "
1833 "is missing");
1834 static registered_string_in const unused;
1835 return unused; // Function must compile for static_assert to be triggered
1836 }
1837#else
1838 template <typename M>
1839 NVTX3_NO_DISCARD static registered_string_in const& get() noexcept
1840 {
1841 static registered_string_in const regstr(M::message);
1842 return regstr;
1843 }
1844#endif
1845
1857 explicit registered_string_in(char const* msg) noexcept
1858 : handle_{nvtxDomainRegisterStringA(domain::get<D>(), msg)}
1859 {
1860 }
1861
1873 explicit registered_string_in(std::string const& msg) noexcept
1874 : registered_string_in{msg.c_str()} {}
1875
1887 explicit registered_string_in(wchar_t const* msg) noexcept
1888 : handle_{nvtxDomainRegisterStringW(domain::get<D>(), msg)}
1889 {
1890 }
1891
1903 explicit registered_string_in(std::wstring const& msg) noexcept
1904 : registered_string_in{msg.c_str()} {}
1905
1910 nvtxStringHandle_t get_handle() const noexcept
1911 {
1912 // We want to ensure that we can use the registered_string in place of a handle
1913 // in a payload data struct.
1914 NVTX3_STATIC_ASSERT(
1915 (detail::is_safe_wrapper_of<registered_string_in<D>, nvtxStringHandle_t>::value),
1916 "Internal error! registered_string_in is potentially unsafe.");
1917 return handle_;
1918 }
1919
1920private:
1921 // Default constructor is only used internally for static_assert(false) cases.
1922 registered_string_in() noexcept {}
1923public:
1924 ~registered_string_in() = default;
1926 registered_string_in& operator=(registered_string_in const&) = default;
1928 registered_string_in& operator=(registered_string_in&&) = default;
1929
1930 private:
1931 nvtxStringHandle_t handle_{};
1933};
1934
1940
1978class message {
1979 public:
1980 using value_type = nvtxMessageValue_t;
1981
1987 NVTX3_CONSTEXPR_IF_CPP14 message(char const* msg) noexcept : type_{NVTX_MESSAGE_TYPE_ASCII}
1988 {
1989 value_.ascii = msg;
1990 }
1991
1997 message(std::string const& msg) noexcept : message{msg.c_str()} {}
1998
2007#ifndef NVTX3_ALLOW_RVALUE_CONSTRUCTORS
2008 message(std::string&&) = delete;
2009#endif
2010
2016 NVTX3_CONSTEXPR_IF_CPP14 message(wchar_t const* msg) noexcept : type_{NVTX_MESSAGE_TYPE_UNICODE}
2017 {
2018 value_.unicode = msg;
2019 }
2020
2026 message(std::wstring const& msg) noexcept : message{msg.c_str()} {}
2027
2036#ifndef NVTX3_ALLOW_RVALUE_CONSTRUCTORS
2037 message(std::wstring&&) = delete;
2038#endif
2039
2048 template <typename D>
2049 NVTX3_CONSTEXPR_IF_CPP14 message(registered_string_in<D> const& msg) noexcept
2050 : type_{NVTX_MESSAGE_TYPE_REGISTERED}
2051 {
2052 value_.registered = msg.get_handle();
2053 }
2054
2061 constexpr message(
2062 nvtxMessageType_t const& type,
2063 nvtxMessageValue_t const& value) noexcept
2064 : type_{type}, value_(value)
2065 {
2066 }
2067
2073 NVTX3_CONSTEXPR_IF_CPP14 message(nvtxStringHandle_t handle) noexcept
2074 : type_{NVTX_MESSAGE_TYPE_REGISTERED}
2075 {
2076 value_.registered = handle;
2077 }
2078
2083 constexpr value_type get_value() const noexcept { return value_; }
2084
2089 constexpr nvtxMessageType_t get_type() const noexcept { return type_; }
2090
2091 private:
2092 nvtxMessageType_t type_{};
2093 nvtxMessageValue_t value_{};
2094};
2095
2112class payload {
2113 public:
2114 using value_type = typename nvtxEventAttributes_v2::payload_t;
2115
2121 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(int64_t value) noexcept
2122 : type_{NVTX_PAYLOAD_TYPE_INT64}, value_{}
2123 {
2124 value_.llValue = value;
2125 }
2126
2132 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(int32_t value) noexcept
2133 : type_{NVTX_PAYLOAD_TYPE_INT32}, value_{}
2134 {
2135 value_.iValue = value;
2136 }
2137
2143 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(uint64_t value) noexcept
2144 : type_{NVTX_PAYLOAD_TYPE_UNSIGNED_INT64}, value_{}
2145 {
2146 value_.ullValue = value;
2147 }
2148
2154 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(uint32_t value) noexcept
2155 : type_{NVTX_PAYLOAD_TYPE_UNSIGNED_INT32}, value_{}
2156 {
2157 value_.uiValue = value;
2158 }
2159
2166 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(float value) noexcept
2167 : type_{NVTX_PAYLOAD_TYPE_FLOAT}, value_{}
2168 {
2169 value_.fValue = value;
2170 }
2171
2178 NVTX3_CONSTEXPR_IF_CPP14 explicit payload(double value) noexcept
2179 : type_{NVTX_PAYLOAD_TYPE_DOUBLE}, value_{}
2180 {
2181 value_.dValue = value;
2182 }
2183
2190 constexpr payload(
2191 nvtxPayloadType_t const& type,
2192 value_type const& value) noexcept
2193 : type_{type}, value_(value)
2194 {
2195 }
2196
2201 constexpr value_type get_value() const noexcept { return value_; }
2202
2207 constexpr nvtxPayloadType_t get_type() const noexcept { return type_; }
2208
2209 private:
2210 nvtxPayloadType_t type_;
2211 value_type value_;
2212};
2213
2226{
2227private:
2233 schema()
2234 : _schema_id{0}
2235 {}
2236
2237 public:
2238 schema(schema const&) = delete;
2239 schema& operator=(schema const&) = delete;
2240 schema(schema&&) = delete;
2241 schema& operator=(schema&&) = delete;
2242
2251 explicit schema(uint64_t id)
2252 : _schema_id{id}
2253 {}
2254
2265 template <typename T>
2266 NVTX3_NO_DISCARD static schema const& get() noexcept
2267 {
2268 NVTX3_STATIC_ASSERT(
2269 detail::always_false<T>::value,
2270 "payload_data schema deduction requires a template specialization. Use the macro "
2271 "NVTX3_DEFINE_SCHEMA_GET to generate this specialization.");
2272 static schema unused;
2273 return unused;
2274 }
2275
2279 uint64_t get_handle() const noexcept
2280 {
2281 return _schema_id;
2282 }
2283
2284private:
2285 uint64_t const _schema_id;
2286};
2287
2296{
2297public:
2305 explicit payload_data(nvtxPayloadData_t const& pd)
2306 : data_(pd)
2307 {}
2308
2322 // We cannot simply delete the rvalue constructor here because with a template
2323 // parameter that would be a forwarding reference. Thus, we have this one
2324 // ctor with a forwarding reference and use a static assert for the rvalue check.
2325 // Disable this for the C-style nvtxPayloadData_t to prefer above ctor for non-const.
2326 template <
2327 typename R,
2328 typename T = typename std::remove_cv<typename std::remove_reference<R>::type>::type,
2329 typename = typename std::enable_if<!std::is_same<T, nvtxPayloadData_t>::value>::type>
2330 explicit payload_data(R&& t)
2331 : data_{schema::get<T>().get_handle(), sizeof(T), &t}
2332 {
2333#ifndef NVTX3_ALLOW_RVALUE_CONSTRUCTORS
2334 NVTX3_STATIC_ASSERT(
2335 std::is_lvalue_reference<R>::value,
2336 "payload_data requires an lvalue reference to the underlying data. Constructing "
2337 "from an rvalue is potentially unsafe and therefore forbidden.");
2338#endif
2339 NVTX3_STATIC_ASSERT(
2340 std::is_standard_layout<T>::value && std::is_trivially_copyable<T>::value,
2341 "structs used for NVTX3 payload schema must be standard layout and trivially copyable");
2342 }
2343
2356 template <typename T>
2357 explicit payload_data(T const& t, schema s)
2358 : data_{s.get_handle(), sizeof(T), &t}
2359 {
2360 NVTX3_STATIC_ASSERT(
2361 std::is_standard_layout<T>::value && std::is_trivially_copyable<T>::value,
2362 "structs used for NVTX3 payload schema must be standard layout and trivially copyable");
2363 }
2364
2369 uint64_t as_ull_value() const noexcept
2370 {
2371 NVTX3_STATIC_ASSERT(
2372 (detail::is_safe_wrapper_of<payload_data, nvtxPayloadData_t>::value),
2373 "Internal error! payload_data is potentially unsafe.");
2374 return NVTX_POINTER_AS_PAYLOAD_ULLVALUE(&data_);
2375 }
2376
2377private:
2378 nvtxPayloadData_t data_;
2379};
2380
2440 public:
2441 using value_type = nvtxEventAttributes_t;
2442
2447 constexpr event_attributes() noexcept
2448 : attributes_{
2449 NVTX_VERSION, // version
2450 sizeof(nvtxEventAttributes_t), // size
2451 0, // category
2452 NVTX_COLOR_UNKNOWN, // color type
2453 0, // color value
2454 NVTX_PAYLOAD_UNKNOWN, // payload type
2455 0, // reserved 4B
2456 {0}, // payload value (union)
2457 NVTX_MESSAGE_UNKNOWN, // message type
2458 {nullptr} // message value (union)
2459 }
2460 {
2461 }
2462
2470 template <typename... Args>
2471 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(category const& c, Args const&... args) noexcept
2472 : event_attributes(args...)
2473 {
2474 attributes_.category = c.get_id();
2475 }
2476
2484 template <typename... Args>
2485 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(color const& c, Args const&... args) noexcept
2486 : event_attributes(args...)
2487 {
2488 attributes_.color = c.get_value();
2489 attributes_.colorType = c.get_type();
2490 }
2491
2499 template <typename... Args>
2500 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(payload const& p, Args const&... args) noexcept
2501 : event_attributes(args...)
2502 {
2503 attributes_.payload = p.get_value();
2504 attributes_.payloadType = p.get_type();
2505 }
2506
2514 template <typename... Args>
2515 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(payload_data const& pd, Args const&... args) noexcept
2516 : event_attributes(args...)
2517 {
2518 attributes_.payloadType = NVTX_PAYLOAD_TYPE_EXT;
2519 attributes_.reserved0 = 1;
2520 attributes_.payload.ullValue = pd.as_ull_value();
2521 }
2522
2530#ifndef NVTX3_ALLOW_RVALUE_CONSTRUCTORS
2531 template <typename... Args>
2532 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(payload_data&& pd, Args const&... args) = delete;
2533#endif
2534
2544 template <
2545 typename T,
2546 typename... Args,
2547 typename = typename std::enable_if<
2548 detail::has_data_member<T, payload_data>::value && detail::has_size_member<T>::value>::type>
2549 NVTX3_CONSTEXPR_IF_CPP20 explicit event_attributes(T&& pdc, Args const&... args) noexcept
2550 : event_attributes(args...)
2551 {
2552 NVTX3_STATIC_ASSERT(
2553 std::is_lvalue_reference<T>::value,
2554 "event_attributes requires an lvalue reference to the underlying data. "
2555 "Constructing from an rvalue is potentially unsafe and therefore forbidden.");
2556 attributes_.payloadType = NVTX_PAYLOAD_TYPE_EXT;
2557 attributes_.reserved0 = static_cast<int32_t>(pdc.size()); // Cast size to int32_t
2558 attributes_.payload.ullValue = pdc.data()->as_ull_value();
2559 }
2560
2568 template <typename... Args>
2569 NVTX3_CONSTEXPR_IF_CPP14 explicit event_attributes(message const& m, Args const&... args) noexcept
2570 : event_attributes(args...)
2571 {
2572 attributes_.message = m.get_value();
2573 attributes_.messageType = m.get_type();
2574 }
2575
2576 ~event_attributes() = default;
2577 event_attributes(event_attributes const&) = default;
2578 event_attributes& operator=(event_attributes const&) = default;
2580 event_attributes& operator=(event_attributes&&) = default;
2581
2586 constexpr value_type const* get() const noexcept { return &attributes_; }
2587
2588 private:
2589 value_type attributes_{};
2590};
2591
2639template <class D = domain::global>
2640class NVTX3_MAYBE_UNUSED scoped_range_in {
2641 public:
2656 explicit scoped_range_in(event_attributes const& attr) noexcept
2657 {
2658#ifndef NVTX_DISABLE
2659 nvtxDomainRangePushEx(domain::get<D>(), attr.get());
2660#else
2661 (void)attr;
2662#endif
2663 }
2664
2685 template <typename... Args>
2686 explicit scoped_range_in(Args const&... args) noexcept
2688 {
2689 }
2690
2697
2704 void* operator new(std::size_t) = delete;
2705
2706 scoped_range_in(scoped_range_in const&) = delete;
2707 scoped_range_in& operator=(scoped_range_in const&) = delete;
2708 scoped_range_in(scoped_range_in&&) = delete;
2709 scoped_range_in& operator=(scoped_range_in&&) = delete;
2710
2715 {
2716#ifndef NVTX_DISABLE
2717 nvtxDomainRangePop(domain::get<D>());
2718#endif
2719 }
2720};
2721
2727
2760template <typename D = domain::global>
2761inline int push_range_in(event_attributes const& attr) noexcept
2762{
2763#ifndef NVTX_DISABLE
2764 return nvtxDomainRangePushEx(domain::get<D>(), attr.get());
2765#else
2766 (void)attr;
2767 return 0;
2768#endif
2769}
2770
2800template <typename D = domain::global, typename... Args>
2801inline int push_range_in(Args const&... args) noexcept
2802{
2803#ifndef NVTX_DISABLE
2804 return push_range_in<D>(event_attributes{args...});
2805#else
2806 detail::silence_unused(args...);
2807 return 0;
2808#endif
2809}
2810
2831inline int push_range(event_attributes const& attr) noexcept
2832{
2833#ifndef NVTX_DISABLE
2834 return push_range_in<domain::global>(attr);
2835#else
2836 (void)attr;
2837 return 0;
2838#endif
2839}
2840
2863template <typename... Args>
2864inline int push_range(Args const&... args) noexcept
2865{
2866#ifndef NVTX_DISABLE
2867 return push_range_in<domain::global>(args...);
2868#else
2869 detail::silence_unused(args...);
2870 return 0;
2871#endif
2872}
2873
2895template <typename D = domain::global>
2896inline int pop_range_in() noexcept
2897{
2898#ifndef NVTX_DISABLE
2899 return nvtxDomainRangePop(domain::get<D>());
2900#else
2901 return 0;
2902#endif
2903}
2904
2923inline int pop_range() noexcept
2924{
2925#ifndef NVTX_DISABLE
2926 return pop_range_in<domain::global>();
2927#else
2928 return 0;
2929#endif
2930}
2931
2932namespace detail {
2933
2935template <typename D = domain::global>
2936class NVTX3_MAYBE_UNUSED optional_scoped_range_in
2937{
2938public:
2939 optional_scoped_range_in() = default;
2940
2941 void begin(event_attributes const& attr) noexcept
2942 {
2943#ifndef NVTX_DISABLE
2944 // This class is not meant to be part of the public NVTX C++ API and should
2945 // only be used in the `NVTX3_FUNC_RANGE_IF` and `NVTX3_FUNC_RANGE_IF_IN`
2946 // macros. However, to prevent developers from misusing this class, make
2947 // sure to not start multiple ranges.
2948 if (initialized) { return; }
2949
2950 nvtxDomainRangePushEx(domain::get<D>(), attr.get());
2951 initialized = true;
2952#else
2953 (void)attr;
2954#endif
2955 }
2956
2957 ~optional_scoped_range_in() noexcept
2958 {
2959#ifndef NVTX_DISABLE
2960 if (initialized) { nvtxDomainRangePop(domain::get<D>()); }
2961#endif
2962 }
2963
2964 void* operator new(std::size_t) = delete;
2965 optional_scoped_range_in(optional_scoped_range_in const&) = delete;
2966 optional_scoped_range_in& operator=(optional_scoped_range_in const&) = delete;
2967 optional_scoped_range_in(optional_scoped_range_in&&) = delete;
2968 optional_scoped_range_in& operator=(optional_scoped_range_in&&) = delete;
2969
2970private:
2971#ifndef NVTX_DISABLE
2972 bool initialized = false;
2973#endif
2974};
2976
2977} // namespace detail
2978
2987 using value_type = nvtxRangeId_t;
2988
2989
2994 constexpr explicit range_handle(value_type id) noexcept : _range_id{id} {}
2995
3003 constexpr range_handle() noexcept = default;
3004
3016 constexpr explicit operator bool() const noexcept { return get_value() != null_range_id; }
3017
3024 constexpr range_handle(std::nullptr_t) noexcept {}
3025
3031 constexpr value_type get_value() const noexcept { return _range_id; }
3032
3033 private:
3035 static constexpr value_type null_range_id = nvtxRangeId_t{0};
3036
3037 value_type _range_id{null_range_id};
3038};
3039
3046inline constexpr bool operator==(range_handle lhs, range_handle rhs) noexcept
3047{
3048 return lhs.get_value() == rhs.get_value();
3049}
3050
3057inline constexpr bool operator!=(range_handle lhs, range_handle rhs) noexcept { return !(lhs == rhs); }
3058
3088template <typename D = domain::global>
3089NVTX3_NO_DISCARD inline range_handle start_range_in(event_attributes const& attr) noexcept
3090{
3091#ifndef NVTX_DISABLE
3092 return range_handle{nvtxDomainRangeStartEx(domain::get<D>(), attr.get())};
3093#else
3094 (void)attr;
3095 return {};
3096#endif
3097}
3098
3129template <typename D = domain::global, typename... Args>
3130NVTX3_NO_DISCARD inline range_handle start_range_in(Args const&... args) noexcept
3131{
3132#ifndef NVTX_DISABLE
3133 return start_range_in<D>(event_attributes{args...});
3134#else
3135 detail::silence_unused(args...);
3136 return {};
3137#endif
3138}
3139
3166NVTX3_NO_DISCARD inline range_handle start_range(event_attributes const& attr) noexcept
3167{
3168#ifndef NVTX_DISABLE
3169 return start_range_in<domain::global>(attr);
3170#else
3171 (void)attr;
3172 return {};
3173#endif
3174}
3175
3203template <typename... Args>
3204NVTX3_NO_DISCARD inline range_handle start_range(Args const&... args) noexcept
3205{
3206#ifndef NVTX_DISABLE
3207 return start_range_in<domain::global>(args...);
3208#else
3209 detail::silence_unused(args...);
3210 return {};
3211#endif
3212}
3213
3229template <typename D = domain::global>
3230inline void end_range_in(range_handle r) noexcept
3231{
3232#ifndef NVTX_DISABLE
3233 nvtxDomainRangeEnd(domain::get<D>(), r.get_value());
3234#else
3235 (void)r;
3236#endif
3237}
3238
3252inline void end_range(range_handle r) noexcept
3253{
3254#ifndef NVTX_DISABLE
3255 end_range_in<domain::global>(r);
3256#else
3257 (void)r;
3258#endif
3259}
3260
3282template <typename D = domain::global>
3283class NVTX3_MAYBE_UNUSED unique_range_in {
3284 public:
3298 explicit unique_range_in(event_attributes const& attr) noexcept
3299 : handle_{start_range_in<D>(attr)}
3300 {
3301 }
3302
3322 template <typename... Args>
3323 explicit unique_range_in(Args const&... args) noexcept
3325 {
3326 }
3327
3334
3339 ~unique_range_in() noexcept = default;
3340
3347 unique_range_in(unique_range_in&& other) noexcept = default;
3348
3355 unique_range_in& operator=(unique_range_in&& other) noexcept = default;
3356
3360
3363 unique_range_in& operator=(unique_range_in const&) = delete;
3364
3365 private:
3366
3367 struct end_range_handle {
3368 using pointer = range_handle;
3369 void operator()(range_handle h) const noexcept { end_range_in<D>(h); }
3370 };
3371
3373 std::unique_ptr<range_handle, end_range_handle> handle_;
3374};
3375
3381
3405template <typename D = domain::global>
3406inline void mark_in(event_attributes const& attr) noexcept
3407{
3408#ifndef NVTX_DISABLE
3409 nvtxDomainMarkEx(domain::get<D>(), attr.get());
3410#else
3411 (void)(attr);
3412#endif
3413}
3414
3442template <typename D = domain::global, typename... Args>
3443inline void mark_in(Args const&... args) noexcept
3444{
3445#ifndef NVTX_DISABLE
3446 mark_in<D>(event_attributes{args...});
3447#else
3448 detail::silence_unused(args...);
3449#endif
3450}
3451
3472inline void mark(event_attributes const& attr) noexcept
3473{
3474#ifndef NVTX_DISABLE
3475 mark_in<domain::global>(attr);
3476#else
3477 (void)attr;
3478#endif
3479}
3480
3505template <typename... Args>
3506inline void mark(Args const&... args) noexcept
3507{
3508#ifndef NVTX_DISABLE
3509 mark_in<domain::global>(args...);
3510#else
3511 detail::silence_unused(args...);
3512#endif
3513}
3514
3515/* ===== Counter Semantics API ============================================== */
3516
3538class scope {
3539public:
3540 using value_type = uint64_t;
3541
3550 constexpr explicit scope(value_type id) noexcept : id_{id} {}
3551
3556 constexpr value_type get() const noexcept { return id_; }
3557
3559 static constexpr scope none() noexcept { return scope{NVTX_SCOPE_NONE}; }
3561 static constexpr scope root() noexcept { return scope{NVTX_SCOPE_ROOT}; }
3562
3563 /* Hardware events */
3565 static constexpr scope current_hw_machine() noexcept { return scope{NVTX_SCOPE_CURRENT_HW_MACHINE}; }
3566 static constexpr scope current_hw_socket() noexcept { return scope{NVTX_SCOPE_CURRENT_HW_SOCKET}; }
3568 static constexpr scope current_hw_cpu_physical() noexcept { return scope{NVTX_SCOPE_CURRENT_HW_CPU_PHYSICAL}; }
3570 static constexpr scope current_hw_cpu_logical() noexcept { return scope{NVTX_SCOPE_CURRENT_HW_CPU_LOGICAL}; }
3572 static constexpr scope current_hw_innermost() noexcept { return scope{NVTX_SCOPE_CURRENT_HW_INNERMOST}; }
3573
3574 /* Virtualized hardware, virtual machines */
3575 static constexpr scope current_hypervisor() noexcept { return scope{NVTX_SCOPE_CURRENT_HYPERVISOR}; }
3576 static constexpr scope current_vm() noexcept { return scope{NVTX_SCOPE_CURRENT_VM}; }
3577 static constexpr scope current_kernel() noexcept { return scope{NVTX_SCOPE_CURRENT_KERNEL}; }
3578 static constexpr scope current_container() noexcept { return scope{NVTX_SCOPE_CURRENT_CONTAINER}; }
3579 static constexpr scope current_os() noexcept { return scope{NVTX_SCOPE_CURRENT_OS}; }
3580
3581 /* Software scopes */
3583 static constexpr scope current_sw_process() noexcept { return scope{NVTX_SCOPE_CURRENT_SW_PROCESS}; }
3585 static constexpr scope current_sw_thread() noexcept { return scope{NVTX_SCOPE_CURRENT_SW_THREAD}; }
3587 static constexpr scope current_sw_innermost() noexcept { return scope{NVTX_SCOPE_CURRENT_SW_INNERMOST}; }
3588
3589private:
3590 value_type id_;
3591};
3592
3593namespace detail {
3594
3595// scope_semantic::scope is a builder method whose name hides the scope type
3596// during member lookup. This version-local alias avoids spelling the fully
3597// qualified type name, ::nvtx3::NVTX3_VERSION_NAMESPACE::scope, and depending
3598// on the optional nvtx3::scope name, which is absent when
3599// NVTX3_CPP_REQUIRE_EXPLICIT_VERSION is defined.
3600using scope_type = scope;
3601
3602} // namespace detail
3603
3610enum class no_value_reason : uint8_t {
3611 zero = NVTX_COUNTER_SAMPLE_ZERO,
3612 unchanged = NVTX_COUNTER_SAMPLE_UNCHANGED,
3613 unavailable = NVTX_COUNTER_SAMPLE_UNAVAILABLE
3614};
3615
3641class counter_semantic : public detail::semantic_base<nvtxSemanticsCounter_t> {
3642public:
3647 : detail::semantic_base<nvtxSemanticsCounter_t>{
3648 {{sizeof(nvtxSemanticsCounter_t), NVTX_SEMANTIC_ID_COUNTERS_V1,
3649 NVTX_COUNTER_SEMANTIC_VERSION, nullptr},
3650 NVTX_COUNTER_FLAGS_NONE,
3651 nullptr,
3652 1,
3653 1,
3654 NVTX_COUNTER_LIMIT_UNDEFINED,
3655 {0},
3656 {0}}}
3657 {
3658 }
3659
3660 // Raw C-header chaining is non-owning. Prefer the semantic-wrapper overload.
3666 explicit counter_semantic(nvtxSemanticsHeader_t const* next)
3668 {
3669 set_next(next);
3670 }
3671
3682 template <typename OtherDataType>
3683 explicit counter_semantic(detail::semantic_base<OtherDataType> const& next)
3685 {
3686 own_next(next);
3687 }
3688
3694 counter_semantic& unit(const char* unit_name) noexcept
3695 {
3696 data_.unit = unit_name;
3697 return *this;
3698 }
3699
3705 counter_semantic& unit(std::string const& unit_name) noexcept
3706 {
3707 return unit(unit_name.c_str());
3708 }
3709
3713 counter_semantic& unit(std::string&& unit_name) = delete;
3714
3722 counter_semantic& unit_scale(uint64_t numerator, uint64_t denominator = 1) noexcept
3723 {
3724 data_.unitScaleNumerator = numerator;
3725 data_.unitScaleDenominator = denominator;
3726 return *this;
3727 }
3728
3739 {
3740 data_.flags |= NVTX_COUNTER_FLAG_NORMALIZE;
3741 return *this;
3742 }
3743
3752 {
3753 set_enum_group_flag(NVTX_COUNTER_FLAG_VALUETYPES,
3754 NVTX_COUNTER_FLAG_VALUETYPE_ABSOLUTE, "valuetype");
3755 return *this;
3756 }
3757
3766 {
3767 set_enum_group_flag(NVTX_COUNTER_FLAG_VALUETYPES,
3768 NVTX_COUNTER_FLAG_VALUETYPE_DELTA, "valuetype");
3769 return *this;
3770 }
3771
3780 {
3781 set_enum_group_flag(NVTX_COUNTER_FLAG_VALUETYPES,
3782 NVTX_COUNTER_FLAG_VALUETYPE_DELTA_SINCE_START, "valuetype");
3783 return *this;
3784 }
3785
3794 {
3795 set_enum_group_flag(NVTX_COUNTER_FLAG_INTERPOLATIONS,
3796 NVTX_COUNTER_FLAG_INTERPOLATION_POINT, "interpolation");
3797 return *this;
3798 }
3799
3808 {
3809 set_enum_group_flag(NVTX_COUNTER_FLAG_INTERPOLATIONS,
3810 NVTX_COUNTER_FLAG_INTERPOLATION_SINCE_LAST, "interpolation");
3811 return *this;
3812 }
3813
3822 {
3823 set_enum_group_flag(NVTX_COUNTER_FLAG_INTERPOLATIONS,
3824 NVTX_COUNTER_FLAG_INTERPOLATION_UNTIL_NEXT, "interpolation");
3825 return *this;
3826 }
3827
3836 {
3837 set_enum_group_flag(NVTX_COUNTER_FLAG_INTERPOLATIONS,
3838 NVTX_COUNTER_FLAG_INTERPOLATION_LINEAR, "interpolation");
3839 return *this;
3840 }
3841
3858 template <typename T>
3859 counter_semantic& limits(T min_val, T max_val) noexcept
3860 {
3861 using traits = detail::counter_limit_traits<T>;
3862 data_.limitType = traits::limit_type_value;
3863 data_.flags |= NVTX_COUNTER_FLAG_LIMITS;
3864 traits::store(data_.min, min_val);
3865 traits::store(data_.max, max_val);
3866 return *this;
3867 }
3868
3875 template <typename T>
3876 counter_semantic& limit_min(T min_val) noexcept
3877 {
3878 using traits = detail::counter_limit_traits<T>;
3879 data_.limitType = traits::limit_type_value;
3880 data_.flags |= NVTX_COUNTER_FLAG_LIMIT_MIN;
3881 traits::store(data_.min, min_val);
3882 return *this;
3883 }
3884
3891 template <typename T>
3892 counter_semantic& limit_max(T max_val) noexcept
3893 {
3894 using traits = detail::counter_limit_traits<T>;
3895 data_.limitType = traits::limit_type_value;
3896 data_.flags |= NVTX_COUNTER_FLAG_LIMIT_MAX;
3897 traits::store(data_.max, max_val);
3898 return *this;
3899 }
3900
3901private:
3902 void set_enum_group_flag(uint64_t group_mask, uint64_t value, char const* group_name)
3903 {
3904 if ((data_.flags & group_mask) != 0) {
3905 throw std::logic_error(std::string("counter_semantic: conflicting ") + group_name
3906 + " setter; the " + group_name + " can be set only once");
3907 }
3908 data_.flags |= value;
3909 }
3910};
3911
3919class scope_semantic : public detail::semantic_base<nvtxSemanticsScope_t> {
3920public:
3925 : detail::semantic_base<nvtxSemanticsScope_t>{
3926 {{sizeof(nvtxSemanticsScope_t), NVTX_SEMANTIC_ID_SCOPE_V1,
3927 NVTX_SCOPE_SEMANTIC_VERSION, nullptr},
3928 NVTX_SCOPE_NONE}}
3929 {
3930 }
3931
3932 // Raw C-header chaining is non-owning. Prefer the semantic-wrapper overload.
3938 explicit scope_semantic(nvtxSemanticsHeader_t const* next)
3939 : scope_semantic{}
3940 {
3941 set_next(next);
3942 }
3943
3954 template <typename OtherDataType>
3955 explicit scope_semantic(detail::semantic_base<OtherDataType> const& next)
3956 : scope_semantic{}
3957 {
3958 own_next(next);
3959 }
3960
3966 scope_semantic& scope(uint64_t scope_id) noexcept
3967 {
3968 data_.scopeId = scope_id;
3969 return *this;
3970 }
3971
3978 {
3979 data_.scopeId = s.get();
3980 return *this;
3981 }
3982};
3983
3995template <typename D = domain::global>
3997public:
4011 explicit scope_in(char const* path,
4012 detail::scope_type parent = detail::scope_type::none(),
4013 uint64_t static_id = NVTX_SCOPE_NONE) noexcept
4014 {
4015#ifndef NVTX_DISABLE
4016 nvtxScopeAttr_t attr{};
4017 attr.structSize = sizeof(nvtxScopeAttr_t);
4018 attr.path = path;
4019 attr.parentScope = parent.get();
4020 attr.scopeId = static_id;
4021 id_ = nvtxScopeRegister(domain::get<D>(), &attr);
4022#else
4023 (void)path;
4024 (void)parent;
4025 (void)static_id;
4026 id_ = NVTX_SCOPE_NONE;
4027#endif
4028 }
4029
4043 explicit scope_in(std::string const& path,
4044 detail::scope_type parent = detail::scope_type::none(),
4045 uint64_t static_id = NVTX_SCOPE_NONE) noexcept
4046 : scope_in{path.c_str(), parent, static_id} {}
4047
4049 uint64_t id() const noexcept { return id_; }
4050
4052 operator detail::scope_type() const noexcept { return detail::scope_type{id_}; }
4053
4054private:
4055 uint64_t id_;
4056};
4057
4065class time_semantic : public detail::semantic_base<nvtxSemanticsTime_t> {
4066public:
4070 time_semantic() noexcept
4071 : detail::semantic_base<nvtxSemanticsTime_t>{
4072 {{sizeof(nvtxSemanticsTime_t), NVTX_SEMANTIC_ID_TIME_V1,
4073 NVTX_TIME_SEMANTIC_VERSION, nullptr},
4074 0}}
4075 {
4076 }
4077
4078 // Raw C-header chaining is non-owning. Prefer the semantic-wrapper overload.
4084 explicit time_semantic(nvtxSemanticsHeader_t const* next)
4085 : time_semantic{}
4086 {
4087 set_next(next);
4088 }
4089
4100 template <typename OtherDataType>
4101 explicit time_semantic(detail::semantic_base<OtherDataType> const& next)
4102 : time_semantic{}
4103 {
4104 own_next(next);
4105 }
4106
4113 time_semantic& time_domain(uint64_t domain_id) noexcept
4114 {
4115 data_.timeDomainId = domain_id;
4116 return *this;
4117 }
4118};
4119
4129inline int64_t timestamp() noexcept
4130{
4131#ifndef NVTX_DISABLE
4132 return nvtxTimestampGet();
4133#else
4134 return 0;
4135#endif
4136}
4137
4148template <typename D = domain::global>
4150public:
4165 explicit time_domain_in(uint64_t timestamp_type_id,
4166 detail::scope_type s = detail::scope_type::none(),
4167 uint64_t timer_flags = NVTX_TIMER_FLAG_NONE,
4168 int64_t timer_resolution = 0,
4169 uint64_t timer_start = NVTX_TIMER_START_UNKNOWN,
4170 uint64_t static_id = 0) noexcept
4171 {
4172#ifndef NVTX_DISABLE
4173 nvtxTimeDomainAttr_t attr{};
4174 attr.scopeId = s.get();
4175 attr.timestampTypeId = timestamp_type_id;
4176 attr.timeDomainId = static_id;
4177 attr.timerFlags = timer_flags;
4178 attr.timerResolution = timer_resolution;
4179 attr.timerStart = timer_start;
4180 id_ = nvtxTimeDomainRegister(domain::get<D>(), &attr);
4181#else
4182 (void)timestamp_type_id;
4183 (void)s;
4184 (void)timer_flags;
4185 (void)timer_resolution;
4186 (void)timer_start;
4187 (void)static_id;
4188 id_ = 0;
4189#endif
4190 }
4191
4193 uint64_t id() const noexcept { return id_; }
4194
4204 void set_timer_source(uint64_t flags, int64_t (*provider)()) noexcept
4205 {
4206#ifndef NVTX_DISABLE
4207 nvtxTimerSource(domain::get<D>(), id_, flags, provider);
4208#else
4209 (void)flags;
4210 (void)provider;
4211#endif
4212 }
4213
4224 void set_timer_source(uint64_t flags,
4225 int64_t (*provider)(void*),
4226 void* data) noexcept
4227 {
4228#ifndef NVTX_DISABLE
4229 nvtxTimerSourceWithData(domain::get<D>(), id_, flags, provider, data);
4230#else
4231 (void)flags;
4232 (void)provider;
4233 (void)data;
4234#endif
4235 }
4236
4247 void sync_point(uint64_t other_id, int64_t ts_self, int64_t ts_other) noexcept
4248 {
4249#ifndef NVTX_DISABLE
4250 nvtxTimeSyncPoint(domain::get<D>(), id_, other_id, ts_self, ts_other);
4251#else
4252 (void)other_id;
4253 (void)ts_self;
4254 (void)ts_other;
4255#endif
4256 }
4257
4267 void sync_point_table(uint64_t other_id,
4268 nvtxSyncPoint_t const* points,
4269 size_t count) noexcept
4270 {
4271#ifndef NVTX_DISABLE
4272 nvtxTimeSyncPointTable(domain::get<D>(), id_, other_id, points, count);
4273#else
4274 (void)other_id;
4275 (void)points;
4276 (void)count;
4277#endif
4278 }
4279
4290 void conversion_factor(uint64_t other_id,
4291 double slope,
4292 int64_t ts_self,
4293 int64_t ts_other) noexcept
4294 {
4295#ifndef NVTX_DISABLE
4296 nvtxTimestampConversionFactor(domain::get<D>(), id_, other_id, slope, ts_self, ts_other);
4297#else
4298 (void)other_id;
4299 (void)slope;
4300 (void)ts_self;
4301 (void)ts_other;
4302#endif
4303 }
4304
4305private:
4306 uint64_t id_;
4307};
4308
4317class correlation_semantic : public detail::semantic_base<nvtxSemanticsCorrelation_t> {
4318public:
4323 : detail::semantic_base<nvtxSemanticsCorrelation_t>{
4324 {{sizeof(nvtxSemanticsCorrelation_t), NVTX_SEMANTIC_ID_CORRELATION_V1,
4325 NVTX_CORRELATION_SEMANTIC_VERSION, nullptr},
4326 {0},
4327 nullptr,
4328 NVTX_CORRELATION_ROLE_NONE}}
4329 {
4330 }
4331
4332 // Raw C-header chaining is non-owning. Prefer the semantic-wrapper overload.
4338 explicit correlation_semantic(nvtxSemanticsHeader_t const* next)
4340 {
4341 set_next(next);
4342 }
4343
4354 template <typename OtherDataType>
4355 explicit correlation_semantic(detail::semantic_base<OtherDataType> const& next)
4357 {
4358 own_next(next);
4359 }
4360
4366 correlation_semantic& domain_uuid(const unsigned char uuid[16]) noexcept
4367 {
4368 for (int i = 0; i < 16; ++i) {
4369 data_.correlationDomainUuid[i] = uuid[i];
4370 }
4371 return *this;
4372 }
4373
4380 correlation_semantic& display_name(const char* name) noexcept
4381 {
4382 data_.displayName = name;
4383 return *this;
4384 }
4385
4392 correlation_semantic& display_name(std::string const& name) noexcept
4393 {
4394 return display_name(name.c_str());
4395 }
4396
4400 correlation_semantic& display_name(std::string&& name) = delete;
4401
4407 correlation_semantic& role(uint64_t role_id) noexcept
4408 {
4409 data_.role = role_id;
4410 return *this;
4411 }
4412};
4413
4414namespace detail {
4415
4422template <typename T, typename = void>
4423struct counter_schema_id {
4424 static uint64_t get() noexcept
4425 {
4426 return schema::get<T>().get_handle();
4427 }
4428};
4429
4430// Specializations for primitive types
4431template <>
4432struct counter_schema_id<int64_t> {
4433 static constexpr uint64_t get() noexcept { return NVTX_PAYLOAD_ENTRY_TYPE_INT64; }
4434};
4435
4436template <>
4437struct counter_schema_id<uint64_t> {
4438 static constexpr uint64_t get() noexcept { return NVTX_PAYLOAD_ENTRY_TYPE_UINT64; }
4439};
4440
4441template <>
4442struct counter_schema_id<int32_t> {
4443 static constexpr uint64_t get() noexcept { return NVTX_PAYLOAD_ENTRY_TYPE_INT32; }
4444};
4445
4446template <>
4447struct counter_schema_id<uint32_t> {
4448 static constexpr uint64_t get() noexcept { return NVTX_PAYLOAD_ENTRY_TYPE_UINT32; }
4449};
4450
4451template <>
4452struct counter_schema_id<double> {
4453 static constexpr uint64_t get() noexcept { return NVTX_PAYLOAD_ENTRY_TYPE_FLOAT64; }
4454};
4455
4456template <>
4457struct counter_schema_id<float> {
4458 static constexpr uint64_t get() noexcept { return NVTX_PAYLOAD_ENTRY_TYPE_FLOAT; }
4459};
4460
4461} // namespace detail
4462
4497template <typename T, typename D = domain::global>
4499public:
4500 using value_type = T;
4501
4509 counter_in(const char* name, const char* description = nullptr, scope s = scope::none() ) noexcept
4510 : counter_in{name, description, s, nullptr}
4511 {
4512 }
4513
4520 counter_in(std::string const& name, scope s = scope::none()) noexcept
4521 : counter_in{name.c_str(), nullptr, s, nullptr}
4522 {
4523 }
4524
4532 counter_in(std::string const& name,
4533 std::string const& description,
4534 scope s = scope::none()) noexcept
4535 : counter_in{name.c_str(), description.c_str(), s, nullptr}
4536 {
4537 }
4538
4547 counter_in(const char* name, const char* description, scope s, const counter_semantic& semantic) noexcept
4548 : counter_in{name, description, s, &semantic}
4549 {
4550 }
4551
4560 counter_in(std::string const& name,
4561 std::string const& description,
4562 scope s,
4563 const counter_semantic& semantic) noexcept
4564 : counter_in{name.c_str(), description.c_str(), s, &semantic}
4565 {
4566 }
4567
4577 void sample(T const& value) noexcept
4578 {
4579#ifndef NVTX_DISABLE
4580 sample_impl(value, std::is_same<T, int64_t>{}, std::is_same<T, double>{});
4581#else
4582 (void)value;
4583#endif
4584 }
4585
4593 void sample_no_value(no_value_reason reason) noexcept
4594 {
4595#ifndef NVTX_DISABLE
4596 nvtxCounterSampleNoValue(domain::get<D>(), id_, static_cast<uint8_t>(reason));
4597#else
4598 (void)reason;
4599#endif
4600 }
4601
4612 void submit_batch(T const* values,
4613 size_t count,
4614 uint64_t flags = NVTX_BATCH_FLAG_TIME_SORTED) noexcept
4615 {
4616 submit_batch(values, count, nullptr, 0, flags);
4617 }
4618
4628 void submit_batch(T const* values,
4629 size_t count,
4630 int64_t const* timestamps,
4631 size_t timestamp_count,
4632 uint64_t flags = NVTX_BATCH_FLAG_TIME_SORTED) noexcept
4633 {
4634#ifndef NVTX_DISABLE
4635 nvtxCounterBatch_t batch{};
4636 batch.counterId = id_;
4637 batch.counters = values;
4638 batch.countersSize = count * sizeof(T);
4639 batch.flags = flags;
4640 batch.timestamps = timestamps;
4641 batch.timestampsSize = timestamp_count * sizeof(int64_t);
4642
4643 nvtxCounterBatchSubmit(domain::get<D>(), &batch);
4644#else
4645 (void)values;
4646 (void)count;
4647 (void)timestamps;
4648 (void)timestamp_count;
4649 (void)flags;
4650#endif
4651 }
4652
4659 template <
4660 typename CounterContainer,
4661 typename = typename std::enable_if<
4662 detail::has_data_member<CounterContainer, T>::value
4663 && detail::has_size_member<CounterContainer>::value>::type>
4664 void submit_batch(CounterContainer const& values,
4665 uint64_t flags = NVTX_BATCH_FLAG_TIME_SORTED) noexcept
4666 {
4667 submit_batch(values.data(), values.size(), flags);
4668 }
4669
4676 template <
4677 typename CounterContainer,
4678 typename TimestampContainer,
4679 typename = typename std::enable_if<
4680 detail::has_data_member<CounterContainer, T>::value
4681 && detail::has_size_member<CounterContainer>::value
4682 && detail::has_data_member<TimestampContainer, int64_t>::value
4683 && detail::has_size_member<TimestampContainer>::value>::type>
4684 void submit_batch(CounterContainer const& values,
4685 TimestampContainer const& timestamps,
4686 uint64_t flags = NVTX_BATCH_FLAG_TIME_SORTED) noexcept
4687 {
4688 submit_batch(values.data(), values.size(), timestamps.data(), timestamps.size(), flags);
4689 }
4690
4698 uint64_t id() const noexcept { return id_; }
4699
4700private:
4701 counter_in(const char* name, const char* description, scope s, counter_semantic const* semantic) noexcept
4702 {
4703#ifndef NVTX_DISABLE
4704 nvtxCounterAttr_t attr{};
4705 attr.structSize = sizeof(nvtxCounterAttr_t);
4706 attr.schemaId = detail::counter_schema_id<T>::get();
4707 attr.name = name;
4708 attr.description = description;
4709 attr.scopeId = s.get();
4710 attr.semantics = semantic ? semantic->get() : nullptr;
4711
4712 id_ = nvtxCounterRegister(domain::get<D>(), &attr);
4713#else
4714 (void)name;
4715 (void)description;
4716 (void)s;
4717 (void)semantic;
4718#endif
4719 }
4720
4721 // Overloads for optimized primitive sampling (int64_t)
4722 void sample_impl(int64_t value, std::true_type /*is_int64*/, std::false_type) noexcept
4723 {
4724 nvtxCounterSampleInt64(domain::get<D>(), id_, value);
4725 }
4726
4727 // Overloads for optimized primitive sampling (double)
4728 void sample_impl(double value, std::false_type, std::true_type /*is_double*/) noexcept
4729 {
4730 nvtxCounterSampleFloat64(domain::get<D>(), id_, value);
4731 }
4732
4733 // Generic fallback for struct types
4734 void sample_impl(T const& value, std::false_type, std::false_type) noexcept
4735 {
4736 nvtxCounterSample(domain::get<D>(), id_, &value, sizeof(T));
4737 }
4738
4739 uint64_t id_{0};
4740};
4741
4750template <typename T>
4752
4753} // namespace NVTX3_MINOR_VERSION_NAMESPACE
4754} // namespace NVTX3_VERSION_NAMESPACE
4755} // namespace nvtx3
4756
4757#ifndef NVTX_DISABLE
4786#define NVTX3_V1_FUNC_RANGE_IN(D) \
4787 static ::nvtx3::v1::registered_string_in<D> const nvtx3_func_name__{__func__}; \
4788 static ::nvtx3::v1::event_attributes const nvtx3_func_attr__{nvtx3_func_name__}; \
4789 ::nvtx3::v1::scoped_range_in<D> const nvtx3_range__{nvtx3_func_attr__}
4790
4807#define NVTX3_V1_FUNC_RANGE_IF_IN(D, C) \
4808 ::nvtx3::v1::detail::optional_scoped_range_in<D> optional_nvtx3_range__; \
4809 if (C) { \
4810 static ::nvtx3::v1::registered_string_in<D> const nvtx3_func_name__{__func__}; \
4811 static ::nvtx3::v1::event_attributes const nvtx3_func_attr__{nvtx3_func_name__}; \
4812 optional_nvtx3_range__.begin(nvtx3_func_attr__); \
4813 } (void)0
4814#else /* NVTX_DISABLE */
4815#define NVTX3_V1_FUNC_RANGE_IN(D) (void)0
4816#define NVTX3_V1_FUNC_RANGE_IF_IN(D, C) (void)(C)
4817#endif /* NVTX_DISABLE */
4818
4841#define NVTX3_V1_FUNC_RANGE() NVTX3_V1_FUNC_RANGE_IN(::nvtx3::v1::domain::global)
4842
4854#define NVTX3_V1_FUNC_RANGE_IF(C) NVTX3_V1_FUNC_RANGE_IF_IN(::nvtx3::v1::domain::global, C)
4855
4856// We need another helper macro because the other one will get undefined
4857#if __has_cpp_attribute(nodiscard)
4858#define NVTX3_V1_NO_DISCARD [[nodiscard]]
4859#else
4860#define NVTX3_V1_NO_DISCARD
4861#endif
4898#define NVTX3_V1_DEFINE_SCHEMA_GET(dom, struct_id, schema_name, entries) \
4899 template <> \
4900 NVTX3_V1_NO_DISCARD inline nvtx3::v1::schema const& nvtx3::v1::schema::get<struct_id>() noexcept \
4901 { \
4902 static_assert( \
4903 std::is_standard_layout<struct_id>::value, \
4904 "structs used for NVTX3 payload schema must be standard layout"); \
4905 static_assert( \
4906 std::is_trivially_copyable<struct_id>::value, \
4907 "structs used for NVTX3 payload schema must be trivially copyable"); \
4908 using nvtx_struct_id = struct_id; /* avoids issues with namespaced struct_id */ \
4909 _NVTX_DEFINE_SCHEMA_FOR_STRUCT(nvtx_struct_id, schema_name, static const, entries) \
4910 static const schema s{ \
4911 nvtxPayloadSchemaRegister(nvtx3::v1::domain::get<dom>(), &nvtx_struct_id##Attr)}; \
4912 return s; \
4913 }
4914
4944#define NVTX3_V1_SEMANTIC(expr) \
4945 ([]() -> nvtxSemanticsHeader_t const* { \
4946 static auto const s_ = (expr); \
4947 return s_.get(); \
4948 }())
4949
4950/* When inlining this version, versioned macros must have unversioned aliases.
4951 * For each NVTX3_Vx_ #define, make an NVTX3_ alias of it here.*/
4952#if defined(NVTX3_INLINE_THIS_VERSION)
4953/* clang format off */
4954#define NVTX3_FUNC_RANGE NVTX3_V1_FUNC_RANGE
4955#define NVTX3_FUNC_RANGE_IF NVTX3_V1_FUNC_RANGE_IF
4956#define NVTX3_FUNC_RANGE_IN NVTX3_V1_FUNC_RANGE_IN
4957#define NVTX3_FUNC_RANGE_IF_IN NVTX3_V1_FUNC_RANGE_IF_IN
4958#define NVTX3_DEFINE_SCHEMA_GET NVTX3_V1_DEFINE_SCHEMA_GET
4959#define NVTX3_SEMANTIC NVTX3_V1_SEMANTIC
4960/* clang format on */
4961#endif
4962
4963#endif // NVTX3_CPP_DEFINITIONS_V1_0
4964
4965/* Undefine all temporarily-defined unversioned macros, which would conflict with
4966 * subsequent includes of different versions of this header. */
4967#undef NVTX3_CPP_VERSION_MAJOR
4968#undef NVTX3_CPP_VERSION_MINOR
4969#undef NVTX3_CONCAT
4970#undef NVTX3_NAMESPACE_FOR
4971#undef NVTX3_VERSION_NAMESPACE
4972#undef NVTX3_MINOR_NAMESPACE_FOR
4973#undef NVTX3_MINOR_VERSION_NAMESPACE
4974#undef NVTX3_INLINE_IF_REQUESTED
4975#undef NVTX3_CONSTEXPR_IF_CPP14
4976#undef NVTX3_CONSTEXPR_IF_CPP20
4977#undef NVTX3_MAYBE_UNUSED
4978#undef NVTX3_NO_DISCARD
4979
4980#if defined(NVTX3_INLINE_THIS_VERSION)
4981#undef NVTX3_INLINE_THIS_VERSION
4982#endif
4983
4984#if defined(NVTX3_USE_CHECKED_OVERLOADS_FOR_GET_DEFINED_HERE)
4985#undef NVTX3_USE_CHECKED_OVERLOADS_FOR_GET_DEFINED_HERE
4986#undef NVTX3_USE_CHECKED_OVERLOADS_FOR_GET
4987#endif
4988
4989#if defined(NVTX3_STATIC_ASSERT_DEFINED_HERE)
4990#undef NVTX3_STATIC_ASSERT_DEFINED_HERE
4991#undef NVTX3_STATIC_ASSERT
4992#endif
Object for intra-domain grouping of NVTX events.
Definition nvtx3.hpp:1446
constexpr category(id_type id) noexcept
Construct a category with the specified id.
Definition nvtx3.hpp:1460
constexpr id_type get_id() const noexcept
Returns the id of the category.
Definition nvtx3.hpp:1466
uint32_t id_type
Type used for categorys integer id.
Definition nvtx3.hpp:1449
Represents a custom color that can be associated with an NVTX event via its event_attributes.
Definition nvtx3.hpp:1339
constexpr color(rgb rgb_) noexcept
Construct a color using the red, green, blue components in rgb.
Definition nvtx3.hpp:1382
uint32_t value_type
Type used for the color's value.
Definition nvtx3.hpp:1342
constexpr color(argb argb_) noexcept
Construct a color using the alpha, red, green, blue components in argb.
Definition nvtx3.hpp:1369
constexpr nvtxColorType_t get_type() const noexcept
Return the NVTX color type of the color.
Definition nvtx3.hpp:1397
constexpr color(value_type hex_code) noexcept
Constructs a color using the value provided by hex_code.
Definition nvtx3.hpp:1361
constexpr value_type get_value() const noexcept
Returns the colors argb hex code.
Definition nvtx3.hpp:1391
Builder for the correlation semantic applied to a payload entry.
Definition nvtx3.hpp:4317
correlation_semantic(detail::semantic_base< OtherDataType > const &next)
Construct a correlation semantic that chains to another semantic builder.
Definition nvtx3.hpp:4355
correlation_semantic & display_name(const char *name) noexcept
Set the optional display name for the correlation domain.
Definition nvtx3.hpp:4380
correlation_semantic & role(uint64_t role_id) noexcept
Set the role this entry plays in the correlation.
Definition nvtx3.hpp:4407
correlation_semantic(nvtxSemanticsHeader_t const *next)
Construct a correlation semantic chained to another semantic header.
Definition nvtx3.hpp:4338
correlation_semantic & domain_uuid(const unsigned char uuid[16]) noexcept
Set the correlation domain UUID.
Definition nvtx3.hpp:4366
correlation_semantic & display_name(std::string &&name)=delete
Disallow setting the borrowed display name from a temporary string.
correlation_semantic() noexcept
Construct an unchained correlation semantic.
Definition nvtx3.hpp:4322
correlation_semantic & display_name(std::string const &name) noexcept
Set the optional display name for the correlation domain.
Definition nvtx3.hpp:4392
A type-safe NVTX counter in a specific domain.
Definition nvtx3.hpp:4498
void submit_batch(T const *values, size_t count, int64_t const *timestamps, size_t timestamp_count, uint64_t flags=0) noexcept
Submit a batch of counter samples with external timestamps.
Definition nvtx3.hpp:4628
void sample(T const &value) noexcept
Sample the counter with a value.
Definition nvtx3.hpp:4577
void sample_no_value(no_value_reason reason) noexcept
Sample the counter without a value.
Definition nvtx3.hpp:4593
void submit_batch(T const *values, size_t count, uint64_t flags=0) noexcept
Submit a batch of counter samples.
Definition nvtx3.hpp:4612
counter_in(const char *name, const char *description, scope s, const counter_semantic &semantic) noexcept
Construct a counter with name, description, scope, and semantics.
Definition nvtx3.hpp:4547
void submit_batch(CounterContainer const &values, TimestampContainer const &timestamps, uint64_t flags=0) noexcept
Submit a batch from contiguous sample and timestamp containers.
Definition nvtx3.hpp:4684
uint64_t id() const noexcept
Get the underlying counter ID.
Definition nvtx3.hpp:4698
counter_in(std::string const &name, scope s=scope::none()) noexcept
Construct a counter with a name and scope.
Definition nvtx3.hpp:4520
counter_in(std::string const &name, std::string const &description, scope s, const counter_semantic &semantic) noexcept
Construct a counter with name, description, scope, and semantics.
Definition nvtx3.hpp:4560
counter_in(const char *name, const char *description=nullptr, scope s=scope::none()) noexcept
Construct a counter with a name, description, and scope.
Definition nvtx3.hpp:4509
counter_in(std::string const &name, std::string const &description, scope s=scope::none()) noexcept
Construct a counter with a name, description, and scope.
Definition nvtx3.hpp:4532
void submit_batch(CounterContainer const &values, uint64_t flags=0) noexcept
Submit a batch from a contiguous container.
Definition nvtx3.hpp:4664
Builder class for configuring counter semantics.
Definition nvtx3.hpp:3641
counter_semantic & unit_scale(uint64_t numerator, uint64_t denominator=1) noexcept
Set the unit scale as a fraction (numerator/denominator).
Definition nvtx3.hpp:3722
counter_semantic & normalize() noexcept
Enable normalization of counter values.
Definition nvtx3.hpp:3738
counter_semantic & limit_min(T min_val) noexcept
Set only the minimum limit, typed.
Definition nvtx3.hpp:3876
counter_semantic & valuetype_delta()
Set value type to delta from previous sample.
Definition nvtx3.hpp:3765
counter_semantic & interpolation_linear()
Set interpolation to linear between samples.
Definition nvtx3.hpp:3835
counter_semantic & limits(T min_val, T max_val) noexcept
Set minimum and maximum limits, typed.
Definition nvtx3.hpp:3859
counter_semantic() noexcept
Construct an unchained counter semantic.
Definition nvtx3.hpp:3646
counter_semantic & unit(std::string &&unit_name)=delete
Disallow setting the borrowed unit string from a temporary string.
counter_semantic & interpolation_until_next()
Set interpolation to piecewise constant until next sample.
Definition nvtx3.hpp:3821
counter_semantic & unit(const char *unit_name) noexcept
Set the unit string for the counter (e.g., "bytes", "ms", "%").
Definition nvtx3.hpp:3694
counter_semantic(nvtxSemanticsHeader_t const *next)
Construct a counter semantic chained to another semantic header.
Definition nvtx3.hpp:3666
counter_semantic(detail::semantic_base< OtherDataType > const &next)
Construct a counter semantic that chains to another semantic builder.
Definition nvtx3.hpp:3683
counter_semantic & limit_max(T max_val) noexcept
Set only the maximum limit, typed.
Definition nvtx3.hpp:3892
counter_semantic & valuetype_delta_since_start()
Set value type to delta since start.
Definition nvtx3.hpp:3779
counter_semantic & valuetype_absolute()
Set value type to absolute.
Definition nvtx3.hpp:3751
counter_semantic & unit(std::string const &unit_name) noexcept
Set the unit string for the counter (e.g., "bytes", "ms", "%").
Definition nvtx3.hpp:3705
counter_semantic & interpolation_since_last()
Set interpolation to piecewise constant from last sample.
Definition nvtx3.hpp:3807
counter_semantic & interpolation_point()
Set interpolation to point (no interpolation between samples).
Definition nvtx3.hpp:3793
domains allow for grouping NVTX events into a single scope to differentiate them from events in other...
Definition nvtx3.hpp:1049
static domain const & get() noexcept
Returns reference to an instance of a function local static domain object.
Definition nvtx3.hpp:1119
Describes the attributes of a NVTX event.
Definition nvtx3.hpp:2439
event_attributes(category const &c, Args const &... args) noexcept
Variadic constructor where the first argument is a category.
Definition nvtx3.hpp:2471
event_attributes(message const &m, Args const &... args) noexcept
Variadic constructor where the first argument is a message.
Definition nvtx3.hpp:2569
constexpr event_attributes() noexcept
Default constructor creates an event_attributes with no category, color, payload, nor message.
Definition nvtx3.hpp:2447
event_attributes(T &&pdc, Args const &... args) noexcept
Variadic constructor template for containers of payload_data.
Definition nvtx3.hpp:2549
event_attributes(payload const &p, Args const &... args) noexcept
Variadic constructor where the first argument is a payload.
Definition nvtx3.hpp:2500
event_attributes(color const &c, Args const &... args) noexcept
Variadic constructor where the first argument is a color.
Definition nvtx3.hpp:2485
event_attributes(payload_data const &pd, Args const &... args) noexcept
Variadic constructor where the first argument is a single payload_data.
Definition nvtx3.hpp:2515
constexpr value_type const * get() const noexcept
Get raw pointer to underlying NVTX attributes object.
Definition nvtx3.hpp:2586
event_attributes(payload_data &&pd, Args const &... args)=delete
Deleted constructor for payload_data rvalue references.
Allows associating a message string with an NVTX event via its EventAttributes.
Definition nvtx3.hpp:1978
message(std::string const &msg) noexcept
Construct a message whose contents are specified by msg.
Definition nvtx3.hpp:1997
message(std::wstring const &msg) noexcept
Construct a message whose contents are specified by msg.
Definition nvtx3.hpp:2026
constexpr nvtxMessageType_t get_type() const noexcept
Return the type information about the value the union holds.
Definition nvtx3.hpp:2089
message(std::string &&)=delete
Disallow construction for std::string r-value.
message(wchar_t const *msg) noexcept
Construct a message whose contents are specified by msg.
Definition nvtx3.hpp:2016
message(nvtxStringHandle_t handle) noexcept
Construct a message from NVTX C API registered string handle.
Definition nvtx3.hpp:2073
message(std::wstring &&)=delete
Disallow construction for std::wstring r-value.
constexpr value_type get_value() const noexcept
Return the union holding the value of the message.
Definition nvtx3.hpp:2083
message(registered_string_in< D > const &msg) noexcept
Construct a message from a registered_string_in.
Definition nvtx3.hpp:2049
constexpr message(nvtxMessageType_t const &type, nvtxMessageValue_t const &value) noexcept
Construct a message from NVTX C API type and value.
Definition nvtx3.hpp:2061
message(char const *msg) noexcept
Construct a message whose contents are specified by msg.
Definition nvtx3.hpp:1987
A category with an associated name string.
Definition nvtx3.hpp:1529
named_category_in(id_type id, char const *name) noexcept
Construct a named_category_in with the specified id and name.
Definition nvtx3.hpp:1645
static named_category_in const & get() noexcept
Returns a global instance of a named_category_in as a function-local static.
Definition nvtx3.hpp:1571
named_category_in(id_type id, std::string const &name) noexcept
Construct a named_category_in with the specified id and name.
Definition nvtx3.hpp:1665
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:1678
named_category_in(id_type id, std::wstring const &name) noexcept
Construct a named_category_in with the specified id and name.
Definition nvtx3.hpp:1698
Wrapper around the NVTX C API nvtxPayloadData_t struct.
Definition nvtx3.hpp:2296
uint64_t as_ull_value() const noexcept
Definition nvtx3.hpp:2369
payload_data(nvtxPayloadData_t const &pd)
Constructs payload_data from an existing NVTX C API struct.
Definition nvtx3.hpp:2305
payload_data(T const &t, schema s)
Constructs payload_data for a payload instance with a given schema.
Definition nvtx3.hpp:2357
payload_data(R &&t)
Constructs payload_data for a specific payload struct instance.
Definition nvtx3.hpp:2330
A numerical value that can be associated with an NVTX event via its event_attributes.
Definition nvtx3.hpp:2112
constexpr nvtxPayloadType_t get_type() const noexcept
Return the information about the type the union holds.
Definition nvtx3.hpp:2207
payload(float value) noexcept
Construct a payload from a single-precision floating point value.
Definition nvtx3.hpp:2166
constexpr value_type get_value() const noexcept
Return the union holding the value of the payload.
Definition nvtx3.hpp:2201
constexpr payload(nvtxPayloadType_t const &type, value_type const &value) noexcept
Construct a payload from NVTX C API type and value.
Definition nvtx3.hpp:2190
payload(int64_t value) noexcept
Construct a payload from a signed, 8 byte integer.
Definition nvtx3.hpp:2121
payload(uint32_t value) noexcept
Construct a payload from an unsigned, 4 byte integer.
Definition nvtx3.hpp:2154
payload(int32_t value) noexcept
Construct a payload from a signed, 4 byte integer.
Definition nvtx3.hpp:2132
payload(double value) noexcept
Construct a payload from a double-precision floating point value.
Definition nvtx3.hpp:2178
payload(uint64_t value) noexcept
Construct a payload from an unsigned, 8 byte integer.
Definition nvtx3.hpp:2143
A message registered with NVTX.
Definition nvtx3.hpp:1755
registered_string_in(std::string const &msg) noexcept
Constructs a registered_string_in from the specified msg string.
Definition nvtx3.hpp:1873
nvtxStringHandle_t get_handle() const noexcept
Returns the registered string's handle.
Definition nvtx3.hpp:1910
registered_string_in(std::wstring const &msg) noexcept
Constructs a registered_string_in from the specified msg string.
Definition nvtx3.hpp:1903
registered_string_in(char const *msg) noexcept
Constructs a registered_string_in from the specified msg string.
Definition nvtx3.hpp:1857
static registered_string_in const & get() noexcept
Returns a global instance of a registered_string_in as a function local static.
Definition nvtx3.hpp:1795
registered_string_in(wchar_t const *msg) noexcept
Constructs a registered_string_in from the specified msg string.
Definition nvtx3.hpp:1887
Represents the registered schema for a payload struct.
Definition nvtx3.hpp:2226
static schema const & get() noexcept
Gets the schema instance for a specific payload struct type.
Definition nvtx3.hpp:2266
schema(uint64_t id)
Constructs a schema object directly from a schema ID.
Definition nvtx3.hpp:2251
uint64_t get_handle() const noexcept
Return the underlying C handle of the schema.
Definition nvtx3.hpp:2279
A domain-scoped handle to a user-registered NVTX scope.
Definition nvtx3.hpp:3996
uint64_t id() const noexcept
The registered scope ID (NVTX_SCOPE_NONE on failure).
Definition nvtx3.hpp:4049
scope_in(std::string const &path, detail::scope_type parent=detail::scope_type::none(), uint64_t static_id=0) noexcept
Register a scope in the given domain from the specified path string.
Definition nvtx3.hpp:4043
scope_in(char const *path, detail::scope_type parent=detail::scope_type::none(), uint64_t static_id=0) noexcept
Register a scope in the given domain.
Definition nvtx3.hpp:4011
Builder for the scope semantic applied to a payload entry.
Definition nvtx3.hpp:3919
scope_semantic & scope(detail::scope_type s) noexcept
Set the scope by nvtx3::scope identifier.
Definition nvtx3.hpp:3977
scope_semantic(nvtxSemanticsHeader_t const *next)
Construct a scope semantic chained to another semantic header.
Definition nvtx3.hpp:3938
scope_semantic & scope(uint64_t scope_id) noexcept
Set the scope by raw NVTX scope identifier.
Definition nvtx3.hpp:3966
scope_semantic() noexcept
Construct an unchained scope semantic.
Definition nvtx3.hpp:3924
scope_semantic(detail::semantic_base< OtherDataType > const &next)
Construct a scope semantic that chains to another semantic builder.
Definition nvtx3.hpp:3955
Type-safe wrapper for NVTX scope identifiers.
Definition nvtx3.hpp:3538
static constexpr scope current_hw_cpu_logical() noexcept
Logical CPU core.
Definition nvtx3.hpp:3570
static constexpr scope none() noexcept
No scope specified.
Definition nvtx3.hpp:3559
static constexpr scope current_hw_innermost() noexcept
Innermost HW execution context.
Definition nvtx3.hpp:3572
static constexpr scope current_hw_machine() noexcept
Node/machine name.
Definition nvtx3.hpp:3565
static constexpr scope current_sw_process() noexcept
Process scope.
Definition nvtx3.hpp:3583
static constexpr scope current_sw_innermost() noexcept
Innermost SW execution context.
Definition nvtx3.hpp:3587
static constexpr scope current_sw_thread() noexcept
Thread scope.
Definition nvtx3.hpp:3585
static constexpr scope root() noexcept
The root in a hierarchy.
Definition nvtx3.hpp:3561
constexpr value_type get() const noexcept
Get the underlying scope ID.
Definition nvtx3.hpp:3556
static constexpr scope current_hw_cpu_physical() noexcept
Physical CPU core.
Definition nvtx3.hpp:3568
constexpr scope(value_type id) noexcept
Explicit constructor from a raw scope ID.
Definition nvtx3.hpp:3550
A RAII object for creating a NVTX range local to a thread within a domain.
Definition nvtx3.hpp:2640
scoped_range_in() noexcept
Default constructor creates a scoped_range_in with no message, color, payload, nor category.
Definition nvtx3.hpp:2696
scoped_range_in(Args const &... args) noexcept
Constructs a scoped_range_in from the constructor arguments of an event_attributes.
Definition nvtx3.hpp:2686
~scoped_range_in() noexcept
Destroy the scoped_range_in, ending the NVTX range event.
Definition nvtx3.hpp:2714
scoped_range_in(event_attributes const &attr) noexcept
Construct a scoped_range_in with the specified event_attributes
Definition nvtx3.hpp:2656
A domain-scoped handle to a user-registered NVTX time domain.
Definition nvtx3.hpp:4149
void conversion_factor(uint64_t other_id, double slope, int64_t ts_self, int64_t ts_other) noexcept
Report a conversion factor from this domain to another.
Definition nvtx3.hpp:4290
void set_timer_source(uint64_t flags, int64_t(*provider)(void *), void *data) noexcept
Describe the timer source with a user data pointer.
Definition nvtx3.hpp:4224
uint64_t id() const noexcept
The registered time domain ID.
Definition nvtx3.hpp:4193
void set_timer_source(uint64_t flags, int64_t(*provider)()) noexcept
Describe the timer source for this time domain.
Definition nvtx3.hpp:4204
void sync_point(uint64_t other_id, int64_t ts_self, int64_t ts_other) noexcept
Report one synchronization point to another time domain.
Definition nvtx3.hpp:4247
void sync_point_table(uint64_t other_id, nvtxSyncPoint_t const *points, size_t count) noexcept
Report a table of synchronization points to another time domain.
Definition nvtx3.hpp:4267
time_domain_in(uint64_t timestamp_type_id, detail::scope_type s=detail::scope_type::none(), uint64_t timer_flags=0, int64_t timer_resolution=0, uint64_t timer_start=0, uint64_t static_id=0) noexcept
Register a time domain in the given NVTX domain.
Definition nvtx3.hpp:4165
Builder for the time semantic applied to a payload entry.
Definition nvtx3.hpp:4065
time_semantic(detail::semantic_base< OtherDataType > const &next)
Construct a time semantic that chains to another semantic builder.
Definition nvtx3.hpp:4101
time_semantic(nvtxSemanticsHeader_t const *next)
Construct a time semantic chained to another semantic header.
Definition nvtx3.hpp:4084
time_semantic & time_domain(uint64_t domain_id) noexcept
Set the time domain by identifier.
Definition nvtx3.hpp:4113
time_semantic() noexcept
Construct an unchained time semantic.
Definition nvtx3.hpp:4070
A RAII object for creating a NVTX range within a domain that can be created and destroyed on differen...
Definition nvtx3.hpp:3283
unique_range_in(event_attributes const &attr) noexcept
Construct a new unique_range_in object with the specified event attributes.
Definition nvtx3.hpp:3298
~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:3323
constexpr unique_range_in() noexcept
Default constructor creates a unique_range_in with no message, color, payload, nor category.
Definition nvtx3.hpp:3333
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:3472
int push_range_in(event_attributes const &attr) noexcept
Manually begin a nested thread range in a domain.
Definition nvtx3.hpp:2761
int pop_range() noexcept
Manually end the current nested thread range in the global domain.
Definition nvtx3.hpp:2923
constexpr bool operator!=(range_handle lhs, range_handle rhs) noexcept
Compares two range_handles for inequality.
Definition nvtx3.hpp:3057
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:3406
void end_range(range_handle r) noexcept
Manually end the range associated with the handle r in the global domain.
Definition nvtx3.hpp:3252
range_handle start_range_in(event_attributes const &attr) noexcept
Manually begin an NVTX range.
Definition nvtx3.hpp:3089
no_value_reason
Reasons for sampling a counter without a value.
Definition nvtx3.hpp:3610
void end_range_in(range_handle r) noexcept
Manually end the range associated with the handle r in domain D.
Definition nvtx3.hpp:3230
int64_t timestamp() noexcept
Read a timestamp from the NVTX handler (wraps nvtxTimestampGet).
Definition nvtx3.hpp:4129
int pop_range_in() noexcept
Manually end the current nested thread range in a domain.
Definition nvtx3.hpp:2896
range_handle start_range(event_attributes const &attr) noexcept
Manually begin an NVTX range in the global domain.
Definition nvtx3.hpp:3166
constexpr bool operator==(range_handle lhs, range_handle rhs) noexcept
Compares two range_handles for equality.
Definition nvtx3.hpp:3046
int push_range(event_attributes const &attr) noexcept
Manually begin a nested thread range in the global domain.
Definition nvtx3.hpp:2831
Indicates the value of the alpha, red, green, and blue color channels for an ARGB color to use as an ...
Definition nvtx3.hpp:1305
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:1318
Tag type for the "global" NVTX domain.
Definition nvtx3.hpp:1067
Handle used for correlating explicit range start and end events.
Definition nvtx3.hpp:2985
nvtxRangeId_t value_type
Type used for the handle's value.
Definition nvtx3.hpp:2987
constexpr range_handle(std::nullptr_t) noexcept
Implicit conversion from nullptr constructs a null handle.
Definition nvtx3.hpp:3024
constexpr range_handle() noexcept=default
Constructs a null range handle.
constexpr range_handle(value_type id) noexcept
Construct a range_handle from the given id.
Definition nvtx3.hpp:2994
constexpr value_type get_value() const noexcept
Returns the range_handle's value.
Definition nvtx3.hpp:3031
Indicates the values of the red, green, and blue color channels for an RGB color to use as an event a...
Definition nvtx3.hpp:1273
uint8_t component_type
Type used for component values.
Definition nvtx3.hpp:1275
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:1287