18 #if defined(NVTX3_MINOR_VERSION) and NVTX3_MINOR_VERSION < 0 20 "Trying to #include NVTX version 3 in a source file where an older NVTX version has already been included. If you are not directly using NVTX (the NVIDIA Tools Extension library), you are getting this error because libraries you are using have included different versions of NVTX. Suggested solutions are: (1) reorder #includes so the newest NVTX version is included first, (2) avoid using the conflicting libraries in the same .c/.cpp file, or (3) update the library using the older NVTX version to use the newer version instead." 32 #define NVTX3_MINOR_VERSION 0 34 #include <nvToolsExt.h> 511 #if __cpp_constexpr >= 201304L 512 #define NVTX3_RELAXED_CONSTEXPR constexpr 514 #define NVTX3_RELAXED_CONSTEXPR 528 template <
typename T>
530 return (std::is_same<
char const*,
531 typename std::decay<decltype(T::name)>::type>::value or
532 std::is_same<
wchar_t const*,
533 typename std::decay<decltype(T::name)>::type>::value);
642 template <
typename DomainName>
644 static_assert(detail::has_name_member<DomainName>(),
645 "Type used to identify a domain must contain a name member of" 646 "type const char* or const wchar_t*");
647 static domain const d{DomainName::name};
657 operator nvtxDomainHandle_t() const noexcept {
return _domain; }
681 explicit domain(
char const* name) noexcept
682 : _domain{nvtxDomainCreateA(name)} {}
692 explicit domain(
wchar_t const* name) noexcept
693 : _domain{nvtxDomainCreateW(name)} {}
703 explicit domain(std::string
const& name) noexcept :
domain{name.c_str()} {}
713 explicit domain(std::wstring
const& name) noexcept :
domain{name.c_str()} {}
729 ~
domain() noexcept { nvtxDomainDestroy(_domain); }
732 nvtxDomainHandle_t
const _domain{};
749 inline domain const& domain::get<domain::global>() {
775 : red{red_}, green{green_}, blue{blue_} {}
802 :
rgb{red_, green_, blue_}, alpha{alpha_} {}
871 constexpr nvtxColorType_t
get_type() const noexcept {
return _type; }
886 constexpr
static value_type from_bytes_msb_to_lsb(uint8_t byte3,
889 uint8_t byte0) noexcept {
890 return uint32_t{byte3} << 24 | uint32_t{byte2} << 16 |
891 uint32_t{byte1} << 8 | uint32_t{byte0};
895 nvtxColorType_t
const _type{NVTX_COLOR_ARGB};
1001 template <
typename D = domain::global>
1038 template <
typename C>
1040 static_assert(detail::has_name_member<C>(),
1041 "Type used to name a category must contain a name member.");
1056 nvtxDomainNameCategoryA(domain::get<D>(), get_id(), name);
1070 nvtxDomainNameCategoryW(domain::get<D>(), get_id(), name);
1120 template <
typename D = domain::global>
1156 template <
typename M>
1174 : handle_{nvtxDomainRegisterStringA(domain::get<D>(), msg)} {}
1202 : handle_{nvtxDomainRegisterStringW(domain::get<D>(), msg)} {}
1222 nvtxStringHandle_t
get_handle() const noexcept {
return handle_; }
1232 nvtxStringHandle_t
const handle_{};
1275 using value_type = nvtxMessageValue_t;
1283 : type_{NVTX_MESSAGE_TYPE_ASCII} {
1302 message(std::string&&) =
delete;
1310 : type_{NVTX_MESSAGE_TYPE_UNICODE} {
1311 value_.unicode = msg;
1329 message(std::wstring&&) =
delete;
1339 template <
typename D>
1341 : type_{NVTX_MESSAGE_TYPE_REGISTERED} {
1342 value_.registered = msg.get_handle();
1362 nvtxMessageType_t
const type_{};
1363 nvtxMessageValue_t value_{};
1385 using value_type =
typename nvtxEventAttributes_v2::payload_t;
1393 : type_{NVTX_PAYLOAD_TYPE_INT64}, value_{} {
1394 value_.llValue = value;
1403 : type_{NVTX_PAYLOAD_TYPE_INT32}, value_{} {
1404 value_.iValue = value;
1413 : type_{NVTX_PAYLOAD_TYPE_UNSIGNED_INT64}, value_{} {
1414 value_.ullValue = value;
1423 : type_{NVTX_PAYLOAD_TYPE_UNSIGNED_INT32}, value_{} {
1424 value_.uiValue = value;
1434 : type_{NVTX_PAYLOAD_TYPE_FLOAT}, value_{} {
1435 value_.fValue = value;
1445 : type_{NVTX_PAYLOAD_TYPE_DOUBLE}, value_{} {
1446 value_.dValue = value;
1466 nvtxPayloadType_t
const type_;
1533 using value_type = nvtxEventAttributes_t;
1542 sizeof(nvtxEventAttributes_t),
1546 NVTX_PAYLOAD_UNKNOWN,
1548 NVTX_MESSAGE_UNKNOWN,
1559 template <
typename... Args>
1561 category const& c, Args
const&... args) noexcept
1563 attributes_.category = c.get_id();
1573 template <
typename... Args>
1575 color const& c, Args
const&... args) noexcept
1577 attributes_.color = c.get_value();
1578 attributes_.colorType = c.get_type();
1588 template <
typename... Args>
1590 payload const& p, Args
const&... args) noexcept
1592 attributes_.payload = p.get_value();
1593 attributes_.payloadType = p.get_type();
1603 template <
typename... Args>
1605 message const& m, Args
const&... args) noexcept
1607 attributes_.message = m.get_value();
1608 attributes_.messageType = m.get_type();
1621 constexpr value_type
const*
get()
const noexcept {
return &attributes_; }
1624 value_type attributes_{};
1674 template <
class D = domain::global>
1693 nvtxDomainRangePushEx(domain::get<D>(), attr.get());
1723 template <
typename First,
typename... Args,
1724 typename =
typename std::enable_if<not std::is_same<
1772 template <
typename D = domain::global>
1781 : range_id_{nvtxDomainRangeStartEx(domain::get<D>(), attr.get())} {}
1789 template <
typename First,
typename... Args,
1790 typename =
typename std::enable_if<not std::is_same<
1793 Args
const&... args) noexcept
1808 if (not moved_from_) {
1809 nvtxRangeEnd(range_id_);
1817 : range_id_{other.range_id_} {
1818 other.moved_from_ =
true;
1822 range_id_ = other.range_id_;
1823 other.moved_from_ =
true;
1827 nvtxRangeId_t range_id_;
1828 bool moved_from_{
false};
1862 template <
typename D = nvtx3::domain::global>
1864 nvtxDomainMarkEx(domain::get<D>(), attr.get());
1897 #define NVTX3_FUNC_RANGE_IN(D) \ 1898 static ::nvtx3::registered_message<D> const nvtx3_func_name__{__func__}; \ 1899 static ::nvtx3::event_attributes const nvtx3_func_attr__{nvtx3_func_name__}; \ 1900 ::nvtx3::domain_thread_range<D> const nvtx3_range__{nvtx3_func_attr__}; 1924 #define NVTX3_FUNC_RANGE() NVTX3_FUNC_RANGE_IN(::nvtx3::domain::global) NVTX3_RELAXED_CONSTEXPR value_type get_value() const noexcept
Return the union holding the value of the payload.
Definition: nvtx3.hpp:1453
registered_message(char const *msg) noexcept
Constructs a registered_message from the specified msg string.
Definition: nvtx3.hpp:1173
registered_message(std::string const &msg) noexcept
Constructs a registered_message from the specified msg string.
Definition: nvtx3.hpp:1187
NVTX3_RELAXED_CONSTEXPR message(wchar_t const *msg) noexcept
Construct a message whose contents are specified by msg.
Definition: nvtx3.hpp:1309
constexpr auto has_name_member() noexcept-> decltype(T::name, bool())
Verifies if a type T contains a member T::name of type const char* or const wchar_t*.
Definition: nvtx3.hpp:529
void mark(event_attributes const &attr) noexcept
Annotates an instantaneous point in time with the attributes specified by attr.
Definition: nvtx3.hpp:1863
NVTX3_RELAXED_CONSTEXPR event_attributes(message const &m, Args const &...args) noexcept
Variadic constructor where the first argument is a message.
Definition: nvtx3.hpp:1604
domain_process_range(First const &first, Args const &...args) noexcept
Construct a new domain process range object.
Definition: nvtx3.hpp:1792
registered_message(std::wstring const &msg) noexcept
Constructs a registered_message from the specified msg string.
Definition: nvtx3.hpp:1215
NVTX3_RELAXED_CONSTEXPR payload(int32_t value) noexcept
Construct a payload from a signed, 4 byte integer.
Definition: nvtx3.hpp:1402
NVTX3_RELAXED_CONSTEXPR payload(int64_t value) noexcept
Construct a payload from a signed, 8 byte integer.
Definition: nvtx3.hpp:1392
~domain_thread_range() noexcept
Destroy the domain_thread_range, ending the NVTX range event.
Definition: nvtx3.hpp:1744
Object for intra-domain grouping of NVTX events.
Definition: nvtx3.hpp:919
Tag type for the "global" NVTX domain.
Definition: nvtx3.hpp:670
domain_thread_range(First const &first, Args const &...args) noexcept
Constructs a domain_thread_range from the constructor arguments of an event_attributes.
Definition: nvtx3.hpp:1726
NVTX3_RELAXED_CONSTEXPR payload(uint32_t value) noexcept
Construct a payload from an unsigned, 4 byte integer.
Definition: nvtx3.hpp:1422
constexpr domain_process_range() noexcept
Construct a new domain process range object.
Definition: nvtx3.hpp:1800
named_category(id_type id, wchar_t const *name) noexcept
Construct a category with the specified id and name.
Definition: nvtx3.hpp:1069
named_category(id_type id, char const *name) noexcept
Construct a category with the specified id and name.
Definition: nvtx3.hpp:1055
Indicates the value of the alpha, red, green, and blue color channels for an argb color code...
Definition: nvtx3.hpp:787
domain_process_range(event_attributes const &attr) noexcept
Construct a new domain process range object.
Definition: nvtx3.hpp:1780
nvtxStringHandle_t get_handle() const noexcept
Returns the registered message's handle.
Definition: nvtx3.hpp:1222
NVTX3_RELAXED_CONSTEXPR payload(float value) noexcept
Construct a payload from a single-precision floating point value.
Definition: nvtx3.hpp:1433
component_type const red
Red channel value.
Definition: nvtx3.hpp:777
component_type const blue
Blue channel value.
Definition: nvtx3.hpp:779
Represents a custom color that can be associated with an NVTX event via it's event_attributes.
Definition: nvtx3.hpp:816
A message registered with NVTX.
Definition: nvtx3.hpp:1121
NVTX3_RELAXED_CONSTEXPR event_attributes(payload const &p, Args const &...args) noexcept
Variadic constructor where the first argument is a payload.
Definition: nvtx3.hpp:1589
NVTX3_RELAXED_CONSTEXPR nvtxMessageType_t get_type() const noexcept
Return the type information about the value the union holds.
Definition: nvtx3.hpp:1357
NVTX3_RELAXED_CONSTEXPR payload(uint64_t value) noexcept
Construct a payload from an unsigned, 8 byte integer.
Definition: nvtx3.hpp:1412
A RAII object for creating a NVTX range local to a thread within a domain.
Definition: nvtx3.hpp:1675
A numerical value that can be associated with an NVTX event via its event_attributes.
Definition: nvtx3.hpp:1383
constexpr category(id_type id) noexcept
Construct a category with the specified id.
Definition: nvtx3.hpp:933
NVTX3_RELAXED_CONSTEXPR value_type get_value() const noexcept
Return the union holding the value of the message.
Definition: nvtx3.hpp:1349
registered_message(wchar_t const *msg) noexcept
Constructs a registered_message from the specified msg string.
Definition: nvtx3.hpp:1201
NVTX3_RELAXED_CONSTEXPR payload(double value) noexcept
Construct a payload from a double-precision floating point value.
Definition: nvtx3.hpp:1444
uint32_t value_type
Type used for the color's value.
Definition: nvtx3.hpp:819
constexpr nvtxColorType_t get_type() const noexcept
Return the NVTX color type of the color.
Definition: nvtx3.hpp:871
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_, green_, and blue_, respectively.
Definition: nvtx3.hpp:800
domains allow for grouping NVTX events into a single scope to differentiate them from events in other...
Definition: nvtx3.hpp:591
constexpr color(rgb rgb) noexcept
Construct a color using the red, green, blue components in rgb.
Definition: nvtx3.hpp:858
constexpr id_type get_id() const noexcept
Returns the id of the category.
Definition: nvtx3.hpp:939
component_type const alpha
Alpha channel value.
Definition: nvtx3.hpp:804
Definition: nvtx3.hpp:517
A RAII object for creating a NVTX range within a domain that can be created and destroyed on differen...
Definition: nvtx3.hpp:1773
uint8_t component_type
Type used for component values.
Definition: nvtx3.hpp:761
domain_thread_range(event_attributes const &attr) noexcept
Construct a domain_thread_range with the specified event_attributes
Definition: nvtx3.hpp:1692
Allows associating a message string with an NVTX event via its EventAttributes.
Definition: nvtx3.hpp:1273
Describes the attributes of a NVTX event.
Definition: nvtx3.hpp:1531
~domain_process_range() noexcept
Destroy the domain_process_range ending the range.
Definition: nvtx3.hpp:1807
A category with an associated name string.
Definition: nvtx3.hpp:1002
constexpr value_type get_value() const noexcept
Returns the colors argb hex code.
Definition: nvtx3.hpp:865
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:773
constexpr color(value_type hex_code) noexcept
Constructs a color using the value provided by hex_code.
Definition: nvtx3.hpp:838
message(std::wstring const &msg) noexcept
Construct a message whose contents are specified by msg.
Definition: nvtx3.hpp:1319
domain_thread_range()
Default constructor creates a domain_thread_range with no message, color, payload, nor category.
Definition: nvtx3.hpp:1734
#define NVTX3_RELAXED_CONSTEXPR
Enables the use of constexpr when support for C++14 relaxed constexpr is present. ...
Definition: nvtx3.hpp:514
message(std::string const &msg) noexcept
Construct a message whose contents are specified by msg.
Definition: nvtx3.hpp:1292
Indicates the values of the red, green, blue color channels for a rgb color code. ...
Definition: nvtx3.hpp:759
NVTX3_RELAXED_CONSTEXPR nvtxPayloadType_t get_type() const noexcept
Return the information about the type the union holds.
Definition: nvtx3.hpp:1461
NVTX3_RELAXED_CONSTEXPR event_attributes(category const &c, Args const &...args) noexcept
Variadic constructor where the first argument is a category.
Definition: nvtx3.hpp:1560
component_type const green
Green channel value.
Definition: nvtx3.hpp:778
constexpr event_attributes() noexcept
Default constructor creates an event_attributes with no category, color, payload, nor message...
Definition: nvtx3.hpp:1539
uint32_t id_type
Type used for categorys integer id.
Definition: nvtx3.hpp:922
NVTX3_RELAXED_CONSTEXPR message(registered_message< D > const &msg) noexcept
Construct a message from a registered_message.
Definition: nvtx3.hpp:1340
NVTX3_RELAXED_CONSTEXPR event_attributes(color const &c, Args const &...args) noexcept
Variadic constructor where the first argument is a color.
Definition: nvtx3.hpp:1574
constexpr color(argb argb) noexcept
Construct a color using the alpha, red, green, blue components in argb.
Definition: nvtx3.hpp:846
NVTX3_RELAXED_CONSTEXPR message(char const *msg) noexcept
Construct a message whose contents are specified by msg.
Definition: nvtx3.hpp:1282