kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
counter.hpp
Go to the documentation of this file.
1
#ifndef KOKKOS_EXECUTION_TESTS_UTILS_FUNCTORS_COUNTER_HPP
2
#define KOKKOS_EXECUTION_TESTS_UTILS_FUNCTORS_COUNTER_HPP
3
4
#include "Kokkos_Macros.hpp"
5
#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
6
import
kokkos.core;
7
#else
8
# include "Kokkos_Core.hpp"
9
#endif
10
11
namespace
Tests::Utils::Functors
{
12
14
struct
Counter
{
15
static
inline
std::atomic<unsigned int>
default_constructions
{0};
16
static
inline
std::atomic<unsigned int>
destructions
{0};
17
static
inline
std::atomic<unsigned int>
copy_constructions
{0};
18
static
inline
std::atomic<unsigned int>
copy_assignments
{0};
19
static
inline
std::atomic<unsigned int>
move_constructions
{0};
20
static
inline
std::atomic<unsigned int>
move_assignments
{0};
21
22
static
inline
std::atomic<unsigned int>
next_id
{0};
23
24
unsigned
int
id
{0};
25
26
Counter
() noexcept
27
:
id
(
next_id
.fetch_add(1, std::memory_order_relaxed)) {
28
default_constructions
.fetch_add(1, std::memory_order_relaxed);
29
}
30
31
~Counter
() noexcept {
32
destructions
.fetch_add(1, std::memory_order_relaxed);
33
}
34
35
Counter
(
const
Counter
&) noexcept
36
:
id
(
next_id
.fetch_add(1, std::memory_order_relaxed)) {
37
copy_constructions
.fetch_add(1, std::memory_order_relaxed);
38
}
39
40
Counter
&
operator=
(
const
Counter
&)
noexcept
{
41
copy_assignments
.fetch_add(1, std::memory_order_relaxed);
42
return
*
this
;
43
}
44
45
Counter
(
Counter
&&) noexcept
46
:
id
(
next_id
.fetch_add(1, std::memory_order_relaxed)) {
47
move_constructions
.fetch_add(1, std::memory_order_relaxed);
48
}
49
50
Counter
&
operator=
(
Counter
&&) noexcept {
51
move_assignments
.fetch_add(1, std::memory_order_relaxed);
52
return
*
this
;
53
}
54
55
template
<
typename
... Args>
56
KOKKOS_FUNCTION
void
operator()
(Args&&...) const noexcept {
57
}
58
59
static
void
reset
() {
60
default_constructions
= 0;
61
destructions
= 0;
62
copy_constructions
= 0;
63
copy_assignments
= 0;
64
move_constructions
= 0;
65
move_assignments
= 0;
66
}
67
};
68
70
struct
CounterRef
{
71
struct
counters
{
72
unsigned
int
constructions
= 0;
73
unsigned
int
destructions
= 0;
74
unsigned
int
copy_constructions
= 0;
75
unsigned
int
copy_assignments
= 0;
76
unsigned
int
move_constructions
= 0;
77
unsigned
int
move_assignments
= 0;
78
};
79
80
counters
&
m_counts
;
// NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
81
82
explicit
constexpr
CounterRef
(
counters
& counts) noexcept
83
:
m_counts
(counts) {
84
++
m_counts
.
constructions
;
85
}
86
87
constexpr
~CounterRef
() noexcept {
88
++
m_counts
.
destructions
;
89
}
90
91
constexpr
CounterRef
(
const
CounterRef
& other) noexcept
92
:
m_counts
(other.m_counts) {
93
++
m_counts
.
copy_constructions
;
94
}
95
96
constexpr
CounterRef
&
operator=
(
const
CounterRef
& other)
noexcept
{
97
m_counts
= other.m_counts;
98
++
m_counts
.
copy_assignments
;
99
return
*
this
;
100
}
101
102
constexpr
CounterRef
(
CounterRef
&& other) noexcept
103
:
m_counts
(other.m_counts) {
104
++
m_counts
.
move_constructions
;
105
}
106
107
constexpr
CounterRef
&
operator=
(
CounterRef
&& other)
noexcept
{
108
m_counts
= other.m_counts;
109
++
m_counts
.
move_assignments
;
110
return
*
this
;
111
}
112
};
113
114
}
// namespace Tests::Utils::Functors
115
116
#endif
// KOKKOS_EXECUTION_TESTS_UTILS_FUNCTORS_COUNTER_HPP
Tests::Utils::Functors
Definition
counter.hpp:11
Tests::Utils::Functors::CounterRef::counters
Definition
counter.hpp:71
Tests::Utils::Functors::CounterRef::counters::move_constructions
unsigned int move_constructions
Definition
counter.hpp:76
Tests::Utils::Functors::CounterRef::counters::move_assignments
unsigned int move_assignments
Definition
counter.hpp:77
Tests::Utils::Functors::CounterRef::counters::destructions
unsigned int destructions
Definition
counter.hpp:73
Tests::Utils::Functors::CounterRef::counters::copy_constructions
unsigned int copy_constructions
Definition
counter.hpp:74
Tests::Utils::Functors::CounterRef::counters::constructions
unsigned int constructions
Definition
counter.hpp:72
Tests::Utils::Functors::CounterRef::counters::copy_assignments
unsigned int copy_assignments
Definition
counter.hpp:75
Tests::Utils::Functors::CounterRef::CounterRef
constexpr CounterRef(counters &counts) noexcept
Definition
counter.hpp:82
Tests::Utils::Functors::CounterRef::CounterRef
constexpr CounterRef(const CounterRef &other) noexcept
Definition
counter.hpp:91
Tests::Utils::Functors::CounterRef::operator=
constexpr CounterRef & operator=(const CounterRef &other) noexcept
Definition
counter.hpp:96
Tests::Utils::Functors::CounterRef::CounterRef
constexpr CounterRef(CounterRef &&other) noexcept
Definition
counter.hpp:102
Tests::Utils::Functors::CounterRef::~CounterRef
constexpr ~CounterRef() noexcept
Definition
counter.hpp:87
Tests::Utils::Functors::CounterRef::operator=
constexpr CounterRef & operator=(CounterRef &&other) noexcept
Definition
counter.hpp:107
Tests::Utils::Functors::CounterRef::m_counts
counters & m_counts
Definition
counter.hpp:80
Tests::Utils::Functors::Counter::move_assignments
static std::atomic< unsigned int > move_assignments
Definition
counter.hpp:20
Tests::Utils::Functors::Counter::copy_constructions
static std::atomic< unsigned int > copy_constructions
Definition
counter.hpp:17
Tests::Utils::Functors::Counter::Counter
Counter() noexcept
Definition
counter.hpp:26
Tests::Utils::Functors::Counter::~Counter
~Counter() noexcept
Definition
counter.hpp:31
Tests::Utils::Functors::Counter::operator=
Counter & operator=(Counter &&) noexcept
Definition
counter.hpp:50
Tests::Utils::Functors::Counter::destructions
static std::atomic< unsigned int > destructions
Definition
counter.hpp:16
Tests::Utils::Functors::Counter::reset
static void reset()
Definition
counter.hpp:59
Tests::Utils::Functors::Counter::operator()
void operator()(Args &&...) const noexcept
Definition
counter.hpp:56
Tests::Utils::Functors::Counter::Counter
Counter(Counter &&) noexcept
Definition
counter.hpp:45
Tests::Utils::Functors::Counter::next_id
static std::atomic< unsigned int > next_id
Definition
counter.hpp:22
Tests::Utils::Functors::Counter::default_constructions
static std::atomic< unsigned int > default_constructions
Definition
counter.hpp:15
Tests::Utils::Functors::Counter::id
unsigned int id
Definition
counter.hpp:24
Tests::Utils::Functors::Counter::move_constructions
static std::atomic< unsigned int > move_constructions
Definition
counter.hpp:19
Tests::Utils::Functors::Counter::copy_assignments
static std::atomic< unsigned int > copy_assignments
Definition
counter.hpp:18
Tests::Utils::Functors::Counter::operator=
Counter & operator=(const Counter &) noexcept
Definition
counter.hpp:40
Tests::Utils::Functors::Counter::Counter
Counter(const Counter &) noexcept
Definition
counter.hpp:35
tests
utils
functors
counter.hpp
Generated on
for kokkos-execution by
1.18.0