NVTX C++ API Reference 1.0
C++ convenience wrappers for NVTX v3 C API
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
nvtx3::v1::mv2::counter_in< T, D > Class Template Reference

A type-safe NVTX counter in a specific domain. More...

#include <nvtx3.hpp>

Public Types

using value_type = T
 

Public Member Functions

 counter_in (const char *name, const char *description=nullptr, scope s=scope::none()) noexcept
 Construct a counter with a name, description, and scope.
 
 counter_in (std::string const &name, scope s=scope::none()) noexcept
 Construct a counter with a name and scope.
 
 counter_in (std::string const &name, std::string const &description, scope s=scope::none()) noexcept
 Construct a counter with a name, description, and scope.
 
 counter_in (const char *name, const char *description, scope s, const counter_semantic &semantic) noexcept
 Construct a counter with name, description, scope, and semantics.
 
 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.
 
void sample (T const &value) noexcept
 Sample the counter with a value.
 
void sample_no_value (no_value_reason reason) noexcept
 Sample the counter without a value.
 
void submit_batch (T const *values, size_t count, uint64_t flags=0) noexcept
 Submit a batch of counter samples.
 
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.
 
template<typename CounterContainer , typename = typename std::enable_if< detail::has_data_member<CounterContainer, T>::value && detail::has_size_member<CounterContainer>::value>::type>
void submit_batch (CounterContainer const &values, uint64_t flags=0) noexcept
 Submit a batch from a contiguous container.
 
template<typename CounterContainer , typename TimestampContainer , typename = typename std::enable_if< detail::has_data_member<CounterContainer, T>::value && detail::has_size_member<CounterContainer>::value && detail::has_data_member<TimestampContainer, int64_t>::value && detail::has_size_member<TimestampContainer>::value>::type>
void submit_batch (CounterContainer const &values, TimestampContainer const &timestamps, uint64_t flags=0) noexcept
 Submit a batch from contiguous sample and timestamp containers.
 
uint64_t id () const noexcept
 Get the underlying counter ID.
 

Detailed Description

template<typename T, typename D = domain::global>
class nvtx3::v1::mv2::counter_in< T, D >

A type-safe NVTX counter in a specific domain.

counter_in provides a type-safe interface for NVTX counters. The counter value type is specified as a template parameter, ensuring that only values of the correct type can be sampled.

For primitive types (int64_t, double, etc.), the schema is automatically determined. For user-defined struct types, a schema must be registered using NVTX3_DEFINE_SCHEMA_GET.

Template Parameters
TThe value type of the counter.
DThe domain type (defaults to global domain).

Example:

// Simple int64_t counter
nvtx3::counter<int64_t> iterations{"iteration_count"};
iterations.sample(42);
// Counter with semantics
sem.unit("bytes").limits(int64_t{0}, int64_t{1024 * 1024});
nvtx3::counter<int64_t> memory{"heap_size",
"Process heap size",
nvtx3::scope::current_sw_process(),
sem};
memory.sample(512 * 1024);
// Struct counter (requires NVTX3_DEFINE_SCHEMA_GET)
nvtx3::counter<gpu_metrics> gpu{"gpu_0"};
gpu.sample({72.5f, 250, 0.85});
Builder class for configuring counter semantics.
Definition nvtx3.hpp:3641
counter_semantic & limits(T min_val, T max_val) noexcept
Set minimum and maximum limits, typed.
Definition nvtx3.hpp:3859
counter_semantic & unit(const char *unit_name) noexcept
Set the unit string for the counter (e.g., "bytes", "ms", "%").
Definition nvtx3.hpp:3694

Definition at line 4498 of file nvtx3.hpp.

Member Typedef Documentation

◆ value_type

template<typename T , typename D = domain::global>
using nvtx3::v1::mv2::counter_in< T, D >::value_type = T

Definition at line 4500 of file nvtx3.hpp.

Constructor & Destructor Documentation

◆ counter_in() [1/5]

template<typename T , typename D = domain::global>
nvtx3::v1::mv2::counter_in< T, D >::counter_in ( const char *  name,
const char *  description = nullptr,
scope  s = scope::none() 
)
inlinenoexcept

Construct a counter with a name, description, and scope.

Parameters
nameThe counter name.
descriptionThe counter description.
sThe scope for this counter.

Definition at line 4509 of file nvtx3.hpp.

◆ counter_in() [2/5]

template<typename T , typename D = domain::global>
nvtx3::v1::mv2::counter_in< T, D >::counter_in ( std::string const &  name,
scope  s = scope::none() 
)
inlinenoexcept

Construct a counter with a name and scope.

Parameters
nameThe counter name.
sThe scope for this counter.

Definition at line 4520 of file nvtx3.hpp.

◆ counter_in() [3/5]

template<typename T , typename D = domain::global>
nvtx3::v1::mv2::counter_in< T, D >::counter_in ( std::string const &  name,
std::string const &  description,
scope  s = scope::none() 
)
inlinenoexcept

Construct a counter with a name, description, and scope.

