Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1838: add WeightedCommunicationVolume load model #1888

Merged
merged 15 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/vt/vrt/collection/balance/model/composed_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ ComposedModel::getModeledLoad(ElementIDStruct object, PhaseOffset when) const {
return base_->getModeledLoad(object, when);
}

TimeType
ComposedModel::getModeledComm(ElementIDStruct object, PhaseOffset when) const {
return base_->getModeledComm(object, when);
}

bool ComposedModel::hasRawLoad() const {
return base_->hasRawLoad();
}
Expand Down
1 change: 1 addition & 0 deletions src/vt/vrt/collection/balance/model/composed_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class ComposedModel : public LoadModel
void updateLoads(PhaseType last_completed_phase) override;

TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;
TimeType getModeledComm(ElementIDStruct object, PhaseOffset when) const override;
bool hasRawLoad() const override;
TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) const override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) const override;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
//@HEADER
// *****************************************************************************
//
// weighted_communication_volume.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 "vt/vrt/collection/balance/model/weighted_communication_volume.h"
#include "vt/vrt/collection/balance/model/composed_model.h"

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

TimeType WeightedCommunicationVolume::getModeledLoad(
ElementIDStruct object, PhaseOffset when
) const {
return alpha_ * ComposedModel::getModeledLoad(object, when) +
beta_ * ComposedModel::getModeledComm(object, when) + gamma_;
}

}}}} // namespace vt::vrt::collection::balance
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
//@HEADER
// *****************************************************************************
//
// weighted_communication_volume.h
// 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
*/

#if !defined INCLUDED_VT_VRT_COLLECTION_BALANCE_MODEL_WEIGHTED_COMMUNICATION_VOLUME_H
#define INCLUDED_VT_VRT_COLLECTION_BALANCE_MODEL_WEIGHTED_COMMUNICATION_VOLUME_H

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

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

/**
* \brief Models work as an affine combination of load and communication.
*/
class WeightedCommunicationVolume : public ComposedModel {
public:
/**
* \param[in] base underlying source of object work loads
* \param[in] alpha load part coefficient
* \param[in] beta communication part coefficient
* \param[in] gamma unspecified constant cost
*/
WeightedCommunicationVolume(
std::shared_ptr<LoadModel> base,
double alpha = 1.0, double beta = 0.0, double gamma = 0.0)
: ComposedModel(base),
alpha_(alpha),
beta_(beta),
gamma_(gamma) { }

TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;

private:
double alpha_;
double beta_;
double gamma_;
};

}}}} // namespace vt::vrt::collection::balance

