From 8024e1d7aa1ac4089ccda3c6e823cf42406fe8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Thu, 13 Oct 2022 20:24:36 +0200 Subject: [PATCH 01/14] #1659: lb: remove redundant argument --- src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc | 11 ++++------- src/vt/vrt/collection/balance/lb_invoke/lb_manager.h | 7 ++----- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc index 45a369f8c1..44f74a648e 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc @@ -215,19 +215,17 @@ void LBManager::defaultPostLBWork(ReassignmentMsg* msg) { } void -LBManager::runLB( - LBProxyType base_proxy, PhaseType phase, vt::Callback cb -) { +LBManager::runLB(PhaseType phase, vt::Callback cb) { runInEpochCollective("LBManager::runLB -> updateLoads", [=] { model_->updateLoads(phase); }); + auto base_proxy = lb_instances_["chosen"]; lb::BaseLB* strat = base_proxy.get(); - auto proxy = lb_instances_["chosen"]; if (strat->isCommAware()) { runInEpochCollective( "LBManager::runLB -> makeGraphSymmetric", - [phase, proxy] { makeGraphSymmetric(phase, proxy); } + [phase, base_proxy] { makeGraphSymmetric(phase, base_proxy); } ); } @@ -342,8 +340,7 @@ void LBManager::startLB( break; } - LBProxyType base_proxy = lb_instances_["chosen"]; - runLB(base_proxy, phase, cb); + runLB(phase, cb); } /*static*/ diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h index 04890bafc2..d319935d49 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h @@ -235,15 +235,12 @@ struct LBManager : runtime::component::Component { protected: /** * \internal - * \brief Run the load balancer + * \brief Run the currently chosen load balancer * - * \param[in] base_proxy the base proxy for the LB * \param[in] phase the phase * \param[in] cb the callback for delivering the reassignment */ - void runLB( - LBProxyType base_proxy, PhaseType phase, vt::Callback cb - ); + void runLB(PhaseType phase, vt::Callback cb); void defaultPostLBWork(ReassignmentMsg* r); From f874ccd2a8d6b9faaf5b01078ca9e02919e82269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Thu, 13 Oct 2022 20:45:45 +0200 Subject: [PATCH 02/14] #1659: clean-up LBType --- src/vt/vrt/collection/balance/lb_common.cc | 2 +- src/vt/vrt/collection/balance/lb_common.h | 2 +- src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc | 2 +- src/vt/vrt/collection/balance/lb_type.cc | 7 +++---- src/vt/vrt/collection/balance/lb_type.h | 10 +++------- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/vt/vrt/collection/balance/lb_common.cc b/src/vt/vrt/collection/balance/lb_common.cc index 039555f11a..2a52049170 100644 --- a/src/vt/vrt/collection/balance/lb_common.cc +++ b/src/vt/vrt/collection/balance/lb_common.cc @@ -152,7 +152,7 @@ nlohmann::json jsonifyPhaseStatistics(const StatisticMap &statistics) { nlohmann::json j; for (auto &entry : statistics) { - auto &name = get_lb_stat_name()[entry.first]; + auto &name = get_lb_stat_names()[entry.first]; nlohmann::json &this_stat = j[name]; for (auto &quant : entry.second) { const nlohmann::json quant_name = quant.first; diff --git a/src/vt/vrt/collection/balance/lb_common.h b/src/vt/vrt/collection/balance/lb_common.h index 46e9e8922f..13ea1ec753 100644 --- a/src/vt/vrt/collection/balance/lb_common.h +++ b/src/vt/vrt/collection/balance/lb_common.h @@ -217,7 +217,7 @@ struct hash { namespace vt { namespace vrt { namespace collection { namespace lb { -std::unordered_map& get_lb_stat_name(); +std::unordered_map& get_lb_stat_names(); }}}} /* end namespace vt::vrt::collection::lb */ diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc index 44f74a648e..c47b411e10 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc @@ -529,7 +529,7 @@ void LBManager::statsHandler(StatsMsgType* msg) { " max={:.2f}, min={:.2f}, sum={:.2f}, avg={:.2f}, var={:.2f}," " stdev={:.2f}, nproc={}, cardinality={} skewness={:.2f}, kurtosis={:.2f}," " npr={}, imb={:.2f}, num_stats={}\n", - lb::get_lb_stat_name()[stat], + lb::get_lb_stat_names()[stat], max, min, sum, avg, var, stdv, npr, car, skew, krte, npr, imb, stats.size() ); diff --git a/src/vt/vrt/collection/balance/lb_type.cc b/src/vt/vrt/collection/balance/lb_type.cc index 3238b7e64f..e856cd787b 100644 --- a/src/vt/vrt/collection/balance/lb_type.cc +++ b/src/vt/vrt/collection/balance/lb_type.cc @@ -41,7 +41,6 @@ //@HEADER */ -#include "vt/config.h" #include "vt/vrt/collection/balance/lb_common.h" #include "vt/vrt/collection/balance/lb_type.h" @@ -72,7 +71,7 @@ std::unordered_map& get_lb_names() { namespace lb { -static std::unordered_map lb_stat_name_ = { +static std::unordered_map lb_stat_names_ = { {Statistic::Rank_load_modeled, std::string{"Rank_load_modeled"}}, {Statistic::Rank_load_raw, std::string{"Rank_load_raw"}}, {Statistic::Rank_comm, std::string{"Rank_comm"}}, @@ -85,8 +84,8 @@ static std::unordered_map lb_stat_name_ = { {Statistic::EdgeRatio, std::string{"EdgeRatio"}} }; -std::unordered_map& get_lb_stat_name() { - return lb_stat_name_; +std::unordered_map& get_lb_stat_names() { + return lb_stat_names_; } } /* end namespace lb */ diff --git a/src/vt/vrt/collection/balance/lb_type.h b/src/vt/vrt/collection/balance/lb_type.h index f7d7d148fa..395e89036a 100644 --- a/src/vt/vrt/collection/balance/lb_type.h +++ b/src/vt/vrt/collection/balance/lb_type.h @@ -46,9 +46,9 @@ #include "vt/configs/features/features_defines.h" -#include #include #include +#include namespace vt { namespace vrt { namespace collection { namespace balance { @@ -67,6 +67,8 @@ enum struct LBType : int8_t { , TemperedWMin = 9 }; +std::unordered_map& get_lb_names(); + }}}} /* end namespace vt::vrt::collection::balance */ namespace std { @@ -83,10 +85,4 @@ struct hash { } /* end namespace std */ -namespace vt { namespace vrt { namespace collection { namespace balance { - -std::unordered_map& get_lb_names(); - -}}}} /* end namespace vt::vrt::collection::balance */ - #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_LB_TYPE_H*/ From 07624f26fba2930876b7df7a555a915fb601bb13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Tue, 8 Nov 2022 17:03:02 +0100 Subject: [PATCH 03/14] #1659: lb: add custom model handling to LBManager --- .../balance/lb_invoke/lb_manager.cc | 21 +++++++++++++++++++ .../collection/balance/lb_invoke/lb_manager.h | 5 +++++ .../balance/temperedwmin/temperedwmin.cc | 5 ++++- .../balance/temperedwmin/temperedwmin.h | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc index c47b411e10..07e22ddcf5 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc @@ -666,6 +666,27 @@ void LBManager::computeStatistics( lb::Statistic::Object_load_modeled, std::move(obj_load_model) )); + if (custom_model_) { + auto total_work_from_model = 0.; + std::vector obj_work_model; + for (auto elm : *custom_model_) { + auto work = custom_model_->getModeledLoad( + elm, {balance::PhaseOffset::NEXT_PHASE, balance::PhaseOffset::WHOLE_PHASE} + ); + obj_work_model.emplace_back( + LoadData{lb::Statistic::Object_load_modeled, work} + ); + total_work_from_model += work; + } + + lstats.emplace_back( + LoadData{lb::Statistic::Rank_work_modeled, total_work_from_model} + ); + lstats.emplace_back(reduceVec( + lb::Statistic::Object_work_modeled, std::move(obj_work_model) + )); + } + if (model->hasRawLoad()) { lstats.emplace_back( LoadData{lb::Statistic::Rank_load_raw, total_load_raw} diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h index d319935d49..33c5765b83 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h @@ -193,6 +193,10 @@ struct LBManager : runtime::component::Component { */ void setLoadModel(std::shared_ptr model); + void setCustomLoadModel(std::shared_ptr model) { + custom_model_ = model; + } + /** * \brief Get the system-set basic model of object load */ @@ -281,6 +285,7 @@ struct LBManager : runtime::component::Component { objgroup::proxy::Proxy proxy_; std::shared_ptr base_model_; std::shared_ptr model_; + std::shared_ptr custom_model_; std::unordered_map lb_instances_; StatisticMapType stats; TimeType total_load_from_model = 0.; diff --git a/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc b/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc index 36e954e605..39c78cde7b 100644 --- a/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc +++ b/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc @@ -97,9 +97,12 @@ void TemperedWMin::inputParams(balance::ConfigEntry* config) { alpha_, beta_, gamma_ ); - total_work_model_ = std::make_unique( + total_work_model_ = std::make_shared( theLBManager()->getLoadModel(), alpha_, beta_, gamma_ ); + theLBManager()->setCustomLoadModel(total_work_model_); + + // for later assertion only load_model_ptr = theLBManager()->getLoadModel().get(); } diff --git a/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.h b/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.h index d6f61bbaa4..fbda76d1f4 100644 --- a/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.h +++ b/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.h @@ -67,7 +67,7 @@ struct TemperedWMin : TemperedLB { TimeType getModeledValue(const elm::ElementIDStruct& obj) override; private: - std::unique_ptr total_work_model_ = nullptr; + std::shared_ptr total_work_model_ = nullptr; balance::LoadModel* load_model_ptr = nullptr; double alpha_ = 1.0; From ffcb97bd5ceea85290e776ee94bb3c26201ad80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Tue, 8 Nov 2022 17:10:01 +0100 Subject: [PATCH 04/14] #1659: lb: avoid repetition --- .../collection/balance/lb_invoke/lb_manager.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc index 07e22ddcf5..35eb86ba58 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc @@ -623,14 +623,14 @@ void LBManager::computeStatistics( "computeStatistics\n" ); - using ReduceOp = collective::PlusOp>; + const balance::PhaseOffset when = { + balance::PhaseOffset::NEXT_PHASE, balance::PhaseOffset::WHOLE_PHASE + }; total_load_from_model = 0.; std::vector obj_load_model; for (auto elm : *model) { - auto work = model->getModeledLoad( - elm, {balance::PhaseOffset::NEXT_PHASE, balance::PhaseOffset::WHOLE_PHASE} - ); + auto work = model->getModeledLoad(elm, when); obj_load_model.emplace_back( LoadData{lb::Statistic::Object_load_modeled, work} ); @@ -641,9 +641,7 @@ void LBManager::computeStatistics( std::vector obj_load_raw; if (model->hasRawLoad()) { for (auto elm : *model) { - auto raw_load = model->getRawLoad( - elm, {balance::PhaseOffset::NEXT_PHASE, balance::PhaseOffset::WHOLE_PHASE} - ); + auto raw_load = model->getRawLoad(elm, when); obj_load_raw.emplace_back( LoadData{lb::Statistic::Object_load_raw, raw_load} ); @@ -670,9 +668,7 @@ void LBManager::computeStatistics( auto total_work_from_model = 0.; std::vector obj_work_model; for (auto elm : *custom_model_) { - auto work = custom_model_->getModeledLoad( - elm, {balance::PhaseOffset::NEXT_PHASE, balance::PhaseOffset::WHOLE_PHASE} - ); + auto work = custom_model_->getModeledLoad(elm, when); obj_work_model.emplace_back( LoadData{lb::Statistic::Object_load_modeled, work} ); @@ -719,6 +715,7 @@ void LBManager::computeStatistics( lb::Statistic::Object_comm, std::move(obj_comm) )); + using ReduceOp = collective::PlusOp>; auto msg = makeMessage(std::move(lstats)); proxy_.template reduce(msg,cb); } From 0570bd07deefa5ce1bbaf09d878235b3e7513a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Tue, 8 Nov 2022 18:14:21 +0100 Subject: [PATCH 05/14] #1659: lb: clear custom model when TemperedWMin is destroyed --- src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc | 4 ++++ src/vt/vrt/collection/balance/temperedwmin/temperedwmin.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc b/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc index 39c78cde7b..9c1f59d585 100644 --- a/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc +++ b/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc @@ -50,6 +50,10 @@ namespace vt { namespace vrt { namespace collection { namespace lb { +TemperedWMin::~TemperedWMin() { + theLBManager()->setCustomLoadModel(nullptr); +} + void TemperedWMin::init(objgroup::proxy::Proxy in_proxy) { auto proxy_bits = in_proxy.getProxy(); auto proxy = objgroup::proxy::Proxy(proxy_bits); diff --git a/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.h b/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.h index fbda76d1f4..dcdaa43bff 100644 --- a/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.h +++ b/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.h @@ -55,7 +55,7 @@ struct TemperedWMin : TemperedLB { TemperedWMin() { comm_aware_ = true; } TemperedWMin(TemperedWMin const&) = delete; - virtual ~TemperedWMin() { } + virtual ~TemperedWMin(); public: void init(objgroup::proxy::Proxy in_proxy); From 65eeba624ed965a2b48c23abc7162d3133d7127e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Wed, 9 Nov 2022 18:22:02 +0100 Subject: [PATCH 06/14] #1659: lb: use correct statistic when calculating work --- src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc index 35eb86ba58..ce6df60546 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc @@ -670,7 +670,7 @@ void LBManager::computeStatistics( for (auto elm : *custom_model_) { auto work = custom_model_->getModeledLoad(elm, when); obj_work_model.emplace_back( - LoadData{lb::Statistic::Object_load_modeled, work} + LoadData{lb::Statistic::Object_work_modeled, work} ); total_work_from_model += work; } From 2b9b23872e016747eeea6d7c586b5210bae8b45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Mon, 14 Nov 2022 18:10:38 +0100 Subject: [PATCH 07/14] #1659: lb: remove redundant std::hash specialization (LBType) --- src/vt/vrt/collection/balance/lb_type.h | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/vt/vrt/collection/balance/lb_type.h b/src/vt/vrt/collection/balance/lb_type.h index 395e89036a..a618cb991f 100644 --- a/src/vt/vrt/collection/balance/lb_type.h +++ b/src/vt/vrt/collection/balance/lb_type.h @@ -71,18 +71,4 @@ std::unordered_map& get_lb_names(); }}}} /* end namespace vt::vrt::collection::balance */ -namespace std { - -template <> -struct hash { - size_t operator()(vt::vrt::collection::balance::LBType const& in) const { - using LBUnderType = - std::underlying_type::type; - auto const val = static_cast(in); - return std::hash()(val); - } -}; - -} /* end namespace std */ - #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_LB_TYPE_H*/ From 7cdaa4343899a2075eb4c845887adfa207b4931e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Mon, 14 Nov 2022 18:17:03 +0100 Subject: [PATCH 08/14] #1659: remove redundant std::hash specializations --- src/vt/elm/elm_comm.h | 9 ---- src/vt/utils/memory/memory_units.h | 14 ------ .../collection/balance/greedylb/greedylb.h | 13 ----- src/vt/vrt/collection/balance/lb_common.h | 14 ------ .../balance/temperedlb/tempered_enums.h | 49 ------------------- tests/unit/lb/test_lbargs_enum_conv.nompi.cc | 11 ----- 6 files changed, 110 deletions(-) diff --git a/src/vt/elm/elm_comm.h b/src/vt/elm/elm_comm.h index 60be58c073..692d06700a 100644 --- a/src/vt/elm/elm_comm.h +++ b/src/vt/elm/elm_comm.h @@ -184,15 +184,6 @@ using CommMapType = std::unordered_map; namespace std { -template <> -struct hash { - size_t operator()(vt::elm::CommCategory const& in) const { - using LBUnderType = std::underlying_type::type; - auto const val = static_cast(in); - return std::hash()(val); - } -}; - template <> struct hash { size_t operator()(vt::elm::CommKey const& in) const { diff --git a/src/vt/utils/memory/memory_units.h b/src/vt/utils/memory/memory_units.h index dd8d7e4fe8..8910d1bb87 100644 --- a/src/vt/utils/memory/memory_units.h +++ b/src/vt/utils/memory/memory_units.h @@ -68,18 +68,4 @@ std::tuple getBestMemoryUnit(std::size_t bytes); }}} /* end namespace vt::util::memory */ -namespace std { - -template <> -struct hash { - size_t operator()(vt::util::memory::MemoryUnitEnum const& in) const { - using MemoryUnitUnderType = - std::underlying_type::type; - auto const val = static_cast(in); - return std::hash()(val); - } -}; - -} /* end namespace std */ - #endif /*INCLUDED_VT_UTILS_MEMORY_MEMORY_UNITS_H*/ diff --git a/src/vt/vrt/collection/balance/greedylb/greedylb.h b/src/vt/vrt/collection/balance/greedylb/greedylb.h index 47590627e8..1dccca5763 100644 --- a/src/vt/vrt/collection/balance/greedylb/greedylb.h +++ b/src/vt/vrt/collection/balance/greedylb/greedylb.h @@ -127,17 +127,4 @@ struct GreedyLB : LoadSamplerBaseLB { }}}} /* end namespace vt::vrt::collection::lb */ -namespace std { - -template <> -struct hash { - size_t operator()(vt::vrt::collection::lb::DataDistStrategy const& in) const { - using UnderType = - std::underlying_type::type; - return std::hash()(static_cast(in)); - } -}; - -} /* end namespace std */ - #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_GREEDYLB_GREEDYLB_H*/ diff --git a/src/vt/vrt/collection/balance/lb_common.h b/src/vt/vrt/collection/balance/lb_common.h index 13ea1ec753..9515d4e4c2 100644 --- a/src/vt/vrt/collection/balance/lb_common.h +++ b/src/vt/vrt/collection/balance/lb_common.h @@ -201,20 +201,6 @@ nlohmann::json jsonifyPhaseStatistics(const StatisticMap &statistics); }}} /* end namespace vt::vrt::collection */ -namespace std { - -template <> -struct hash { - size_t operator()(vt::vrt::collection::lb::Statistic const& in) const { - using StatisticUnderType = - std::underlying_type::type; - auto const val = static_cast(in); - return std::hash()(val); - } -}; - -} /* end namespace std */ - namespace vt { namespace vrt { namespace collection { namespace lb { std::unordered_map& get_lb_stat_names(); diff --git a/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h b/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h index 06d1fd9d0a..b56414a333 100644 --- a/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h +++ b/src/vt/vrt/collection/balance/temperedlb/tempered_enums.h @@ -167,53 +167,4 @@ enum struct KnowledgeEnum : uint8_t { }}}} /* end namespace vt::vrt::collection::lb */ -namespace std { - -template <> -struct hash { - size_t operator()(vt::vrt::collection::lb::CriterionEnum const& in) const { - using UnderType = - std::underlying_type::type; - return std::hash()(static_cast(in)); - } -}; - -template <> -struct hash { - size_t operator()(vt::vrt::collection::lb::InformTypeEnum const& in) const { - using UnderType = - std::underlying_type::type; - return std::hash()(static_cast(in)); - } -}; - -template <> -struct hash { - size_t operator()(vt::vrt::collection::lb::ObjectOrderEnum const& in) const { - using UnderType = - std::underlying_type::type; - return std::hash()(static_cast(in)); - } -}; - -template <> -struct hash { - size_t operator()(vt::vrt::collection::lb::CMFTypeEnum const& in) const { - using UnderType = - std::underlying_type::type; - return std::hash()(static_cast(in)); - } -}; - -template <> -struct hash { - size_t operator()(vt::vrt::collection::lb::KnowledgeEnum const& in) const { - using UnderType = - std::underlying_type::type; - return std::hash()(static_cast(in)); - } -}; - -} /* end namespace std */ - #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_TEMPEREDLB_TEMPERED_ENUMS_H*/ diff --git a/tests/unit/lb/test_lbargs_enum_conv.nompi.cc b/tests/unit/lb/test_lbargs_enum_conv.nompi.cc index 44ad59e5a8..d258bee0a1 100644 --- a/tests/unit/lb/test_lbargs_enum_conv.nompi.cc +++ b/tests/unit/lb/test_lbargs_enum_conv.nompi.cc @@ -58,17 +58,6 @@ enum struct DummyEnum : uint8_t { }}} // end namespace vt::tests::unit -namespace std { - -template <> -struct hash<::vt::tests::unit::DummyEnum> { - size_t operator()(::vt::tests::unit::DummyEnum const& in) const { - return std::hash()(static_cast(in)); - } -}; - -} // end namespace std - namespace vt { namespace tests { namespace unit { template From ba70458bbf49bf1f78870deb5ca837daee2bf06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Mon, 14 Nov 2022 18:36:36 +0100 Subject: [PATCH 09/14] #1659: remove obsolete code --- src/vt/vrt/collection/balance/lb_common.h | 6 ------ tests/unit/lb/test_lbargs_enum_conv.nompi.cc | 4 ---- 2 files changed, 10 deletions(-) diff --git a/src/vt/vrt/collection/balance/lb_common.h b/src/vt/vrt/collection/balance/lb_common.h index 9515d4e4c2..88ece5c0a4 100644 --- a/src/vt/vrt/collection/balance/lb_common.h +++ b/src/vt/vrt/collection/balance/lb_common.h @@ -197,12 +197,6 @@ using StatisticMap = std::unordered_map; nlohmann::json jsonifyPhaseStatistics(const StatisticMap &statistics); -} /* end namespace lb */ - -}}} /* end namespace vt::vrt::collection */ - -namespace vt { namespace vrt { namespace collection { namespace lb { - std::unordered_map& get_lb_stat_names(); }}}} /* end namespace vt::vrt::collection::lb */ diff --git a/tests/unit/lb/test_lbargs_enum_conv.nompi.cc b/tests/unit/lb/test_lbargs_enum_conv.nompi.cc index d258bee0a1..a523b0a4bd 100644 --- a/tests/unit/lb/test_lbargs_enum_conv.nompi.cc +++ b/tests/unit/lb/test_lbargs_enum_conv.nompi.cc @@ -56,10 +56,6 @@ enum struct DummyEnum : uint8_t { Three = 3 }; -}}} // end namespace vt::tests::unit - -namespace vt { namespace tests { namespace unit { - template void checkEnum(vrt::collection::balance::LBArgsEnumConverter &conv, E e) { EXPECT_EQ(conv.getEnum(conv.getString(e)), e); From f44cd5c6586c279d6a5fe2ae8fac566951d9dee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Mon, 14 Nov 2022 18:58:23 +0100 Subject: [PATCH 10/14] #1659: lb: control strategy specific model through BaseLB --- src/vt/vrt/collection/balance/baselb/baselb.cc | 6 ++++++ src/vt/vrt/collection/balance/baselb/baselb.h | 4 ++++ .../collection/balance/lb_invoke/lb_manager.cc | 6 +++--- .../vrt/collection/balance/lb_invoke/lb_manager.h | 15 ++++++++------- .../balance/temperedwmin/temperedwmin.cc | 4 ++-- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/vt/vrt/collection/balance/baselb/baselb.cc b/src/vt/vrt/collection/balance/baselb/baselb.cc index ae35ce89b3..0a38e01b84 100644 --- a/src/vt/vrt/collection/balance/baselb/baselb.cc +++ b/src/vt/vrt/collection/balance/baselb/baselb.cc @@ -277,6 +277,12 @@ void BaseLB::recvSharedEdges(CommMsg* msg) { } } +void BaseLB::setStrategySpecificModel( + std::shared_ptr model +) { + theLBManager()->setStrategySpecificModel(model); +} + }}}} /* end namespace vt::vrt::collection::lb */ #endif /*INCLUDED_VT_VRT_COLLECTION_BALANCE_BASELB_BASELB_CC*/ diff --git a/src/vt/vrt/collection/balance/baselb/baselb.h b/src/vt/vrt/collection/balance/baselb/baselb.h index c878c0365a..8c2670c668 100644 --- a/src/vt/vrt/collection/balance/baselb/baselb.h +++ b/src/vt/vrt/collection/balance/baselb/baselb.h @@ -148,6 +148,10 @@ struct BaseLB { bool isCommAware() const { return comm_aware_; } void recvSharedEdges(CommMsg* msg); + static void setStrategySpecificModel( + std::shared_ptr model + ); + protected: void getArgs(PhaseType phase); diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc index ce6df60546..cc70e21335 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc @@ -664,11 +664,11 @@ void LBManager::computeStatistics( lb::Statistic::Object_load_modeled, std::move(obj_load_model) )); - if (custom_model_) { + if (strategy_specific_model_) { auto total_work_from_model = 0.; std::vector obj_work_model; - for (auto elm : *custom_model_) { - auto work = custom_model_->getModeledLoad(elm, when); + for (auto elm : *strategy_specific_model_) { + auto work = strategy_specific_model_->getModeledLoad(elm, when); obj_work_model.emplace_back( LoadData{lb::Statistic::Object_work_modeled, work} ); diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h index 33c5765b83..7c584ff0a2 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h @@ -193,10 +193,6 @@ struct LBManager : runtime::component::Component { */ void setLoadModel(std::shared_ptr model); - void setCustomLoadModel(std::shared_ptr model) { - custom_model_ = model; - } - /** * \brief Get the system-set basic model of object load */ @@ -267,7 +263,6 @@ struct LBManager : runtime::component::Component { private: bool isCollectiveComm(elm::CommCategory cat) const; -private: /** * \internal \brief Create the statistics file */ @@ -278,14 +273,20 @@ struct LBManager : runtime::component::Component { */ void closeStatisticsFile(); -private: + void setStrategySpecificModel(std::shared_ptr model) { + strategy_specific_model_ = model; + } + friend void lb::BaseLB::setStrategySpecificModel( + std::shared_ptr model + ); + PhaseType cached_phase_ = no_lb_phase; LBType cached_lb_ = LBType::NoLB; std::function destroy_lb_ = nullptr; objgroup::proxy::Proxy proxy_; std::shared_ptr base_model_; std::shared_ptr model_; - std::shared_ptr custom_model_; + std::shared_ptr strategy_specific_model_; std::unordered_map lb_instances_; StatisticMapType stats; TimeType total_load_from_model = 0.; diff --git a/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc b/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc index 9c1f59d585..76362c5466 100644 --- a/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc +++ b/src/vt/vrt/collection/balance/temperedwmin/temperedwmin.cc @@ -51,7 +51,7 @@ namespace vt { namespace vrt { namespace collection { namespace lb { TemperedWMin::~TemperedWMin() { - theLBManager()->setCustomLoadModel(nullptr); + setStrategySpecificModel(nullptr); } void TemperedWMin::init(objgroup::proxy::Proxy in_proxy) { @@ -104,7 +104,7 @@ void TemperedWMin::inputParams(balance::ConfigEntry* config) { total_work_model_ = std::make_shared( theLBManager()->getLoadModel(), alpha_, beta_, gamma_ ); - theLBManager()->setCustomLoadModel(total_work_model_); + setStrategySpecificModel(total_work_model_); // for later assertion only load_model_ptr = theLBManager()->getLoadModel().get(); From c5219da0d2a47efb9e14affd37ae5214824c3d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Mon, 28 Nov 2022 10:41:28 +0100 Subject: [PATCH 11/14] #1659: lb: make BaseLB a friend of LBManager --- src/vt/vrt/collection/balance/baselb/baselb.h | 10 ++++------ src/vt/vrt/collection/balance/lb_invoke/lb_manager.h | 5 ++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/vt/vrt/collection/balance/baselb/baselb.h b/src/vt/vrt/collection/balance/baselb/baselb.h index 8c2670c668..c2fd19fa4c 100644 --- a/src/vt/vrt/collection/balance/baselb/baselb.h +++ b/src/vt/vrt/collection/balance/baselb/baselb.h @@ -148,14 +148,9 @@ struct BaseLB { bool isCommAware() const { return comm_aware_; } void recvSharedEdges(CommMsg* msg); - static void setStrategySpecificModel( - std::shared_ptr model - ); - protected: void getArgs(PhaseType phase); -protected: double start_time_ = 0.0f; ElementCommType const* comm_data = nullptr; objgroup::proxy::Proxy proxy_ = {}; @@ -165,7 +160,6 @@ struct BaseLB { balance::LoadModel* load_model_ = nullptr; bool comm_aware_ = false; -protected: /** * \brief Normalizes the reassignment graph by setting up in/out edges on both * sides regardless of how they are passed to \c migrateObjectTo @@ -174,6 +168,10 @@ struct BaseLB { */ std::shared_ptr normalizeReassignments(); + static void setStrategySpecificModel( + std::shared_ptr model + ); + private: TransferVecType transfers_ = {}; TransferType off_node_migrate_ = {}; diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h index 7c584ff0a2..eb6d730223 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.h @@ -79,6 +79,8 @@ struct LBManager : runtime::component::Component { using QuantityType = lb::StatisticQuantityMap; using StatisticMapType = lb::StatisticMap; + friend lb::BaseLB; + /** * \internal \brief System call to construct a \c LBManager */ @@ -276,9 +278,6 @@ struct LBManager : runtime::component::Component { void setStrategySpecificModel(std::shared_ptr model) { strategy_specific_model_ = model; } - friend void lb::BaseLB::setStrategySpecificModel( - std::shared_ptr model - ); PhaseType cached_phase_ = no_lb_phase; LBType cached_lb_ = LBType::NoLB; From 5feffc29e1916d427dcd1a4e2b3a70c4b06997a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Tue, 6 Dec 2022 01:30:45 +0100 Subject: [PATCH 12/14] #1659: lb: use more general language --- .../vrt/collection/balance/lb_invoke/lb_manager.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc index cc70e21335..f7839eb909 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc @@ -665,21 +665,21 @@ void LBManager::computeStatistics( )); if (strategy_specific_model_) { - auto total_work_from_model = 0.; - std::vector obj_work_model; + auto rank_work_modeled = 0.; + std::vector obj_work_modeled; for (auto elm : *strategy_specific_model_) { auto work = strategy_specific_model_->getModeledLoad(elm, when); - obj_work_model.emplace_back( + obj_work_modeled.emplace_back( LoadData{lb::Statistic::Object_work_modeled, work} ); - total_work_from_model += work; + rank_work_modeled += work; } lstats.emplace_back( - LoadData{lb::Statistic::Rank_work_modeled, total_work_from_model} + LoadData{lb::Statistic::Rank_work_modeled, rank_work_modeled} ); lstats.emplace_back(reduceVec( - lb::Statistic::Object_work_modeled, std::move(obj_work_model) + lb::Statistic::Object_work_modeled, std::move(obj_work_modeled) )); } From 484a4c4f588048715be6186f95303aad267ef533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Tue, 6 Dec 2022 19:21:26 +0100 Subject: [PATCH 13/14] #1659: lb: update JSON schema --- scripts/JSON_data_files_validator.py | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/scripts/JSON_data_files_validator.py b/scripts/JSON_data_files_validator.py index 63ac1c820a..1bd5d7d8e5 100644 --- a/scripts/JSON_data_files_validator.py +++ b/scripts/JSON_data_files_validator.py @@ -146,6 +146,19 @@ def _get_valid_schema(self) -> Schema: "sum": float, "var": float }, + Optional("Object_work_modeled"): { + "avg": float, + "car": float, + "imb": float, + "kur": float, + "max": float, + "min": float, + "npr": float, + "skw": float, + "std": float, + "sum": float, + "var": float + }, "Rank_comm": { "avg": float, "car": float, @@ -184,6 +197,19 @@ def _get_valid_schema(self) -> Schema: "std": float, "sum": float, "var": float + }, + Optional("Rank_work_modeled"): { + "avg": float, + "car": float, + "imb": float, + "kur": float, + "max": float, + "min": float, + "npr": float, + "skw": float, + "std": float, + "sum": float, + "var": float } }, "pre-LB": { @@ -226,6 +252,19 @@ def _get_valid_schema(self) -> Schema: "sum": float, "var": float }, + Optional("Object_work_modeled"): { + "avg": float, + "car": float, + "imb": float, + "kur": float, + "max": float, + "min": float, + "npr": float, + "skw": float, + "std": float, + "sum": float, + "var": float + }, "Rank_comm": { "avg": float, "car": float, @@ -264,6 +303,19 @@ def _get_valid_schema(self) -> Schema: "std": float, "sum": float, "var": float + }, + Optional("Rank_work_modeled"): { + "avg": float, + "car": float, + "imb": float, + "kur": float, + "max": float, + "min": float, + "npr": float, + "skw": float, + "std": float, + "sum": float, + "var": float } } }, From 52d48086333455451adb76d9fe963ad3291cff97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Tue, 13 Dec 2022 20:59:13 +0100 Subject: [PATCH 14/14] #1659: lb: improve naming --- scripts/JSON_data_files_validator.py | 8 ++++---- src/vt/vrt/collection/balance/lb_common.h | 4 ++-- .../collection/balance/lb_invoke/lb_manager.cc | 16 +++++++++------- src/vt/vrt/collection/balance/lb_type.cc | 6 ++++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/scripts/JSON_data_files_validator.py b/scripts/JSON_data_files_validator.py index 1bd5d7d8e5..8f81933559 100644 --- a/scripts/JSON_data_files_validator.py +++ b/scripts/JSON_data_files_validator.py @@ -146,7 +146,7 @@ def _get_valid_schema(self) -> Schema: "sum": float, "var": float }, - Optional("Object_work_modeled"): { + Optional("Object_strategy_specific_load_modeled"): { "avg": float, "car": float, "imb": float, @@ -198,7 +198,7 @@ def _get_valid_schema(self) -> Schema: "sum": float, "var": float }, - Optional("Rank_work_modeled"): { + Optional("Rank_strategy_specific_load_modeled"): { "avg": float, "car": float, "imb": float, @@ -252,7 +252,7 @@ def _get_valid_schema(self) -> Schema: "sum": float, "var": float }, - Optional("Object_work_modeled"): { + Optional("Object_strategy_specific_load_modeled"): { "avg": float, "car": float, "imb": float, @@ -304,7 +304,7 @@ def _get_valid_schema(self) -> Schema: "sum": float, "var": float }, - Optional("Rank_work_modeled"): { + Optional("Rank_strategy_specific_load_modeled"): { "avg": float, "car": float, "imb": float, diff --git a/src/vt/vrt/collection/balance/lb_common.h b/src/vt/vrt/collection/balance/lb_common.h index 88ece5c0a4..d0922fb9e5 100644 --- a/src/vt/vrt/collection/balance/lb_common.h +++ b/src/vt/vrt/collection/balance/lb_common.h @@ -179,8 +179,8 @@ enum struct StatisticQuantity : int8_t { }; enum struct Statistic : int8_t { - Rank_load_modeled, Rank_load_raw, Rank_comm, Rank_work_modeled, - Object_load_modeled, Object_load_raw, Object_comm, Object_work_modeled, + Rank_load_modeled, Rank_load_raw, Rank_comm, Rank_strategy_specific_load_modeled, + Object_load_modeled, Object_load_raw, Object_comm, Object_strategy_specific_load_modeled, // W_l_min, W_l_max, W_l_avg, W_l_std, W_l_var, W_l_skewness, W_l_kurtosis, // W_c_min, W_c_max, W_c_avg, W_c_std, W_c_var, W_c_skewness, W_c_kurtosis, // W_t_min, W_t_max, W_t_avg, W_t_std, W_t_var, W_t_skewness, W_t_kurtosis, diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc index f7839eb909..f6f8ce8ace 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc @@ -665,21 +665,23 @@ void LBManager::computeStatistics( )); if (strategy_specific_model_) { - auto rank_work_modeled = 0.; - std::vector obj_work_modeled; + auto rank_strat_specific_load = 0.; + std::vector obj_strat_specific_load; for (auto elm : *strategy_specific_model_) { auto work = strategy_specific_model_->getModeledLoad(elm, when); - obj_work_modeled.emplace_back( - LoadData{lb::Statistic::Object_work_modeled, work} + obj_strat_specific_load.emplace_back( + LoadData{lb::Statistic::Object_strategy_specific_load_modeled, work} ); - rank_work_modeled += work; + rank_strat_specific_load += work; } lstats.emplace_back( - LoadData{lb::Statistic::Rank_work_modeled, rank_work_modeled} + LoadData{lb::Statistic::Rank_strategy_specific_load_modeled, + rank_strat_specific_load} ); lstats.emplace_back(reduceVec( - lb::Statistic::Object_work_modeled, std::move(obj_work_modeled) + lb::Statistic::Object_strategy_specific_load_modeled, + std::move(obj_strat_specific_load) )); } diff --git a/src/vt/vrt/collection/balance/lb_type.cc b/src/vt/vrt/collection/balance/lb_type.cc index e856cd787b..d9f05ecac7 100644 --- a/src/vt/vrt/collection/balance/lb_type.cc +++ b/src/vt/vrt/collection/balance/lb_type.cc @@ -75,11 +75,13 @@ static std::unordered_map lb_stat_names_ = { {Statistic::Rank_load_modeled, std::string{"Rank_load_modeled"}}, {Statistic::Rank_load_raw, std::string{"Rank_load_raw"}}, {Statistic::Rank_comm, std::string{"Rank_comm"}}, - {Statistic::Rank_work_modeled, std::string{"Rank_work_modeled"}}, + {Statistic::Rank_strategy_specific_load_modeled, + std::string{"Rank_strategy_specific_load_modeled"}}, {Statistic::Object_load_modeled, std::string{"Object_load_modeled"}}, {Statistic::Object_load_raw, std::string{"Object_load_raw"}}, {Statistic::Object_comm, std::string{"Object_comm"}}, - {Statistic::Object_work_modeled, std::string{"Object_work_modeled"}}, + {Statistic::Object_strategy_specific_load_modeled, + std::string{"Object_strategy_specific_load_modeled"}}, {Statistic::ObjectRatio, std::string{"ObjectRatio"}}, {Statistic::EdgeRatio, std::string{"EdgeRatio"}} };