Javier Bueno Hedo has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/16062

Change subject: mem-cache: Added the Slim AMPM Prefetcher and the DCPT Prefetcher
......................................................................

mem-cache: Added the Slim AMPM Prefetcher and the DCPT Prefetcher

This patch adds two prefetchers:

1. Delta Correlating Prediction Tables:
    Multi-level hardware prefetching using low complexity delta correlating
    prediction tables with partial matching.
    Marius Grannaes, Magnus Jahre, and Lasse Natvig. 2010.
    In Proceedings of the 5th international conference on High Performance
    Embedded Architectures and Compilers (HiPEAC'10)

2. Slim AMPM
    Towards Bandwidth-Efficient Prefetching with Slim AMPM.
    Young, V., & Krishna, A. (2015). The 2nd Data Prefetching Championship.

Slim AMPM is composed of two prefetchers, the DPCT and the AMPM (already
in gem5).

Change-Id: I7b5d7ede9284862a427cfd5693a47652a69ed49d
---
M src/mem/cache/prefetch/Prefetcher.py
M src/mem/cache/prefetch/SConscript
M src/mem/cache/prefetch/access_map_pattern_matching.cc
M src/mem/cache/prefetch/access_map_pattern_matching.hh
M src/mem/cache/prefetch/base.hh
A src/mem/cache/prefetch/delta_correlating_prediction_tables.cc
A src/mem/cache/prefetch/delta_correlating_prediction_tables.hh
M src/mem/cache/prefetch/queued.hh
A src/mem/cache/prefetch/slim_ampm.cc
A src/mem/cache/prefetch/slim_ampm.hh
10 files changed, 537 insertions(+), 26 deletions(-)



diff --git a/src/mem/cache/prefetch/Prefetcher.py b/src/mem/cache/prefetch/Prefetcher.py
index 0825908..7bc0439 100644
--- a/src/mem/cache/prefetch/Prefetcher.py
+++ b/src/mem/cache/prefetch/Prefetcher.py
@@ -203,11 +203,16 @@
global_history_register_replacement_policy = Param.BaseReplacementPolicy(
         LRURP(), "Replacement policy of the global history register")

-class AccessMapPatternMatchingPrefetcher(QueuedPrefetcher):
-    type = 'AccessMapPatternMatchingPrefetcher'
-    cxx_class = 'AccessMapPatternMatchingPrefetcher'
+class AccessMapPatternMatching(ClockedObject):
+    type = 'AccessMapPatternMatching'
+    cxx_class = 'AccessMapPatternMatching'
     cxx_header = "mem/cache/prefetch/access_map_pattern_matching.hh"

+    block_size = Param.Unsigned(Parent.block_size,
+        "Cacheline size used by the prefetcher using this object")
+
+    limit_stride = Param.Unsigned(0,
+        "Limit the strides checked up to -X/X, if 0, disable the limit")
     start_degree = Param.Unsigned(4,
         "Initial degree (Maximum number of prefetches generated")
     hot_zone_size = Param.MemorySize("2kB", "Memory covered by a hot zone")
@@ -236,3 +241,57 @@
     epoch_cycles = Param.Cycles(256000, "Cycles in an epoch period")
     offchip_memory_latency = Param.Latency("30ns",
         "Memory latency used to compute the required memory bandwidth")
+
+class AMPMPrefetcher(QueuedPrefetcher):
+    type = 'AMPMPrefetcher'
+    cxx_class = 'AMPMPrefetcher'
+    cxx_header = "mem/cache/prefetch/access_map_pattern_matching.hh"
+    ampm = Param.AccessMapPatternMatching(AccessMapPatternMatching(),
+        "Access Map Pattern Matching object")
+
+class DeltaCorrelatingPredictionTables(SimObject):
+    type = 'DeltaCorrelatingPredictionTables'
+    cxx_class = 'DeltaCorrelatingPredictionTables'
+ cxx_header = "mem/cache/prefetch/delta_correlating_prediction_tables.hh"
+    deltas_per_entry = Param.Unsigned(20,
+        "Number of deltas stored in each table entry")
+    delta_bits = Param.Unsigned(12, "Bits per delta")
+ delta_mask = Param.Unsigned(8, "Lower bits to mask when comparing deltas")
+    table_entries = Param.MemorySize("128",
+        "Number of entries in the table")
+    table_assoc = Param.Unsigned(128,
+        "Associativity of the table")
+    table_indexing_policy = Param.BaseIndexingPolicy(
+        SetAssociative(entry_size = 1, assoc = Parent.table_assoc,
+        size = Parent.table_entries),
+        "Indexing policy of the table")
+    table_replacement_policy = Param.BaseReplacementPolicy(LRURP(),
+        "Replacement policy of the table")
+
+class DCPTPrefetcher(QueuedPrefetcher):
+    type = 'DCPTPrefetcher'
+    cxx_class = 'DCPTPrefetcher'
+ cxx_header = "mem/cache/prefetch/delta_correlating_prediction_tables.hh"
+    dcpt = Param.DeltaCorrelatingPredictionTables(
+        DeltaCorrelatingPredictionTables(),
+        "Delta Correlating Prediction Tables object")
+
+class SlimAccessMapPatternMatching(AccessMapPatternMatching):
+    start_degree = 2
+    limit_stride = 4
+
+class SlimDeltaCorrelatingPredictionTables(DeltaCorrelatingPredictionTables):
+    table_entries = "256"
+    table_assoc = 256
+    deltas_per_entry = 9
+
+class SlimAMPMPrefetcher(QueuedPrefetcher):
+    type = 'SlimAMPMPrefetcher'
+    cxx_class = 'SlimAMPMPrefetcher'
+    cxx_header = "mem/cache/prefetch/slim_ampm.hh"
+
+    ampm = Param.AccessMapPatternMatching(SlimAccessMapPatternMatching(),
+        "Access Map Pattern Matching object")
+    dcpt = Param.DeltaCorrelatingPredictionTables(
+        SlimDeltaCorrelatingPredictionTables(),
+        "Delta Correlating Prediction Tables object")
diff --git a/src/mem/cache/prefetch/SConscript b/src/mem/cache/prefetch/SConscript
index f9582b5..fdb2de9 100644
--- a/src/mem/cache/prefetch/SConscript
+++ b/src/mem/cache/prefetch/SConscript
@@ -34,8 +34,10 @@

 Source('access_map_pattern_matching.cc')
 Source('base.cc')
+Source('delta_correlating_prediction_tables.cc')
 Source('queued.cc')
 Source('signature_path.cc')
 Source('signature_path_v2.cc')
+Source('slim_ampm.cc')
 Source('stride.cc')
 Source('tagged.cc')
diff --git a/src/mem/cache/prefetch/access_map_pattern_matching.cc b/src/mem/cache/prefetch/access_map_pattern_matching.cc
index 0f46eff..df2a9f7 100644
--- a/src/mem/cache/prefetch/access_map_pattern_matching.cc
+++ b/src/mem/cache/prefetch/access_map_pattern_matching.cc
@@ -32,11 +32,12 @@

 #include "debug/HWPrefetch.hh"
 #include "mem/cache/prefetch/associative_set_impl.hh"
-#include "params/AccessMapPatternMatchingPrefetcher.hh"
+#include "params/AMPMPrefetcher.hh"
+#include "params/AccessMapPatternMatching.hh"

-AccessMapPatternMatchingPrefetcher::AccessMapPatternMatchingPrefetcher(
-    const AccessMapPatternMatchingPrefetcherParams *p)
-    : QueuedPrefetcher(p),
+AccessMapPatternMatching::AccessMapPatternMatching(
+    const AccessMapPatternMatchingParams *p)
+ : ClockedObject(p), blkSize(p->block_size), limitStride(p->limit_stride),
       startDegree(p->start_degree), hotZoneSize(p->hot_zone_size),
       highCoverageThreshold(p->high_coverage_threshold),
       lowCoverageThreshold(p->low_coverage_threshold),
@@ -62,7 +63,7 @@
 }

 void
