Skip to content

Revert "[Exegesis] Add the ability to dry-run the measurement phase (… #122371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion llvm/docs/CommandGuide/llvm-exegesis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ OPTIONS
* ``prepare-and-assemble-snippet``: Same as ``prepare-snippet``, but also dumps an excerpt of the sequence (hex encoded).
* ``assemble-measured-code``: Same as ``prepare-and-assemble-snippet``. but also creates the full sequence that can be dumped to a file using ``--dump-object-to-disk``.
* ``measure``: Same as ``assemble-measured-code``, but also runs the measurement.
* ``dry-run-measurement``: Same as measure, but does not actually execute the snippet.

.. option:: --x86-lbr-sample-period=<nBranches/sample>

Expand Down
11 changes: 0 additions & 11 deletions llvm/test/tools/llvm-exegesis/dry-run-measurement.test

This file was deleted.

1 change: 0 additions & 1 deletion llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ enum class BenchmarkPhaseSelectorE {
PrepareAndAssembleSnippet,
AssembleMeasuredCode,
Measure,
DryRunMeasure,
};

enum class BenchmarkFilter { All, RegOnly, WithMem };
Expand Down
33 changes: 8 additions & 25 deletions llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,22 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
static Expected<std::unique_ptr<InProcessFunctionExecutorImpl>>
create(const LLVMState &State, object::OwningBinary<object::ObjectFile> Obj,
BenchmarkRunner::ScratchSpace *Scratch,
std::optional<int> BenchmarkProcessCPU, bool DryRun) {
std::optional<int> BenchmarkProcessCPU) {
Expected<ExecutableFunction> EF =
ExecutableFunction::create(State.createTargetMachine(), std::move(Obj));

if (!EF)
return EF.takeError();

return std::unique_ptr<InProcessFunctionExecutorImpl>(
new InProcessFunctionExecutorImpl(State, std::move(*EF), Scratch,
DryRun));
new InProcessFunctionExecutorImpl(State, std::move(*EF), Scratch));
}

private:
InProcessFunctionExecutorImpl(const LLVMState &State,
ExecutableFunction Function,
BenchmarkRunner::ScratchSpace *Scratch,
bool DryRun)
: State(State), Function(std::move(Function)), Scratch(Scratch),
DryRun(DryRun) {}
BenchmarkRunner::ScratchSpace *Scratch)
: State(State), Function(std::move(Function)), Scratch(Scratch) {}

static void accumulateCounterValues(const SmallVector<int64_t, 4> &NewValues,
SmallVector<int64_t, 4> *Result) {
Expand Down Expand Up @@ -146,14 +143,9 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
CrashRecoveryContext CRC;
CrashRecoveryContext::Enable();
const bool Crashed = !CRC.RunSafely([this, Counter, ScratchPtr]() {
if (DryRun) {
Counter->start();
Counter->stop();
} else {
Counter->start();
this->Function(ScratchPtr);
Counter->stop();
}
Counter->start();
this->Function(ScratchPtr);
Counter->stop();
});
CrashRecoveryContext::Disable();
PS.reset();
Expand Down Expand Up @@ -185,7 +177,6 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
const LLVMState &State;
const ExecutableFunction Function;
BenchmarkRunner::ScratchSpace *const Scratch;
bool DryRun = false;
};

#ifdef __linux__
Expand Down Expand Up @@ -673,29 +664,21 @@ Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>>
BenchmarkRunner::createFunctionExecutor(
object::OwningBinary<object::ObjectFile> ObjectFile,
const BenchmarkKey &Key, std::optional<int> BenchmarkProcessCPU) const {
bool DryRun =
BenchmarkPhaseSelector == BenchmarkPhaseSelectorE::DryRunMeasure;

switch (ExecutionMode) {
case ExecutionModeE::InProcess: {
if (BenchmarkProcessCPU.has_value())
return make_error<Failure>("The inprocess execution mode does not "
"support benchmark core pinning.");

auto InProcessExecutorOrErr = InProcessFunctionExecutorImpl::create(
State, std::move(ObjectFile), Scratch.get(), BenchmarkProcessCPU,
DryRun);
State, std::move(ObjectFile), Scratch.get(), BenchmarkProcessCPU);
if (!InProcessExecutorOrErr)
return InProcessExecutorOrErr.takeError();

return std::move(*InProcessExecutorOrErr);
}
case ExecutionModeE::SubProcess: {
#ifdef __linux__
if (DryRun)
return make_error<Failure>("The subprocess execution mode cannot "
"dry-run measurement at this moment.");

auto SubProcessExecutorOrErr = SubProcessFunctionExecutorImpl::create(
State, std::move(ObjectFile), Key, BenchmarkProcessCPU);
if (!SubProcessExecutorOrErr)
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/llvm-exegesis/lib/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ExegesisTarget::createBenchmarkRunner(
return nullptr;
case Benchmark::Latency:
case Benchmark::InverseThroughput:
if (BenchmarkPhaseSelector >= BenchmarkPhaseSelectorE::Measure &&
if (BenchmarkPhaseSelector == BenchmarkPhaseSelectorE::Measure &&
!PfmCounters.CycleCounter) {
const char *ModeName = Mode == Benchmark::Latency
? "latency"
Expand All @@ -116,7 +116,7 @@ ExegesisTarget::createBenchmarkRunner(
State, Mode, BenchmarkPhaseSelector, ResultAggMode, ExecutionMode,
ValidationCounters, BenchmarkRepeatCount);
case Benchmark::Uops:
if (BenchmarkPhaseSelector >= BenchmarkPhaseSelectorE::Measure &&
if (BenchmarkPhaseSelector == BenchmarkPhaseSelectorE::Measure &&
!PfmCounters.UopsCounter && !PfmCounters.IssueCounters)
return make_error<Failure>(
"can't run 'uops' mode, sched model does not define uops or issue "
Expand Down
9 changes: 3 additions & 6 deletions llvm/tools/llvm-exegesis/llvm-exegesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ static cl::opt<BenchmarkPhaseSelectorE> BenchmarkPhaseSelector(
clEnumValN(
BenchmarkPhaseSelectorE::Measure, "measure",
"Same as prepare-measured-code, but also runs the measurement "
"(default)"),
clEnumValN(
BenchmarkPhaseSelectorE::DryRunMeasure, "dry-run-measurement",
"Same as measure, but does not actually execute the snippet")),
"(default)")),
cl::init(BenchmarkPhaseSelectorE::Measure));

static cl::opt<bool>
Expand Down Expand Up @@ -479,7 +476,7 @@ static void runBenchmarkConfigurations(
}

void benchmarkMain() {
if (BenchmarkPhaseSelector >= BenchmarkPhaseSelectorE::Measure &&
if (BenchmarkPhaseSelector == BenchmarkPhaseSelectorE::Measure &&
!UseDummyPerfCounters) {
#ifndef HAVE_LIBPFM
ExitWithError(
Expand All @@ -504,7 +501,7 @@ void benchmarkMain() {

// Preliminary check to ensure features needed for requested
// benchmark mode are present on target CPU and/or OS.
if (BenchmarkPhaseSelector >= BenchmarkPhaseSelectorE::Measure)
if (BenchmarkPhaseSelector == BenchmarkPhaseSelectorE::Measure)
ExitOnErr(State.getExegesisTarget().checkFeatureSupport());

if (ExecutionMode == BenchmarkRunner::ExecutionModeE::SubProcess &&
Expand Down
Loading