Skip to content

Commit a5ce2ce

Browse files
committed
Squashed commit of the following:
commit 4b17a5a Author: tonibohnlein <[email protected]> Date: Fri Oct 31 09:52:51 2025 +0100 fixed tests commit dfbd33d Author: tonibohnlein <[email protected]> Date: Thu Oct 30 16:16:51 2025 +0100 trimed scheduler flag fix commit 3ee5e0a Author: tonibohnlein <[email protected]> Date: Thu Oct 30 15:33:20 2025 +0100 revision adaptive symmetry commit 1155c2f Author: tonibohnlein <[email protected]> Date: Thu Oct 30 10:46:43 2025 +0100 added adaptive symmetry commit 3b74770 Author: tonibohnlein <[email protected]> Date: Wed Oct 29 16:28:15 2025 +0100 hacky eft change commit 6cfd05a Author: tonibohnlein <[email protected]> Date: Wed Oct 29 15:21:39 2025 +0100 update etf scheduler max_proc added to eft commit 8af812c Author: tonibohnlein <[email protected]> Date: Wed Oct 29 11:55:31 2025 +0100 added BspScheduleCostEvaluator commit 1f440d0 Author: tonibohnlein <[email protected]> Date: Wed Oct 29 11:10:36 2025 +0100 added GreedyMetaScheduler commit 336a5dc Author: tonibohnlein <[email protected]> Date: Tue Oct 28 22:43:24 2025 +0100 serial for node types update update bugfix includes commit eeb1caa Author: tonibohnlein <[email protected]> Date: Tue Oct 28 14:32:57 2025 +0100 added architecture getProcessorIdsByType, TrimmedSubgraphScheduler update update update update update update update update update commit ecc6f56 Author: tonibohnlein <[email protected]> Date: Tue Oct 28 11:07:42 2025 +0100 bugfix commit 18fac57 Author: tonibohnlein <[email protected]> Date: Tue Oct 28 11:00:34 2025 +0100 bugfix commit 61539d3 Author: tonibohnlein <[email protected]> Date: Tue Oct 28 10:59:47 2025 +0100 Revert "revision trim reverse" This reverts commit 3f0681d. commit 3f0681d Author: tonibohnlein <[email protected]> Date: Tue Oct 28 10:23:36 2025 +0100 revision trim reverse commit 6a82b32 Author: tonibohnlein <[email protected]> Date: Tue Oct 28 09:11:36 2025 +0100 revision OrbitGraphProcessor update fix tests commit 9c097ed Author: tonibohnlein <[email protected]> Date: Mon Oct 27 18:57:28 2025 +0100 more parameter exposed, revision trim commit a7e0a63 Author: tonibohnlein <[email protected]> Date: Mon Oct 27 15:23:28 2025 +0100 kl parameter setter commit c40f9d0 Author: tonibohnlein <[email protected]> Date: Mon Oct 27 14:02:59 2025 +0100 added precom_bwd_merkle_node_hash_func commit e49b2ff Author: tonibohnlein <[email protected]> Date: Mon Oct 27 13:16:32 2025 +0100 reverse confusion commit 62cd1a2 Author: tonibohnlein <[email protected]> Date: Mon Oct 27 12:59:34 2025 +0100 bugfix commit 24df7dc Author: tonibohnlein <[email protected]> Date: Mon Oct 27 12:51:55 2025 +0100 bugfix commit 97b4026 Author: tonibohnlein <[email protected]> Date: Mon Oct 27 12:48:17 2025 +0100 hash size_t, printing of block graph commit 83f1604 Author: tonibohnlein <[email protected]> Date: Sun Oct 26 18:07:34 2025 +0100 added debugger checks commit 2936740 Author: tonibohnlein <[email protected]> Date: Sun Oct 26 17:55:33 2025 +0100 update merge rules commit 9df102c Author: tonibohnlein <[email protected]> Date: Sun Oct 26 15:14:24 2025 +0100 bugfix commit 6c0e468 Author: tonibohnlein <[email protected]> Date: Sun Oct 26 10:52:53 2025 +0100 memorize edges commit 34c6a9c Author: tonibohnlein <[email protected]> Date: Sun Oct 26 10:23:17 2025 +0100 refactor OrbitGraphProcessor commit 685f54d Author: tonibohnlein <[email protected]> Date: Sun Oct 26 10:02:58 2025 +0100 revision merge rules commit 713ca73 Author: tonibohnlein <[email protected]> Date: Sat Oct 25 20:34:59 2025 +0200 bugfix commit 6851ea3 Author: tonibohnlein <[email protected]> Date: Sat Oct 25 20:27:23 2025 +0200 revision orbit processor commit 1056477 Author: tonibohnlein <[email protected]> Date: Sat Oct 25 12:18:49 2025 +0200 print orbits commit 59186ab Author: tonibohnlein <[email protected]> Date: Sat Oct 25 11:37:33 2025 +0200 fix commit bc5e7fb Author: tonibohnlein <[email protected]> Date: Fri Oct 24 21:48:31 2025 +0200 added HashComputer commit de59faa Author: tonibohnlein <[email protected]> Date: Fri Oct 24 14:24:19 2025 +0200 revise bwd merkle hash computer, orbit error commit f6b0794 Author: tonibohnlein <[email protected]> Date: Fri Oct 24 13:51:45 2025 +0200 kl mt improver seed constructor commit 6b78161 Author: tonibohnlein <[email protected]> Date: Fri Oct 24 09:24:56 2025 +0200 greedy children commit cb4be05 Author: tonibohnlein <[email protected]> Date: Thu Oct 23 18:17:51 2025 +0200 test update commit 80a0497 Author: tonibohnlein <[email protected]> Date: Thu Oct 23 18:14:18 2025 +0200 bug fix
1 parent 9a42108 commit a5ce2ce

