Skip to content

Commit

Permalink
#1930: Add new microbenchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander authored and cz4rs committed Dec 28, 2022
1 parent e99df0b commit b513b79
Show file tree
Hide file tree
Showing 4 changed files with 383 additions and 8 deletions.
125 changes: 125 additions & 0 deletions tests/perf/make_runnable_micro.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
//@HEADER
// *****************************************************************************
//
// reduce.cc
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 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.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact darma@sandia.gov
//
// *****************************************************************************
//@HEADER
*/
#include "common/test_harness.h"
#include <vt/collective/collective_ops.h>
#include <vt/objgroup/manager.h>
#include <vt/messaging/active.h>

#include <fmt-vt/core.h>

using namespace vt;
using namespace vt::tests::perf::common;

static constexpr int num_iters = 1000000;

struct MyTest : PerfTestHarness { };
struct MyMsg : vt::Message {};

struct NodeObj;
vt::objgroup::proxy::Proxy<NodeObj> global_proxy;

void dummyHandler(MyMsg*) {}

struct NodeObj {
struct ReduceMsg : vt::collective::ReduceNoneMsg { };

explicit NodeObj(MyTest* test_obj) : test_obj_(test_obj) { }
void initialize() {
proxy_ = global_proxy = vt::theObjGroup()->getProxy<NodeObj>(this);
}

void complete() {
}

void perfMakeRunnable(MyMsg* in_msg) {
for (int i = 0; i < num_iters; i++) {
msgs.emplace_back(makeMessage<MyMsg>());
}

han = auto_registry::makeAutoHandler<MyMsg, &dummyHandler>();

theTerm()->any_epoch_state_.incrementDependency();

test_obj_->StartTimer(fmt::format("makeRunnable {}", num_iters));
perfRunBenchmark();
test_obj_->StopTimer(fmt::format("makeRunnable {}", num_iters));

theTerm()->any_epoch_state_.decrementDependency();
}

void perfRunBenchmark() {
for (int i = 0; i < num_iters; i++) {
{
bool add_context = true;
auto r = runnable::makeRunnable(msgs[i], false, han, 0, add_context)
.withContinuation(nullptr)
.withTag(TagType{0})
.withTDEpochFromMsg(false);
r.enqueue();
}
vt::theSched()->runSchedulerOnceImpl();
}
}

private:
std::vector<MsgSharedPtr<MyMsg>> msgs;
HandlerType han;
MyTest* test_obj_ = nullptr;
vt::objgroup::proxy::Proxy<NodeObj> proxy_ = {};
int reduce_counter_ = -1;
int i = 0;
};

