Skip to content

Commit

Permalink
Fix: Reduction commands must anti-depend on their partial-result pushes
Browse files Browse the repository at this point in the history
  • Loading branch information
fknorr committed Oct 25, 2023
1 parent 5cc76fa commit bf03a5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/distributed_graph_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@ void distributed_graph_generator::generate_distributed_commands(const task& tsk)
}
m_cdag.add_dependency(writer_cmd, push_cmd, dependency_kind::anti_dep, dependency_origin::dataflow);
}

// reduction commands will overwrite their buffer, so they must anti-depend on their partial-result push-commands
if(utils::isa<reduction_command>(writer_cmd)
&& utils::as<reduction_command>(writer_cmd)->get_reduction_info().rid == push_cmd->get_reduction_id()) {
m_cdag.add_dependency(writer_cmd, push_cmd, dependency_kind::anti_dep, dependency_origin::dataflow);
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/graph_gen_reduction_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,18 @@ TEST_CASE("reductions that do not include the current value generate anti-depend
const auto tid_reduce = dctx.device_compute<class UKN(reduce)>(range<1>(1)).reduce(buf0, false /* include_current_buffer_value */).submit();
CHECK(dctx.query(tid_write).have_successors(dctx.query(tid_reduce), dependency_kind::anti_dep));
}

TEST_CASE("reduction commands anti-depend on their partial-result push commands", "[distributed_graph_generator][command-graph][reductions]") {
const size_t num_nodes = 2;
dist_cdag_test_context dctx(2);
auto buf = dctx.create_buffer(range<1>(1));

const auto tid_producer = dctx.device_compute(range<1>(num_nodes)).reduce(buf, false /* include_current_buffer_value */).submit();
const auto tid_consumer = dctx.device_compute(range<1>(num_nodes)).read(buf, acc::all{}).submit();

CHECK(dctx.query(tid_producer)
.assert_count_per_node(1)
.find_successors(command_type::push, dependency_kind::true_dep)
.assert_count_per_node(1)
.have_successors(dctx.query(command_type::reduction).assert_count_per_node(1), dependency_kind::anti_dep));
}

0 comments on commit bf03a5d

Please sign in to comment.