[PATCH] D54514: [llvm-exegesis] InstructionBenchmarkClustering::dbScan(): use manual std::deque<size_t> + std::vector<char> instead of SetVector.

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 14 00:41:52 PST 2018


lebedev.ri created this revision.
lebedev.ri added reviewers: courbet, MaskRay, RKSimon, gchatelet, john.brawn.
Herald added a subscriber: tschuett.

Initially this was https://reviews.llvm.org/D54418 "[llvm-exegesis] InstructionBenchmarkClustering::dbScan(): replace SetVector with custom BitVectorVector"
but the review was strongly negative about having an abstraction for this. Also, @MaskRay has //suggested// in https://reviews.llvm.org/D54418/https://reviews.llvm.org/D54442
that plain `std::vector<char>` may be better than `llvm::BitVector` here, at the cost of more memory usage.

This replaces https://reviews.llvm.org/D54418+https://reviews.llvm.org/D54445.

Old: (https://reviews.llvm.org/D54415)

   Performance counter stats for './bin/llvm-exegesis -mode=analysis -analysis-epsilon=100000 -benchmarks-file=/tmp/benchmarks.yaml -analysis-inconsistencies-output-file=/tmp/clusters.html' (16 runs):
  
         6169.091472      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.26% )
  ...
              6.1713 +- 0.0160 seconds time elapsed  ( +-  0.26% )

Old: (https://reviews.llvm.org/D54445)

   Performance counter stats for './bin/llvm-exegesis -mode=analysis -analysis-epsilon=100000 -benchmarks-file=/tmp/benchmarks.yaml -analysis-inconsistencies-output-file=/tmp/clusters.html' (16 runs):
  
         5612.071736      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.16% )
  ...
             5.61284 +- 0.00896 seconds time elapsed  ( +-  0.16% )

New:

   Performance counter stats for './bin/llvm-exegesis -mode=analysis -analysis-epsilon=100000 -benchmarks-file=/tmp/benchmarks.yaml -analysis-inconsistencies-output-file=/tmp/clusters.html' (16 runs):
  
         5455.563761      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.28% )
  ...
              5.4569 +- 0.0155 seconds time elapsed  ( +-  0.28% )

So this is -11.5% as compared to https://reviews.llvm.org/D54415, or -3% as compared to BitVector/https://reviews.llvm.org/D54445


Repository:
  rL LLVM

https://reviews.llvm.org/D54514

Files:
  tools/llvm-exegesis/lib/Clustering.cpp


Index: tools/llvm-exegesis/lib/Clustering.cpp
===================================================================
--- tools/llvm-exegesis/lib/Clustering.cpp
+++ tools/llvm-exegesis/lib/Clustering.cpp
@@ -8,7 +8,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "Clustering.h"
-#include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallVector.h"
 #include <string>
 
@@ -93,6 +92,8 @@
 
 void InstructionBenchmarkClustering::dbScan(const size_t MinPts) {
   std::vector<size_t> Neighbors; // Persistent buffer to avoid allocs.
+  std::deque<size_t> Workqueue(Points_.size());
+  std::vector<char> Set(Points_.size(), char(0));
   for (size_t P = 0, NumPoints = Points_.size(); P < NumPoints; ++P) {
     if (!ClusterIdForPoint_[P].isUndef())
       continue; // Previously processed in inner loop.
@@ -111,12 +112,14 @@
     CurrentCluster.PointIndices.push_back(P);
 
     // Process P's neighbors.
-    llvm::SetVector<size_t, std::deque<size_t>> ToProcess;
-    ToProcess.insert(Neighbors.begin(), Neighbors.end());
-    while (!ToProcess.empty()) {
+    Workqueue.assign(Neighbors.begin(), Neighbors.end());
+    for (size_t Neighbor : Neighbors)
+      Set[Neighbor] = 1;
+    while (!Workqueue.empty()) {
       // Retrieve a point from the set.
-      const size_t Q = *ToProcess.begin();
-      ToProcess.erase(ToProcess.begin());
+      const size_t Q = Workqueue.front();
+      Workqueue.pop_front();
+      Set[Q] = 0;
 
       if (ClusterIdForPoint_[Q].isNoise()) {
         // Change noise point to border point.
@@ -133,7 +136,12 @@
       // And extend to the neighbors of Q if the region is dense enough.
       rangeQuery(Q, Neighbors);
       if (Neighbors.size() + 1 >= MinPts) {
-        ToProcess.insert(Neighbors.begin(), Neighbors.end());
+        for (size_t Neighbor : Neighbors) {
+          if (Set[Neighbor])
+            continue;
+          Set[Neighbor] = 1;
+          Workqueue.push_back(Neighbor);
+        }
       }
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54514.173992.patch
Type: text/x-patch
Size: 2012 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181114/9a5f7d93/attachment.bin>


More information about the llvm-commits mailing list