Skip to content

Commit

Permalink
#2036: Tests: Remove duplication in collection_local_send perf tests …
Browse files Browse the repository at this point in the history
…by using updated macros in a single file
  • Loading branch information
JacobDomagala committed Mar 23, 2023
1 parent 47ac068 commit 6f715fb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 34 deletions.
34 changes: 31 additions & 3 deletions tests/perf/collection_local_send.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeObj>(this);
preallocate_ = preallocate;

auto range = vt::Index1D(8);
col_proxy = vt::makeCollection<TestCol>("test")
Expand All @@ -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<TestCol::ColMsg>());
}

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();

Expand All @@ -93,7 +108,7 @@ struct NodeObj {

void perfRunBenchmark() {
for (int i = 0; i < num_iters; i++) {
auto m = makeMessage<TestCol::ColMsg>();
auto m = preallocate_ ? msgs[i] : makeMessage<TestCol::ColMsg>();
col_proxy[0].template sendMsg<&TestCol::han>(m);
vt::theSched()->runSchedulerOnceImpl();
}
Expand All @@ -107,18 +122,31 @@ struct NodeObj {
vt::CollectionProxy<TestCol> col_proxy;
int reduce_counter_ = -1;
int i = 0;
bool preallocate_ = false;
};

VT_PERF_TEST(MyTest, test_collection_local_send) {
auto grp_proxy = vt::theObjGroup()->makeCollective<NodeObj>(
"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<NodeObj>(
"test_collection_local_send_preallocate", this
);

grp_proxy[my_node_].invoke<&NodeObj::initialize>(true);

if (theContext()->getNode() == 0) {
grp_proxy[my_node_].send<MyMsg, &NodeObj::perfMakeRunnablePreAllocate>();
}
}

VT_PERF_TEST_MAIN()
16 changes: 9 additions & 7 deletions tests/perf/common/test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -66,6 +67,7 @@ struct TestResultHolder {

struct PerfTestHarness : TestHarnessBase {
using TestName = std::string;
using TestResult = std::pair<TestName, TimeType>;

using FinalTestResult = std::pair<TestName, TestResultHolder<TimeType>>;
using TestResults = std::vector<std::vector<TestResult>>;
Expand All @@ -78,8 +80,8 @@ struct PerfTestHarness : TestHarnessBase {
using CombinedMemoryUse =
std::unordered_map<NodeType, std::vector<TestResultHolder<std::size_t>>>;

void SetUp() override;
void TearDown() override;
virtual void SetUp();
virtual void TearDown();

/**
* \brief Initialize internal variables and parse args
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand Down
22 changes: 10 additions & 12 deletions tests/perf/common/test_harness_base.h
Original file line number Diff line number Diff line change
@@ -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 <cstdint>
#include <string>
// #include <cstdint>
// #include <string>

namespace vt::tests::perf::common {

struct TestHarnessBase {
using TestName = std::string;
using TestResult = std::pair<TestName, TimeType>;

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;
};
Expand Down
35 changes: 23 additions & 12 deletions tests/perf/common/test_harness_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,51 @@ struct PerfTestRegistry{
inline static std::vector<TestHarnessBase*> 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<PerfTestHarness*>(test_base); \
test->Initialize(argc, argv); \
auto const num_runs = test->GetNumRuns(); \
StopWatch timer; \
if (rank == 0) { \
fmt::print("{}RUNNING TEST:{} {} (Number of runs = {}) ...\n", \
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(); \
Expand Down

0 comments on commit 6f715fb

Please sign in to comment.