From 64ca586350265129765b6b962b09318cdfe34782 Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Thu, 1 Aug 2024 13:25:00 -0400 Subject: [PATCH 1/9] Add View of Views debugging tool --- CMakeLists.txt | 1 + debugging/vov-bug-finder/CMakeLists.txt | 1 + .../kp_view_of_views_bug_finder.cpp | 169 ++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/vov-bug-finder/CMakeLists.txt | 5 + .../test_view_of_views_bug_finder.cpp | 102 +++++++++++ 6 files changed, 279 insertions(+) create mode 100644 debugging/vov-bug-finder/CMakeLists.txt create mode 100644 debugging/vov-bug-finder/kp_view_of_views_bug_finder.cpp create mode 100644 tests/vov-bug-finder/CMakeLists.txt create mode 100644 tests/vov-bug-finder/test_view_of_views_bug_finder.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 45299188b..2a9f45c5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,6 +144,7 @@ if(NOT WIN32) add_subdirectory(common/kokkos-sampler) endif() add_subdirectory(debugging/kernel-logger) +add_subdirectory(debugging/vov-bug-finder) # Profilers if(NOT WIN32) diff --git a/debugging/vov-bug-finder/CMakeLists.txt b/debugging/vov-bug-finder/CMakeLists.txt new file mode 100644 index 000000000..7f704cbb9 --- /dev/null +++ b/debugging/vov-bug-finder/CMakeLists.txt @@ -0,0 +1 @@ +kp_add_library(kp_view_of_views_bug_finder kp_view_of_views_bug_finder.cpp) 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 new file mode 100644 index 000000000..0bd832dd2 --- /dev/null +++ b/debugging/vov-bug-finder/kp_view_of_views_bug_finder.cpp @@ -0,0 +1,169 @@ +//@HEADER +// ************************************************************************ +// +// Kokkos v. 4.0 +// Copyright (2022) National Technology & Engineering +// Solutions of Sandia, LLC (NTESS). +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. +// See https://kokkos.org/LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//@HEADER + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +bool verbose = false; +bool abort_on_error = true; + +class { + uint64_t count_; + std::map map_; + + public: + std::mutex mutex; + uint64_t push(std::string s) { + auto it = map_.emplace_hint(map_.end(), count_, std::move(s)); + assert(++it == map_.end()); + return count_++; + } + void pop(uint64_t x) { + auto it = map_.find(x); + assert(it != map_.end()); + map_.erase(it); + } + std::string const &top() { + assert(!map_.empty()); + return map_.begin()->second; + } + bool is_empty() noexcept { return map_.empty(); } +} current; + +bool ignore_fence(std::string_view s) { + return (s == "Kokkos::Impl::ViewValueFunctor: View init/destroy fence") || + (s == "Kokkos::ThreadsInternal::fence: Unnamed Instance Fence"); +} + +std::optional get_substr(std::string const &str, + std::string_view prefix, + std::string_view suffix) { + if (auto found = str.find(prefix); found != std::string::npos) { + found += prefix.length(); + return str.substr(found, str.rfind(suffix) - found); + } + return std::nullopt; +} + +} // namespace + +extern "C" void kokkosp_request_tool_settings( + const uint32_t, Kokkos_Tools_ToolSettings *settings) { + settings->requires_global_fencing = false; +} + +extern "C" void kokkosp_begin_parallel_for(char const *kernelName, + uint32_t deviceID, + uint64_t *kernelID) { + std::lock_guard lock(current.mutex); + if (!current.is_empty()) { + if (auto lbl = + get_substr(kernelName, "Kokkos::View::initialization [", "]")) { + std::cerr << "constructing view \"" << *lbl + << "\" within a parallel region \"" << current.top() << "\"\n"; + if (abort_on_error) { + std::abort(); + } + } + } + *kernelID = current.push(kernelName); + + if (verbose) { + std::cout << "begin kernel " << *kernelID << " " << kernelName + << " on device " << deviceID << '\n'; + } +} + +extern "C" void kokkosp_end_parallel_for(uint64_t kernelID) { + std::lock_guard lock(current.mutex); + current.pop(kernelID); + + if (verbose) { + std::cout << "end kernel " << kernelID << '\n'; + } +} + +extern "C" void kokkosp_begin_fence(char const *fenceName, uint32_t deviceID, + uint64_t *fenceID) { + std::lock_guard lock(current.mutex); + if (!current.is_empty() && !ignore_fence(fenceName)) { + if (auto lbl = + get_substr(current.top(), "Kokkos::View::destruction [", "]")) { + std::cerr << "view of views \"" << *lbl + << "\" not properly cleared this fence labelled \"" << fenceName + << "\" will hang\n"; + if (abort_on_error) { + std::abort(); + } + } + } + *fenceID = -1; + + if (verbose) { + std::cout << "begin fence " << *fenceID << " " << fenceName << " on device " + << deviceID << '\n'; + } +} + +extern "C" void kokkosp_end_fence(uint64_t fenceID) { + if (verbose) { + std::cout << "end fence " << fenceID << '\n'; + } +} + +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()) { + std::cerr << "allocating \"" << name << "\" within parallel region \"" + << current.top() << "\"\n"; + if (abort_on_error) { + std::abort(); + } + } + + if (verbose) { + std::cout << "alloc (" << handle.name << ") " << name << " pointer " << ptr + << "size " << size << '\n'; + } +} + +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()) { + std::cerr << "deallocating \"" << name << "\" within parallel region \"" + << current.top() << "\"\n"; + if (abort_on_error) { + std::abort(); + } + } + + if (verbose) { + std::cout << "dealloc (" << handle.name << ") " << name << " pointer " + << ptr << "size " << size << '\n'; + } +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4ca3a79b6..de3851418 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -114,3 +114,4 @@ target_link_libraries(test_common PUBLIC GTest::gtest GTest::gmock Kokkos::kokko add_subdirectory(space-time-stack) add_subdirectory(sampler) +add_subdirectory(vov-bug-finder) diff --git a/tests/vov-bug-finder/CMakeLists.txt b/tests/vov-bug-finder/CMakeLists.txt new file mode 100644 index 000000000..bd1591980 --- /dev/null +++ b/tests/vov-bug-finder/CMakeLists.txt @@ -0,0 +1,5 @@ +kp_add_executable_and_test( + TARGET_NAME test_vov_bug_finder + SOURCE_FILE test_view_of_views_bug_finder.cpp + KOKKOS_TOOLS_LIBS kp_view_of_views_bug_finder +) 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 new file mode 100644 index 000000000..98380ce90 --- /dev/null +++ b/tests/vov-bug-finder/test_view_of_views_bug_finder.cpp @@ -0,0 +1,102 @@ +//@HEADER +// ************************************************************************ +// +// Kokkos v. 4.0 +// Copyright (2022) National Technology & Engineering +// Solutions of Sandia, LLC (NTESS). +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. +// See https://kokkos.org/LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//@HEADER + +#include "Kokkos_Core.hpp" +#include "gtest/gtest.h" + +// TODO intialixe in main and split unit tests +TEST(ViewOfViews, find_bugs) { + Kokkos::initialize(); + { + ASSERT_NO_THROW(({ + using V = Kokkos::View; + Kokkos::View vov("vov", 2, 3); + V a("a", 4); + V b("b", 5); + vov(0, 0) = a; + vov(0, 1) = a; + vov(1, 0) = b; + + vov(0, 0) = V(); + vov(0, 1) = V(); + vov(1, 0) = V(); + })); + + ASSERT_NO_THROW(({ + using V = Kokkos::View; + Kokkos::View vov( + Kokkos::view_alloc("vov", Kokkos::WithoutInitializing), 2, 3); + V a("a", 4); + V b("b", 5); + new (&vov(0, 0)) V(a); + new (&vov(0, 1)) V(a); + new (&vov(1, 0)) V(b); + + vov(0, 0).~V(); + vov(0, 1).~V(); + // vov(1, 0).~V(); + // ^ leaking "b" but not caught by the tool + })); + + ASSERT_DEATH(({ + using V = Kokkos::View; + Kokkos::View vov("vo]v", 2, 3); + // ^ included a closing square bracket in the label to try + // to trip the substring extraction + V a("a", 4); + V b("b", 5); + vov(0, 0) = a; + vov(0, 1) = a; + vov(1, 0) = b; + }), + "view of views \"vo]v\" not properly cleared"); + + ASSERT_NO_THROW(({ + using V = Kokkos::View; + Kokkos::View vov( + Kokkos::view_alloc("vov", Kokkos::WithoutInitializing), 2, 3); + V a("a", 4); + V b("b", 5); + Kokkos::parallel_for( + "Fine", Kokkos::RangePolicy(0, 1), + KOKKOS_LAMBDA(int) { + new (&vov(0, 0)) V(a); + new (&vov(0, 1)) V(a); + new (&vov(1, 0)) V(b); + }); + })); + + ASSERT_DEATH( + ({ + using V = Kokkos::View; + Kokkos::View vov( + Kokkos::view_alloc("vov", Kokkos::WithoutInitializing), 2, 3); + V a("a", 4); + new (&vov(0, 0)) V(a); + new (&vov(0, 1)) V(a); + Kokkos::parallel_for( + "AllocatesInParallel]For", + Kokkos::RangePolicy(0, 1), + KOKKOS_LAMBDA(int) { + V b("b", 5); + new (&vov(1, 0)) V(b); + }); + }), + "allocating \"b\" within parallel region \"AllocatesInParallel]For\""); + } + Kokkos::finalize(); +} + From a5b4987f0fb70c9accb1024bb7e052345a377359 Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Tue, 6 Aug 2024 09:57:00 -0400 Subject: [PATCH 2/9] Remove trailing empty line --- tests/vov-bug-finder/test_view_of_views_bug_finder.cpp | 1 - 1 file changed, 1 deletion(-) 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 98380ce90..e988830dc 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 @@ -99,4 +99,3 @@ TEST(ViewOfViews, find_bugs) { } Kokkos::finalize(); } - From 63c2d2ea023b87e2a882f33b5eee087a7153286e Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Tue, 6 Aug 2024 14:34:53 -0400 Subject: [PATCH 3/9] Fix typo and workaround lambda support in NVCC --- .../test_view_of_views_bug_finder.cpp | 72 ++++++++++--------- 1 file changed, 40 insertions(+), 32 deletions(-) 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 e988830dc..4314b8df2 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 @@ -17,7 +17,44 @@ #include "Kokkos_Core.hpp" #include "gtest/gtest.h" -// TODO intialixe in main and split unit tests +void test_no_throw_placement_new_in_parallel_for() { + ASSERT_NO_THROW(({ + using V = Kokkos::View; + Kokkos::View vov( + Kokkos::view_alloc("vov", Kokkos::WithoutInitializing), 2, 3); + V a("a", 4); + V b("b", 5); + Kokkos::parallel_for( + "Fine", Kokkos::RangePolicy(0, 1), + KOKKOS_LAMBDA(int) { + new (&vov(0, 0)) V(a); + new (&vov(0, 1)) V(a); + new (&vov(1, 0)) V(b); + }); + })); +} + +void test_death_allocation_in_parallel_for() { + ASSERT_DEATH( + ({ + using V = Kokkos::View; + Kokkos::View vov( + Kokkos::view_alloc("vov", Kokkos::WithoutInitializing), 2, 3); + V a("a", 4); + new (&vov(0, 0)) V(a); + new (&vov(0, 1)) V(a); + Kokkos::parallel_for( + "AllocatesInParallel]For", + Kokkos::RangePolicy(0, 1), + KOKKOS_LAMBDA(int) { + V b("b", 5); + new (&vov(1, 0)) V(b); + }); + }), + "allocating \"b\" within parallel region \"AllocatesInParallel]For\""); +} + +// TODO intialize in main and split unit tests TEST(ViewOfViews, find_bugs) { Kokkos::initialize(); { @@ -64,38 +101,9 @@ TEST(ViewOfViews, find_bugs) { }), "view of views \"vo]v\" not properly cleared"); - ASSERT_NO_THROW(({ - using V = Kokkos::View; - Kokkos::View vov( - Kokkos::view_alloc("vov", Kokkos::WithoutInitializing), 2, 3); - V a("a", 4); - V b("b", 5); - Kokkos::parallel_for( - "Fine", Kokkos::RangePolicy(0, 1), - KOKKOS_LAMBDA(int) { - new (&vov(0, 0)) V(a); - new (&vov(0, 1)) V(a); - new (&vov(1, 0)) V(b); - }); - })); + test_no_throw_placement_new_in_parallel_for(); - ASSERT_DEATH( - ({ - using V = Kokkos::View; - Kokkos::View vov( - Kokkos::view_alloc("vov", Kokkos::WithoutInitializing), 2, 3); - V a("a", 4); - new (&vov(0, 0)) V(a); - new (&vov(0, 1)) V(a); - Kokkos::parallel_for( - "AllocatesInParallel]For", - Kokkos::RangePolicy(0, 1), - KOKKOS_LAMBDA(int) { - V b("b", 5); - new (&vov(1, 0)) V(b); - }); - }), - "allocating \"b\" within parallel region \"AllocatesInParallel]For\""); + test_death_allocation_in_parallel_for(); } Kokkos::finalize(); } From 9e7a2d248f2bb8eecac7bd9463324cd034a0b0fa Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Tue, 6 Aug 2024 17:49:33 -0400 Subject: [PATCH 4/9] 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(); } From a8372b34e34ae0d9b3d92c0f7b01f3303cccafbf Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Tue, 6 Aug 2024 17:57:00 -0400 Subject: [PATCH 5/9] Fixup Threads backend does not label scratch pad allocs like other host backends --- debugging/vov-bug-finder/kp_view_of_views_bug_finder.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 375fc06bd..2a395d6dc 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 @@ -61,7 +61,8 @@ bool ignore_fence(std::string_view s) { 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); + s.rfind("::scratch_mem") == s.length() - 13) || + (s == "Kokkos::thread_scratch"); } std::optional get_substr(std::string const &str, From 497908dccfd6e209f541b5832e5e8c9c51926043 Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Tue, 6 Aug 2024 18:04:19 -0400 Subject: [PATCH 6/9] Drop verbose option --- .../kp_view_of_views_bug_finder.cpp | 43 +++---------------- 1 file changed, 6 insertions(+), 37 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 2a395d6dc..c4c544888 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 @@ -27,7 +27,6 @@ namespace { -bool verbose = false; bool abort_on_error = true; class { @@ -83,7 +82,7 @@ extern "C" void kokkosp_request_tool_settings( } extern "C" void kokkosp_begin_parallel_for(char const *kernelName, - uint32_t deviceID, + uint32_t /*deviceID*/, uint64_t *kernelID) { std::lock_guard lock(current.mutex); if (!current.is_empty()) { @@ -97,24 +96,16 @@ extern "C" void kokkosp_begin_parallel_for(char const *kernelName, } } *kernelID = current.push(kernelName); - - if (verbose) { - std::cout << "begin kernel " << *kernelID << " " << kernelName - << " on device " << deviceID << '\n'; - } } extern "C" void kokkosp_end_parallel_for(uint64_t kernelID) { std::lock_guard lock(current.mutex); current.pop(kernelID); - - if (verbose) { - std::cout << "end kernel " << kernelID << '\n'; - } } -extern "C" void kokkosp_begin_fence(char const *fenceName, uint32_t deviceID, - uint64_t *fenceID) { +extern "C" void kokkosp_begin_fence(char const *fenceName, + uint32_t /*deviceID*/, + uint64_t * /*fenceID*/) { std::lock_guard lock(current.mutex); if (!current.is_empty() && !ignore_fence(fenceName)) { if (auto lbl = @@ -127,22 +118,10 @@ extern "C" void kokkosp_begin_fence(char const *fenceName, uint32_t deviceID, } } } - *fenceID = -1; - - if (verbose) { - std::cout << "begin fence " << *fenceID << " " << fenceName << " on device " - << deviceID << '\n'; - } -} - -extern "C" void kokkosp_end_fence(uint64_t fenceID) { - if (verbose) { - std::cout << "end fence " << fenceID << '\n'; - } } extern "C" void kokkosp_allocate_data(SpaceHandle handle, const char *name, - void *ptr, uint64_t size) { + void * /*ptr*/, uint64_t /*size*/) { std::lock_guard lock(current.mutex); if (!current.is_empty() && !ignore_alloc(name)) { std::cerr << "allocating \"" << name << "\" within parallel region \"" @@ -151,15 +130,10 @@ extern "C" void kokkosp_allocate_data(SpaceHandle handle, const char *name, std::abort(); } } - - if (verbose) { - std::cout << "alloc (" << handle.name << ") " << name << " pointer " << ptr - << "size " << size << '\n'; - } } extern "C" void kokkosp_deallocate_data(SpaceHandle handle, const char *name, - void *ptr, uint64_t size) { + void * /*ptr*/, uint64_t /*size*/) { std::lock_guard lock(current.mutex); if (!current.is_empty() && !ignore_alloc(name)) { std::cerr << "deallocating \"" << name << "\" within parallel region \"" @@ -168,9 +142,4 @@ extern "C" void kokkosp_deallocate_data(SpaceHandle handle, const char *name, std::abort(); } } - - if (verbose) { - std::cout << "dealloc (" << handle.name << ") " << name << " pointer " - << ptr << "size " << size << '\n'; - } } From d511c6b6161d6f2bd9760bf15335f09ac6bf39c4 Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Tue, 6 Aug 2024 18:15:29 -0400 Subject: [PATCH 7/9] Enable linking against the tool --- .../kp_view_of_views_bug_finder.cpp | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 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 c4c544888..d8ba1f9c4 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 @@ -74,16 +74,14 @@ std::optional get_substr(std::string const &str, return std::nullopt; } -} // namespace - -extern "C" void kokkosp_request_tool_settings( - const uint32_t, Kokkos_Tools_ToolSettings *settings) { +void vov_bug_finder_request_tool_settings(const uint32_t, + Kokkos_Tools_ToolSettings *settings) { settings->requires_global_fencing = false; } -extern "C" void kokkosp_begin_parallel_for(char const *kernelName, - uint32_t /*deviceID*/, - uint64_t *kernelID) { +void vov_bug_finder_begin_parallel_for(char const *kernelName, + uint32_t /*deviceID*/, + uint64_t *kernelID) { std::lock_guard lock(current.mutex); if (!current.is_empty()) { if (auto lbl = @@ -98,14 +96,13 @@ extern "C" void kokkosp_begin_parallel_for(char const *kernelName, *kernelID = current.push(kernelName); } -extern "C" void kokkosp_end_parallel_for(uint64_t kernelID) { +void vov_bug_finder_end_parallel_for(uint64_t kernelID) { std::lock_guard lock(current.mutex); current.pop(kernelID); } -extern "C" void kokkosp_begin_fence(char const *fenceName, - uint32_t /*deviceID*/, - uint64_t * /*fenceID*/) { +void vov_bug_finder_begin_fence(char const *fenceName, uint32_t /*deviceID*/, + uint64_t * /*fenceID*/) { std::lock_guard lock(current.mutex); if (!current.is_empty() && !ignore_fence(fenceName)) { if (auto lbl = @@ -120,8 +117,8 @@ extern "C" void kokkosp_begin_fence(char const *fenceName, } } -extern "C" void kokkosp_allocate_data(SpaceHandle handle, const char *name, - void * /*ptr*/, uint64_t /*size*/) { +void vov_bug_finder_allocate_data(SpaceHandle handle, char const *name, + void const * /*ptr*/, uint64_t /*size*/) { std::lock_guard lock(current.mutex); if (!current.is_empty() && !ignore_alloc(name)) { std::cerr << "allocating \"" << name << "\" within parallel region \"" @@ -132,8 +129,8 @@ 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*/) { +void vov_bug_finder_deallocate_data(SpaceHandle handle, char const *name, + void const * /*ptr*/, uint64_t /*size*/) { std::lock_guard lock(current.mutex); if (!current.is_empty() && !ignore_alloc(name)) { std::cerr << "deallocating \"" << name << "\" within parallel region \"" @@ -143,3 +140,14 @@ extern "C" void kokkosp_deallocate_data(SpaceHandle handle, const char *name, } } } + +} // namespace + +extern "C" { +EXPOSE_TOOL_SETTINGS(vov_bug_finder_request_tool_settings) +EXPOSE_BEGIN_PARALLEL_FOR(vov_bug_finder_begin_parallel_for) +EXPOSE_END_PARALLEL_FOR(vov_bug_finder_end_parallel_for) +EXPOSE_BEGIN_FENCE(vov_bug_finder_begin_fence) +EXPOSE_ALLOCATE(vov_bug_finder_allocate_data) +EXPOSE_DEALLOCATE(vov_bug_finder_deallocate_data) +} From 4ab43a249e0d4c1dbb51cca52ce1bbb0cd1dd322 Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Tue, 6 Aug 2024 18:33:47 -0400 Subject: [PATCH 8/9] Use Christians big hammer --- debugging/vov-bug-finder/kp_view_of_views_bug_finder.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 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 d8ba1f9c4..34db33e36 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 @@ -57,12 +57,7 @@ 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) || - (s == "Kokkos::thread_scratch"); -} +bool ignore_alloc(std::string_view s) { return (s.find("Kokkos::") == 0); } std::optional get_substr(std::string const &str, std::string_view prefix, From 2808025ea5490143d521af6371b54ec9981790c9 Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Tue, 6 Aug 2024 18:35:30 -0400 Subject: [PATCH 9/9] Avoid unused parameter warning --- debugging/vov-bug-finder/kp_view_of_views_bug_finder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 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 34db33e36..fb04300c4 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 @@ -112,7 +112,7 @@ void vov_bug_finder_begin_fence(char const *fenceName, uint32_t /*deviceID*/, } } -void vov_bug_finder_allocate_data(SpaceHandle handle, char const *name, +void vov_bug_finder_allocate_data(SpaceHandle /*handle*/, char const *name, void const * /*ptr*/, uint64_t /*size*/) { std::lock_guard lock(current.mutex); if (!current.is_empty() && !ignore_alloc(name)) { @@ -124,7 +124,7 @@ void vov_bug_finder_allocate_data(SpaceHandle handle, char const *name, } } -void vov_bug_finder_deallocate_data(SpaceHandle handle, char const *name, +void vov_bug_finder_deallocate_data(SpaceHandle /*handle*/, char const *name, void const * /*ptr*/, uint64_t /*size*/) { std::lock_guard lock(current.mutex); if (!current.is_empty() && !ignore_alloc(name)) {