24 files changed

+2041
-473
lines changed

include/osp/auxiliary/hash_util.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ struct uniform_node_hash_func {
2828
result_type operator()(const VertexType& ) { return defautlVal; }
2929
};
3030

31+
32+
template<typename VertexType>
33+
struct vector_node_hash_func {
34+
const std::vector<std::size_t>& node_hashes_;
35+
vector_node_hash_func(const std::vector<std::size_t>& node_hashes) : node_hashes_(node_hashes) {}
36+
using result_type = std::size_t;
37+
result_type operator()(const VertexType& v) const { return node_hashes_[v]; }
38+
};
39+
3140
template<class T>
3241
void hash_combine(std::size_t &seed, const T &v) {
3342
std::hash<T> hasher;

include/osp/bsp/model/BspArchitecture.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,14 @@ class BspArchitecture {
651651
}
652652
}
653653

654+
std::vector<std::vector<unsigned>> getProcessorIdsByType() const {
655+
std::vector<std::vector<unsigned>> processor_ids_by_type(number_of_processor_types);
656+
for (unsigned i = 0; i < numberOfProcessors(); ++i) {
657+
processor_ids_by_type[processorType(i)].push_back(i);
658+
}
659+
return processor_ids_by_type;
660+
}
661+
654662
inline unsigned getNumberOfProcessorTypes() const { return number_of_processor_types; };
655663