VT_PERF_TEST(MyTest, test_ping_pong) {
auto grp_proxy = vt::theObjGroup()->makeCollective<NodeObj>(
"test_reduce", this
);

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

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

VT_PERF_TEST_MAIN()
23 changes: 15 additions & 8 deletions tests/perf/ping_pong.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ using namespace vt::tests::perf::common;
static constexpr int64_t const min_bytes = 1;
static constexpr int64_t const max_bytes = 16777216;

static constexpr int64_t num_pings = 20;
static constexpr int64_t num_pings = 10;

static constexpr NodeType const ping_node = 0;
static constexpr NodeType const pong_node = 1;

vt::EpochType the_epoch = vt::no_epoch;

struct MyTest : PerfTestHarness { };

struct NodeObj {
Expand Down Expand Up @@ -101,6 +103,7 @@ struct NodeObj {
.send<
NodeObj::PingMsg<new_num_bytes>, &NodeObj::pingPong<new_num_bytes>
>();
} else {
}
}

Expand Down Expand Up @@ -136,6 +139,8 @@ struct NodeObj {
template <>
void NodeObj::finishedPing<max_bytes>(FinishedPingMsg<max_bytes>* msg) {
addPerfStats(max_bytes);

theTerm()->any_epoch_state_.decrementDependency();
}

VT_PERF_TEST(MyTest, test_ping_pong) {
Expand All @@ -145,14 +150,16 @@ VT_PERF_TEST(MyTest, test_ping_pong) {
grp_proxy[my_node_]
.invoke<decltype(&NodeObj::initialize), &NodeObj::initialize>();

vt::runInEpochCollective([this, grp_proxy] {
StartTimer(fmt::format("{} Bytes", min_bytes));
if (theContext()->getNode() == 0) {
theTerm()->any_epoch_state_.incrementDependency();
}

if (my_node_ == 0) {
grp_proxy[pong_node]
.send<NodeObj::PingMsg<min_bytes>, &NodeObj::pingPong<min_bytes>>();
}
});
StartTimer(fmt::format("{} Bytes", min_bytes));

if (my_node_ == 0) {
grp_proxy[pong_node]
.send<NodeObj::PingMsg<min_bytes>, &NodeObj::pingPong<min_bytes>>();
}
}

VT_PERF_TEST_MAIN()
136 changes: 136 additions & 0 deletions tests/perf/ping_pong_am.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
//@HEADER
// *****************************************************************************
//
// reduce.cc
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 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.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact darma@sandia.gov
//
// *****************************************************************************
//@HEADER
*/
#include "common/test_harness.h"
#include <vt/collective/collective_ops.h>
#include <vt/objgroup/manager.h>
#include <vt/messaging/active.h>

#include <fmt-vt/core.h>

using namespace vt;
using namespace vt::tests::perf::common;

static constexpr int num_iters = 1000;
//static constexpr int num_iters = 1000000;
static int i = 0;

struct MyTest : PerfTestHarness { };

struct MyMsg : vt::Message {};

std::vector<MsgSharedPtr<MyMsg>> msgs;

struct NodeObj;
vt::objgroup::proxy::Proxy<NodeObj> global_proxy;
void handlerFinished(MyMsg* msg);
void handler(MyMsg* in_msg) {
//fmt::print("{} handler\n", theContext()->getNode());
auto msg = makeMessage<MyMsg>();
// auto msg = msgs.back();
// msgs.pop_back();
theMsg()->sendMsg<MyMsg, &handlerFinished>(0, msg);
}

struct NodeObj {
struct ReduceMsg : vt::collective::ReduceNoneMsg { };

explicit NodeObj(MyTest* test_obj) : test_obj_(test_obj) { }
void initialize() { proxy_ = global_proxy = vt::theObjGroup()->getProxy<NodeObj>(this); }

void complete() {
fmt::print("{} complete\n", theContext()->getNode());
test_obj_->StopTimer(fmt::format("{} ping-pong", i));
if (theContext()->getNode() == 0) {
theTerm()->any_epoch_state_.decrementDependency();
}
msgs.clear();
}

void perfPingPong(MyMsg* in_msg) {
fmt::print("{} perfPingPong\n", theContext()->getNode());
test_obj_->StartTimer(fmt::format("{} ping-pong", i));
auto msg = makeMessage<MyMsg>();
theMsg()->sendMsg<MyMsg, &handler>(1, msg);
}

private:
MyTest* test_obj_ = nullptr;
vt::objgroup::proxy::Proxy<NodeObj> proxy_ = {};
int reduce_counter_ = -1;
int i = 0;
};

void handlerFinished(MyMsg* msg) {
//fmt::print("{} handlerFinished i={}\n", theContext()->getNode(), i);
if (i >= num_iters) {
global_proxy[0].invoke<decltype(&NodeObj::complete), &NodeObj::complete>();
} else {
i++;
auto msg = makeMessage<MyMsg>();
// auto msg = msgs.back();
// msgs.pop_back();
theMsg()->sendMsg<MyMsg, &handler>(1, msg);
}
}

VT_PERF_TEST(MyTest, test_ping_pong) {
auto grp_proxy = vt::theObjGroup()->makeCollective<NodeObj>(
"test_reduce", this
);

if (theContext()->getNode() == 0) {
theTerm()->any_epoch_state_.incrementDependency();
}

// for (int x = 0; x < num_iters+1; x++) {
// msgs.emplace_back(makeMessage<MyMsg>());
// }

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

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

VT_PERF_TEST_MAIN()
Loading

0 comments on commit b513b79

Please sign in to comment.