-AccessMapPatternMatchingPrefetcher::processEpochEvent()
+AccessMapPatternMatching::processEpochEvent()
 {
     schedule(epochEvent, clockEdge(epochCycles));
     double prefetch_accuracy =
@@ -95,8 +96,8 @@
     numRawCacheHits = 0.0;
 }

-AccessMapPatternMatchingPrefetcher::AccessMapEntry *
-AccessMapPatternMatchingPrefetcher::getAccessMapEntry(Addr am_addr,
+AccessMapPatternMatching::AccessMapEntry *
+AccessMapPatternMatching::getAccessMapEntry(Addr am_addr,
                 bool is_secure)
 {
AccessMapEntry *am_entry = accessMapTable.findEntry(am_addr, is_secure);
@@ -112,7 +113,7 @@
 }

 void
-AccessMapPatternMatchingPrefetcher::setEntryState(AccessMapEntry &entry,
+AccessMapPatternMatching::setEntryState(AccessMapEntry &entry,
     Addr block, enum AccessMapState state)
 {
     enum AccessMapState old = entry.states[block];
@@ -147,8 +148,9 @@
 }

 void
-AccessMapPatternMatchingPrefetcher::calculatePrefetch(const PrefetchInfo &pfi,
-    std::vector<AddrPriority> &addresses)
+AccessMapPatternMatching::calculatePrefetch(
+    const BasePrefetcher::PrefetchInfo &pfi,
+    std::vector<QueuedPrefetcher::AddrPriority> &addresses)
 {
     assert(addresses.empty());
     bool is_secure = pfi.isSecure();
@@ -194,7 +196,8 @@
     // index of the current_block in the new vector
     Addr states_current_block = current_block + lines_per_zone;
     // consider strides 1..lines_per_zone/2
-    for (int stride = 1; stride < lines_per_zone/2; stride += 1) {
+ int max_stride = limitStride == 0 ? lines_per_zone / 2 : limitStride + 1;
+    for (int stride = 1; stride < max_stride; stride += 1) {
         // Test accessed positive strides
         if (checkCandidate(states, states_current_block, stride)) {
             // candidate found, current_block - stride
@@ -213,7 +216,7 @@
                 pf_addr = am_addr * hotZoneSize + blk * blkSize;
                 setEntryState(*am_entry_curr, blk, AM_PREFETCH);
             }
-            addresses.push_back(AddrPriority(pf_addr, 0));
+ addresses.push_back(QueuedPrefetcher::AddrPriority(pf_addr, 0));
             if (addresses.size() == degree) {
                 break;
             }
@@ -237,7 +240,7 @@
                 pf_addr = am_addr * hotZoneSize + blk * blkSize;
                 setEntryState(*am_entry_curr, blk, AM_PREFETCH);
             }
-            addresses.push_back(AddrPriority(pf_addr, 0));
+ addresses.push_back(QueuedPrefetcher::AddrPriority(pf_addr, 0));
             if (addresses.size() == degree) {
                 break;
             }
@@ -245,8 +248,26 @@
     }
 }

-AccessMapPatternMatchingPrefetcher*
-AccessMapPatternMatchingPrefetcherParams::create()
+AccessMapPatternMatching*
+AccessMapPatternMatchingParams::create()
 {
-    return new AccessMapPatternMatchingPrefetcher(this);
+    return new AccessMapPatternMatching(this);
+}
+
+AMPMPrefetcher::AMPMPrefetcher(const AMPMPrefetcherParams *p)
+  : QueuedPrefetcher(p), ampm(*p->ampm)
+{
+}
+
+void
+AMPMPrefetcher::calculatePrefetch(const PrefetchInfo &pfi,
+    std::vector<AddrPriority> &addresses)
+{
+    ampm.calculatePrefetch(pfi, addresses);
+}
+
+AMPMPrefetcher*
+AMPMPrefetcherParams::create()
+{
+    return new AMPMPrefetcher(this);
 }
diff --git a/src/mem/cache/prefetch/access_map_pattern_matching.hh b/src/mem/cache/prefetch/access_map_pattern_matching.hh
index 33a20a2..311946b 100644
--- a/src/mem/cache/prefetch/access_map_pattern_matching.hh
+++ b/src/mem/cache/prefetch/access_map_pattern_matching.hh
@@ -45,10 +45,14 @@
 #include "mem/cache/prefetch/queued.hh"
 #include "mem/packet.hh"

-struct AccessMapPatternMatchingPrefetcherParams;
+struct AccessMapPatternMatchingParams;

-class AccessMapPatternMatchingPrefetcher : public QueuedPrefetcher
+class AccessMapPatternMatching : public ClockedObject
 {
+    /** Cacheline size used by the prefetcher using this object */
+    const unsigned blkSize;
+    /** Limit the stride checking to -limitStride/+limitStride */
+    const unsigned limitStride;
     /** Maximum number of prefetch generated */
     const unsigned startDegree;
     /** Amount of memory covered by a hot zone */
@@ -173,9 +177,22 @@
     EventFunctionWrapper epochEvent;

   public:
-    AccessMapPatternMatchingPrefetcher(
-        const AccessMapPatternMatchingPrefetcherParams* p);
-    ~AccessMapPatternMatchingPrefetcher() {}
+    AccessMapPatternMatching(const AccessMapPatternMatchingParams* p);
+    ~AccessMapPatternMatching()
+    {}
+    void calculatePrefetch(const BasePrefetcher::PrefetchInfo &pfi,
+        std::vector<QueuedPrefetcher::AddrPriority> &addresses);
+};
+
+struct AMPMPrefetcherParams;
+
+class AMPMPrefetcher : public QueuedPrefetcher
+{
+    AccessMapPatternMatching &ampm;
+  public:
+    AMPMPrefetcher(const AMPMPrefetcherParams* p);
+    ~AMPMPrefetcher()
+    {}
     void calculatePrefetch(const PrefetchInfo &pfi,
                            std::vector<AddrPriority> &addresses) override;
 };
diff --git a/src/mem/cache/prefetch/base.hh b/src/mem/cache/prefetch/base.hh
index 06f7749..de275f8 100644
--- a/src/mem/cache/prefetch/base.hh
+++ b/src/mem/cache/prefetch/base.hh
@@ -76,7 +76,8 @@
     };

     std::vector<PrefetchListener *> listeners;
-  protected:
+
+  public:

     /**
      * Class containing the information needed by the prefetch to train and
@@ -168,6 +169,8 @@
         PrefetchInfo(PrefetchInfo const &pfi, Addr addr);
     };

+  protected:
+
     // PARAMETERS

     /** Pointr to the parent cache. */
diff --git a/src/mem/cache/prefetch/delta_correlating_prediction_tables.cc b/src/mem/cache/prefetch/delta_correlating_prediction_tables.cc
new file mode 100644
index 0000000..cfe5037
--- /dev/null
+++ b/src/mem/cache/prefetch/delta_correlating_prediction_tables.cc
@@ -0,0 +1,156 @@
+/**
+ * Copyright (c) 2018 Metempsy Technology Consulting
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Javier Bueno
+ */
+
+#include "mem/cache/prefetch/delta_correlating_prediction_tables.hh"
+
+#include "debug/HWPrefetch.hh"
+#include "mem/cache/prefetch/associative_set_impl.hh"
+#include "params/DCPTPrefetcher.hh"
+#include "params/DeltaCorrelatingPredictionTables.hh"
+
+DeltaCorrelatingPredictionTables::DeltaCorrelatingPredictionTables(
+   DeltaCorrelatingPredictionTablesParams *p) : SimObject(p),
+   deltaBits(p->delta_bits), deltaMask(p->delta_mask),
+   table(p->table_assoc, p->table_entries, p->table_indexing_policy,
+         p->table_replacement_policy, DCPTEntry(p->deltas_per_entry))
+{
+}
+
+void
+DeltaCorrelatingPredictionTables::DCPTEntry::reset()
+{
+    for (auto &delta : deltas) {
+        delta = 0;
+    }
+    lastAddress = 0;
+    deltaPointer = 0;
+}
+
+void
+DeltaCorrelatingPredictionTables::DCPTEntry::addAddress(Addr address,
+    unsigned int delta_bits)
+{
+    if ((address - lastAddress) != 0) {
+        deltas[deltaPointer] =
+            (address - lastAddress) & ((1 << delta_bits) - 1);
+        deltaPointer = (deltaPointer + 1) % deltas.size();
+        lastAddress = address;
+    }
+}
+
+void
+DeltaCorrelatingPredictionTables::DCPTEntry::getCandidates(
+ std::vector<QueuedPrefetcher::AddrPriority> &pfs, unsigned int mask) const
+{
+    // most recent index
+    int last = (deltaPointer + deltas.size() - 1) % deltas.size();
+    // second most recent index
+    int last_prev = (deltaPointer + deltas.size() - 2) % deltas.size();
+    int delta_0 = deltas[last_prev];
+    int delta_1 = deltas[last];
+
+    // a delta 0 means that it overflowed, we can not match it
+    if (delta_0 == 0 || delta_1 == 0) {
+        return;
+    }
+
+    // oldest index
+    int idx_0 = deltaPointer + 1;
+    // second oldest index
+    int idx_1 = deltaPointer + 2;
+    for (int i = 0; i < deltas.size() - 2; i += 1) {
+        int this_delta_0 = deltas[(idx_0 + i) % deltas.size()];
+        int this_delta_1 = deltas[(idx_1 + i) % deltas.size()];
+        if ((this_delta_0 >> mask) == (delta_0 >> mask) &&
+            (this_delta_1 >> mask) == (delta_1 >> mask)) {
+            Addr addr = lastAddress;
+ // Pattern found, issue prefetches with the remaining deltas after
+            // this pair
+            i += 2; // skip the matching pair
+            do {
+                int pf_delta = deltas[(idx_0 + i) % deltas.size()];
+                addr += pf_delta;
+                pfs.push_back(QueuedPrefetcher::AddrPriority(addr, 0));
+                i += 1;
+            } while (i < deltas.size() - 2);
+        }
+    }
+}
+
+void
+DeltaCorrelatingPredictionTables::calculatePrefetch(
+    const BasePrefetcher::PrefetchInfo &pfi,
+    std::vector<QueuedPrefetcher::AddrPriority> &addresses)
+{
+    if (!pfi.hasPC()) {
+        DPRINTF(HWPrefetch, "Ignoring request with no PC.\n");
+        return;
+    }
+    Addr address = pfi.getAddr();
+    Addr pc = pfi.getPC();
+    // Look up table entry
+    /* is_secure is unused in findEntry because we index using the pc */
+    DCPTEntry *entry = table.findEntry(pc, false /* unused */);
+    if (entry != nullptr) {
+        entry->addAddress(address, deltaBits);
+        //Delta correlating
+        entry->getCandidates(addresses, deltaMask);
+    } else {
+        entry = table.findVictim(pc);
+
+        table.insertEntry(pc, false /* unused */, entry);
+
+        entry->lastAddress = address;
+    }
+}
+
+DeltaCorrelatingPredictionTables *
+DeltaCorrelatingPredictionTablesParams::create()
+{
+   return new DeltaCorrelatingPredictionTables(this);
+}
+
+DCPTPrefetcher::DCPTPrefetcher(const DCPTPrefetcherParams *p)
+  : QueuedPrefetcher(p), dcpt(*p->dcpt)
+{
+}
+
+void
+DCPTPrefetcher::calculatePrefetch(const PrefetchInfo &pfi,
+    std::vector<AddrPriority> &addresses)
+{
+    dcpt.calculatePrefetch(pfi, addresses);
+}
+
+DCPTPrefetcher*
+DCPTPrefetcherParams::create()
+{
+    return new DCPTPrefetcher(this);
+}
diff --git a/src/mem/cache/prefetch/delta_correlating_prediction_tables.hh b/src/mem/cache/prefetch/delta_correlating_prediction_tables.hh
new file mode 100644
index 0000000..08763ab
--- /dev/null
+++ b/src/mem/cache/prefetch/delta_correlating_prediction_tables.hh
@@ -0,0 +1,134 @@
+/**
+ * Copyright (c) 2018 Metempsy Technology Consulting
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Javier Bueno
+ */
+
+#ifndef __MEM_CACHE_PREFETCH_DELTA_CORRELATINC_PREDICTION_TABLES_HH_
+#define __MEM_CACHE_PREFETCH_DELTA_CORRELATINC_PREDICTION_TABLES_HH_
+
+#include "mem/cache/prefetch/associative_set.hh"
+#include "mem/cache/prefetch/queued.hh"
+
+struct DeltaCorrelatingPredictionTablesParams;
+
+/**
+ * Delta Correlating Prediction Tables Prefetcher
+ * References:
+ * Multi-level hardware prefetching using low complexity delta correlating
+ *   prediction tables with partial matching.
+ *   Marius Grannaes, Magnus Jahre, and Lasse Natvig. 2010.
+ *   In Proceedings of the 5th international conference on High Performance
+ *   Embedded Architectures and Compilers (HiPEAC'10)
+ *
+ * The filter feature is not implemented as gem5 already drops redundant
+ * prefetches.
+ * The main prefetcher logic is implemented on a separate SimObject as there
+ * are other prefetcher that can rehuse this component.
+ */
+
+class DeltaCorrelatingPredictionTables : public SimObject
+{
+    /** Number of bits of each delta */
+    const unsigned int deltaBits;
+    /** Number of lower bits to ignore from the deltas */
+    const unsigned int deltaMask;
+
+    /** DCTP Table entry datatype */
+    struct DCPTEntry : public TaggedEntry
+    {
+        /** Last accessed address */
+        Addr lastAddress;
+        /** Position of the last added delta */
+        unsigned int deltaPointer;
+        /** Stored deltas */
+        std::vector<Addr> deltas;
+
+        /**
+         * Constructor
+         * @param num_deltas number of deltas stored in the entry
+         */
+ DCPTEntry(unsigned int num_deltas) : lastAddress(0), deltaPointer(0),
+            deltas(num_deltas)
+        {}
+
+        /** Reset callback called when invalidating the entry */
+        void reset() override;
+
+        /**
+ * Adds an address to the entry, if the entry already existed, a delta
+         * will be generated
+         * @param address address to add
+         * @param delta_bits number of bits of the delta
+         */
+        void addAddress(Addr address, unsigned int delta_bits);
+
+        /**
+ * Attempt to generate prefetch candidates using the two most recent
+         * deltas. Prefetch candidates are added to the provided vector.
+         * @param pfs reference to a vector where candidates will be added
+ * @param mask the number of lower bits that should be masked (ignored)
+         *        when comparing deltas
+         */
+ void getCandidates(std::vector<QueuedPrefetcher::AddrPriority> &pfs,
+                           unsigned int mask) const;
+
+    };
+    /** The main table */
+    AssociativeSet<DCPTEntry> table;
+
+  public:
+    DeltaCorrelatingPredictionTables(
+        DeltaCorrelatingPredictionTablesParams *p);
+    ~DeltaCorrelatingPredictionTables()
+    {}
+
+    /**
+     * Computes the prefetch candidates given a prefetch event.
+     * @param pfi The prefetch event information
+     * @param addresses prefetch candidates generated
+     */
+    void calculatePrefetch(const BasePrefetcher::PrefetchInfo &pfi,
+        std::vector<QueuedPrefetcher::AddrPriority> &addresses);
+
+};
+
+struct DCPTPrefetcherParams;
+
+/** The prefetcher object using the DCPT */
+class DCPTPrefetcher : public QueuedPrefetcher
+{
+    /** DCPT object */
+    DeltaCorrelatingPredictionTables &dcpt;
+  public:
+    DCPTPrefetcher(const DCPTPrefetcherParams *p);
+    ~DCPTPrefetcher()
+    {}
+    void calculatePrefetch(const PrefetchInfo &pfi,
+        std::vector<AddrPriority> &addresses) override;
+};
+#endif//__MEM_CACHE_PREFETCH_DELTA_CORRELATINC_PREDICTION_TABLES_HH_
diff --git a/src/mem/cache/prefetch/queued.hh b/src/mem/cache/prefetch/queued.hh
index 1c63977..97a7ec6 100644
--- a/src/mem/cache/prefetch/queued.hh
+++ b/src/mem/cache/prefetch/queued.hh
@@ -89,7 +89,6 @@
             return !(*this > that);
         }
     };
