diff --git a/profiling/space-time-stack/kp_space_time_stack.cpp b/profiling/space-time-stack/kp_space_time_stack.cpp index ead4f57f5..da377f92e 100644 --- a/profiling/space-time-stack/kp_space_time_stack.cpp +++ b/profiling/space-time-stack/kp_space_time_stack.cpp @@ -954,5 +954,7 @@ EXPOSE_BEGIN_PARALLEL_SCAN(impl::kokkosp_begin_parallel_scan) EXPOSE_END_PARALLEL_SCAN(impl::kokkosp_end_parallel_scan) EXPOSE_BEGIN_PARALLEL_REDUCE(impl::kokkosp_begin_parallel_reduce) EXPOSE_END_PARALLEL_REDUCE(impl::kokkosp_end_parallel_reduce) +EXPOSE_BEGIN_DEEP_COPY(impl::kokkosp_begin_deep_copy) +EXPOSE_END_DEEP_COPY(impl::kokkosp_end_deep_copy) } // extern "C" diff --git a/tests/space-time-stack/CMakeLists.txt b/tests/space-time-stack/CMakeLists.txt index e16b0448c..b835008f7 100644 --- a/tests/space-time-stack/CMakeLists.txt +++ b/tests/space-time-stack/CMakeLists.txt @@ -3,3 +3,9 @@ kp_add_executable_and_test( SOURCE_FILE test_demangling.cpp KOKKOS_TOOLS_LIBS kp_space_time_stack ) + +kp_add_executable_and_test( + TARGET_NAME test_space_time_stack_deep_copy + SOURCE_FILE test_deep_copy.cpp + KOKKOS_TOOLS_LIBS kp_space_time_stack +) \ No newline at end of file diff --git a/tests/space-time-stack/test_deep_copy.cpp b/tests/space-time-stack/test_deep_copy.cpp new file mode 100644 index 000000000..f8989d433 --- /dev/null +++ b/tests/space-time-stack/test_deep_copy.cpp @@ -0,0 +1,64 @@ +#include +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "Kokkos_Core.hpp" + +struct Tester { + struct TagNamed {}; + struct TagUnnamed {}; + + template + explicit Tester(const execution_space& space) { + Kokkos::View a("view_a", 10); + Kokkos::View b("view_b", 10); + + Kokkos::deep_copy(a, 1.5); + Kokkos::deep_copy(space, b, 2.0); + Kokkos::deep_copy(space, b, a); + } +}; + +static const std::vector matchers{ + // copy of scalar into view_a + "[0-9.e]+ sec [0-9.]+% [0-9.]+% 0.0% ------ 1 \"view_a\"=\"Scalar\" " + "\\([A-Z]+->[A-Z]+\\) \\[copy\\]", + // copy of scalar into view_b, execution space overload which apparently + // reports (none) for the source instead of Scalar + "[0-9.e]+ sec [0-9.]+% [0-9.]+% 0.0% ------ 1 \"view_b\"=\".*\" " + "\\([A-Z]+->[A-Z]+\\) \\[copy\\]", + // copy of view_a into view_b + "[0-9.e]+ sec [0-9.]+% [0-9.]+% 0.0% ------ 1 \"view_b\"=\"view_a\" " + "\\([A-Z]+->[A-Z]+\\) \\[copy\\]", +}; + +/** + * @test This test checks that the tool outputs deep_copy statistics. + */ +TEST(SpaceTimeStackTest, deep_copy) { + //! Initialize @c Kokkos. + Kokkos::initialize(); + + //! Redirect output for later analysis. + std::cout.flush(); + std::ostringstream output; + std::streambuf* coutbuf = std::cout.rdbuf(output.rdbuf()); + + //! Run tests. @todo Replace this with Google Test. + Tester tester(Kokkos::DefaultExecutionSpace{}); + + //! Finalize @c Kokkos. + Kokkos::finalize(); + + //! Restore output buffer. + std::cout.flush(); + std::cout.rdbuf(coutbuf); + std::cout << output.str() << std::endl; + + //! Analyze test output. + for (const auto& matcher : matchers) { + EXPECT_THAT(output.str(), ::testing::ContainsRegex(matcher)); + } +}