Skip to content

Commit 24f4c12

Browse files
committed
Test: Multiple epochs without intermediate tasks/commands have defined behavior
1 parent fd3935c commit 24f4c12

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/print_graph.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ namespace detail {
6666
std::string label = fmt::format("[{}] Node {}:\\n", cmd->get_cid(), cmd->get_nid());
6767
if(const auto ecmd = dynamic_cast<const epoch_command*>(cmd)) {
6868
label += "EPOCH";
69+
if(ecmd->get_epoch_action() == epoch_action::barrier) { label += " (barrier)"; }
70+
if(ecmd->get_epoch_action() == epoch_action::shutdown) { label += " (shutdown)"; }
6971
} else if(const auto xcmd = dynamic_cast<const execution_command*>(cmd)) {
7072
label += fmt::format("EXECUTION {}\\n{}", subrange_to_grid_box(xcmd->get_execution_range()), cmd->debug_label);
7173
} else if(const auto pcmd = dynamic_cast<const push_command*>(cmd)) {

test/graph_generation_tests.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,31 @@ namespace detail {
16621662
maybe_print_graphs(ctx);
16631663
}
16641664

1665+
TEST_CASE("a sequence of epochs without intermediate commands has defined behavior", "[graph_generator][command-graph][epoch]") {
1666+
const size_t num_nodes = 2;
1667+
test_utils::cdag_test_context ctx(num_nodes);
1668+
auto& tm = ctx.get_task_manager();
1669+
auto& inspector = ctx.get_inspector();
1670+
auto& cdag = ctx.get_command_graph();
1671+
1672+
auto tid_before = task_manager::initial_epoch_task;
1673+
for(const auto action : {epoch_action::barrier, epoch_action::shutdown}) {
1674+
const auto tid = test_utils::build_and_flush(ctx, num_nodes, tm.finish_epoch(action));
1675+
CAPTURE(tid_before, tid);
1676+
for(const auto cid : inspector.get_commands(tid, std::nullopt, std::nullopt)) {
1677+
CAPTURE(cid);
1678+
const auto deps = cdag.get(cid)->get_dependencies();
1679+
CHECK(std::distance(deps.begin(), deps.end()) == 1);
1680+
for(const auto& d : deps) {
1681+
CHECK(d.kind == dependency_kind::TRUE_DEP);
1682+
CHECKED_IF(isa<task_command>(d.node)) { CHECK(static_cast<task_command*>(d.node)->get_tid() == tid_before); }
1683+
}
1684+
}
1685+
tid_before = tid;
1686+
}
1687+
1688+
maybe_print_graphs(ctx);
1689+
}
16651690

16661691
} // namespace detail
16671692
} // namespace celerity

test/task_graph_tests.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ namespace detail {
635635

636636
maybe_print_graph(tm);
637637
}
638+
638639
TEST_CASE("epochs create appropriate dependencies to predecessors and successors", "[task_manager][task-graph][epoch]") {
639640
task_manager tm{1, nullptr, nullptr};
640641
test_utils::mock_buffer_factory mbf(&tm);
@@ -668,7 +669,6 @@ namespace detail {
668669
maybe_print_graph(tm);
669670
}
670671

671-
672672
TEST_CASE("inserting epochs resets the need for horizons", "[task_manager][task-graph][task-horizon][epoch]") {
673673
task_manager tm{1, nullptr, nullptr};
674674
tm.set_horizon_step(2);
@@ -685,5 +685,24 @@ namespace detail {
685685
maybe_print_graph(tm);
686686
}
687687

688+
TEST_CASE("a sequence of epochs without intermediate tasks has defined behavior", "[task_manager][task-graph][epoch]") {
689+
task_manager tm{1, nullptr, nullptr};
690+
691+
auto tid_before = task_manager::initial_epoch_task;
692+
for(const auto action : {epoch_action::barrier, epoch_action::shutdown}) {
693+
const auto tid = tm.finish_epoch(action);
694+
CAPTURE(tid_before, tid);
695+
const auto deps = tm.get_task(tid)->get_dependencies();
696+
CHECK(std::distance(deps.begin(), deps.end()) == 1);
697+
for(const auto& d : deps) {
698+
CHECK(d.kind == dependency_kind::TRUE_DEP);
699+
CHECK(d.node->get_id() == tid_before);
700+
}
701+
tid_before = tid;
702+
}
703+
704+
maybe_print_graph(tm);
705+
}
706+
688707
} // namespace detail
689708
} // namespace celerity

0 commit comments

Comments
 (0)