Skip to content

Commit 66a2e93

Browse files
author
Christos Konstantinos Matzoros
committed
Fixes
1 parent ad3bad4 commit 66a2e93

File tree

7 files changed

+164
-99
lines changed

7 files changed

+164
-99
lines changed

include/osp/bsp/model/BspSchedule.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BspSchedule : public IBspSchedule<Graph_t>, public IBspScheduleEval<Graph_
6565
unsigned number_of_supersteps;
6666

6767
std::vector<unsigned> node_to_processor_assignment;
68-
std::vector<unsigned> node_to_superstep_assignment;
68+
std::vector<unsigned> node_to_superstep_assignment;
6969

7070
template<unsigned staleness>
7171
inline bool satisfies_precedence_constraints_staleness() const {

include/osp/bsp/scheduler/GreedySchedulers/GreedyVarianceSspScheduler.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ limitations under the License.
3131

3232
#include "MemoryConstraintModules.hpp"
3333
#include "osp/auxiliary/misc.hpp"
34-
#include "osp/bsp/model/BspSchedule.hpp"
35-
#include "osp/bsp/model/MaxBspSchedule.hpp"
36-
#include "osp/bsp/scheduler/Scheduler.hpp"
34+
#include "osp/bsp/scheduler/MaxBspScheduler.hpp"
3735
#include "osp/graph_algorithms/directed_graph_top_sort.hpp"
3836

3937
namespace osp {
@@ -45,7 +43,7 @@ namespace osp {
4543
* It computes schedules for BspInstance using variance-based priorities.
4644
*/
4745
template<typename Graph_t, typename MemoryConstraint_t = no_memory_constraint>
48-
class GreedyVarianceSspScheduler : public Scheduler<Graph_t> {
46+
class GreedyVarianceSspScheduler : public MaxBspScheduler<Graph_t> {
4947

5048
static_assert(is_computational_dag_v<Graph_t>, "GreedyVarianceSspScheduler can only be used with computational DAGs.");
5149

@@ -111,7 +109,7 @@ class GreedyVarianceSspScheduler : public Scheduler<Graph_t> {
111109

112110
struct VarianceCompare {
113111
bool operator()(const std::pair<VertexType, double> &lhs, const std::pair<VertexType, double> &rhs) const {
114-
return ((lhs.second > rhs.second) || ((lhs.second == rhs.second) && (lhs.first < rhs.first)));
112+
return ((lhs.second > rhs.second) || ((lhs.second >= rhs.second) && (lhs.first < rhs.first)));
115113
}
116114
};
117115

@@ -624,12 +622,10 @@ class GreedyVarianceSspScheduler : public Scheduler<Graph_t> {
624622
}
625623

626624
RETURN_STATUS computeSchedule(BspSchedule<Graph_t> &schedule) override {
627-
std::cout<< "BspSchedule"<< std::endl;
628625
return computeSspSchedule(schedule, 1U);
629626
}
630627

631628
RETURN_STATUS computeSchedule(MaxBspSchedule<Graph_t> &schedule) override {
632-
std::cout<< "MaxBspSchedule"<< std::endl;
633629
return computeSspSchedule(schedule, 2U);
634630
}
635631

include/osp/bsp/scheduler/MaxBspScheduler.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace osp {
3333
*/
3434
template<typename Graph_t>
3535
class MaxBspScheduler : public Scheduler<Graph_t> {
36+
public:
3637

3738
static_assert(is_computational_dag_v<Graph_t>, "BspSchedule can only be used with computational DAGs.");
3839

@@ -54,10 +55,11 @@ class MaxBspScheduler : public Scheduler<Graph_t> {
5455
return status;
5556
}
5657

57-
virtual RETURN_STATUS computeScheduleCS(BspScheduleCS<Graph_t> &schedule) {
58-
59-
auto result = computeSchedule(schedule);
58+
virtual RETURN_STATUS computeScheduleCS(BspScheduleCS<Graph_t> &schedule) override {
59+
MaxBspScheduleCS<Graph_t> tmpSchedule(schedule.getInstance());
60+
auto result = computeScheduleCS(tmpSchedule);
6061
if (result == RETURN_STATUS::OSP_SUCCESS || result == RETURN_STATUS::BEST_FOUND) {
62+
schedule = tmpSchedule;
6163
schedule.setAutoCommunicationSchedule();
6264
return result;
6365
} else {
@@ -73,15 +75,14 @@ class MaxBspScheduler : public Scheduler<Graph_t> {
7375
virtual RETURN_STATUS computeSchedule(MaxBspSchedule<Graph_t> &schedule) = 0;
7476

7577
virtual RETURN_STATUS computeScheduleCS(MaxBspScheduleCS<Graph_t> &schedule) {
76-
// Fix me todo
7778
auto result = computeSchedule(schedule);
7879
if (result == RETURN_STATUS::OSP_SUCCESS || result == RETURN_STATUS::BEST_FOUND) {
7980
// schedule.setAutoCommunicationSchedule();
8081
return result;
8182
} else {
8283
return RETURN_STATUS::ERROR;
8384
}
84-
}
85+
};
8586
};
8687

8788
} // namespace osp

include/osp/bsp/scheduler/Scheduler.hpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,6 @@ class Scheduler {
9494
*/
9595
virtual RETURN_STATUS computeSchedule(BspSchedule<Graph_t> &schedule) = 0;
9696

97-
/**
98-
* @brief Compute a Max-BSP (Stale Synchronous Parallel) schedule for the given instance.
99-
*
100-
* This overload allows schedulers that support the Max-BSP or SSP model
101-
* to implement asynchronous-like scheduling with configurable staleness.
102-
* By default, this base implementation throws an exception, since not all
103-
* schedulers provide Max-BSP support. Derived schedulers such as
104-
* GreedyVarianceSspScheduler should override this function to perform
105-
* their custom SSP scheduling logic.
106-
*
107-
* @param schedule Reference to a MaxBspSchedule object representing
108-
* the schedule to be computed and populated.
109-
* @return A RETURN_STATUS code indicating the success or failure of the computation.
110-
* @throws std::runtime_error If the scheduler does not implement Max-BSP scheduling.
111-
*/
112-
virtual RETURN_STATUS computeSchedule(MaxBspSchedule<Graph_t> &schedule) {
113-
(void)schedule;
114-
throw std::runtime_error("Not implemented for this scheduler");
115-
}
116-
11797
virtual RETURN_STATUS computeScheduleCS(BspScheduleCS<Graph_t> &schedule) {
11898

11999
auto result = computeSchedule(schedule);

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ endif()
122122

123123
_add_test( bsp_schedulers )
124124

125+
_add_test( max_bsp_schedulers )
126+
125127
_add_test( bsp_schedulers_mem_const )
126128

127129
_add_test( bsp_improvementschedulers )

tests/bsp_schedulers.cpp

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ limitations under the License.
3838
#include "osp/bsp/scheduler/LoadBalanceScheduler/VariancePartitioner.hpp"
3939
#include "osp/bsp/scheduler/LocalSearch/HillClimbing/hill_climbing.hpp"
4040
#include "osp/bsp/scheduler/Serial.hpp"
41-
#include "osp/bsp/scheduler/MaxBspScheduler.hpp"
4241
#include "osp/coarser/Sarkar/SarkarMul.hpp"
4342
#include "osp/coarser/SquashA/SquashAMul.hpp"
4443
#include "osp/graph_implementations/adj_list_impl/compact_sparse_graph.hpp"
@@ -149,51 +148,6 @@ void run_test_2(Scheduler<Graph_t> *test_scheduler) {
149148
}
150149
};
151150

152-
template<typename Graph_t>
153-
void run_test_max_bsp(Scheduler<Graph_t>* test_scheduler) {
154-
std::vector<std::string> filenames_graph = tiny_spaa_graphs();
155-
std::vector<std::string> filenames_architectures = test_architectures();
156-
157-
// Locate project root
158-
std::filesystem::path cwd = std::filesystem::current_path();
159-
while ((!cwd.empty()) && (cwd.filename() != "OneStopParallel")) {
160-
cwd = cwd.parent_path();
161-
}
162-
163-
for (auto& filename_graph : filenames_graph) {
164-
for (auto& filename_machine : filenames_architectures) {
165-
std::string name_graph = filename_graph.substr(filename_graph.find_last_of("/\\") + 1);
166-
name_graph = name_graph.substr(0, name_graph.find_last_of("."));
167-
std::string name_machine = filename_machine.substr(filename_machine.find_last_of("/\\") + 1);
168-
name_machine = name_machine.substr(0, name_machine.rfind("."));
169-
170-
std::cout << std::endl
171-
<< "Scheduler (MaxBsp): " << test_scheduler->getScheduleName() << std::endl
172-
<< "Graph: " << name_graph << std::endl
173-
<< "Architecture: " << name_machine << std::endl;
174-
175-
computational_dag_edge_idx_vector_impl_def_int_t graph;
176-
BspArchitecture<Graph_t> arch;
177-
178-
bool status_graph = file_reader::readGraph((cwd / filename_graph).string(), graph);
179-
bool status_architecture =
180-
file_reader::readBspArchitecture((cwd / filename_machine).string(), arch);
181-
182-
BOOST_REQUIRE_MESSAGE(status_graph, "Failed to read graph: " << filename_graph);
183-
BOOST_REQUIRE_MESSAGE(status_architecture, "Failed to read architecture: " << filename_machine);
184-
185-
BspInstance<Graph_t> instance(graph, arch);
186-
187-
MaxBspSchedule<Graph_t> schedule(instance);
188-
189-
const auto result = test_scheduler->computeSchedule(schedule);
190-
191-
BOOST_CHECK_EQUAL(result, RETURN_STATUS::OSP_SUCCESS);
192-
BOOST_CHECK(schedule.satisfiesPrecedenceConstraints());
193-
}
194-
}
195-
}
196-
197151
BOOST_AUTO_TEST_CASE(GreedyBspScheduler_test) {
198152

199153
GreedyBspScheduler<computational_dag_vector_impl_def_t> test;
@@ -407,23 +361,4 @@ BOOST_AUTO_TEST_CASE(SarkarMul_improver_test) {
407361
MultilevelCoarseAndSchedule<computational_dag_edge_idx_vector_impl_def_t, computational_dag_edge_idx_vector_impl_def_t> coarsen_test(sched, improver, ml_coarsen);
408362

409363
run_test(&coarsen_test);
410-
}
411-
412-
// Tests computeSchedule(BspSchedule&) → staleness = 1
413-
BOOST_AUTO_TEST_CASE(GreedyVarianceSspScheduler_test_vector_impl) {
414-
GreedyVarianceSspScheduler<computational_dag_vector_impl_def_t> test;
415-
run_test(&test);
416-
}
417-
418-
// Tests computeSchedule(BspSchedule&) → staleness = 1 (different graph impl)
419-
BOOST_AUTO_TEST_CASE(GreedyVarianceSspScheduler_test_edge_idx_impl) {
420-
GreedyVarianceSspScheduler<computational_dag_edge_idx_vector_impl_def_t> test;
421-
run_test(&test);
422-
}
423-
424-
// Tests computeSchedule(MaxBspSchedule&) → staleness = 2
425-
BOOST_AUTO_TEST_CASE(GreedyVarianceSspScheduler_MaxBspSchedule_large_test) {
426-
using Graph_t = computational_dag_edge_idx_vector_impl_def_int_t;
427-
GreedyVarianceSspScheduler<Graph_t> test;
428-
run_test_max_bsp(&test);
429-
}
364+
}

tests/max_bsp_schedulers.cpp

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
#define BOOST_TEST_MODULE BSP_SCHEDULERS
20+
#include <boost/test/unit_test.hpp>
21+
22+
#include <filesystem>
23+
#include <string>
24+
#include <vector>
25+
26+
27+
#include "osp/bsp/scheduler/GreedySchedulers/GreedyBspScheduler.hpp"
28+
#include "osp/bsp/scheduler/GreedySchedulers/GreedyVarianceSspScheduler.hpp"
29+
#include "osp/bsp/scheduler/Serial.hpp"
30+
#include "osp/bsp/scheduler/MaxBspScheduler.hpp"
31+
#include "osp/graph_implementations/adj_list_impl/compact_sparse_graph.hpp"
32+
#include "osp/graph_implementations/adj_list_impl/computational_dag_edge_idx_vector_impl.hpp"
33+
#include "osp/graph_implementations/adj_list_impl/computational_dag_vector_impl.hpp"
34+
#include "osp/auxiliary/io/arch_file_reader.hpp"
35+
#include "osp/auxiliary/io/hdag_graph_file_reader.hpp"
36+
#include "osp/auxiliary/io/general_file_reader.hpp"
37+
#include "test_graphs.hpp"
38+
39+
using namespace osp;
40+
41+
std::vector<std::string> test_architectures() { return {"data/machine_params/p3.arch"}; }
42+
43+
template<typename Graph_t>
44+
void run_test(Scheduler<Graph_t> *test_scheduler) {
45+
// static_assert(std::is_base_of<Scheduler, T>::value, "Class is not a scheduler!");
46+
std::vector<std::string> filenames_graph = tiny_spaa_graphs();
47+
std::vector<std::string> filenames_architectures = test_architectures();
48+
49+
// Getting root git directory
50+
std::filesystem::path cwd = std::filesystem::current_path();
51+
std::cout << cwd << std::endl;
52+
while ((!cwd.empty()) && (cwd.filename() != "OneStopParallel")) {
53+
cwd = cwd.parent_path();
54+
std::cout << cwd << std::endl;
55+
}
56+
57+
for (auto &filename_graph : filenames_graph) {
58+
for (auto &filename_machine : filenames_architectures) {
59+
std::string name_graph = filename_graph.substr(filename_graph.find_last_of("/\\") + 1);
60+
name_graph = name_graph.substr(0, name_graph.find_last_of("."));
61+
std::string name_machine = filename_machine.substr(filename_machine.find_last_of("/\\") + 1);
62+
name_machine = name_machine.substr(0, name_machine.rfind("."));
63+
64+
std::cout << std::endl << "Scheduler: " << test_scheduler->getScheduleName() << std::endl;
65+
std::cout << "Graph: " << name_graph << std::endl;
66+
std::cout << "Architecture: " << name_machine << std::endl;
67+
68+
BspInstance<Graph_t> instance;
69+
70+
bool status_graph = file_reader::readGraph((cwd / filename_graph).string(),
71+
instance.getComputationalDag());
72+
bool status_architecture = file_reader::readBspArchitecture((cwd / "data/machine_params/p3.arch").string(),
73+
instance.getArchitecture());
74+
75+
if (!status_graph || !status_architecture) {
76+
77+
std::cout << "Reading files failed." << std::endl;
78+
BOOST_CHECK(false);
79+
}
80+
81+
BspSchedule<Graph_t> schedule(instance);
82+
const auto result = test_scheduler->computeSchedule(schedule);
83+
84+
BOOST_CHECK_EQUAL(RETURN_STATUS::OSP_SUCCESS, result);
85+
BOOST_CHECK(schedule.satisfiesPrecedenceConstraints());
86+
}
87+
}
88+
};
89+
90+
template<typename Graph_t>
91+
void run_test_max_bsp(MaxBspScheduler<Graph_t>* test_scheduler) {
92+
std::vector<std::string> filenames_graph = tiny_spaa_graphs();
93+
std::vector<std::string> filenames_architectures = test_architectures();
94+
95+
// Locate project root
96+
std::filesystem::path cwd = std::filesystem::current_path();
97+
while ((!cwd.empty()) && (cwd.filename() != "OneStopParallel")) {
98+
cwd = cwd.parent_path();
99+
}
100+
101+
for (auto& filename_graph : filenames_graph) {
102+
for (auto& filename_machine : filenames_architectures) {
103+
std::string name_graph = filename_graph.substr(filename_graph.find_last_of("/\\") + 1);
104+
name_graph = name_graph.substr(0, name_graph.find_last_of("."));
105+
std::string name_machine = filename_machine.substr(filename_machine.find_last_of("/\\") + 1);
106+
name_machine = name_machine.substr(0, name_machine.rfind("."));
107+
108+
std::cout << std::endl
109+
<< "Scheduler (MaxBsp): " << test_scheduler->getScheduleName() << std::endl
110+
<< "Graph: " << name_graph << std::endl
111+
<< "Architecture: " << name_machine << std::endl;
112+
113+
computational_dag_edge_idx_vector_impl_def_int_t graph;
114+
BspArchitecture<Graph_t> arch;
115+
116+
bool status_graph = file_reader::readGraph((cwd / filename_graph).string(), graph);
117+
bool status_architecture =
118+
file_reader::readBspArchitecture((cwd / filename_machine).string(), arch);
119+
120+
BOOST_REQUIRE_MESSAGE(status_graph, "Failed to read graph: " << filename_graph);
121+
BOOST_REQUIRE_MESSAGE(status_architecture, "Failed to read architecture: " << filename_machine);
122+
123+
BspInstance<Graph_t> instance(graph, arch);
124+
125+
MaxBspSchedule<Graph_t> schedule(instance);
126+
127+
const auto result = test_scheduler->computeSchedule(schedule);
128+
129+
BOOST_CHECK_EQUAL(result, RETURN_STATUS::OSP_SUCCESS);
130+
BOOST_CHECK(schedule.satisfiesPrecedenceConstraints());
131+
}
132+
}
133+
}
134+
135+
// Tests computeSchedule(BspSchedule&) → staleness = 1
136+
BOOST_AUTO_TEST_CASE(GreedyVarianceSspScheduler_test_vector_impl) {
137+
GreedyVarianceSspScheduler<computational_dag_vector_impl_def_t> test;
138+
run_test(&test);
139+
}
140+
141+
// Tests computeSchedule(BspSchedule&) → staleness = 1 (different graph impl)
142+
BOOST_AUTO_TEST_CASE(GreedyVarianceSspScheduler_test_edge_idx_impl) {
143+
GreedyVarianceSspScheduler<computational_dag_edge_idx_vector_impl_def_t> test;
144+
run_test(&test);
145+
}
146+
147+
// Tests computeSchedule(MaxBspSchedule&) → staleness = 2
148+
BOOST_AUTO_TEST_CASE(GreedyVarianceSspScheduler_MaxBspSchedule_large_test) {
149+
GreedyVarianceSspScheduler<computational_dag_edge_idx_vector_impl_def_int_t> test;
150+
run_test_max_bsp(&test);
151+
}

0 commit comments

Comments
 (0)