diff options
author | Clement Courbet <courbet@google.com> | 2018-05-14 11:30:56 +0000 |
---|---|---|
committer | Clement Courbet <courbet@google.com> | 2018-05-14 11:30:56 +0000 |
commit | 3d479fe81cbc533ea4bbe74e51c3a1dd3ae8ffef (patch) | |
tree | e308918cdd0ba1058e769c1e649fd48858ad4998 /llvm/tools/llvm-exegesis/lib/Clustering.cpp | |
parent | [CodeGen] Disable aggressive structor optimizations at -O0 (diff) | |
download | llvm-project-3d479fe81cbc533ea4bbe74e51c3a1dd3ae8ffef.tar.gz llvm-project-3d479fe81cbc533ea4bbe74e51c3a1dd3ae8ffef.tar.bz2 llvm-project-3d479fe81cbc533ea4bbe74e51c3a1dd3ae8ffef.zip |
[llvm-exegesis] Add an analysis mode.
The analysis mode gives the user a clustered view of the measurement results and
highlights any inconsistencies with the checked-in data.
llvm-svn: 332229
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/Clustering.cpp')
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Clustering.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/Clustering.cpp b/llvm/tools/llvm-exegesis/lib/Clustering.cpp index c8646c7c3997..b3f42a38ac89 100644 --- a/llvm/tools/llvm-exegesis/lib/Clustering.cpp +++ b/llvm/tools/llvm-exegesis/lib/Clustering.cpp @@ -19,7 +19,7 @@ namespace exegesis { // (B) - Number of points : ~thousands (points are measurements of an MCInst) // (C) - Number of clusters: ~tens. // (D) - The number of clusters is not known /a priory/. -// (E) - The amount of noise is relatively small. +// (E) - The amoint of noise is relatively small. // The problem is rather small. In terms of algorithms, (D) disqualifies // k-means and makes algorithms such as DBSCAN[1] or OPTICS[2] more applicable. // @@ -57,17 +57,18 @@ std::vector<size_t> rangeQuery(const std::vector<InstructionBenchmark> &Points, } // namespace -InstructionBenchmarkClustering::InstructionBenchmarkClustering() - : NoiseCluster_(ClusterId::noise()), ErrorCluster_(ClusterId::error()) {} +InstructionBenchmarkClustering::InstructionBenchmarkClustering( + const std::vector<InstructionBenchmark> &Points) + : Points_(Points), NoiseCluster_(ClusterId::noise()), + ErrorCluster_(ClusterId::error()) {} -llvm::Error InstructionBenchmarkClustering::validateAndSetup( - const std::vector<InstructionBenchmark> &Points) { - ClusterIdForPoint_.resize(Points.size()); +llvm::Error InstructionBenchmarkClustering::validateAndSetup() { + ClusterIdForPoint_.resize(Points_.size()); // Mark erroneous measurements out. // All points must have the same number of dimensions, in the same order. const std::vector<BenchmarkMeasure> *LastMeasurement = nullptr; - for (size_t P = 0, NumPoints = Points.size(); P < NumPoints; ++P) { - const auto &Point = Points[P]; + for (size_t P = 0, NumPoints = Points_.size(); P < NumPoints; ++P) { + const auto &Point = Points_[P]; if (!Point.Error.empty()) { ClusterIdForPoint_[P] = ClusterId::error(); ErrorCluster_.PointIndices.push_back(P); @@ -96,13 +97,12 @@ llvm::Error InstructionBenchmarkClustering::validateAndSetup( return llvm::Error::success(); } -void InstructionBenchmarkClustering::dbScan( - const std::vector<InstructionBenchmark> &Points, const size_t MinPts, - const double EpsilonSquared) { - for (size_t P = 0, NumPoints = Points.size(); P < NumPoints; ++P) { +void InstructionBenchmarkClustering::dbScan(const size_t MinPts, + const double EpsilonSquared) { + for (size_t P = 0, NumPoints = Points_.size(); P < NumPoints; ++P) { if (!ClusterIdForPoint_[P].isUndef()) continue; // Previously processed in inner loop. - const auto Neighbors = rangeQuery(Points, P, EpsilonSquared); + const auto Neighbors = rangeQuery(Points_, P, EpsilonSquared); if (Neighbors.size() + 1 < MinPts) { // Density check. // The region around P is not dense enough to create a new cluster, mark // as noise for now. @@ -136,7 +136,7 @@ void InstructionBenchmarkClustering::dbScan( ClusterIdForPoint_[Q] = CurrentCluster.Id; CurrentCluster.PointIndices.push_back(Q); // And extend to the neighbors of Q if the region is dense enough. - const auto Neighbors = rangeQuery(Points, Q, EpsilonSquared); + const auto Neighbors = rangeQuery(Points_, Q, EpsilonSquared); if (Neighbors.size() + 1 >= MinPts) { ToProcess.insert(Neighbors.begin(), Neighbors.end()); } @@ -144,7 +144,7 @@ void InstructionBenchmarkClustering::dbScan( } // Add noisy points to noise cluster. - for (size_t P = 0, NumPoints = Points.size(); P < NumPoints; ++P) { + for (size_t P = 0, NumPoints = Points_.size(); P < NumPoints; ++P) { if (ClusterIdForPoint_[P].isNoise()) { NoiseCluster_.PointIndices.push_back(P); } @@ -155,15 +155,15 @@ llvm::Expected<InstructionBenchmarkClustering> InstructionBenchmarkClustering::create( const std::vector<InstructionBenchmark> &Points, const size_t MinPts, const double Epsilon) { - InstructionBenchmarkClustering Clustering; - if (auto Error = Clustering.validateAndSetup(Points)) { - return std::move(Error); + InstructionBenchmarkClustering Clustering(Points); + if (auto Error = Clustering.validateAndSetup()) { + return Error; } if (Clustering.ErrorCluster_.PointIndices.size() == Points.size()) { return Clustering; // Nothing to cluster. } - Clustering.dbScan(Points, MinPts, Epsilon * Epsilon); + Clustering.dbScan(MinPts, Epsilon * Epsilon); return Clustering; } |