From 6f715fb64bc2518051ed7c255563f51686d6f82e Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Sat, 4 Mar 2023 20:25:27 +0100 Subject: [PATCH] #2036: Tests: Remove duplication in collection_local_send perf tests by using updated macros in a single file --- tests/perf/collection_local_send.cc | 34 +++++++++++++++++++++--- tests/perf/common/test_harness.h | 16 ++++++----- tests/perf/common/test_harness_base.h | 22 +++++++--------- tests/perf/common/test_harness_macros.h | 35 ++++++++++++++++--------- 4 files changed, 73 insertions(+), 34 deletions(-) diff --git a/tests/perf/collection_local_send.cc b/tests/perf/collection_local_send.cc index 41d1df31da..50f1fd042a 100644 --- a/tests/perf/collection_local_send.cc +++ b/tests/perf/collection_local_send.cc @@ -67,8 +67,9 @@ struct NodeObj { struct ReduceMsg : vt::collective::ReduceNoneMsg { }; explicit NodeObj(MyTest* test_obj) : test_obj_(test_obj) { } - void initialize() { + void initialize(bool preallocate) { proxy_ = global_proxy = vt::theObjGroup()->getProxy(this); + preallocate_ = preallocate; auto range = vt::Index1D(8); col_proxy = vt::makeCollection("test") @@ -81,6 +82,20 @@ struct NodeObj { void complete() { } + void perfMakeRunnablePreAllocate(MyMsg* in_msg) { + for (int i = 0; i < num_iters; i++) { + msgs.emplace_back(makeMessage()); + } + + theTerm()->disableTD(); + + test_obj_->StartTimer(fmt::format("colSend {}", num_iters)); + perfRunBenchmark(); + test_obj_->StopTimer(fmt::format("colSend {}", num_iters)); + + theTerm()->enableTD(); + } + void perfMakeRunnable(MyMsg* in_msg) { theTerm()->disableTD(); @@ -93,7 +108,7 @@ struct NodeObj { void perfRunBenchmark() { for (int i = 0; i < num_iters; i++) { - auto m = makeMessage(); + auto m = preallocate_ ? msgs[i] : makeMessage(); col_proxy[0].template sendMsg<&TestCol::han>(m); vt::theSched()->runSchedulerOnceImpl(); } @@ -107,6 +122,7 @@ struct NodeObj { vt::CollectionProxy col_proxy; int reduce_counter_ = -1; int i = 0; + bool preallocate_ = false; }; VT_PERF_TEST(MyTest, test_collection_local_send) { @@ -114,11 +130,23 @@ VT_PERF_TEST(MyTest, test_collection_local_send) { "test_collection_local_send", this ); - grp_proxy[my_node_].invoke<&NodeObj::initialize>(); + grp_proxy[my_node_].invoke<&NodeObj::initialize>(false); if (theContext()->getNode() == 0) { grp_proxy[my_node_].send<&NodeObj::perfMakeRunnable>(); } } +VT_PERF_TEST(MyTest, test_collection_local_send_preallocate) { + auto grp_proxy = vt::theObjGroup()->makeCollective( + "test_collection_local_send_preallocate", this + ); + + grp_proxy[my_node_].invoke<&NodeObj::initialize>(true); + + if (theContext()->getNode() == 0) { + grp_proxy[my_node_].send(); + } +} + VT_PERF_TEST_MAIN() diff --git a/tests/perf/common/test_harness.h b/tests/perf/common/test_harness.h index a1431519ec..5504307658 100644 --- a/tests/perf/common/test_harness.h +++ b/tests/perf/common/test_harness.h @@ -44,6 +44,7 @@ #if !defined INCLUDED_PERF_COMMON_TEST_HARNESS_H #define INCLUDED_PERF_COMMON_TEST_HARNESS_H +#include "timers.h" #include "test_harness_base.h" #include "test_harness_macros.h" @@ -66,6 +67,7 @@ struct TestResultHolder { struct PerfTestHarness : TestHarnessBase { using TestName = std::string; + using TestResult = std::pair; using FinalTestResult = std::pair>; using TestResults = std::vector>; @@ -78,8 +80,8 @@ struct PerfTestHarness : TestHarnessBase { using CombinedMemoryUse = std::unordered_map>>; - void SetUp() override; - void TearDown() override; + virtual void SetUp(); + virtual void TearDown(); /** * \brief Initialize internal variables and parse args @@ -96,14 +98,14 @@ struct PerfTestHarness : TestHarnessBase { * * \return name */ - std::string GetName() const override; + std::string GetName() const; /** * \brief Get the number of runs that this test will run * * \return Number of runs */ - uint32_t GetNumRuns() const override; + uint32_t GetNumRuns() const; /** * \brief Dump the test results to stdout and CSV files. @@ -112,14 +114,14 @@ struct PerfTestHarness : TestHarnessBase { * * This is called at the end of running test suite. */ - void DumpResults() override; + void DumpResults(); /** * \brief Add a single test result (name-time pair) * * \param[in] test_result name-time pair of test result */ - void AddResult(TestResult const& test_result) override; + void AddResult(TestResult const& test_result); /** * \brief Add and start a timer with name \c name @@ -140,7 +142,7 @@ struct PerfTestHarness : TestHarnessBase { * \brief Send the tests' results to root node. * This is called after each test run. */ - void SyncResults() override; + void SyncResults(); /** * \brief Copies the test results into combined structures. diff --git a/tests/perf/common/test_harness_base.h b/tests/perf/common/test_harness_base.h index f39d522ab7..eb94085043 100644 --- a/tests/perf/common/test_harness_base.h +++ b/tests/perf/common/test_harness_base.h @@ -1,25 +1,23 @@ #if !defined INCLUDED_PERF_COMMON_TEST_HARNESS_BASE_H #define INCLUDED_PERF_COMMON_TEST_HARNESS_BASE_H -#include "timers.h" +// #include "timers.h" -#include -#include +// #include +// #include namespace vt::tests::perf::common { struct TestHarnessBase { - using TestName = std::string; - using TestResult = std::pair; - virtual void SetUp() = 0; - virtual void TearDown() = 0; - virtual std::string GetName() const = 0; - virtual uint32_t GetNumRuns() const = 0; + // virtual void SetUp() = 0; + // virtual void TearDown() = 0; + // virtual std::string GetName() const = 0; + // virtual uint32_t GetNumRuns() const = 0; virtual void TestFunc() {} - virtual void AddResult(TestResult const& test_result) = 0; - virtual void DumpResults() = 0; - virtual void SyncResults() = 0; + // virtual void AddResult(TestResult const& test_result) = 0; + // virtual void DumpResults() = 0; + // virtual void SyncResults() = 0; virtual ~TestHarnessBase() = default; }; diff --git a/tests/perf/common/test_harness_macros.h b/tests/perf/common/test_harness_macros.h index c17c71f7ce..28a15f4bd6 100644 --- a/tests/perf/common/test_harness_macros.h +++ b/tests/perf/common/test_harness_macros.h @@ -83,24 +83,32 @@ struct PerfTestRegistry{ inline static std::vector tests_ = {}; }; -#define VT_PERF_TEST(StructName, TestName) \ - struct StructName##TestName : StructName { \ - StructName##TestName() { \ - PerfTestRegistry::AddTest(this); \ - name_ = #TestName; } \ - void SetUp() override { StructName::SetUp(); } \ - void TearDown() override { StructName::TearDown(); } \ - void TestFunc() override; \ - }; \ +#define VT_PERF_TEST(StructName, TestName) \ + struct StructName##TestName : StructName { \ + StructName##TestName() { \ + name_ = #TestName; } \ + void SetUp() override { StructName::SetUp(); } \ + void TearDown() override { StructName::TearDown(); } \ + void TestFunc() override; \ + }; \ + \ + static struct StructName##TestName##_registerer_t { \ + StructName##TestName##_registerer_t() { \ + PerfTestRegistry::AddTest(new StructName##TestName());\ + } \ + } StructName##TestName##_registerer; \ void StructName##TestName::TestFunc() + #define VT_PERF_TEST_MAIN() \ int main(int argc, char** argv) { \ using namespace vt::tests::perf::common; \ MPI_Init(&argc, &argv); \ int rank; \ MPI_Comm_rank(MPI_COMM_WORLD, &rank); \ - for (const auto& test : PerfTestRegistry::GetTests()) { \ + for (const auto& test_base : PerfTestRegistry::GetTests()) { \ + auto* test = dynamic_cast(test_base); \ + test->Initialize(argc, argv); \ auto const num_runs = test->GetNumRuns(); \ StopWatch timer; \ if (rank == 0) { \ @@ -108,15 +116,18 @@ struct PerfTestRegistry{ vt::debug::bold(), vt::debug::reset(), vt::debug::reg(test->GetName()),\ vt::debug::reg(fmt::format("{}", num_runs))); \ } \ - for (uint32_t j = 1; j <= num_runs; ++j) { \ + for (uint32_t run_num = 1; run_num <= num_runs; ++run_num) { \ test->SetUp(); \ + \ timer.Start(); \ test->TestFunc(); \ PerfTestHarness::SpinScheduler(); \ test->AddResult({test->GetName(), timer.Stop()}); \ - if (j == num_runs) { \ + \ + if (run_num == num_runs) { \ test->SyncResults(); \ } \ + \ test->TearDown(); \ } \ test->DumpResults(); \