Skip to content

Commit

Permalink
Tolerate empty FunctionBases in critical path analysis and benchmark_…
Browse files Browse the repository at this point in the history
…main.

PiperOrigin-RevId: 683702773
  • Loading branch information
meheffernan authored and copybara-github committed Oct 8, 2024
1 parent 6a04649 commit 600dfac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
6 changes: 3 additions & 3 deletions xls/dev_tools/benchmark_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ absl::Status PrintCriticalPath(
const synthesis::SynthesizedDelayDiffByStage& delay_diff) {
const std::vector<CriticalPathEntry>& critical_path =
delay_diff.total_diff.critical_path;
std::cout << absl::StrFormat("Critical path delay: %dps\n",
critical_path.front().path_delay_ps);
int64_t total_delay =
critical_path.empty() ? 0 : critical_path.front().path_delay_ps;
std::cout << absl::StrFormat("Critical path delay: %dps\n", total_delay);
std::cout << absl::StrFormat("Critical path entry count: %d\n",
critical_path.size());

Expand All @@ -283,7 +284,6 @@ absl::Status PrintCriticalPath(
tally.second += 1;
}

int64_t total_delay = critical_path.front().path_delay_ps;
std::cout << absl::StrFormat("Contribution by op (total %dps):\n",
total_delay);
std::vector<Op> ops(kAllOps.begin(), kAllOps.end());
Expand Down
8 changes: 6 additions & 2 deletions xls/estimators/delay_model/analyze_critical_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ absl::StatusOr<std::vector<CriticalPathEntry>> AnalyzeCriticalPath(
}
}

// Starting with the operation with the longest pat hdelay, walk back up its
// `latest_entry` has no value for empty FunctionBases.
if (!latest_entry.has_value()) {
return std::vector<CriticalPathEntry>();
}

// Starting with the operation with the longest path delay, walk back up its
// critical path constructing CriticalPathEntry's as we go.
std::vector<CriticalPathEntry> critical_path;
XLS_RET_CHECK(latest_entry.has_value());
NodeEntry* entry = &(latest_entry.value());
while (true) {
critical_path.push_back(CriticalPathEntry{
Expand Down
12 changes: 12 additions & 0 deletions xls/estimators/delay_model/analyze_critical_path_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,17 @@ TEST_F(AnalyzeCriticalPathTest, ProcWithSendReceive) {
FieldsAre(m::Literal(Value::Token()), _, _, _)));
}

TEST_F(AnalyzeCriticalPathTest, EmptyProc) {
auto p = CreatePackage();
ProcBuilder b(TestName(), p.get());
XLS_ASSERT_OK_AND_ASSIGN(Proc * proc, b.Build({}));

XLS_ASSERT_OK_AND_ASSIGN(
std::vector<CriticalPathEntry> cp,
AnalyzeCriticalPath(proc, /*clock_period_ps=*/std::nullopt,
*delay_estimator_));
EXPECT_TRUE(cp.empty());
}

} // namespace
} // namespace xls

0 comments on commit 600dfac

Please sign in to comment.