[llvm] fc791b6 - [llvm-exegesis] Add option to specify the number of measurement repetitions (#74276)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 7 00:32:37 PST 2023
Author: Aiden Grossman
Date: 2023-12-07T00:32:33-08:00
New Revision: fc791b61272322d72238533dccadd9564e117894
URL: https://github.com/llvm/llvm-project/commit/fc791b61272322d72238533dccadd9564e117894
DIFF: https://github.com/llvm/llvm-project/commit/fc791b61272322d72238533dccadd9564e117894.diff
LOG: [llvm-exegesis] Add option to specify the number of measurement repetitions (#74276)
Currently, the llvm-exegesis LatencyBenchmarkRunner repeats the
benchmark several times (currently 30) and then aggregates the result to
deal with noise in the measurement process. With this patch, the number
of repetitions to perform is made configurable rather than left as a
static number. This allows for significantly faster execution in
situations where someone is performing a task like experimenting with
memory annotations where the exact cycle counts might not be useful, and
also allows for increased precision when desired.
Added:
Modified:
llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.h
llvm/tools/llvm-exegesis/lib/Target.cpp
llvm/tools/llvm-exegesis/lib/Target.h
llvm/tools/llvm-exegesis/llvm-exegesis.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.cpp
index 753efed138163..eda450579a583 100644
--- a/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.cpp
@@ -21,11 +21,13 @@ namespace exegesis {
LatencyBenchmarkRunner::LatencyBenchmarkRunner(
const LLVMState &State, Benchmark::ModeE Mode,
BenchmarkPhaseSelectorE BenchmarkPhaseSelector,
- Benchmark::ResultAggregationModeE ResultAgg, ExecutionModeE ExecutionMode)
+ Benchmark::ResultAggregationModeE ResultAgg, ExecutionModeE ExecutionMode,
+ unsigned BenchmarkRepeatCount)
: BenchmarkRunner(State, Mode, BenchmarkPhaseSelector, ExecutionMode) {
assert((Mode == Benchmark::Latency || Mode == Benchmark::InverseThroughput) &&
"invalid mode");
ResultAggMode = ResultAgg;
+ NumMeasurements = BenchmarkRepeatCount;
}
LatencyBenchmarkRunner::~LatencyBenchmarkRunner() = default;
@@ -68,7 +70,6 @@ Expected<std::vector<BenchmarkMeasure>> LatencyBenchmarkRunner::runMeasurements(
// Cycle measurements include some overhead from the kernel. Repeat the
// measure several times and return the aggregated value, as specified by
// ResultAggMode.
- constexpr const int NumMeasurements = 30;
llvm::SmallVector<int64_t, 4> AccumulatedValues;
double MinVariance = std::numeric_limits<double>::infinity();
const char *CounterName = State.getPfmCounters().CycleCounter;
diff --git a/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.h b/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.h
index 34b912f0abded..fc159d7d9b5e9 100644
--- a/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.h
+++ b/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.h
@@ -24,7 +24,8 @@ class LatencyBenchmarkRunner : public BenchmarkRunner {
LatencyBenchmarkRunner(const LLVMState &State, Benchmark::ModeE Mode,
BenchmarkPhaseSelectorE BenchmarkPhaseSelector,
Benchmark::ResultAggregationModeE ResultAggMode,
- ExecutionModeE ExecutionMode);
+ ExecutionModeE ExecutionMode,
+ unsigned BenchmarkRepeatCount);
~LatencyBenchmarkRunner() override;
private:
@@ -32,6 +33,7 @@ class LatencyBenchmarkRunner : public BenchmarkRunner {
runMeasurements(const FunctionExecutor &Executor) const override;
Benchmark::ResultAggregationModeE ResultAggMode;
+ unsigned NumMeasurements;
};
} // namespace exegesis
} // namespace llvm
diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp b/llvm/tools/llvm-exegesis/lib/Target.cpp
index aed093548f158..23c80e5b98953 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -79,6 +79,7 @@ ExegesisTarget::createBenchmarkRunner(
Benchmark::ModeE Mode, const LLVMState &State,
BenchmarkPhaseSelectorE BenchmarkPhaseSelector,
BenchmarkRunner::ExecutionModeE ExecutionMode,
+ unsigned BenchmarkRepeatCount,
Benchmark::ResultAggregationModeE ResultAggMode) const {
PfmCountersInfo PfmCounters = State.getPfmCounters();
switch (Mode) {
@@ -101,7 +102,8 @@ ExegesisTarget::createBenchmarkRunner(
"the kernel for real event counts."));
}
return createLatencyBenchmarkRunner(State, Mode, BenchmarkPhaseSelector,
- ResultAggMode, ExecutionMode);
+ ResultAggMode, ExecutionMode,
+ BenchmarkRepeatCount);
case Benchmark::Uops:
if (BenchmarkPhaseSelector == BenchmarkPhaseSelectorE::Measure &&
!PfmCounters.UopsCounter && !PfmCounters.IssueCounters)
@@ -130,9 +132,11 @@ std::unique_ptr<BenchmarkRunner> ExegesisTarget::createLatencyBenchmarkRunner(
const LLVMState &State, Benchmark::ModeE Mode,
BenchmarkPhaseSelectorE BenchmarkPhaseSelector,
Benchmark::ResultAggregationModeE ResultAggMode,
- BenchmarkRunner::ExecutionModeE ExecutionMode) const {
+ BenchmarkRunner::ExecutionModeE ExecutionMode,
+ unsigned BenchmarkRepeatCount) const {
return std::make_unique<LatencyBenchmarkRunner>(
- State, Mode, BenchmarkPhaseSelector, ResultAggMode, ExecutionMode);
+ State, Mode, BenchmarkPhaseSelector, ResultAggMode, ExecutionMode,
+ BenchmarkRepeatCount);
}
std::unique_ptr<BenchmarkRunner> ExegesisTarget::createUopsBenchmarkRunner(
diff --git a/llvm/tools/llvm-exegesis/lib/Target.h b/llvm/tools/llvm-exegesis/lib/Target.h
index 6de5b3c1065f1..c37dd8b708216 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.h
+++ b/llvm/tools/llvm-exegesis/lib/Target.h
@@ -262,6 +262,7 @@ class ExegesisTarget {
Benchmark::ModeE Mode, const LLVMState &State,
BenchmarkPhaseSelectorE BenchmarkPhaseSelector,
BenchmarkRunner::ExecutionModeE ExecutionMode,
+ unsigned BenchmarkRepeatCount,
Benchmark::ResultAggregationModeE ResultAggMode = Benchmark::Min) const;
// Returns the ExegesisTarget for the given triple or nullptr if the target
@@ -305,7 +306,8 @@ class ExegesisTarget {
const LLVMState &State, Benchmark::ModeE Mode,
BenchmarkPhaseSelectorE BenchmarkPhaseSelector,
Benchmark::ResultAggregationModeE ResultAggMode,
- BenchmarkRunner::ExecutionModeE ExecutionMode) const;
+ BenchmarkRunner::ExecutionModeE ExecutionMode,
+ unsigned BenchmarkRepeatCount) const;
std::unique_ptr<BenchmarkRunner> virtual createUopsBenchmarkRunner(
const LLVMState &State, BenchmarkPhaseSelectorE BenchmarkPhaseSelector,
Benchmark::ResultAggregationModeE ResultAggMode,
diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
index 66bc94271756c..4e466303c9dbf 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -262,6 +262,12 @@ static cl::opt<BenchmarkRunner::ExecutionModeE> ExecutionMode(
"allows for the use of memory annotations")),
cl::init(BenchmarkRunner::ExecutionModeE::InProcess));
+static cl::opt<unsigned> BenchmarkRepeatCount(
+ "benchmark-repeat-count",
+ cl::desc("The number of times to repeat measurements on the benchmark k "
+ "before aggregating the results"),
+ cl::cat(BenchmarkOptions), cl::init(30));
+
static ExitOnError ExitOnErr("llvm-exegesis error: ");
// Helper function that logs the error(s) and exits.
@@ -485,7 +491,7 @@ void benchmarkMain() {
const std::unique_ptr<BenchmarkRunner> Runner =
ExitOnErr(State.getExegesisTarget().createBenchmarkRunner(
BenchmarkMode, State, BenchmarkPhaseSelector, ExecutionMode,
- ResultAggMode));
+ BenchmarkRepeatCount, ResultAggMode));
if (!Runner) {
ExitWithError("cannot create benchmark runner");
}
More information about the llvm-commits
mailing list