656664
inline MEMORY_CONSTRAINT_TYPE getMemoryConstraintType() const { return memory_const_type; }
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
Copyright 2024 Huawei Technologies Co., Ltd.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
@author Toni Boehnlein, Benjamin Lozes, Pal Andras Papp, Raphael S. Steiner
17+
*/
18+
19+
#pragma once
20+
21+
#include "BspSchedule.hpp"
22+
23+
namespace osp {
24+
25+
/**
26+
* @class BspScheduleCostEvaluator
27+
* @brief A class to compute various cost functions for a BspSchedule.
28+
*
29+
* This class wraps a BspSchedule by reference to avoid unnecessary copies
30+
* while providing an interface to compute different cost models.
31+
*/
32+
template<typename Graph_t>
33+
class BspScheduleCostEvaluator {
34+
35+
static_assert(is_computational_dag_v<Graph_t>, "BspScheduleCostEvaluator can only be used with computational DAGs.");
36+
static_assert(std::is_same_v<v_workw_t<Graph_t>, v_commw_t<Graph_t>>,
37+
"BspScheduleCostEvaluator requires work and comm. weights to have the same type.");
38+
39+
protected:
40+
const BspSchedule<Graph_t>& schedule;
41+
const BspInstance<Graph_t>& instance;
42+
43+
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 {
44+
const unsigned number_of_supersteps = schedule.numberOfSupersteps();
45+
for (const auto &node : instance.vertices()) {
46+
47+
std::vector<unsigned> step_needed(instance.numberOfProcessors(), number_of_supersteps);
48+
for (const auto &target : instance.getComputationalDag().children(node)) {
49+
50+
if (schedule.assignedProcessor(node) != schedule.assignedProcessor(target)) {
51+
step_needed[schedule.assignedProcessor(target)] = std::min(
52+
step_needed[schedule.assignedProcessor(target)], schedule.assignedSuperstep(target));
53+
}
54+
}
55+
56+
for (unsigned proc = 0; proc < instance.numberOfProcessors(); proc++) {
57+
58+
if (step_needed[proc] < number_of_supersteps) {
59+
60+
send[schedule.assignedProcessor(node)][step_needed[proc] - 1] +=
61+
instance.sendCosts(schedule.assignedProcessor(node), proc) *
62+
instance.getComputationalDag().vertex_comm_weight(node);
63+
64+
rec[proc][step_needed[proc] - 1] += instance.sendCosts(schedule.assignedProcessor(node), proc) *
65+
instance.getComputationalDag().vertex_comm_weight(node);
66+
}
67+
}
68+
}
69+
}
70+
71+
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 {
72+
const unsigned number_of_supersteps = schedule.numberOfSupersteps();
73+
std::vector<v_commw_t<Graph_t>> max_comm_per_step(number_of_supersteps, 0);
74+
for (unsigned step = 0; step < number_of_supersteps; step++) {
75+
v_commw_t<Graph_t> max_send = 0;
76+
v_commw_t<Graph_t> max_rec = 0;
77+
78+
for (unsigned proc = 0; proc < instance.numberOfProcessors(); proc++) {
79+
if (max_send < send[proc][step])
80+
max_send = send[proc][step];
81+
if (max_rec < rec[proc][step])
82+
max_rec = rec[proc][step];
83+
}
84+
max_comm_per_step[step] = std::max(max_send, max_rec) * instance.communicationCosts();
85+
}
86+
return max_comm_per_step;
87+
}
88+
89+
std::vector<v_workw_t<Graph_t>> compute_max_work_per_step_helper() const {
90+
const unsigned number_of_supersteps = schedule.numberOfSupersteps();
91+
std::vector<std::vector<v_workw_t<Graph_t>>> work = std::vector<std::vector<v_workw_t<Graph_t>>>(
92+
number_of_supersteps, std::vector<v_workw_t<Graph_t>>(instance.numberOfProcessors(), 0));
93+
for (const auto &node : instance.vertices()) {
94+
work[schedule.assignedSuperstep(node)][schedule.assignedProcessor(node)] +=
95+
instance.getComputationalDag().vertex_work_weight(node);
96+
}
97+
98+
std::vector<v_workw_t<Graph_t>> max_work_per_step(number_of_supersteps, 0);
99+
for (unsigned step = 0; step < number_of_supersteps; step++) {
100+
v_workw_t<Graph_t> max_work = 0;
101+
for (unsigned proc = 0; proc < instance.numberOfProcessors(); proc++) {
102+
if (max_work < work[step][proc]) {
103+
max_work = work[step][proc];
104+
}
105+
}
106+
107+
max_work_per_step[step] = max_work;
108+
}
109+
110+
return max_work_per_step;
111+
}
112+
113+
public:
114+
/**
115+
* @brief Construct a new Bsp Schedule Cost Evaluator object.
116+
*
117+
* @param sched The BspSchedule to evaluate.
118+
*/
119+
BspScheduleCostEvaluator(const BspSchedule<Graph_t>& sched) : schedule(sched), instance(sched.getInstance()) {}
120+
121+
/**
122+
* @brief Computes the communication costs using the lazy sending model.
123+
*
124+
* In the lazy sending model, data is sent in the superstep immediately
125+
* preceding the superstep where it is first needed.
126+
*
127+
* @return The lazy communication costs.
128+
*/
129+
v_commw_t<Graph_t> compute_lazy_communication_costs() const {
130+
131+
const unsigned number_of_supersteps = schedule.numberOfSupersteps();
132+
133+
std::vector<std::vector<v_commw_t<Graph_t>>> rec(instance.numberOfProcessors(),
134+
std::vector<v_commw_t<Graph_t>>(number_of_supersteps, 0));
135+
std::vector<std::vector<v_commw_t<Graph_t>>> send(instance.numberOfProcessors(),
136+
std::vector<v_commw_t<Graph_t>>(number_of_supersteps, 0));
137+
138+
compute_lazy_communication_costs_helper(rec, send);
139+
const std::vector<v_commw_t<Graph_t>> max_comm_per_step = compute_max_comm_per_step_helper(rec, send);
140+
141+
v_commw_t<Graph_t> costs = 0;
142+
for (unsigned step = 0; step < number_of_supersteps; step++) {
143+
const auto step_comm_cost = max_comm_per_step[step];
144+
costs += step_comm_cost;
145+
146+
costs += instance.synchronisationCosts();
147+
148+
}
149+
150+
return costs;
151+
}
152+
153+
/**
154+
* @brief Computes the total work costs of the schedule.
155+
*
156+
* The work cost is the sum of the maximum work done in each superstep
157+
* across all processors.
158+
*
159+
* @return The total work costs.
160+
*/
161+
v_workw_t<Graph_t> computeWorkCosts() const {
162+
const std::vector<v_workw_t<Graph_t>> work_per_step = compute_max_work_per_step_helper();
163+
return std::accumulate(work_per_step.begin(), work_per_step.end(), static_cast<v_workw_t<Graph_t>>(0));
164+
}
165+
166+
/**
167+
* @brief Computes the total costs of the schedule using the lazy communication model.
168+
*
169+
* @return The total costs.
170+
*/
171+
v_workw_t<Graph_t> computeCosts() const { return compute_lazy_communication_costs() + computeWorkCosts(); }
172+
};
173+
174+
} // namespace osp
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2024 Huawei Technologies Co., Ltd.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
@author Toni Boehnlein, Benjamin Lozes, Pal Andras Papp, Raphael S. Steiner
17+
*/
18+
19+
#pragma once
20+
21+
#include "osp/bsp/model/BspScheduleCostEvaluator.hpp"
22+
#include "osp/bsp/scheduler/Scheduler.hpp"
23+
#include "osp/bsp/scheduler/Serial.hpp"
24+
#include <vector>
25+
#include <string>
26+
27+
namespace osp {
28+
29+
template<typename Graph_t>
30+
class GreedyMetaScheduler : public Scheduler<Graph_t> {
31+
32+
Serial<Graph_t> serial_scheduler_;
33+
std::vector<Scheduler<Graph_t>*> schedulers_;
34+
35+
static constexpr bool verbose = true;
36+
37+
public:
38+
/**
39+
* @brief Default constructor for MetaScheduler.
40+
*/
41+
GreedyMetaScheduler() : Scheduler<Graph_t>() {}
42+
43+
/**
44+
* @brief Default destructor for MetaScheduler.
45+
*/
46+
~GreedyMetaScheduler() override = default;
47+
48+
void addSerialScheduler() { schedulers_.push_back(&serial_scheduler_); }
49+
void addScheduler(Scheduler<Graph_t> & s) { schedulers_.push_back(&s); }
50+
void resetScheduler() { schedulers_.clear(); }
51+
52+
RETURN_STATUS computeSchedule(BspSchedule<Graph_t> &schedule) override {
53+
if (schedule.getInstance().getArchitecture().numberOfProcessors() == 1) {
54+
if constexpr (verbose) std::cout << "Using serial scheduler for P=1." << std::endl;
55+
serial_scheduler_.computeSchedule(schedule);
56+
return RETURN_STATUS::OSP_SUCCESS;
57+
}
58+
59+
v_workw_t<Graph_t> best_schedule_cost = std::numeric_limits<v_workw_t<Graph_t>>::max();
60+
BspSchedule<Graph_t> current_schedule(schedule.getInstance());
61+
62+
for (Scheduler<Graph_t>* scheduler : schedulers_) {
63+
scheduler->computeSchedule(current_schedule);
64+
BspScheduleCostEvaluator<Graph_t> evaluator(current_schedule);
65+
const v_workw_t<Graph_t> schedule_cost = evaluator.computeCosts();
66+
67+
if constexpr (verbose) std::cout << "Executed scheduler " << scheduler->getScheduleName() << ", costs: " << schedule_cost << ", nr. supersteps: " << current_schedule.numberOfSupersteps() << std::endl;
68+
69+
if (schedule_cost < best_schedule_cost) {
70+
best_schedule_cost = schedule_cost;
71+
schedule = current_schedule;
72+
if constexpr (verbose) std::cout << "New best schedule!" << std::endl;
73+
}
74+
75+
}
76+
77+
return RETURN_STATUS::OSP_SUCCESS;
78+
}
79+
80+
std::string getScheduleName() const override { return "GreedyMetaScheduler"; }
81+
};
82+
83+
} // namespace osp

