Skip to content

Commit d794952

Browse files
Sarkar simple buffer merges (#28)
* homogeneous buffer merges * Added Buffer merge modes * small fix * simple in and out buffer merges * update multilevel Sarkar * Added reverse Fan Buffer to Full Buffer logic
1 parent 24698a8 commit d794952

File tree

12 files changed

+545
-200
lines changed

12 files changed

+545
-200
lines changed

apps/coarser_plotter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ int main(int argc, char *argv[]) {
5151
params.commCostVec = std::vector<v_workw_t<Graph_t>>({1, 2, 5, 10, 20, 50, 100, 200, 500, 1000});
5252
params.max_num_iteration_without_changes = 3;
5353
params.leniency = 0.005;
54-
// params.maxWeight = 15000;
54+
params.maxWeight = 15000;
55+
params.smallWeightThreshold = 4000;
56+
params.buffer_merge_mode = SarkarParams::BufferMergeMode::FULL;
5557

5658
SarkarMul<Graph_t, Graph_t> coarser;
5759
coarser.setParameters(params);

apps/test_suite_runner/StringToScheduler/get_coarser.hpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ get_coarser_by_name(const ConfigParser &, const boost::property_tree::ptree &coa
148148
if (auto params_opt = coarser_algorithm.get_child_optional("parameters")) {
149149
const auto &params_pt = params_opt.get();
150150
params.commCost = params_pt.get_optional<v_workw_t<Graph_t_in>>("commCost").value_or(params.commCost);
151+
params.maxWeight = params_pt.get_optional<v_workw_t<Graph_t_in>>("maxWeight").value_or(params.maxWeight);
152+
params.smallWeightThreshold = params_pt.get_optional<v_workw_t<Graph_t_in>>("smallWeightThreshold").value_or(params.smallWeightThreshold);
151153
params.useTopPoset = params_pt.get_optional<bool>("useTopPoset").value_or(params.useTopPoset);
154+
params.geomDecay = params_pt.get_optional<double>("geomDecay").value_or(params.geomDecay);
155+
params.leniency = params_pt.get_optional<double>("leniency").value_or(params.leniency);
152156

153157
if (auto mode_str_opt = params_pt.get_optional<std::string>("mode")) {
154158
const std::string &mode_str = mode_str_opt.get();
@@ -161,8 +165,9 @@ get_coarser_by_name(const ConfigParser &, const boost::property_tree::ptree &coa
161165
else if (mode_str == "LEVEL_ODD") params.mode = SarkarParams::Mode::LEVEL_ODD;
162166
else if (mode_str == "FAN_IN_BUFFER") params.mode = SarkarParams::Mode::FAN_IN_BUFFER;
163167
else if (mode_str == "FAN_OUT_BUFFER") params.mode = SarkarParams::Mode::FAN_OUT_BUFFER;
168+
else if (mode_str == "HOMOGENEOUS_BUFFER") params.mode = SarkarParams::Mode::HOMOGENEOUS_BUFFER;
164169
else throw std::invalid_argument("Invalid Sarkar mode: " + mode_str
165-
+ "!\nChoose from: LINES, FAN_IN_FULL, FAN_IN_PARTIAL, FAN_OUT_FULL, FAN_OUT_PARTIAL, LEVEL_EVEN, LEVEL_ODD, FAN_IN_BUFFER, FAN_OUT_BUFFER.");
170+
+ "!\nChoose from: LINES, FAN_IN_FULL, FAN_IN_PARTIAL, FAN_OUT_FULL, FAN_OUT_PARTIAL, LEVEL_EVEN, LEVEL_ODD, FAN_IN_BUFFER, FAN_OUT_BUFFER, HOMOGENEOUS_BUFFER.");
166171
}
167172
}
168173
return std::make_unique<Sarkar<Graph_t_in, Graph_t_out>>(params);
@@ -216,11 +221,22 @@ get_multilevel_coarser_by_name(const ConfigParser &, const boost::property_tree:
216221
}
217222
ml_params.maxWeight =
218223
params_pt.get_optional<v_workw_t<Graph_t_in>>("maxWeight").value_or(ml_params.maxWeight);
224+
ml_params.smallWeightThreshold =
225+
params_pt.get_optional<v_workw_t<Graph_t_in>>("smallWeightThreshold").value_or(ml_params.smallWeightThreshold);
219226
ml_params.max_num_iteration_without_changes =
220227
params_pt.get_optional<unsigned>("max_num_iteration_without_changes")
221228
.value_or(ml_params.max_num_iteration_without_changes);
222-
ml_params.use_buffer_merge =
223-
params_pt.get_optional<bool>("use_buffer_merge").value_or(ml_params.use_buffer_merge);
229+
230+
if (auto mode_str_opt = params_pt.get_optional<std::string>("buffer_merge_mode")) {
231+
const std::string &mode_str = mode_str_opt.get();
232+
if (mode_str == "OFF") ml_params.buffer_merge_mode = SarkarParams::BufferMergeMode::OFF;
233+
else if (mode_str == "FAN_IN") ml_params.buffer_merge_mode = SarkarParams::BufferMergeMode::FAN_IN;
234+
else if (mode_str == "FAN_OUT") ml_params.buffer_merge_mode = SarkarParams::BufferMergeMode::FAN_OUT;
235+
else if (mode_str == "HOMOGENEOUS") ml_params.buffer_merge_mode = SarkarParams::BufferMergeMode::HOMOGENEOUS;
236+
else if (mode_str == "FULL") ml_params.buffer_merge_mode = SarkarParams::BufferMergeMode::FULL;
237+
else throw std::invalid_argument("Invalid Sarkar Buffer Merge mode: " + mode_str
238+
+ "!\nChoose from: OFF, FAN_IN, FAN_OUT, HOMOGENEOUS, FULL.");
239+
}
224240
}
225241

226242
coarser->setParameters(ml_params);

include/osp/auxiliary/datastructures/union_find.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ struct union_find_object {
4141
: name(name_), parent_index(parent_index_), weight(weight_), memory(memory_) {
4242
rank = 1;
4343
}
44+
45+
union_find_object(const union_find_object &other) = default;
46+
union_find_object& operator=(const union_find_object &other) = default;
4447
};
4548

4649
/// @brief Class to execute a union-find algorithm
@@ -387,6 +390,9 @@ class Union_Find_Universe {
387390
const std::vector<memw_t> &memories) {
388391
add_object(names, weights, memories);
389392
}
393+
394+
Union_Find_Universe(const Union_Find_Universe &other) = default;
395+
Union_Find_Universe& operator=(const Union_Find_Universe &other) = default;
390396
};
391397

392398
template<typename Graph_t>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright 2025 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, Christos Matzoros, Pal Andras Papp, Raphael S. Steiner
17+
*/
18+
#pragma once
19+
20+
#include <cassert>
21+
#include <cmath>
22+
#include <limits>
23+
#include <type_traits>
24+
#include <vector>
25+
26+
namespace osp {
27+
28+
template<typename integral_type>
29+
integral_type intSqrtFloor(integral_type num) {
30+
static_assert(std::is_integral_v<integral_type>);
31+
assert(num > 0);
32+
33+
integral_type sqrt = 1;
34+
integral_type numCopy = num;
35+
while (numCopy >= 4) {
36+
sqrt *= 2;
37+
numCopy /= 4;
38+
}
39+
integral_type power2 = sqrt / 2;
40+
while (power2 > 0) {
41+
integral_type sum = sqrt + power2;
42+
if (sum * sum <= num) {
43+
sqrt = sum;
44+
}
45+
power2 /= 2;
46+
}
47+
48+
return sqrt;
49+
}
50+
51+
52+
template<typename integral_type>
53+
std::vector<integral_type> divisorsList(integral_type num) {
54+
static_assert(std::is_integral_v<integral_type>);
55+
assert(num > 0);
56+
57+
std::vector<integral_type> divs;
58+
59+
integral_type ub = intSqrtFloor<integral_type>(num);
60+
for (integral_type div = 1; div <= ub; ++div) {
61+
if (num % div == 0) {
62+
divs.emplace_back(div);
63+
}
64+
}
65+
for (std::size_t indx = divs.back() * divs.back() == num ? divs.size() - 2U : divs.size() - 1U; indx != std::numeric_limits<std::size_t>::max(); --indx) {
66+
divs.emplace_back(num / divs[indx]);
67+
}
68+
69+
return divs;
70+
}
71+
72+
} // end namespace osp
File renamed without changes.

0 commit comments

Comments
 (0)