|
| 1 | +/* |
| 2 | +//@HEADER |
| 3 | +// ***************************************************************************** |
| 4 | +// |
| 5 | +// test_work_model.cc |
| 6 | +// DARMA/vt-lb => Virtual Transport/Load Balancers |
| 7 | +// |
| 8 | +// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC |
| 9 | +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. |
| 10 | +// Government retains certain rights in this software. |
| 11 | +// |
| 12 | +// Redistribution and use in source and binary forms, with or without |
| 13 | +// modification, are permitted provided that the following conditions are met: |
| 14 | +// |
| 15 | +// * Redistributions of source code must retain the above copyright notice, |
| 16 | +// this list of conditions and the following disclaimer. |
| 17 | +// |
| 18 | +// * Redistributions in binary form must reproduce the above copyright notice, |
| 19 | +// this list of conditions and the following disclaimer in the documentation |
| 20 | +// and/or other materials provided with the distribution. |
| 21 | +// |
| 22 | +// * Neither the name of the copyright holder nor the names of its |
| 23 | +// contributors may be used to endorse or promote products derived from this |
| 24 | +// software without specific prior written permission. |
| 25 | +// |
| 26 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 27 | +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 28 | +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 29 | +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 30 | +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 31 | +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 32 | +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 33 | +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 34 | +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 35 | +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | +// POSSIBILITY OF SUCH DAMAGE. |
| 37 | +// |
| 38 | +// Questions? Contact darma@sandia.gov |
| 39 | +// |
| 40 | +// ***************************************************************************** |
| 41 | +//@HEADER |
| 42 | +*/ |
| 43 | + |
| 44 | +#include <gtest/gtest.h> |
| 45 | + |
| 46 | +#include "test_parallel_harness.h" |
| 47 | +#include "test_helpers.h" |
| 48 | + |
| 49 | +#include <vt-lb/algo/temperedlb/work_model.h> |
| 50 | +#include <vt-lb/algo/temperedlb/configuration.h> |
| 51 | +#include <vt-lb/model/PhaseData.h> |
| 52 | + |
| 53 | +namespace vt_lb { namespace tests { namespace unit { |
| 54 | + |
| 55 | +template <comm::Communicator CommType> |
| 56 | +struct TestWorkModelBasic : TestParallelHarness<CommType> {}; |
| 57 | + |
| 58 | +TYPED_TEST_SUITE(TestWorkModelBasic, CommTypesForTesting, CommNameGenerator); |
| 59 | + |
| 60 | +TYPED_TEST(TestWorkModelBasic, compute_work_uses_max_comm_components) { |
| 61 | + // Build a breakdown with differing send/recv values to test max selection |
| 62 | + algo::temperedlb::WorkBreakdown bd; |
| 63 | + bd.compute = 10.0; |
| 64 | + bd.inter_node_recv_comm = 5.0; |
| 65 | + bd.inter_node_send_comm = 7.5; // inter-node max should be 7.5 |
| 66 | + bd.intra_node_recv_comm = 1.0; |
| 67 | + bd.intra_node_send_comm = 2.0; // intra-node max should be 2.0 |
| 68 | + bd.shared_mem_comm = 3.0; |
| 69 | + |
| 70 | + algo::temperedlb::WorkModel wm; |
| 71 | + wm.rank_alpha = 2.0; |
| 72 | + wm.beta = 1.0; |
| 73 | + wm.gamma = 0.5; |
| 74 | + wm.delta = 3.0; |
| 75 | + |
| 76 | + double w = algo::temperedlb::WorkModelCalculator::computeWork(wm, bd); |
| 77 | + // Expected: 2*10 + 1*7.5 + 0.5*2 + 3*3 = 20 + 7.5 + 1 + 9 = 37.5 |
| 78 | + EXPECT_DOUBLE_EQ(w, 37.5); |
| 79 | +} |
| 80 | + |
| 81 | +TYPED_TEST(TestWorkModelBasic, compute_memory_usage_rank_only) { |
| 82 | + auto& the_comm = this->comm; |
| 83 | + algo::temperedlb::Configuration cfg; |
| 84 | + // Disable all task/shared-block memory flags so only rank footprint contributes |
| 85 | + cfg.work_model_.has_memory_info = true; |
| 86 | + cfg.work_model_.has_task_serialized_memory_info = false; |
| 87 | + cfg.work_model_.has_task_working_memory_info = false; |
| 88 | + cfg.work_model_.has_task_footprint_memory_info = false; |
| 89 | + cfg.work_model_.has_shared_block_memory_info = false; |
| 90 | + |
| 91 | + model::PhaseData pd(the_comm.getRank()); |
| 92 | + pd.setRankFootprintBytes(12345.0); |
| 93 | + pd.setRankMaxMemoryAvailable(999999.0); |
| 94 | + |
| 95 | + auto mb = algo::temperedlb::WorkModelCalculator::computeMemoryUsage(cfg, pd); |
| 96 | + EXPECT_DOUBLE_EQ(mb.current_memory_usage, 12345.0); |
| 97 | + EXPECT_DOUBLE_EQ(mb.current_max_task_working_bytes, 0.0); |
| 98 | + EXPECT_DOUBLE_EQ(mb.current_max_task_serialized_bytes, 0.0); |
| 99 | +} |
| 100 | + |
| 101 | +TYPED_TEST(TestWorkModelBasic, check_memory_fit_basic) { |
| 102 | + auto& the_comm = this->comm; |
| 103 | + algo::temperedlb::Configuration cfg; |
| 104 | + cfg.work_model_.has_memory_info = true; // enable memory checks |
| 105 | + |
| 106 | + model::PhaseData pd(the_comm.getRank()); |
| 107 | + pd.setRankMaxMemoryAvailable(1000.0); |
| 108 | + |
| 109 | + // Fits |
| 110 | + EXPECT_TRUE(algo::temperedlb::WorkModelCalculator::checkMemoryFit(cfg, pd, 999.9)); |
| 111 | + // Boundary |
| 112 | + EXPECT_TRUE(algo::temperedlb::WorkModelCalculator::checkMemoryFit(cfg, pd, 1000.0)); |
| 113 | + // Exceeds |
| 114 | + EXPECT_FALSE(algo::temperedlb::WorkModelCalculator::checkMemoryFit(cfg, pd, 1000.1)); |
| 115 | +} |
| 116 | + |
| 117 | +TYPED_TEST(TestWorkModelBasic, compute_work_update_no_changes_is_identity) { |
| 118 | + auto& the_comm = this->comm; |
| 119 | + |
| 120 | + // Work model with non-zero coefficients |
| 121 | + algo::temperedlb::WorkModel wm; |
| 122 | + wm.rank_alpha = 0.5; |
| 123 | + wm.beta = 0.2; |
| 124 | + wm.gamma = 0.3; |
| 125 | + wm.delta = 1.0; |
| 126 | + |
| 127 | + // Phase data with tasks referencing shared blocks; shared blocks off-home produce bytes |
| 128 | + model::PhaseData pd(the_comm.getRank()); |
| 129 | + // Define two shared blocks with specific homes/sizes |
| 130 | + model::SharedBlock sbA{1, 100.0, (the_comm.getRank() + 1) % the_comm.numRanks()}; |
| 131 | + model::SharedBlock sbB{2, 50.0, the_comm.getRank()}; // local-home; should not add shared_mem_comm |
| 132 | + pd.addSharedBlock(sbA); |
| 133 | + pd.addSharedBlock(sbB); |
| 134 | + |
| 135 | + // Two tasks that reference both blocks |
| 136 | + model::Task t1{10, 11.0}; |
| 137 | + t1.addSharedBlock(sbA.getId()); |
| 138 | + t1.addSharedBlock(sbB.getId()); |
| 139 | + |
| 140 | + model::Task t2{11, 0.0}; |
| 141 | + t2.addSharedBlock(sbA.getId()); |
| 142 | + |
| 143 | + pd.addTask(t1); |
| 144 | + pd.addTask(t2); |
| 145 | + |
| 146 | + // Current breakdown computed from PhaseData and a default config with memory info on |
| 147 | + algo::temperedlb::Configuration cfg; |
| 148 | + cfg.work_model_.has_memory_info = true; |
| 149 | + cfg.work_model_.has_shared_block_memory_info = true; |
| 150 | + cfg.work_model_.has_task_footprint_memory_info = false; |
| 151 | + cfg.work_model_.has_task_working_memory_info = false; |
| 152 | + cfg.work_model_.has_task_serialized_memory_info = false; |
| 153 | + |
| 154 | + auto bd = algo::temperedlb::WorkModelCalculator::computeWorkBreakdown(pd, cfg); |
| 155 | + |
| 156 | + // Baseline work |
| 157 | + double base = algo::temperedlb::WorkModelCalculator::computeWork(wm, bd); |
| 158 | + |
| 159 | + // No changes |
| 160 | + std::vector<model::Task> add_tasks; |
| 161 | + std::vector<model::Edge> add_edges; |
| 162 | + std::vector<model::TaskType> remove_ids; |
| 163 | + |
| 164 | + double updated = algo::temperedlb::WorkModelCalculator::computeWorkUpdate( |
| 165 | + pd, wm, bd, add_tasks, add_edges, remove_ids |
| 166 | + ); |
| 167 | + |
| 168 | + EXPECT_DOUBLE_EQ(updated, base); |
| 169 | +} |
| 170 | + |
| 171 | +}}} // end namespace vt_lb::tests::unit |
0 commit comments