Skip to content

Commit

Permalink
#582: Implement a compositional model of object load prediction
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilMiller committed Jul 20, 2020
1 parent 60d68e4 commit 63cae4f
Show file tree
Hide file tree
Showing 12 changed files with 504 additions and 50 deletions.
3 changes: 2 additions & 1 deletion src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "vt/utils/memory/memory_usage.h"
#include "vt/vrt/collection/balance/model/load_model.h"
#include "vt/vrt/collection/balance/model/naive_persistence.h"
#include "vt/vrt/collection/balance/model/raw_data.h"

namespace vt { namespace vrt { namespace collection { namespace balance {

Expand Down Expand Up @@ -148,7 +149,7 @@ LBManager::makeLB(MsgSharedPtr<StartLBMsg> msg) {
EpochType migrate_epoch = theTerm()->makeEpochCollective("LBManager::migrate_epoch");

if (model_ == nullptr)
setLoadModel(std::make_unique<balance::NaivePersistence>());
setLoadModel(std::make_unique<balance::NaivePersistence>(new balance::RawData));

theMsg()->pushEpoch(model_epoch);
model_->updateLoads(phase);
Expand Down
80 changes: 80 additions & 0 deletions src/vt/vrt/collection/balance/model/comm_overhead.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
//@HEADER
// *****************************************************************************
//
// comm_overhead.cc
// DARMA Toolkit v. 1.0.0
// DARMA/vt => Virtual Transport
//
// Copyright 2019 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 "vt/vrt/collection/balance/model/comm_overhead.h"

namespace vt { namespace vrt { namespace collection { namespace balance {

CommOverhead::CommOverhead(balance::LoadModel *base)
: ComposedModel(base)
{
}

void CommOverhead::setLoads(std::vector<LoadMapType> const* proc_load,
std::vector<SubphaseLoadMapType> const* proc_subphase_load,
std::vector<CommMapType> const* proc_comm) {
proc_comm_ = proc_comm;
ComposedModel::setLoads(proc_load, proc_subphase_load, proc_comm);
}

TimeType CommOverhead::getWork(ElementIDType object, PhaseOffset offset)
{
auto work = ComposedModel::getWork(object, offset);

vtAbort("Not fully implemented yet");
#if 0
// Add a bit of overhead for each off-node received message per object
for (auto &&comm : *comms_) {
auto obj = loads_.find(comm.first.toObj());
if (obj != loads_.end())
work += 0.001 * comm.second.messages;
}
#endif

return work;
}


}}}}
65 changes: 65 additions & 0 deletions src/vt/vrt/collection/balance/model/comm_overhead.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
//@HEADER
// *****************************************************************************
//
// comm_overhead.h
// DARMA Toolkit v. 1.0.0
// DARMA/vt => Virtual Transport
//
// Copyright 2019 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
*/

#if !defined INCLUDED_VRT_COLLECTION_BALANCE_COMM_OVERHEAD_H
#define INCLUDED_VRT_COLLECTION_BALANCE_COMM_OVERHEAD_H

#include "vt/vrt/collection/balance/model/composed_model.h"
#include <unordered_map>

namespace vt { namespace vrt { namespace collection { namespace balance {

struct CommOverhead : public ComposedModel {
CommOverhead(balance::LoadModel *base);
void setLoads(std::vector<LoadMapType> const* proc_load,
std::vector<SubphaseLoadMapType> const* proc_subphase_load,
std::vector<CommMapType> const* proc_comm) override;
TimeType getWork(ElementIDType object, PhaseOffset when) override;

std::vector<CommMapType> const* proc_comm_;
}; // class CommOverhead

}}}} // end namespace

#endif
75 changes: 75 additions & 0 deletions src/vt/vrt/collection/balance/model/composed_model.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
//@HEADER
// *****************************************************************************
//
// composed_model.cc
// DARMA Toolkit v. 1.0.0
// DARMA/vt => Virtual Transport
//
// Copyright 2019 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 "vt/vrt/collection/balance/model/composed_model.h"

namespace vt { namespace vrt { namespace collection { namespace balance {

void ComposedModel::setLoads(std::vector<LoadMapType> const* proc_load,
std::vector<SubphaseLoadMapType> const* proc_subphase_load,
std::vector<CommMapType> const* proc_comm) {
base_.setLoads(proc_load, proc_subphase_load, proc_comm);
}

void ComposedModel::updateLoads(PhaseType last_completed_phase) {
base_.updateLoads(last_completed_phase);
}

TimeType ComposedModel::getWork(ElementIDType object, PhaseOffset when) {
return base_.getWork(object, when);
}

ObjectIterator ComposedModel::begin() {
return base_.begin();
}

ObjectIterator ComposedModel::end() {
return base_.end();
}

int ComposedModel::getNumObjects() {
return base_.getNumObjects();
}

}}}}
78 changes: 78 additions & 0 deletions src/vt/vrt/collection/balance/model/composed_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
//@HEADER
// *****************************************************************************
//
// composed_model.h
// DARMA Toolkit v. 1.0.0
// DARMA/vt => Virtual Transport
//
// Copyright 2019 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
*/

#if !defined INCLUDED_VRT_COLLECTION_BALANCE_COMPOSED_MODEL_H
#define INCLUDED_VRT_COLLECTION_BALANCE_COMPOSED_MODEL_H

#include "vt/config.h"
#include "vt/vrt/collection/balance/model/load_model.h"

namespace vt { namespace vrt { namespace collection { namespace balance {

class ComposedModel : public LoadModel
{
public:
// \param[in] base must not be null
ComposedModel(LoadModel *base) : base_(*base) {}

void setLoads(std::vector<LoadMapType> const* proc_load,
std::vector<SubphaseLoadMapType> const* proc_subphase_load,
std::vector<CommMapType> const* proc_comm) override;

void updateLoads(PhaseType last_completed_phase) override;

TimeType getWork(ElementIDType object, PhaseOffset when) override;

ObjectIterator begin() override;
ObjectIterator end() override;

int getNumObjects() override;

private:
LoadModel &base_;
}; // class ComposedModel

}}}} // namespaces

#endif
28 changes: 9 additions & 19 deletions src/vt/vrt/collection/balance/model/load_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,18 @@ class ObjectIterator {
class LoadModel
{
public:
LoadModel() {}
LoadModel() = default;
virtual ~LoadModel() = default;

/**
* \internal \brief Initialize the model instance with pointers to the measured load data
*
* This would typically be called by LBManager when the user has
* passed a new model instance for a collection
*/
void setLoads(std::vector<LoadMapType> const* proc_load,
std::vector<SubphaseLoadMapType> const* proc_subphase_load,
std::vector<CommMapType> const* proc_comm)
{
proc_load_ = proc_load;
proc_subphase_load_ = proc_subphase_load;
proc_comm_ = proc_comm;
}
virtual void setLoads(std::vector<LoadMapType> const* proc_load,
std::vector<SubphaseLoadMapType> const* proc_subphase_load,
std::vector<CommMapType> const* proc_comm) = 0;

/**
* \brief Signals that load data for a new phase is available
Expand All @@ -115,7 +111,7 @@ class LoadModel
* an epoch that can be used for global communication in advance of
* any calls to getWork()
*/
virtual void updateLoads(PhaseType last_completed_phase) { }
virtual void updateLoads(PhaseType last_completed_phase) = 0;

/**
* \brief Provide an estimate of the given object's load during a specified interval
Expand All @@ -128,16 +124,10 @@ class LoadModel
virtual TimeType getWork(ElementIDType object, PhaseOffset when) = 0;

// Object enumeration, to abstract away access to the underlying structures from ProcStats
ObjectIterator begin() { return ObjectIterator(proc_load_->back().begin()); }
ObjectIterator end() { return ObjectIterator(proc_load_->back().end()); }
virtual ObjectIterator begin() = 0;
virtual ObjectIterator end() = 0;

int getNumObjects() { return end() - begin(); }

protected:
// Observer pointers to the underlying data. In operation, these would be owned by ProcStats
std::vector<LoadMapType> const* proc_load_;
std::vector<SubphaseLoadMapType> const* proc_subphase_load_;
std::vector<CommMapType> const* proc_comm_;
virtual int getNumObjects() = 0;
}; // class LoadModel

}}}} // namespaces
Expand Down
Loading

0 comments on commit 63cae4f

Please sign in to comment.