mem-cache: Added the Slim AMPM Prefetcher
authorJavier Bueno <javier.bueno@metempsy.com>
Thu, 31 Jan 2019 15:24:48 +0000 (16:24 +0100)
committerJavier Bueno Hedo <javier.bueno@metempsy.com>
Thu, 21 Feb 2019 14:41:35 +0000 (14:41 +0000)
Reference:
    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 (both already
in gem5).

Change-Id: I6e868faf216e3e75231cf181d59884ed6f0d382a
Reviewed-on: https://gem5-review.googlesource.com/c/16383
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>

src/mem/cache/prefetch/Prefetcher.py
src/mem/cache/prefetch/SConscript
src/mem/cache/prefetch/access_map_pattern_matching.cc
src/mem/cache/prefetch/access_map_pattern_matching.hh
src/mem/cache/prefetch/slim_ampm.cc [new file with mode: 0644]
src/mem/cache/prefetch/slim_ampm.hh [new file with mode: 0644]

index 2c31de9fc8f78d737f4b55d13c19a8326971e626..36e25415114fdda7e7b7a9d67218ce6914750182 100644 (file)
@@ -204,11 +204,16 @@ class SignaturePathPrefetcherV2(SignaturePathPrefetcher):
     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")
@@ -238,6 +243,13 @@ class AccessMapPatternMatchingPrefetcher(QueuedPrefetcher):
     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'
@@ -309,3 +321,23 @@ class IrregularStreamBufferPrefetcher(QueuedPrefetcher):
     sp_address_map_cache_replacement_policy = Param.BaseReplacementPolicy(
         LRURP(),
         "Replacement policy of the Structural-to-Physical Address Map Cache")
+
+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")
index 0a209ff183a310ad88e234049b65e485bfd86129..48ee218a940889980b2d1cdf388f9e44ff3b8569 100644 (file)
@@ -39,5 +39,6 @@ Source('irregular_stream_buffer.cc')
 Source('queued.cc')
 Source('signature_path.cc')
 Source('signature_path_v2.cc')
+Source('slim_ampm.cc')
 Source('stride.cc')
 Source('tagged.cc')
index 0f46effbf7768cdc20c6375e135d6339d549fd97..df2a9f7ec0f6493e2105b0cb82c51483321d8c79 100644 (file)
 
 #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 @@ AccessMapPatternMatchingPrefetcher::AccessMapPatternMatchingPrefetcher(
 }
 
 void
-AccessMapPatternMatchingPrefetcher::processEpochEvent()
+AccessMapPatternMatching::processEpochEvent()
 {
     schedule(epochEvent, clockEdge(epochCycles));
     double prefetch_accuracy =
@@ -95,8 +96,8 @@ AccessMapPatternMatchingPrefetcher::processEpochEvent()
     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 @@ AccessMapPatternMatchingPrefetcher::getAccessMapEntry(Addr am_addr,
 }
 
 void
-AccessMapPatternMatchingPrefetcher::setEntryState(AccessMapEntry &entry,
+AccessMapPatternMatching::setEntryState(AccessMapEntry &entry,
     Addr block, enum AccessMapState state)
 {
     enum AccessMapState old = entry.states[block];
@@ -147,8 +148,9 @@ AccessMapPatternMatchingPrefetcher::setEntryState(AccessMapEntry &entry,
 }
 
 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 @@ AccessMapPatternMatchingPrefetcher::calculatePrefetch(const PrefetchInfo &pfi,
     // 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 @@ AccessMapPatternMatchingPrefetcher::calculatePrefetch(const PrefetchInfo &pfi,
                 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 @@ AccessMapPatternMatchingPrefetcher::calculatePrefetch(const PrefetchInfo &pfi,
                 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::calculatePrefetch(const PrefetchInfo &pfi,
     }
 }
 
-AccessMapPatternMatchingPrefetcher*
-AccessMapPatternMatchingPrefetcherParams::create()
+AccessMapPatternMatching*
+AccessMapPatternMatchingParams::create()
+{
+    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 AccessMapPatternMatchingPrefetcher(this);
+    return new AMPMPrefetcher(this);
 }
index 33a20a27ed6e315291007ffe436f433f99e304a4..5561cf5413e137ea6bb76099aba180bb7f2f5c10 100644 (file)
 #include "mem/cache/prefetch/associative_set.hh"
 #include "mem/cache/prefetch/queued.hh"
 #include "mem/packet.hh"
+#include "sim/clocked_object.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 +178,22 @@ class AccessMapPatternMatchingPrefetcher : public QueuedPrefetcher
     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/slim_ampm.cc b/src/mem/cache/prefetch/slim_ampm.cc
new file mode 100644 (file)
index 0000000..432d00f
--- /dev/null
@@ -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 (file)
index 0000000..310a165
--- /dev/null
@@ -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__