-
Notifications
You must be signed in to change notification settings - Fork 1
Misc updates #25
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
Merged
Merged
Misc updates #25
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| /* | ||
| Copyright 2024 Huawei Technologies Co., Ltd. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| @author Toni Boehnlein, Benjamin Lozes, Pal Andras Papp, Raphael S. Steiner | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "BspSchedule.hpp" | ||
|
|
||
| namespace osp { | ||
|
|
||
| /** | ||
| * @class BspScheduleCostEvaluator | ||
| * @brief A class to compute various cost functions for a BspSchedule. | ||
| * | ||
| * This class wraps a BspSchedule by reference to avoid unnecessary copies | ||
| * while providing an interface to compute different cost models. | ||
| */ | ||
| template<typename Graph_t> | ||
| class BspScheduleCostEvaluator { | ||
|
|
||
| static_assert(is_computational_dag_v<Graph_t>, "BspScheduleCostEvaluator can only be used with computational DAGs."); | ||
| static_assert(std::is_same_v<v_workw_t<Graph_t>, v_commw_t<Graph_t>>, | ||
| "BspScheduleCostEvaluator requires work and comm. weights to have the same type."); | ||
|
|
||
| protected: | ||
| const BspSchedule<Graph_t>& schedule; | ||
| const BspInstance<Graph_t>& instance; | ||
|
|
||
| void compute_lazy_communication_costs_helper(std::vector<std::vector<v_commw_t<Graph_t>>> & rec, std::vector<std::vector<v_commw_t<Graph_t>>> & send) const { | ||
| const unsigned number_of_supersteps = schedule.numberOfSupersteps(); | ||
| for (const auto &node : instance.vertices()) { | ||
|
|
||
| std::vector<unsigned> step_needed(instance.numberOfProcessors(), number_of_supersteps); | ||
| for (const auto &target : instance.getComputationalDag().children(node)) { | ||
|
|
||
| if (schedule.assignedProcessor(node) != schedule.assignedProcessor(target)) { | ||
| step_needed[schedule.assignedProcessor(target)] = std::min( | ||
| step_needed[schedule.assignedProcessor(target)], schedule.assignedSuperstep(target)); | ||
| } | ||
| } | ||
|
|
||
| for (unsigned proc = 0; proc < instance.numberOfProcessors(); proc++) { | ||
|
|
||
| if (step_needed[proc] < number_of_supersteps) { | ||
|
|
||
| send[schedule.assignedProcessor(node)][step_needed[proc] - 1] += | ||
| instance.sendCosts(schedule.assignedProcessor(node), proc) * | ||
| instance.getComputationalDag().vertex_comm_weight(node); | ||
|
|
||
| rec[proc][step_needed[proc] - 1] += instance.sendCosts(schedule.assignedProcessor(node), proc) * | ||
| instance.getComputationalDag().vertex_comm_weight(node); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| std::vector<v_commw_t<Graph_t>> compute_max_comm_per_step_helper(const std::vector<std::vector<v_commw_t<Graph_t>>> & rec, const std::vector<std::vector<v_commw_t<Graph_t>>> & send) const { | ||
| const unsigned number_of_supersteps = schedule.numberOfSupersteps(); | ||
| std::vector<v_commw_t<Graph_t>> max_comm_per_step(number_of_supersteps, 0); | ||
| for (unsigned step = 0; step < number_of_supersteps; step++) { | ||
| v_commw_t<Graph_t> max_send = 0; | ||
| v_commw_t<Graph_t> max_rec = 0; | ||
|
|
||
| for (unsigned proc = 0; proc < instance.numberOfProcessors(); proc++) { | ||
| if (max_send < send[proc][step]) | ||
| max_send = send[proc][step]; | ||
| if (max_rec < rec[proc][step]) | ||
| max_rec = rec[proc][step]; | ||
| } | ||
| max_comm_per_step[step] = std::max(max_send, max_rec) * instance.communicationCosts(); | ||
| } | ||
| return max_comm_per_step; | ||
| } | ||
|
|
||
| std::vector<v_workw_t<Graph_t>> compute_max_work_per_step_helper() const { | ||
| const unsigned number_of_supersteps = schedule.numberOfSupersteps(); | ||
| std::vector<std::vector<v_workw_t<Graph_t>>> work = std::vector<std::vector<v_workw_t<Graph_t>>>( | ||
| number_of_supersteps, std::vector<v_workw_t<Graph_t>>(instance.numberOfProcessors(), 0)); | ||
| for (const auto &node : instance.vertices()) { | ||
| work[schedule.assignedSuperstep(node)][schedule.assignedProcessor(node)] += | ||
| instance.getComputationalDag().vertex_work_weight(node); | ||
| } | ||
|
|
||
| std::vector<v_workw_t<Graph_t>> max_work_per_step(number_of_supersteps, 0); | ||
| for (unsigned step = 0; step < number_of_supersteps; step++) { | ||
| v_workw_t<Graph_t> max_work = 0; | ||
| for (unsigned proc = 0; proc < instance.numberOfProcessors(); proc++) { | ||
| if (max_work < work[step][proc]) { | ||
| max_work = work[step][proc]; | ||
| } | ||
| } | ||
|
|
||
| max_work_per_step[step] = max_work; | ||
| } | ||
|
|
||
| return max_work_per_step; | ||
| } | ||
|
|
||
| public: | ||
| /** | ||
| * @brief Construct a new Bsp Schedule Cost Evaluator object. | ||
| * | ||
| * @param sched The BspSchedule to evaluate. | ||
| */ | ||
| BspScheduleCostEvaluator(const BspSchedule<Graph_t>& sched) : schedule(sched), instance(sched.getInstance()) {} | ||
|
|
||
| /** | ||
| * @brief Computes the communication costs using the lazy sending model. | ||
| * | ||
| * In the lazy sending model, data is sent in the superstep immediately | ||
| * preceding the superstep where it is first needed. | ||
| * | ||
| * @return The lazy communication costs. | ||
| */ | ||
| v_commw_t<Graph_t> compute_lazy_communication_costs() const { | ||
|
|
||
| const unsigned number_of_supersteps = schedule.numberOfSupersteps(); | ||
|
|
||
| std::vector<std::vector<v_commw_t<Graph_t>>> rec(instance.numberOfProcessors(), | ||
| std::vector<v_commw_t<Graph_t>>(number_of_supersteps, 0)); | ||
| std::vector<std::vector<v_commw_t<Graph_t>>> send(instance.numberOfProcessors(), | ||
| std::vector<v_commw_t<Graph_t>>(number_of_supersteps, 0)); | ||
|
|
||
| compute_lazy_communication_costs_helper(rec, send); | ||
| const std::vector<v_commw_t<Graph_t>> max_comm_per_step = compute_max_comm_per_step_helper(rec, send); | ||
|
|
||
| v_commw_t<Graph_t> costs = 0; | ||
| for (unsigned step = 0; step < number_of_supersteps; step++) { | ||
| const auto step_comm_cost = max_comm_per_step[step]; | ||
| costs += step_comm_cost; | ||
|
|
||
| costs += instance.synchronisationCosts(); | ||
|
|
||
| } | ||
|
|
||
| return costs; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Computes the total work costs of the schedule. | ||
| * | ||
| * The work cost is the sum of the maximum work done in each superstep | ||
| * across all processors. | ||
| * | ||
| * @return The total work costs. | ||
| */ | ||
| v_workw_t<Graph_t> computeWorkCosts() const { | ||
| const std::vector<v_workw_t<Graph_t>> work_per_step = compute_max_work_per_step_helper(); | ||
| return std::accumulate(work_per_step.begin(), work_per_step.end(), static_cast<v_workw_t<Graph_t>>(0)); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Computes the total costs of the schedule using the lazy communication model. | ||
| * | ||
| * @return The total costs. | ||
| */ | ||
| v_workw_t<Graph_t> computeCosts() const { return compute_lazy_communication_costs() + computeWorkCosts(); } | ||
| }; | ||
|
|
||
| } // namespace osp |
93 changes: 93 additions & 0 deletions
93
include/osp/bsp/scheduler/GreedySchedulers/GreedyMetaScheduler.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| Copyright 2024 Huawei Technologies Co., Ltd. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| @author Toni Boehnlein, Benjamin Lozes, Pal Andras Papp, Raphael S. Steiner | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "osp/bsp/model/BspScheduleCostEvaluator.hpp" | ||
| #include "osp/bsp/scheduler/Scheduler.hpp" | ||
| #include "osp/bsp/scheduler/Serial.hpp" | ||
| #include <vector> | ||
| #include <string> | ||
|
|
||
| namespace osp { | ||
|
|
||
|
|
||
| /** | ||
| * @class GreedyMetaScheduler | ||
| * @brief The GreedyMetaScheduler class represents a meta-scheduler that selects the best schedule produced from a list of | ||
| * added schedulers. | ||
| * | ||
| * This class inherits from the Scheduler class and implements the computeSchedule() and getScheduleName() methods. | ||
| * The computeSchedule() method iterates through a list of schedulers, computes a schedule using each one, | ||
| * and returns the schedule with the minimum cost. | ||
| */ | ||
| template<typename Graph_t> | ||
| class GreedyMetaScheduler : public Scheduler<Graph_t> { | ||
|
|
||
| Serial<Graph_t> serial_scheduler_; | ||
| std::vector<Scheduler<Graph_t>*> schedulers_; | ||
|
|
||
| static constexpr bool verbose = false; | ||
|
|
||
| public: | ||
| /** | ||
| * @brief Default constructor for MetaScheduler. | ||
| */ | ||
| GreedyMetaScheduler() : Scheduler<Graph_t>() {} | ||
|
|
||
| /** | ||
| * @brief Default destructor for MetaScheduler. | ||
| */ | ||
| ~GreedyMetaScheduler() override = default; | ||
|
|
||
| void addSerialScheduler() { schedulers_.push_back(&serial_scheduler_); } | ||
| void addScheduler(Scheduler<Graph_t> & s) { schedulers_.push_back(&s); } | ||
| void resetScheduler() { schedulers_.clear(); } | ||
|
|
||
| RETURN_STATUS computeSchedule(BspSchedule<Graph_t> &schedule) override { | ||
| if (schedule.getInstance().getArchitecture().numberOfProcessors() == 1) { | ||
| if constexpr (verbose) std::cout << "Using serial scheduler for P=1." << std::endl; | ||
| serial_scheduler_.computeSchedule(schedule); | ||
| return RETURN_STATUS::OSP_SUCCESS; | ||
| } | ||
|
|
||
| v_workw_t<Graph_t> best_schedule_cost = std::numeric_limits<v_workw_t<Graph_t>>::max(); | ||
| BspSchedule<Graph_t> current_schedule(schedule.getInstance()); | ||
|
|
||
| for (Scheduler<Graph_t>* scheduler : schedulers_) { | ||
| scheduler->computeSchedule(current_schedule); | ||
| BspScheduleCostEvaluator<Graph_t> evaluator(current_schedule); | ||
| const v_workw_t<Graph_t> schedule_cost = evaluator.computeCosts(); | ||
|
|
||
| if constexpr (verbose) std::cout << "Executed scheduler " << scheduler->getScheduleName() << ", costs: " << schedule_cost << ", nr. supersteps: " << current_schedule.numberOfSupersteps() << std::endl; | ||
|
|
||
| if (schedule_cost < best_schedule_cost) { | ||
| best_schedule_cost = schedule_cost; | ||
| schedule = current_schedule; | ||
| if constexpr (verbose) std::cout << "New best schedule!" << std::endl; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return RETURN_STATUS::OSP_SUCCESS; | ||
| } | ||
|
|
||
| std::string getScheduleName() const override { return "GreedyMetaScheduler"; } | ||
| }; | ||
|
|
||
| } // namespace osp | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.