Parameters
nameThe counter name.
descriptionThe counter description.
sThe scope for this counter.

Definition at line 4532 of file nvtx3.hpp.

◆ counter_in() [4/5]

template<typename T , typename D = domain::global>
nvtx3::v1::mv2::counter_in< T, D >::counter_in ( const char *  name,
const char *  description,
scope  s,
const counter_semantic semantic 
)
inlinenoexcept

Construct a counter with name, description, scope, and semantics.

Parameters
nameThe counter name.
descriptionThe counter description.
sThe scope for this counter.
semanticThe counter semantics.

Definition at line 4547 of file nvtx3.hpp.

◆ counter_in() [5/5]

template<typename T , typename D = domain::global>
nvtx3::v1::mv2::counter_in< T, D >::counter_in ( std::string const &  name,
std::string const &  description,
scope  s,
const counter_semantic semantic 
)
inlinenoexcept

Construct a counter with name, description, scope, and semantics.

Parameters
nameThe counter name.
descriptionThe counter description.
sThe scope for this counter.
semanticThe counter semantics.

Definition at line 4560 of file nvtx3.hpp.

Member Function Documentation

◆ id()

template<typename T , typename D = domain::global>
uint64_t nvtx3::v1::mv2::counter_in< T, D >::id ( ) const
inlinenoexcept

Get the underlying counter ID.

Useful for interoperability with the NVTX C API.

Returns
The counter ID.

Definition at line 4698 of file nvtx3.hpp.

◆ sample()

template<typename T , typename D = domain::global>
void nvtx3::v1::mv2::counter_in< T, D >::sample ( T const &  value)
inlinenoexcept

Sample the counter with a value.

The value type must match the counter's template parameter T. For primitive types (int64_t, double), optimized sampling functions are used. For struct types, the value is passed by reference.

Parameters
valueThe counter value to sample.

Definition at line 4577 of file nvtx3.hpp.

◆ sample_no_value()

template<typename T , typename D = domain::global>
void nvtx3::v1::mv2::counter_in< T, D >::sample_no_value ( no_value_reason  reason)
inlinenoexcept

Sample the counter without a value.

Used when a sample cannot be taken but should still be recorded.

Parameters
reasonThe reason for the missing value.

Definition at line 4593 of file nvtx3.hpp.

◆ submit_batch() [1/4]

template<typename T , typename D = domain::global>
template<typename CounterContainer , typename TimestampContainer , typename = typename std::enable_if< detail::has_data_member<CounterContainer, T>::value && detail::has_size_member<CounterContainer>::value && detail::has_data_member<TimestampContainer, int64_t>::value && detail::has_size_member<TimestampContainer>::value>::type>
void nvtx3::v1::mv2::counter_in< T, D >::submit_batch ( CounterContainer const &  values,
TimestampContainer const &  timestamps,
uint64_t  flags = 0 
)
inlinenoexcept

Submit a batch from contiguous sample and timestamp containers.

The sample container must expose T elements. The timestamp container must expose int64_t elements.

Definition at line 4684 of file nvtx3.hpp.

◆ submit_batch() [2/4]

template<typename T , typename D = domain::global>
template<typename CounterContainer , typename = typename std::enable_if< detail::has_data_member<CounterContainer, T>::value && detail::has_size_member<CounterContainer>::value>::type>
void nvtx3::v1::mv2::counter_in< T, D >::submit_batch ( CounterContainer const &  values,
uint64_t  flags = 0 
)
inlinenoexcept

Submit a batch from a contiguous container.

The container must expose data() returning T* or T const*, and size() convertible to size_t.

Definition at line 4664 of file nvtx3.hpp.

◆ submit_batch() [3/4]

template<typename T , typename D = domain::global>
void nvtx3::v1::mv2::counter_in< T, D >::submit_batch ( T const *  values,
size_t  count,
int64_t const *  timestamps,
size_t  timestamp_count,
uint64_t  flags = 0 
)
inlinenoexcept

Submit a batch of counter samples with external timestamps.

Parameters
valuesPointer to a contiguous array of counter samples.
countNumber of samples in values.
timestampsPointer to timestamps or timestamp/interval pairs.
timestamp_countNumber of timestamp values in timestamps.
flagsNVTX_BATCH_FLAG_* and NVTX_COUNTER_BATCH_FLAG_* bits.

Definition at line 4628 of file nvtx3.hpp.

◆ submit_batch() [4/4]

template<typename T , typename D = domain::global>
void nvtx3::v1::mv2::counter_in< T, D >::submit_batch ( T const *  values,
size_t  count,
uint64_t  flags = 0 
)
inlinenoexcept

Submit a batch of counter samples.

Use this overload when the counter sample layout includes timestamp entries. Otherwise, provide timestamps with one of the timestamp overloads.

Parameters
valuesPointer to a contiguous array of counter samples.
countNumber of samples in values.
flagsNVTX_BATCH_FLAG_* and NVTX_COUNTER_BATCH_FLAG_* bits.

Definition at line 4612 of file nvtx3.hpp.


The documentation for this class was generated from the following file: