gem5 v24.0.0.0
Loading...
Searching...
No Matches
dueling.cc
Go to the documentation of this file.
1
30
31#include "base/bitfield.hh"
32#include "base/logging.hh"
33
34namespace gem5
35{
36
38
40 : _isSample(false), _team(0)
41{
42}
43
44void
45Dueler::setSample(uint64_t id, bool team)
46{
47 panic_if(popCount(id) != 1, "The id must have a single bit set.");
49 "This dueler is already a sample for id %llu", id);
50 _isSample |= id;
51 if (team) {
52 _team |= id;
53 }
54}
55
56bool
57Dueler::isSample(uint64_t id, bool& team) const
58{
59 team = _team & id;
60 return _isSample & id;
61}
62
63DuelingMonitor::DuelingMonitor(std::size_t constituency_size,
64 std::size_t team_size, unsigned num_bits, double low_threshold,
65 double high_threshold)
66 : id(1 << numInstances), constituencySize(constituency_size),
67 teamSize(team_size), lowThreshold(low_threshold),
68 highThreshold(high_threshold), selector(num_bits), regionCounter(0),
69 winner(true)
70{
72 "There must be at least team size entries per team in a constituency");
73 fatal_if(numInstances > 63, "Too many Dueling instances");
74 fatal_if((lowThreshold <= 0.0) || (highThreshold >= 1.0),
75 "The low threshold must be within the range ]0.0, 1.0[");
76 fatal_if((highThreshold <= 0.0) || (highThreshold >= 1.0),
77 "The high threshold must be within the range ]0.0, 1.0[");
79 "The low threshold must be below the high threshold");
81
82 // Start selector around its middle value
84 selector >>= 1;
86 winner = false;
87 }
88}
89
90void
92{
93 bool team;
94 if (dueler->isSample(id, team)) {
95 if (team) {
96 selector++;
97
99 winner = true;
100 }
101 } else {
102 selector--;
103
105 winner = false;
106 }
107 }
108 }
109}
110
111bool
112DuelingMonitor::isSample(const Dueler* dueler, bool& team) const
113{
114 return dueler->isSample(id, team);
115}
116
117bool
119{
120 return winner;
121}
122
123void
125{
126 // The first entries of the constituency belong to one team, and the
127 // last entries to the other
128 assert(dueler);
129 if (regionCounter < teamSize) {
130 dueler->setSample(id, false);
131 } else if (regionCounter >= constituencySize - teamSize) {
132 dueler->setSample(id, true);
133 }
134
135 // Check if we changed constituencies
137 regionCounter = 0;
138 }
139}
140
141} // namespace gem5
A dueler is an entry that may or may not be accounted for sampling.
Definition dueling.hh:53
uint64_t _team
If entry is a sample, it belongs to one of two possible teams.
Definition dueling.hh:67
void setSample(uint64_t id, bool team)
Make this entry a sampling entry for a specific Dueling instance.
Definition dueling.cc:45
bool isSample(uint64_t id, bool &team) const
Check if entry is a sample for the given instance.
Definition dueling.cc:57
uint64_t _isSample
Whether this entry is a sample or a follower.
Definition dueling.hh:61
Dueler()
By default initializes entries as followers.
Definition dueling.cc:39
const int NUM_DUELERS
Definition dueling.hh:112
const std::size_t constituencySize
Given a table containing X entries, a constituency is a region of the table such that it contains X/c...
Definition dueling.hh:128
int regionCounter
Counts the number of entries have been initialized in the current constituency.
Definition dueling.hh:155
SatCounter32 selector
Counter that determines which dueler is winning.
Definition dueling.hh:149
const std::size_t teamSize
Number of entries that belong to each team within a constituency.
Definition dueling.hh:131
bool winner
The team that is currently winning.
Definition dueling.hh:158
bool getWinner() const
Get the team that is currently winning the duel.
Definition dueling.cc:118
bool isSample(const Dueler *dueler, bool &team) const
Check if the given dueler is a sample for this instance.
Definition dueling.cc:112
void sample(const Dueler *dueler)
If given dueler is a sampling entry, sample it and check if the winning team must be updated.
Definition dueling.cc:91
const double lowThreshold
If the winning team was "True", and the counter is decreased further than this threshold,...
Definition dueling.hh:137
static unsigned numInstances
Number of times this class has been instantiated.
Definition dueling.hh:165
DuelingMonitor(std::size_t constituency_size, std::size_t team_size=1, unsigned num_bits=10, double low_threshold=0.5, double high_threshold=0.5)
Definition dueling.cc:63
const double highThreshold
If the winning team was "False", and the counter is increased further than this threshold,...
Definition dueling.hh:143
void initEntry(Dueler *dueler)
Initialize a dueler entry, deciding wether it is a sample or not.
Definition dueling.cc:124
constexpr int popCount(uint64_t val)
Returns the number of set ones in the provided value.
Definition bitfield.hh:415
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
double calcSaturation() const
Calculate saturation percentile of the current counter's value with regard to its maximum possible va...
T saturate()
Saturate the counter.
Bitfield< 33 > id
Bitfield< 31, 16 > selector
Definition misc.hh:1038
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0