32#include "params/DuelingRP.hh"
37namespace replacement_policy
41 :
Base(
p), replPolicyA(
p.replacement_policy_a),
42 replPolicyB(
p.replacement_policy_b),
43 duelingMonitor(
p.constituency_size,
p.team_size),
47 "All replacement policies must be instantiated");
53 std::shared_ptr<DuelerReplData> casted_replacement_data =
54 std::static_pointer_cast<DuelerReplData>(replacement_data);
63 std::shared_ptr<DuelerReplData> casted_replacement_data =
64 std::static_pointer_cast<DuelerReplData>(replacement_data);
70Dueling::touch(
const std::shared_ptr<ReplacementData>& replacement_data)
const
72 std::shared_ptr<DuelerReplData> casted_replacement_data =
73 std::static_pointer_cast<DuelerReplData>(replacement_data);
82 std::shared_ptr<DuelerReplData> casted_replacement_data =
83 std::static_pointer_cast<DuelerReplData>(replacement_data);
95Dueling::reset(
const std::shared_ptr<ReplacementData>& replacement_data)
const
97 std::shared_ptr<DuelerReplData> casted_replacement_data =
98 std::static_pointer_cast<DuelerReplData>(replacement_data);
115 panic_if(candidates.size() !=
params().team_size,
"We currently only "
116 "support team sizes that match the number of replacement candidates");
124 std::static_pointer_cast<DuelerReplData>(
125 candidates[0]->replacementData).get()), team);
133 if ((is_sample && !team) || (!is_sample && !winner)) {
144 for (
auto& candidate : candidates) {
145 std::shared_ptr<DuelerReplData> dueler_repl_data =
146 std::static_pointer_cast<DuelerReplData>(
147 candidate->replacementData);
154 (team != candidate_team),
155 "Not all sampled candidates belong to the same team");
159 dueling_replacement_data.push_back(dueler_repl_data);
160 candidate->replacementData = team_a ? dueler_repl_data->replDataA :
161 dueler_repl_data->replDataB;
169 for (
int i = 0;
i < candidates.size();
i++) {
170 candidates[
i]->replacementData = dueling_replacement_data[
i];
176std::shared_ptr<ReplacementData>
182 return std::shared_ptr<DuelerReplData>(replacement_data);
186 : statistics::
Group(parent),
187 ADD_STAT(selectedA,
"Number of times A was selected to victimize"),
188 ADD_STAT(selectedB,
"Number of times B was selected to victimize")
A dueler is an entry that may or may not be accounted for sampling.
bool getWinner() const
Get the team that is currently winning the duel.
bool isSample(const Dueler *dueler, bool &team) const
Check if the given dueler is a sample for this instance.
void sample(const Dueler *dueler)
If given dueler is a sampling entry, sample it and check if the winning team must be updated.
void initEntry(Dueler *dueler)
Initialize a dueler entry, deciding wether it is a sample or not.
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
A common base class of cache replacement policy objects.
virtual void invalidate(const std::shared_ptr< ReplacementData > &replacement_data)=0
Invalidate replacement data to set it as the next probable victim.
virtual void reset(const std::shared_ptr< ReplacementData > &replacement_data, const PacketPtr pkt)
Reset replacement data.
BaseReplacementPolicyParams Params
virtual void touch(const std::shared_ptr< ReplacementData > &replacement_data, const PacketPtr pkt)
Update replacement data.
virtual ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const =0
Find replacement victim among candidates.
virtual std::shared_ptr< ReplacementData > instantiateEntry()=0
Instantiate a replacement data entry.
Base *const replPolicyB
Sub-replacement policy used in this multiple container.
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim among candidates.
void reset(const std::shared_ptr< ReplacementData > &replacement_data, const PacketPtr pkt) override
Reset replacement data.
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
void touch(const std::shared_ptr< ReplacementData > &replacement_data, const PacketPtr pkt) override
Update replacement data.
DuelingMonitor duelingMonitor
A dueling monitor that decides which is the best sub-policy based on their number of misses.
Base *const replPolicyA
Sub-replacement policy used in this multiple container.
gem5::replacement_policy::Dueling::DuelingStats duelingStats
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) override
Invalidate replacement data to set it as the next probable victim.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
const Params & params() const
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Dueler-specific implementation of replacement data.
DuelingStats(statistics::Group *parent)
statistics::Scalar selectedB
Number of times B was selected on victimization.
statistics::Scalar selectedA
Number of times A was selected on victimization.