diff options
author | Clement Courbet <courbet@google.com> | 2018-09-26 08:37:21 +0000 |
---|---|---|
committer | Clement Courbet <courbet@google.com> | 2018-09-26 08:37:21 +0000 |
commit | 684a5f675380ad3e97fbb9b6e6858ee2348f85b3 (patch) | |
tree | ab9c1cecf65cca691bda95a5b312a2ed27179708 /llvm/tools/llvm-exegesis | |
parent | cc525e7b8d62231c3825630a4c1e384031d7b41d (diff) | |
download | llvm-684a5f675380ad3e97fbb9b6e6858ee2348f85b3.zip llvm-684a5f675380ad3e97fbb9b6e6858ee2348f85b3.tar.gz llvm-684a5f675380ad3e97fbb9b6e6858ee2348f85b3.tar.bz2 |
[llvm-exegesis] Output the unscaled value as well as the scaled one.
Summary: See PR38936 for context.
Reviewers: gchatelet
Subscribers: tschuett, llvm-commits
Differential Revision: https://reviews.llvm.org/D52500
llvm-svn: 343081
Diffstat (limited to 'llvm/tools/llvm-exegesis')
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Analysis.cpp | 14 | ||||
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Analysis.h | 4 | ||||
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp | 13 | ||||
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/BenchmarkResult.h | 9 | ||||
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 10 | ||||
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h | 4 | ||||
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Clustering.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Latency.cpp | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Latency.h | 4 | ||||
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Uops.cpp | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Uops.h | 4 |
11 files changed, 45 insertions, 31 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.cpp b/llvm/tools/llvm-exegesis/lib/Analysis.cpp index bb51180..54dc4be 100644 --- a/llvm/tools/llvm-exegesis/lib/Analysis.cpp +++ b/llvm/tools/llvm-exegesis/lib/Analysis.cpp @@ -139,7 +139,7 @@ void Analysis::printInstructionRowCsv(const size_t PointId, #endif for (const auto &Measurement : Point.Measurements) { OS << kCsvSep; - writeMeasurementValue<kEscapeCsv>(OS, Measurement.Value); + writeMeasurementValue<kEscapeCsv>(OS, Measurement.PerInstructionValue); } OS << "\n"; } @@ -410,14 +410,14 @@ bool Analysis::SchedClassCluster::measurementsMatch( return false; } // Find the latency. - SchedClassPoint[0].Value = 0.0; + SchedClassPoint[0].PerInstructionValue = 0.0; for (unsigned I = 0; I < SC.SCDesc->NumWriteLatencyEntries; ++I) { const llvm::MCWriteLatencyEntry *const WLE = STI.getWriteLatencyEntry(SC.SCDesc, I); - SchedClassPoint[0].Value = - std::max<double>(SchedClassPoint[0].Value, WLE->Cycles); + SchedClassPoint[0].PerInstructionValue = + std::max<double>(SchedClassPoint[0].PerInstructionValue, WLE->Cycles); } - ClusterCenterPoint[0].Value = Representative[0].avg(); + ClusterCenterPoint[0].PerInstructionValue = Representative[0].avg(); } else if (Mode == InstructionBenchmark::Uops) { for (int I = 0, E = Representative.size(); I < E; ++I) { // Find the pressure on ProcResIdx `Key`. @@ -433,11 +433,11 @@ bool Analysis::SchedClassCluster::measurementsMatch( [ProcResIdx](const std::pair<uint16_t, float> &WPR) { return WPR.first == ProcResIdx; }); - SchedClassPoint[I].Value = + SchedClassPoint[I].PerInstructionValue = ProcResPressureIt == SC.IdealizedProcResPressure.end() ? 0.0 : ProcResPressureIt->second; - ClusterCenterPoint[I].Value = Representative[I].avg(); + ClusterCenterPoint[I].PerInstructionValue = Representative[I].avg(); } } else { llvm::errs() << "unimplemented measurement matching for mode " << Mode diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.h b/llvm/tools/llvm-exegesis/lib/Analysis.h index 3c33caf..1e6294b 100644 --- a/llvm/tools/llvm-exegesis/lib/Analysis.h +++ b/llvm/tools/llvm-exegesis/lib/Analysis.h @@ -69,7 +69,7 @@ private: const std::vector<size_t> &getPointIds() const { return PointIds; } // Return the cluster centroid. - const std::vector<BenchmarkMeasureStats> &getRepresentative() const { + const std::vector<PerInstructionStats> &getRepresentative() const { return Representative; } @@ -85,7 +85,7 @@ private: InstructionBenchmarkClustering::ClusterId ClusterId; std::vector<size_t> PointIds; // Measurement stats for the points in the SchedClassCluster. - std::vector<BenchmarkMeasureStats> Representative; + std::vector<PerInstructionStats> Representative; }; void printInstructionRowCsv(size_t PointId, llvm::raw_ostream &OS) const; diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp index 9a41114..1748c53 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp @@ -164,9 +164,10 @@ template <> struct SequenceElementTraits<exegesis::BenchmarkMeasure> { // e.g. { "key": "the key", "value": 0123 } template <> struct MappingTraits<exegesis::BenchmarkMeasure> { static void mapping(IO &Io, exegesis::BenchmarkMeasure &Obj) { - Io.mapRequired("key", Obj.Key); - Io.mapRequired("value", Obj.Value); Io.mapOptional("debug_string", Obj.DebugString); + Io.mapRequired("value", Obj.PerInstructionValue); + Io.mapOptional("per_snippet_value", Obj.PerSnippetValue); + Io.mapRequired("key", Obj.Key); } static const bool flow = true; }; @@ -345,14 +346,14 @@ llvm::Error InstructionBenchmark::writeYaml(const LLVMState &State, return llvm::Error::success(); } -void BenchmarkMeasureStats::push(const BenchmarkMeasure &BM) { +void PerInstructionStats::push(const BenchmarkMeasure &BM) { if (Key.empty()) Key = BM.Key; assert(Key == BM.Key); ++NumValues; - SumValues += BM.Value; - MaxValue = std::max(MaxValue, BM.Value); - MinValue = std::min(MinValue, BM.Value); + SumValues += BM.PerInstructionValue; + MaxValue = std::max(MaxValue, BM.PerInstructionValue); + MinValue = std::min(MinValue, BM.PerInstructionValue); } } // namespace exegesis diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h index 62653cd..e4e29ef 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h @@ -42,7 +42,12 @@ struct InstructionBenchmarkKey { struct BenchmarkMeasure { std::string Key; - double Value; + // This is the per-instruction value, i.e. measured quantity scaled per + // instruction. + double PerInstructionValue; + // This is the per-snippet value, i.e. measured quantity for one repetition of + // the whole snippet. + double PerSnippetValue; std::string DebugString; }; @@ -81,7 +86,7 @@ struct InstructionBenchmark { // Utilities to work with Benchmark measures. // A class that measures stats over benchmark measures. -class BenchmarkMeasureStats { +class PerInstructionStats { public: void push(const BenchmarkMeasure &BM); diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index efda689..7addb0a 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -88,7 +88,15 @@ BenchmarkRunner::runConfiguration(const BenchmarkCode &BC, << *ObjectFilePath << "\n"; const ExecutableFunction EF(State.createTargetMachine(), getObjectFromFile(*ObjectFilePath)); - InstrBenchmark.Measurements = runMeasurements(EF, *Scratch, NumRepetitions); + InstrBenchmark.Measurements = runMeasurements(EF, *Scratch); + assert(InstrBenchmark.NumRepetitions > 0 && "invalid NumRepetitions"); + for (BenchmarkMeasure &BM : InstrBenchmark.Measurements) { + // Scale the measurements by instruction. + BM.PerInstructionValue /= InstrBenchmark.NumRepetitions; + // Scale the measurements by snippet. + BM.PerSnippetValue *= static_cast<double>(BC.Instructions.size()) / + InstrBenchmark.NumRepetitions; + } return InstrBenchmark; } diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h index 07ab23c..e5b567f 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h @@ -69,8 +69,8 @@ protected: private: virtual std::vector<BenchmarkMeasure> - runMeasurements(const ExecutableFunction &EF, ScratchSpace &Scratch, - const unsigned NumRepetitions) const = 0; + runMeasurements(const ExecutableFunction &EF, + ScratchSpace &Scratch) const = 0; llvm::Expected<std::string> writeObjectFile(const BenchmarkCode &Configuration, diff --git a/llvm/tools/llvm-exegesis/lib/Clustering.cpp b/llvm/tools/llvm-exegesis/lib/Clustering.cpp index a966c72..b63afec 100644 --- a/llvm/tools/llvm-exegesis/lib/Clustering.cpp +++ b/llvm/tools/llvm-exegesis/lib/Clustering.cpp @@ -53,7 +53,7 @@ bool InstructionBenchmarkClustering::isNeighbour( const std::vector<BenchmarkMeasure> &Q) const { double DistanceSquared = 0.0; for (size_t I = 0, E = P.size(); I < E; ++I) { - const auto Diff = P[I].Value - Q[I].Value; + const auto Diff = P[I].PerInstructionValue - Q[I].PerInstructionValue; DistanceSquared += Diff * Diff; } return DistanceSquared <= EpsilonSquared_; diff --git a/llvm/tools/llvm-exegesis/lib/Latency.cpp b/llvm/tools/llvm-exegesis/lib/Latency.cpp index d09cdc5..3c402c4 100644 --- a/llvm/tools/llvm-exegesis/lib/Latency.cpp +++ b/llvm/tools/llvm-exegesis/lib/Latency.cpp @@ -109,8 +109,7 @@ LatencyBenchmarkRunner::~LatencyBenchmarkRunner() = default; std::vector<BenchmarkMeasure> LatencyBenchmarkRunner::runMeasurements(const ExecutableFunction &Function, - ScratchSpace &Scratch, - const unsigned NumRepetitions) const { + ScratchSpace &Scratch) const { // Cycle measurements include some overhead from the kernel. Repeat the // measure several times and take the minimum value. constexpr const int NumMeasurements = 30; @@ -131,7 +130,8 @@ LatencyBenchmarkRunner::runMeasurements(const ExecutableFunction &Function, if (Value < MinLatency) MinLatency = Value; } - return {{"latency", static_cast<double>(MinLatency) / NumRepetitions, ""}}; + return {{"latency", static_cast<double>(MinLatency), + static_cast<double>(MinLatency), ""}}; } } // namespace exegesis diff --git a/llvm/tools/llvm-exegesis/lib/Latency.h b/llvm/tools/llvm-exegesis/lib/Latency.h index 5b9be00..3a72d02 100644 --- a/llvm/tools/llvm-exegesis/lib/Latency.h +++ b/llvm/tools/llvm-exegesis/lib/Latency.h @@ -44,8 +44,8 @@ public: private: std::vector<BenchmarkMeasure> - runMeasurements(const ExecutableFunction &EF, ScratchSpace &Scratch, - const unsigned NumRepetitions) const override; + runMeasurements(const ExecutableFunction &EF, + ScratchSpace &Scratch) const override; virtual const char *getCounterName() const; }; diff --git a/llvm/tools/llvm-exegesis/lib/Uops.cpp b/llvm/tools/llvm-exegesis/lib/Uops.cpp index beb9fa8..dbecbfe 100644 --- a/llvm/tools/llvm-exegesis/lib/Uops.cpp +++ b/llvm/tools/llvm-exegesis/lib/Uops.cpp @@ -252,8 +252,7 @@ UopsSnippetGenerator::generateCodeTemplate(unsigned Opcode) const { std::vector<BenchmarkMeasure> UopsBenchmarkRunner::runMeasurements(const ExecutableFunction &Function, - ScratchSpace &Scratch, - const unsigned NumRepetitions) const { + ScratchSpace &Scratch) const { const auto &SchedModel = State.getSubtargetInfo().getSchedModel(); std::vector<BenchmarkMeasure> Result; @@ -281,7 +280,8 @@ UopsBenchmarkRunner::runMeasurements(const ExecutableFunction &Function, CounterValue += Counter.read(); } Result.push_back({llvm::itostr(ProcResIdx), - static_cast<double>(CounterValue) / NumRepetitions, + static_cast<double>(CounterValue), + static_cast<double>(CounterValue), SchedModel.getProcResource(ProcResIdx)->Name}); } return Result; diff --git a/llvm/tools/llvm-exegesis/lib/Uops.h b/llvm/tools/llvm-exegesis/lib/Uops.h index 160397a..aff583b 100644 --- a/llvm/tools/llvm-exegesis/lib/Uops.h +++ b/llvm/tools/llvm-exegesis/lib/Uops.h @@ -71,8 +71,8 @@ public: private: std::vector<BenchmarkMeasure> - runMeasurements(const ExecutableFunction &EF, ScratchSpace &Scratch, - const unsigned NumRepetitions) const override; + runMeasurements(const ExecutableFunction &EF, + ScratchSpace &Scratch) const override; }; } // namespace exegesis |