gem5  v22.1.0.0
dueling.cc
Go to the documentation of this file.
1 
30 
31 #include "base/bitfield.hh"
32 #include "base/logging.hh"
33 
34 namespace gem5
35 {
36 
37 unsigned DuelingMonitor::numInstances = 0;
38 
40  : _isSample(false), _team(0)
41 {
42 }
43 
44 void
45 Dueler::setSample(uint64_t id, bool team)
46 {
47  panic_if(popCount(id) != 1, "The id must have a single bit set.");
48  panic_if(_isSample & id,
49  "This dueler is already a sample for id %llu", id);
50  _isSample |= id;
51  if (team) {
52  _team |= id;
53  }
54 }
55 
56 bool
57 Dueler::isSample(uint64_t id, bool& team) const
58 {
59  team = _team & id;
60  return _isSample & id;
61 }
62 
63 DuelingMonitor::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");
80  numInstances++;
81 
82  // Start selector around its middle value
84  selector >>= 1;
86  winner = false;
87  }
88 }
89 
90 void
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 
111 bool
112 DuelingMonitor::isSample(const Dueler* dueler, bool& team) const
113 {
114  return dueler->isSample(id, team);
115 }
116 
117 bool
119 {
120  return winner;
121 }
122 
123 void
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
136  if (++regionCounter >= constituencySize) {
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:334
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:226
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
double calcSaturation() const
Calculate saturation percentile of the current counter's value with regard to its maximum possible va...
Definition: sat_counter.hh:303
uint8_t saturate()
Saturate the counter.
Definition: sat_counter.hh:321
Bitfield< 33 > id
Definition: misc_types.hh:257
Bitfield< 31, 16 > selector
Definition: misc.hh:1010
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....

Generated on Wed Dec 21 2022 10:22:36 for gem5 by doxygen 1.9.1