Skip to content

Commit

Permalink
[llvm-exegesis] Check counters before running
Browse files Browse the repository at this point in the history
Check if the appropriate counters for the specified mode are defined on
the target. This is checked before any other work is done.

Differential Revision: https://reviews.llvm.org/D71927
  • Loading branch information
Miloš Stojanović authored and Miloš Stojanović committed Dec 31, 2019
1 parent b409f73 commit c7dc473
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 0 additions & 2 deletions llvm/tools/llvm-exegesis/lib/Latency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ Expected<std::vector<BenchmarkMeasure>> LatencyBenchmarkRunner::runMeasurements(
constexpr const int NumMeasurements = 30;
int64_t MinValue = std::numeric_limits<int64_t>::max();
const char *CounterName = State.getPfmCounters().CycleCounter;
if (!CounterName)
report_fatal_error("sched model does not define a cycle counter");
for (size_t I = 0; I < NumMeasurements; ++I) {
auto ExpectedCounterValue = Executor.runAndMeasure(CounterName);
if (!ExpectedCounterValue)
Expand Down
11 changes: 11 additions & 0 deletions llvm/tools/llvm-exegesis/lib/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,24 @@ std::unique_ptr<SnippetGenerator> ExegesisTarget::createSnippetGenerator(
std::unique_ptr<BenchmarkRunner>
ExegesisTarget::createBenchmarkRunner(InstructionBenchmark::ModeE Mode,
const LLVMState &State) const {
PfmCountersInfo PfmCounters = State.getPfmCounters();
switch (Mode) {
case InstructionBenchmark::Unknown:
return nullptr;
case InstructionBenchmark::Latency:
case InstructionBenchmark::InverseThroughput:
if (!PfmCounters.CycleCounter) {
const char *ModeName = Mode == InstructionBenchmark::Latency
? "latency"
: "inverse_throughput";
report_fatal_error(Twine("can't run '").concat(ModeName).concat("' mode, "
"sched model does not define a cycle counter."));
}
return createLatencyBenchmarkRunner(State, Mode);
case InstructionBenchmark::Uops:
if (!PfmCounters.UopsCounter && !PfmCounters.IssueCounters)
report_fatal_error("can't run 'uops' mode, sched model does not define "
"uops or issue counters.");
return createUopsBenchmarkRunner(State);
}
return nullptr;
Expand Down
13 changes: 7 additions & 6 deletions llvm/tools/llvm-exegesis/llvm-exegesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ void benchmarkMain() {
InitializeNativeExegesisTarget();

const LLVMState State(CpuName);

const std::unique_ptr<BenchmarkRunner> Runner =
State.getExegesisTarget().createBenchmarkRunner(BenchmarkMode, State);
if (!Runner) {
report_fatal_error("cannot create benchmark runner");
}

const auto Opcodes = getOpcodesOrDie(State.getInstrInfo());

const auto Repetitor = SnippetRepetitor::Create(RepetitionMode, State);
Expand Down Expand Up @@ -272,12 +279,6 @@ void benchmarkMain() {
Configurations = ExitOnErr(readSnippets(State, SnippetsFile));
}

const std::unique_ptr<BenchmarkRunner> Runner =
State.getExegesisTarget().createBenchmarkRunner(BenchmarkMode, State);
if (!Runner) {
report_fatal_error("cannot create benchmark runner");
}

if (NumRepetitions == 0)
report_fatal_error("--num-repetitions must be greater than zero");

Expand Down

0 comments on commit c7dc473

Please sign in to comment.