-    using AddrPriority = std::pair<Addr, int32_t>;

     std::list<DeferredPacket> pfq;

@@ -126,6 +125,8 @@
     Stats::Scalar pfSpanPage;

   public:
+    using AddrPriority = std::pair<Addr, int32_t>;
+
     QueuedPrefetcher(const QueuedPrefetcherParams *p);
     virtual ~QueuedPrefetcher();

diff --git a/src/mem/cache/prefetch/slim_ampm.cc b/src/mem/cache/prefetch/slim_ampm.cc
new file mode 100644
index 0000000..432d00f
--- /dev/null
+++ b/src/mem/cache/prefetch/slim_ampm.cc
@@ -0,0 +1,54 @@
+/**
+ * Copyright (c) 2018 Metempsy Technology Consulting
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Javier Bueno
+ */
+
+#include "mem/cache/prefetch/slim_ampm.hh"
+
+#include "params/SlimAMPMPrefetcher.hh"
+
+SlimAMPMPrefetcher::SlimAMPMPrefetcher(const SlimAMPMPrefetcherParams* p)
+  : QueuedPrefetcher(p), ampm(*p->ampm), dcpt(*p->dcpt)
+{
+}
+
+void
+SlimAMPMPrefetcher::calculatePrefetch(const PrefetchInfo &pfi,
+                  std::vector<AddrPriority> &addresses)
+{
+    dcpt.calculatePrefetch(pfi, addresses);
+    if (addresses.empty()) {
+        ampm.calculatePrefetch(pfi, addresses);
+    }
+}
+
+SlimAMPMPrefetcher*
+SlimAMPMPrefetcherParams::create()
+{
+    return new SlimAMPMPrefetcher(this);
+}
diff --git a/src/mem/cache/prefetch/slim_ampm.hh b/src/mem/cache/prefetch/slim_ampm.hh
new file mode 100644
index 0000000..310a165
--- /dev/null
+++ b/src/mem/cache/prefetch/slim_ampm.hh
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2018 Metempsy Technology Consulting
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Javier Bueno
+ */
+
+#ifndef __MEM_CACHE_PREFETCH_SLIM_AMPM_HH__
+#define __MEM_CACHE_PREFETCH_SLIM_AMPM_HH__
+
+#include "mem/cache/prefetch/access_map_pattern_matching.hh"
+#include "mem/cache/prefetch/delta_correlating_prediction_tables.hh"
+#include "mem/cache/prefetch/queued.hh"
+
+/**
+ * The SlimAMPM Prefetcher
+ * Reference:
+ *    Towards Bandwidth-Efficient Prefetching with Slim AMPM.
+ *    Young, Vinson, and A. Krishna.
+ *    The 2nd Data Prefetching Championship (2015).
+ *
+ * This prefetcher uses two other prefetchers, the AMPM and the DCPT.
+ */
+
+struct SlimAMPMPrefetcherParams;
+
+class SlimAMPMPrefetcher : public QueuedPrefetcher
+{
+   /** AMPM prefetcher object */
+   AccessMapPatternMatching &ampm;
+   /** DCPT prefetcher object */
+   DeltaCorrelatingPredictionTables &dcpt;
+ public:
+   SlimAMPMPrefetcher(const SlimAMPMPrefetcherParams *p);
+   ~SlimAMPMPrefetcher()
+   {}
+
+   void calculatePrefetch(const PrefetchInfo &pfi,
+                          std::vector<AddrPriority> &addresses) override;
+};
+#endif//__MEM_CACHE_PREFETCH_SLIM_AMPM_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/16062
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I7b5d7ede9284862a427cfd5693a47652a69ed49d
Gerrit-Change-Number: 16062
Gerrit-PatchSet: 1
Gerrit-Owner: Javier Bueno Hedo <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to