Skip to content

Commit 1badf92

Browse files
psalzPeterTh
authored andcommitted
Improve wording of uninitialized read warning
1 parent 624db73 commit 1badf92

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

src/task_manager.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,20 @@ namespace detail {
8989
}
9090
}
9191
if(!uninitialized_reads.empty()) {
92-
utils::report_error(m_policy.uninitialized_read_error,
93-
"{} declares a reading access on uninitialized {} {}. Make sure to construct the accessor with no_init if possible.",
94-
print_task_debug_label(tsk, true /* title case */), print_buffer_debug_label(bid), std::move(uninitialized_reads).into_region());
92+
bool is_pure_consumer_access = true;
93+
for(size_t i = 0; i < access_map.get_num_accesses(); ++i) {
94+
const auto [b, mode] = access_map.get_nth_access(i);
95+
if(b == bid && is_producer_mode(mode)) {
96+
is_pure_consumer_access = false;
97+
break;
98+
}
99+
}
100+
const auto verb = is_pure_consumer_access ? "reading" : "consuming";
101+
const auto advice = is_pure_consumer_access ? "" : " Make sure to construct the accessor with no_init if this was unintentional.";
102+
103+
utils::report_error(m_policy.uninitialized_read_error, "{} declares a {} access on uninitialized {} {}.{}",
104+
print_task_debug_label(tsk, true /* title case */), verb, print_buffer_debug_label(bid), std::move(uninitialized_reads).into_region(),
105+
advice);
95106
}
96107
}
97108

test/runtime_tests.cc

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -879,22 +879,39 @@ namespace detail {
879879

880880
std::string expected_warning_message;
881881

882-
SECTION("in device kernels") {
882+
SECTION("in device kernels, pure consumer mode") {
883883
q.submit([&](handler& cgh) {
884884
accessor acc(buf, cgh, celerity::access::all(), celerity::read_only);
885885
cgh.parallel_for(range(1), [=](item<1>) { (void)acc; });
886886
});
887-
expected_warning_message = "Device kernel T1 declares a reading access on uninitialized B0 {[0,0,0] - [1,1,1]}. Make sure to construct the "
888-
"accessor with no_init if possible.";
887+
expected_warning_message = "Device kernel T1 declares a reading access on uninitialized B0 {[0,0,0] - [1,1,1]}.";
889888
}
890889

891-
SECTION("in host tasks") {
890+
SECTION("in device kernels, producer mode") {
891+
q.submit([&](handler& cgh) {
892+
accessor acc(buf, cgh, celerity::access::all(), celerity::write_only);
893+
cgh.parallel_for(range(1), [=](item<1>) { (void)acc; });
894+
});
895+
expected_warning_message = "Device kernel T1 declares a consuming access on uninitialized B0 {[0,0,0] - [1,1,1]}. Make sure to construct the "
896+
"accessor with no_init if this was unintentional.";
897+
}
898+
899+
SECTION("in host tasks, pure consumer mode") {
892900
q.submit([&](handler& cgh) {
893901
accessor acc(buf, cgh, celerity::access::all(), celerity::read_only_host_task);
894902
cgh.host_task(on_master_node, [=] { (void)acc; });
895903
});
896-
expected_warning_message = "Master-node host task T1 declares a reading access on uninitialized B0 {[0,0,0] - [1,1,1]}. Make sure to construct the "
897-
"accessor with no_init if possible.";
904+
expected_warning_message = "Master-node host task T1 declares a reading access on uninitialized B0 {[0,0,0] - [1,1,1]}.";
905+
}
906+
907+
SECTION("in host tasks, producer mode") {
908+
q.submit([&](handler& cgh) {
909+
accessor acc(buf, cgh, celerity::access::all(), celerity::write_only_host_task);
910+
cgh.host_task(on_master_node, [=] { (void)acc; });
911+
});
912+
expected_warning_message =
913+
"Master-node host task T1 declares a consuming access on uninitialized B0 {[0,0,0] - [1,1,1]}. Make sure to construct the "
914+
"accessor with no_init if this was unintentional.";
898915
}
899916

900917
q.wait();

test/task_graph_tests.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,7 @@ namespace detail {
766766

767767
CHECK_THROWS_WITH((test_utils::add_compute_task(
768768
tt.tm, [&](handler& cgh) { debug::set_task_name(cgh, "uninit_read"), buf.get_access<access_mode::read>(cgh, all{}); })),
769-
"Device kernel T1 \"uninit_read\" declares a reading access on uninitialized B0 {[0,0,0] - [1,1,1]}. Make sure to construct the accessor with "
770-
"no_init if possible.");
769+
"Device kernel T1 \"uninit_read\" declares a reading access on uninitialized B0 {[0,0,0] - [1,1,1]}.");
771770
}
772771

773772
SECTION("on a partially initialized buffer") {
@@ -776,10 +775,9 @@ namespace detail {
776775
tt.tm, [&](handler& cgh) { buf.get_access<access_mode::discard_write>(cgh, fixed<2>({{0, 0}, {32, 32}})); });
777776

778777
CHECK_THROWS_WITH((test_utils::add_compute_task(
779-
tt.tm, [&](handler& cgh) { debug::set_task_name(cgh, "uninit_read"), buf.get_access<access_mode::read>(cgh, all{}); })),
780-
"Device kernel T2 \"uninit_read\" declares a reading access on uninitialized B0 {[0,32,0] - [32,64,1], [32,0,0] - [64,64,1]}. Make sure to "
781-
"construct "
782-
"the accessor with no_init if possible.");
778+
tt.tm, [&](handler& cgh) { debug::set_task_name(cgh, "uninit_read"), buf.get_access<access_mode::write>(cgh, all{}); })),
779+
"Device kernel T2 \"uninit_read\" declares a consuming access on uninitialized B0 {[0,32,0] - [32,64,1], [32,0,0] - [64,64,1]}. Make sure to "
780+
"construct the accessor with no_init if this was unintentional.");
783781
}
784782
}
785783

0 commit comments

Comments
 (0)