#endif
6 changes: 3 additions & 3 deletions src/vt/vrt/collection/balance/model/weighted_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct WeightedMessages : public ComposedModel {
*/
explicit WeightedMessages(
std::shared_ptr<balance::LoadModel> base,
TimeType in_per_msg_weight, TimeType in_per_byte_weight
TimeType in_per_msg_weight = 0.0, TimeType in_per_byte_weight = 1.0
) : ComposedModel(base),
per_msg_weight_(in_per_msg_weight),
per_byte_weight_(in_per_byte_weight) { }
Expand All @@ -78,8 +78,8 @@ struct WeightedMessages : public ComposedModel {
// observer pointer to the underlying comm data
std::unordered_map<PhaseType, CommMapType> const* proc_comm_;

TimeType per_msg_weight_ = 0.0;
TimeType per_byte_weight_ = 1.0;
TimeType per_msg_weight_;
TimeType per_byte_weight_;
};

}}}} // namespace vt::vrt::collection::balance
Expand Down
4 changes: 2 additions & 2 deletions src/vt/vrt/collection/balance/temperedlb/temperedlb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ void TemperedLB::doLBStages(TimeType start_imb) {
cur_objs_.clear();
for (auto obj : *load_model_) {
if (obj.isMigratable()) {
cur_objs_[obj] = getModeledWork(obj);
cur_objs_[obj] = getModeledValue(obj);
}
}
this_new_load_ = this_load;
Expand Down Expand Up @@ -1361,7 +1361,7 @@ void TemperedLB::migrate() {
vtAssertExpr(false);
}

TimeType TemperedLB::getModeledWork(const elm::ElementIDStruct& obj) {
TimeType TemperedLB::getModeledValue(const elm::ElementIDStruct& obj) {
return load_model_->getModeledLoad(
obj, {balance::PhaseOffset::NEXT_PHASE, balance::PhaseOffset::WHOLE_PHASE}
);
Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/temperedlb/temperedlb.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct TemperedLB : BaseLB {
ElementLoadType::iterator selectObject(
LoadType size, ElementLoadType& load, std::set<ObjIDType> const& available
);
virtual TimeType getModeledWork(const elm::ElementIDStruct& obj);
virtual TimeType getModeledValue(const elm::ElementIDStruct& obj);

void lazyMigrateObjsTo(EpochType epoch, NodeType node, ObjsType const& objs);
void inLazyMigrations(balance::LazyMigrationMsg* msg);
Expand Down
18 changes: 14 additions & 4 deletions src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@

#include "vt/vrt/collection/balance/temperedwmin/temperedwmin.h"

#include "vt/vrt/collection/balance/lb_common.h"
#include "vt/configs/error/config_assert.h"
#include "vt/vrt/collection/balance/lb_invoke/lb_manager.h"
#include "vt/vrt/collection/balance/model/load_model.h"
#include "vt/vrt/collection/balance/model/weighted_communication_volume.h"

namespace vt { namespace vrt { namespace collection { namespace lb {

Expand Down Expand Up @@ -94,14 +96,22 @@ void TemperedWMin::inputParams(balance::SpecEntry* spec) {
"TemperedWMin::inputParams: alpha={}, beta={}, gamma={}\n",
alpha_, beta_, gamma_
);

total_work_model_ = std::make_unique<balance::WeightedCommunicationVolume>(
cz4rs marked this conversation as resolved.
Show resolved Hide resolved
theLBManager()->getLoadModel(), alpha_, beta_, gamma_
);
load_model_ptr = theLBManager()->getLoadModel().get();
}

TimeType TemperedWMin::getModeledWork(const elm::ElementIDStruct& obj) {
TimeType TemperedWMin::getModeledValue(const elm::ElementIDStruct& obj) {
vtAssert(
theLBManager()->getLoadModel().get() == load_model_ptr,
"Load model must not change"
);
balance::PhaseOffset when =
{balance::PhaseOffset::NEXT_PHASE, balance::PhaseOffset::WHOLE_PHASE};

return alpha_ * load_model_->getModeledLoad(obj, when) +
beta_ * load_model_->getModeledComm(obj, when) + gamma_;
return total_work_model_->getModeledLoad(obj, when);
}

}}}} // namespace vt::vrt::collection::lb
8 changes: 7 additions & 1 deletion src/vt/vrt/collection/balance/temperedwmin/temperedwmin.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
#if !defined INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDWMIN_TEMPEREDWMIN_H
#define INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDWMIN_TEMPEREDWMIN_H

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

#include <memory>

namespace vt { namespace vrt { namespace collection { namespace lb {

struct TemperedWMin : TemperedLB {
Expand All @@ -61,9 +64,12 @@ struct TemperedWMin : TemperedLB {
void inputParams(balance::SpecEntry* spec) override;

protected:
TimeType getModeledWork(const elm::ElementIDStruct& obj) override;
TimeType getModeledValue(const elm::ElementIDStruct& obj) override;

private:
std::unique_ptr<balance::LoadModel> total_work_model_ = nullptr;
balance::LoadModel* load_model_ptr = nullptr;

double alpha_ = 1.0;
double beta_ = 0.0;
double gamma_ = 0.0;
Expand Down
Loading