NVTX++  3.0
C++ convenience wrappers for NVTX.
Classes | Macros | Typedefs | Functions
nvtx3.hpp File Reference

Provides C++ constructs making the NVTX library safer and easier to use with zero overhead. More...

#include <nvToolsExt.h>
#include <string>
Include dependency graph for nvtx3.hpp:

Go to the source code of this file.

Classes

class  nvtx3::domain
 domains allow for grouping NVTX events into a single scope to differentiate them from events in other domains. More...
 
struct  nvtx3::domain::global
 Tag type for the "global" NVTX domain. More...
 
struct  nvtx3::rgb
 Indicates the values of the red, green, blue color channels for a rgb color code. More...
 
struct  nvtx3::argb
 Indicates the value of the alpha, red, green, and blue color channels for an argb color code. More...
 
class  nvtx3::color
 Represents a custom color that can be associated with an NVTX event via it's event_attributes. More...
 
class  nvtx3::category
 Object for intra-domain grouping of NVTX events. More...
 
class  nvtx3::named_category< D >
 A category with an associated name string. More...
 
class  nvtx3::registered_message< D >
 A message registered with NVTX. More...
 
class  nvtx3::message
 Allows associating a message string with an NVTX event via its EventAttributes. More...
 
class  nvtx3::payload
 A numerical value that can be associated with an NVTX event via its event_attributes. More...
 
class  nvtx3::event_attributes
 Describes the attributes of a NVTX event. More...
 
class  nvtx3::domain_thread_range< D >
 A RAII object for creating a NVTX range local to a thread within a domain. More...
 
class  nvtx3::domain_process_range< D >
 A RAII object for creating a NVTX range within a domain that can be created and destroyed on different threads. More...
 

Macros

#define NVTX3_MINOR_VERSION   0
 Semantic minor version number. More...
 
#define NVTX3_RELAXED_CONSTEXPR
 Enables the use of constexpr when support for C++14 relaxed constexpr is present. More...
 
#define NVTX3_FUNC_RANGE_IN(D)
 Convenience macro for generating a range in the specified domain from the lifetime of a function. More...
 
#define NVTX3_FUNC_RANGE()   NVTX3_FUNC_RANGE_IN(::nvtx3::domain::global)
 Convenience macro for generating a range in the global domain from the lifetime of a function. More...
 

Typedefs

using nvtx3::thread_range = domain_thread_range<>
 Alias for a domain_thread_range in the global NVTX domain.
 
using nvtx3::process_range = domain_process_range<>
 Alias for a domain_process_range in the global NVTX domain.
 

Functions

template<typename T >
constexpr auto nvtx3::detail::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*. More...
 
template<>
domain const & nvtx3::domain::get< domain::global > ()
 Returns reference to the domain object that represents the global NVTX domain. More...
 
template<typename D = nvtx3::domain::global>
void nvtx3::mark (event_attributes const &attr) noexcept
 Annotates an instantaneous point in time with the attributes specified by attr. More...
 

Detailed Description

Provides C++ constructs making the NVTX library safer and easier to use with zero overhead.

Macro Definition Documentation

#define NVTX3_FUNC_RANGE ( )    NVTX3_FUNC_RANGE_IN(::nvtx3::domain::global)

Convenience macro for generating a range in the global domain from the lifetime of a function.

This macro is useful for generating an NVTX range in the global domain from the entry point of a function to its exit. It is intended to be the first line of the function.

Constructs a static registered_message using the name of the immediately enclosing function returned by __func__ and constructs a nvtx3::thread_range using the registered function name as the range's message.

Example:

1 void foo(...){
2  NVTX3_FUNC_RANGE(); // Range begins on entry to foo()
3  // do stuff
4  ...
5 } // Range ends on return from foo()
#define NVTX3_FUNC_RANGE_IN (   D)
Value:
static ::nvtx3::registered_message<D> const nvtx3_func_name__{__func__}; \
static ::nvtx3::event_attributes const nvtx3_func_attr__{nvtx3_func_name__}; \
::nvtx3::domain_thread_range<D> const nvtx3_range__{nvtx3_func_attr__};
A RAII object for creating a NVTX range local to a thread within a domain.
Definition: nvtx3.hpp:1675

Convenience macro for generating a range in the specified domain from the lifetime of a function.

This macro is useful for generating an NVTX range in domain from the entry point of a function to its exit. It is intended to be the first line of the function.

Constructs a static registered_message using the name of the immediately enclosing function returned by __func__ and constructs a nvtx3::thread_range using the registered function name as the range's message.

Example:

1 struct my_domain{static constexpr char const* name{"my_domain"};};
2 
3 void foo(...){
4  NVTX3_FUNC_RANGE_IN(my_domain); // Range begins on entry to foo()
5  // do stuff
6  ...
7 } // Range ends on return from foo()
Parameters
[in]DType containing name member used to identify the domain to which the registered_message belongs. Else, domain::global to indicate that the global NVTX domain should be used.
#define NVTX3_MINOR_VERSION   0

Semantic minor version number.

Major version number is hardcoded into the "nvtx3" namespace/prefix.

If this value is incremented, the above version include guard needs to be updated.

#define NVTX3_RELAXED_CONSTEXPR

Enables the use of constexpr when support for C++14 relaxed constexpr is present.

Initializing a legacy-C (i.e., no constructor) union member requires initializing in the constructor body. Non-empty constexpr constructors require C++14 relaxed constexpr.

Function Documentation

template<>
domain const& nvtx3::domain::get< domain::global > ( )
inline

Returns reference to the domain object that represents the global NVTX domain.

This specialization for domain::global returns a default constructed, domain object for use when the "global" domain is desired.

All NVTX events in the global domain across all libraries and applications will be grouped together.

Returns
Reference to the domain corresponding to the global NVTX domain.
template<typename T >
constexpr auto nvtx3::detail::has_name_member ( ) -> decltype(T::name, bool())
noexcept

Verifies if a type T contains a member T::name of type const char* or const wchar_t*.

Template Parameters
TThe type to verify
Returns
True if T contains a member T::name of type const char* or const wchar_t*.
template<typename D = nvtx3::domain::global>
void nvtx3::mark ( event_attributes const &  attr)
inlinenoexcept

Annotates an instantaneous point in time with the attributes specified by attr.

Unlike a "range", a mark is an instantaneous event in an application, e.g., locking/unlocking a mutex.

std::mutex global_lock;
void lock_mutex(){
global_lock.lock();
nvtx3::mark("lock_mutex");
}
Template Parameters
DType containing name member used to identify the domain to which the domain_process_range belongs. Else, domain::global to indicate that the global NVTX domain should be used.
Parameters
[in]attrevent_attributes that describes the desired attributes of the mark.