From 1a9b446ce502018536e2544f9a93df0963af0fd3 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Thu, 11 Aug 2022 11:22:47 -0600 Subject: [PATCH] #1930: Add new microbenchmarks --- tests/perf/make_runnable_micro.cc | 125 +++++++++++++++++++++++++++ tests/perf/ping_pong.cc | 23 +++-- tests/perf/ping_pong_am.cc | 136 ++++++++++++++++++++++++++++++ tests/perf/reduce.cc | 107 +++++++++++++++++++++++ 4 files changed, 383 insertions(+), 8 deletions(-) create mode 100644 tests/perf/make_runnable_micro.cc create mode 100644 tests/perf/ping_pong_am.cc create mode 100644 tests/perf/reduce.cc diff --git a/tests/perf/make_runnable_micro.cc b/tests/perf/make_runnable_micro.cc new file mode 100644 index 0000000000..414786cfdc --- /dev/null +++ b/tests/perf/make_runnable_micro.cc @@ -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 +#include +#include + +#include + +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 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(this); + } + + void complete() { + } + + void perfMakeRunnable(MyMsg* in_msg) { + for (int i = 0; i < num_iters; i++) { + msgs.emplace_back(makeMessage()); + } + + han = auto_registry::makeAutoHandler(); + + 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> msgs; + HandlerType han; + MyTest* test_obj_ = nullptr; + vt::objgroup::proxy::Proxy proxy_ = {}; + int reduce_counter_ = -1; + int i = 0; +}; + +VT_PERF_TEST(MyTest, test_ping_pong) { + auto grp_proxy = vt::theObjGroup()->makeCollective( + "test_reduce", this + ); + + grp_proxy[my_node_].invoke(); + + if (theContext()->getNode() == 0) { + grp_proxy[my_node_].send(); + } +} + +VT_PERF_TEST_MAIN() diff --git a/tests/perf/ping_pong.cc b/tests/perf/ping_pong.cc index 7cf2ecc253..0b7c2cf4b4 100644 --- a/tests/perf/ping_pong.cc +++ b/tests/perf/ping_pong.cc @@ -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 { @@ -101,6 +103,7 @@ struct NodeObj { .send< NodeObj::PingMsg, &NodeObj::pingPong >(); + } else { } } @@ -136,6 +139,8 @@ struct NodeObj { template <> void NodeObj::finishedPing(FinishedPingMsg* msg) { addPerfStats(max_bytes); + + theTerm()->any_epoch_state_.decrementDependency(); } VT_PERF_TEST(MyTest, test_ping_pong) { @@ -145,14 +150,16 @@ VT_PERF_TEST(MyTest, test_ping_pong) { grp_proxy[my_node_] .invoke(); - 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::pingPong>(); - } - }); + StartTimer(fmt::format("{} Bytes", min_bytes)); + + if (my_node_ == 0) { + grp_proxy[pong_node] + .send, &NodeObj::pingPong>(); + } } VT_PERF_TEST_MAIN() diff --git a/tests/perf/ping_pong_am.cc b/tests/perf/ping_pong_am.cc new file mode 100644 index 0000000000..d44e6b89a4 --- /dev/null +++ b/tests/perf/ping_pong_am.cc @@ -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 +#include +#include + +#include + +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> msgs; + +struct NodeObj; +vt::objgroup::proxy::Proxy global_proxy; +void handlerFinished(MyMsg* msg); +void handler(MyMsg* in_msg) { + //fmt::print("{} handler\n", theContext()->getNode()); + auto msg = makeMessage(); + // auto msg = msgs.back(); + // msgs.pop_back(); + theMsg()->sendMsg(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(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(); + theMsg()->sendMsg(1, msg); + } + +private: + MyTest* test_obj_ = nullptr; + vt::objgroup::proxy::Proxy 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(); + } else { + i++; + auto msg = makeMessage(); + // auto msg = msgs.back(); + // msgs.pop_back(); + theMsg()->sendMsg(1, msg); + } +} + +VT_PERF_TEST(MyTest, test_ping_pong) { + auto grp_proxy = vt::theObjGroup()->makeCollective( + "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()); + // } + + grp_proxy[my_node_].invoke(); + + if (theContext()->getNode() == 0) { + grp_proxy[my_node_].send(); + } +} + +VT_PERF_TEST_MAIN() diff --git a/tests/perf/reduce.cc b/tests/perf/reduce.cc new file mode 100644 index 0000000000..dafe0cebf7 --- /dev/null +++ b/tests/perf/reduce.cc @@ -0,0 +1,107 @@ +/* +//@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 +#include +#include + +#include + +using namespace vt; +using namespace vt::tests::perf::common; + +static constexpr int num_iters = 10; + +struct MyTest : PerfTestHarness { }; + +struct NodeObj { + struct ReduceMsg : vt::collective::ReduceNoneMsg { }; + + explicit NodeObj(MyTest* test_obj) : test_obj_(test_obj) { } + void initialize() { proxy_ = vt::theObjGroup()->getProxy(this); } + + struct MyMsg : vt::Message {}; + + void reduceComplete(ReduceMsg* msg) { + reduce_counter_++; + test_obj_->StopTimer(fmt::format("{} reduce", i)); + test_obj_->GetMemoryUsage(); + if (i < num_iters) { + i++; + auto this_node = theContext()->getNode(); + proxy_[this_node].send(); + } else if (theContext()->getNode() == 0) { + theTerm()->any_epoch_state_.decrementDependency(); + } + } + + void perfReduce(MyMsg* in_msg) { + test_obj_->StartTimer(fmt::format("{} reduce", i)); + auto cb = theCB()->makeBcast(proxy_); + auto msg = makeMessage(); + proxy_.reduce(msg.get(), cb); + } + +private: + MyTest* test_obj_ = nullptr; + vt::objgroup::proxy::Proxy proxy_ = {}; + int reduce_counter_ = -1; + int i = 0; +}; + +VT_PERF_TEST(MyTest, test_ping_pong) { + auto grp_proxy = vt::theObjGroup()->makeCollective( + "test_reduce", this + ); + + if (theContext()->getNode() == 0) { + theTerm()->any_epoch_state_.incrementDependency(); + } + + grp_proxy[my_node_].invoke(); + + using MsgType = typename NodeObj::MyMsg; + grp_proxy[my_node_].send(); +} + +VT_PERF_TEST_MAIN()