include/osp/bsp/scheduler/LocalSearch/KernighanLin_v2/kl_improver.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,9 +1067,8 @@ class kl_improver : public ImprovementScheduler<Graph_t> {
10671067
return improveSchedule(schedule);
10681068
}
10691069

1070-
void set_compute_with_time_limit(bool compute_with_time_limit_) {
1071-
compute_with_time_limit = compute_with_time_limit_;
1072-
}
1070+
virtual void setTimeQualityParameter(const double time_quality) { this->parameters.time_quality = time_quality; }
1071+
virtual void setSuperstepRemoveStrengthParameter(const double superstep_remove_strength) { this->parameters.superstep_remove_strength = superstep_remove_strength; }
10731072

10741073
virtual std::string getScheduleName() const {
10751074
return "kl_improver_" + comm_cost_f.name();

include/osp/bsp/scheduler/LocalSearch/KernighanLin_v2/kl_improver_mt.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ class kl_improver_mt : public kl_improver<Graph_t, comm_cost_function_t, MemoryC
9999

100100
public:
101101

102-
kl_improver_mt() : kl_improver<Graph_t, comm_cost_function_t, MemoryConstraint_t, window_size, cost_t>() { }
102+
kl_improver_mt() : kl_improver<Graph_t, comm_cost_function_t, MemoryConstraint_t, window_size, cost_t>() {}
103+
explicit kl_improver_mt(unsigned seed) : kl_improver<Graph_t, comm_cost_function_t, MemoryConstraint_t, window_size, cost_t>(seed) {}
103104
virtual ~kl_improver_mt() = default;
104105

105106
void set_max_num_threads(const unsigned num_threads) {

0 commit comments

Comments
 (0)