Skip to content

Commit 1ad1f39

Browse files
authored
Kl updates (#50)
* compute_comm_affinity added test kl_bsp_cost more tests for max_comm_datastructure update update node affinity added test for affinity update test update affinity tests affinity tests update update small performance optimization more test, pre move data update pre_move_comm_data new unit test update test update tests update update update lambda container, bsp_cost function cost function correction max_comm_datastructures fix fix kl_bsp_cost test update update update update more tests update update comm update update update update update update update added more tests, cmpute working update comm affinity implemenation comm_affinity optimizations enable tests update test debug output update update update update unit tests passing cleaning update datastructure update update numa added mt test * adding more new_nodes after move comments update update * simplification
1 parent 1c9c29e commit 1ad1f39

17 files changed

+5257
-963
lines changed

include/osp/auxiliary/io/hdag_graph_file_reader.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ limitations under the License.
2929
#include "osp/concepts/computational_dag_concept.hpp"
3030
#include "osp/graph_algorithms/directed_graph_util.hpp"
3131
#include "osp/auxiliary/io/filepath_checker.hpp"
32+
#include "osp/concepts/constructable_computational_dag_concept.hpp"
3233

3334
namespace osp {
3435
namespace file_reader {

include/osp/bsp/scheduler/LocalSearch/KernighanLin_v2/comm_cost_modules/comm_cost_policies.hpp

Lines changed: 457 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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 <algorithm>
22+
#include <cassert>
23+
#include <vector>
24+
25+
namespace osp {
26+
27+
template<typename T>
28+
struct DefaultHasEntry {
29+
static inline bool has_entry(const T &val) { return val != 0; }
30+
};
31+
32+
template<typename T>
33+
struct DefaultHasEntry<std::vector<T>> {
34+
static inline bool has_entry(const std::vector<T> &val) { return !val.empty(); }
35+
};
36+
37+
/**
38+
* @brief Generic container for tracking child processor assignments in a BSP schedule using vectors.
39+
*
40+
* This structure tracks information about children assigned to each processor.
41+
* It uses a 2D vector for dense data.
42+
*/
43+
template<typename vertex_idx_t, typename ValueType = unsigned, typename HasEntry = DefaultHasEntry<ValueType>>
44+
struct generic_lambda_vector_container {
45+
46+
/**
47+
* @brief Range adapter for iterating over non-zero/non-empty processor entries.
48+
*/
49+
class lambda_vector_range {
50+
private:
51+
const std::vector<ValueType> &vec_;
52+
53+
public:
54+
class lambda_vector_iterator {
55+
using iterator_category = std::input_iterator_tag;
56+
using value_type = std::pair<unsigned, ValueType>;
57+
using difference_type = std::ptrdiff_t;
58+
using pointer = value_type *;
59+
using reference = value_type &;
60+
61+
private:
62+
const std::vector<ValueType> &vec_;
63+
unsigned index_;
64+
65+
public:
66+
lambda_vector_iterator(const std::vector<ValueType> &vec) : vec_(vec), index_(0) {
67+
while (index_ < vec_.size() && !HasEntry::has_entry(vec_[index_])) {
68+
++index_;
69+
}
70+
}
71+
72+
lambda_vector_iterator(const std::vector<ValueType> &vec, unsigned index) : vec_(vec), index_(index) {}
73+
74+
lambda_vector_iterator &operator++() {
75+
++index_;
76+
while (index_ < vec_.size() && !HasEntry::has_entry(vec_[index_])) {
77+
++index_;
78+
}
79+
return *this;
80+
}
81+
82+
value_type operator*() const { return std::make_pair(index_, vec_[index_]); }
83+
84+
bool operator==(const lambda_vector_iterator &other) const { return index_ == other.index_; }
85+
bool operator!=(const lambda_vector_iterator &other) const { return !(*this == other); }
86+
};
87+
88+
lambda_vector_range(const std::vector<ValueType> &vec) : vec_(vec) {}
89+
90+
lambda_vector_iterator begin() { return lambda_vector_iterator(vec_); }
91+
lambda_vector_iterator end() { return lambda_vector_iterator(vec_, static_cast<unsigned>(vec_.size())); }
92+
};
93+
94+
/// 2D vector: for each node, stores processor assignment info
95+
std::vector<std::vector<ValueType>> node_lambda_vec;
96+
97+
/// Number of processors in the system
98+
unsigned num_procs_ = 0;
99+
100+
inline void initialize(const vertex_idx_t num_vertices, const unsigned num_procs) {
101+
node_lambda_vec.assign(num_vertices, std::vector<ValueType>(num_procs));
102+
num_procs_ = num_procs;
103+
}
104+
105+
inline void reset_node(const vertex_idx_t node) { node_lambda_vec[node].assign(num_procs_, ValueType()); }
106+
107+
inline void clear() { node_lambda_vec.clear(); }
108+
109+
inline bool has_proc_entry(const vertex_idx_t node, const unsigned proc) const {
110+
return HasEntry::has_entry(node_lambda_vec[node][proc]);
111+
}
112+
113+
inline ValueType &get_proc_entry(const vertex_idx_t node, const unsigned proc) {
114+
return node_lambda_vec[node][proc];
115+
}
116+
117+
inline ValueType get_proc_entry(const vertex_idx_t node, const unsigned proc) const {
118+
return node_lambda_vec[node][proc];
119+
}
120+
121+
inline auto iterate_proc_entries(const vertex_idx_t node) { return lambda_vector_range(node_lambda_vec[node]); }
122+
};
123+
124+
} // namespace osp

0 commit comments

Comments
 (0)