Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions profiling/space-time-stack/kp_space_time_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 6 additions & 0 deletions tests/space-time-stack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
64 changes: 64 additions & 0 deletions tests/space-time-stack/test_deep_copy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <iostream>
#include <sstream>

#include "gmock/gmock.h"
#include "gtest/gtest.h"

#include "Kokkos_Core.hpp"

struct Tester {
struct TagNamed {};
struct TagUnnamed {};

template <typename execution_space>
explicit Tester(const execution_space& space) {
Kokkos::View<double*, execution_space> a("view_a", 10);
Kokkos::View<double*, execution_space> 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<std::string> 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));
}
}