From 9e7a2d248f2bb8eecac7bd9463324cd034a0b0fa Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Tue, 6 Aug 2024 17:49:33 -0400 Subject: [PATCH] Filter out private scratch allocations and fix typo for real this time --- .../kp_view_of_views_bug_finder.cpp | 10 ++++++++-- .../test_view_of_views_bug_finder.cpp | 20 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/debugging/vov-bug-finder/kp_view_of_views_bug_finder.cpp b/debugging/vov-bug-finder/kp_view_of_views_bug_finder.cpp index 0bd832dd2..375fc06bd 100644 --- a/debugging/vov-bug-finder/kp_view_of_views_bug_finder.cpp +++ b/debugging/vov-bug-finder/kp_view_of_views_bug_finder.cpp @@ -58,6 +58,12 @@ bool ignore_fence(std::string_view s) { (s == "Kokkos::ThreadsInternal::fence: Unnamed Instance Fence"); } +bool ignore_alloc(std::string_view s) { + // TODO replace poor man's starts_with and ends_with when C++20 is available + return (s.find("Kokkos::") == 0 && + s.rfind("::scratch_mem") == s.length() - 13); +} + std::optional get_substr(std::string const &str, std::string_view prefix, std::string_view suffix) { @@ -137,7 +143,7 @@ extern "C" void kokkosp_end_fence(uint64_t fenceID) { extern "C" void kokkosp_allocate_data(SpaceHandle handle, const char *name, void *ptr, uint64_t size) { std::lock_guard lock(current.mutex); - if (!current.is_empty()) { + if (!current.is_empty() && !ignore_alloc(name)) { std::cerr << "allocating \"" << name << "\" within parallel region \"" << current.top() << "\"\n"; if (abort_on_error) { @@ -154,7 +160,7 @@ extern "C" void kokkosp_allocate_data(SpaceHandle handle, const char *name, extern "C" void kokkosp_deallocate_data(SpaceHandle handle, const char *name, void *ptr, uint64_t size) { std::lock_guard lock(current.mutex); - if (!current.is_empty()) { + if (!current.is_empty() && !ignore_alloc(name)) { std::cerr << "deallocating \"" << name << "\" within parallel region \"" << current.top() << "\"\n"; if (abort_on_error) { diff --git a/tests/vov-bug-finder/test_view_of_views_bug_finder.cpp b/tests/vov-bug-finder/test_view_of_views_bug_finder.cpp index 4314b8df2..07a4bdfb6 100644 --- a/tests/vov-bug-finder/test_view_of_views_bug_finder.cpp +++ b/tests/vov-bug-finder/test_view_of_views_bug_finder.cpp @@ -54,7 +54,23 @@ void test_death_allocation_in_parallel_for() { "allocating \"b\" within parallel region \"AllocatesInParallel]For\""); } -// TODO intialize in main and split unit tests +void test_no_throw_team_scratch_pad_parallel_for() { + ASSERT_NO_THROW(({ + Kokkos::parallel_for( + "L0", + Kokkos::TeamPolicy<>(1, Kokkos::AUTO) + .set_scratch_size(0, Kokkos::PerTeam(1000)), + KOKKOS_LAMBDA(Kokkos::TeamPolicy<>::member_type const &){}); + + Kokkos::parallel_for( + "L1", + Kokkos::TeamPolicy<>(1, Kokkos::AUTO) + .set_scratch_size(1, Kokkos::PerTeam(1000)), + KOKKOS_LAMBDA(Kokkos::TeamPolicy<>::member_type const &){}); + })); +} + +// TODO initialize in main and split unit tests TEST(ViewOfViews, find_bugs) { Kokkos::initialize(); { @@ -104,6 +120,8 @@ TEST(ViewOfViews, find_bugs) { test_no_throw_placement_new_in_parallel_for(); test_death_allocation_in_parallel_for(); + + test_no_throw_team_scratch_pad_parallel_for(); } Kokkos::finalize(); }