-
Notifications
You must be signed in to change notification settings - Fork 1
Kl updates #50
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
Kl updates #50
Changes from all commits
Commits
Show all changes
3 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
457 changes: 457 additions & 0 deletions
457
...de/osp/bsp/scheduler/LocalSearch/KernighanLin_v2/comm_cost_modules/comm_cost_policies.hpp
Large diffs are not rendered by default.
Oops, something went wrong.
124 changes: 124 additions & 0 deletions
124
.../bsp/scheduler/LocalSearch/KernighanLin_v2/comm_cost_modules/generic_lambda_container.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,124 @@ | ||
| /* | ||
| 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 <algorithm> | ||
| #include <cassert> | ||
| #include <vector> | ||
|
|
||
| namespace osp { | ||
|
|
||
| template<typename T> | ||
| struct DefaultHasEntry { | ||
| static inline bool has_entry(const T &val) { return val != 0; } | ||
| }; | ||
|
|
||
| template<typename T> | ||
| struct DefaultHasEntry<std::vector<T>> { | ||
| static inline bool has_entry(const std::vector<T> &val) { return !val.empty(); } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Generic container for tracking child processor assignments in a BSP schedule using vectors. | ||
| * | ||
| * This structure tracks information about children assigned to each processor. | ||
| * It uses a 2D vector for dense data. | ||
| */ | ||
| template<typename vertex_idx_t, typename ValueType = unsigned, typename HasEntry = DefaultHasEntry<ValueType>> | ||
| struct generic_lambda_vector_container { | ||
|
|
||
| /** | ||
| * @brief Range adapter for iterating over non-zero/non-empty processor entries. | ||
| */ | ||
| class lambda_vector_range { | ||
| private: | ||
| const std::vector<ValueType> &vec_; | ||
|
|
||
| public: | ||
| class lambda_vector_iterator { | ||
| using iterator_category = std::input_iterator_tag; | ||
| using value_type = std::pair<unsigned, ValueType>; | ||
| using difference_type = std::ptrdiff_t; | ||
| using pointer = value_type *; | ||
| using reference = value_type &; | ||
|
|
||
| private: | ||
| const std::vector<ValueType> &vec_; | ||
| unsigned index_; | ||
|
|
||
| public: | ||
| lambda_vector_iterator(const std::vector<ValueType> &vec) : vec_(vec), index_(0) { | ||
| while (index_ < vec_.size() && !HasEntry::has_entry(vec_[index_])) { | ||
| ++index_; | ||
| } | ||
| } | ||
|
|
||
| lambda_vector_iterator(const std::vector<ValueType> &vec, unsigned index) : vec_(vec), index_(index) {} | ||
|
|
||
| lambda_vector_iterator &operator++() { | ||
| ++index_; | ||
| while (index_ < vec_.size() && !HasEntry::has_entry(vec_[index_])) { | ||
| ++index_; | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| value_type operator*() const { return std::make_pair(index_, vec_[index_]); } | ||
|
|
||
| bool operator==(const lambda_vector_iterator &other) const { return index_ == other.index_; } | ||
| bool operator!=(const lambda_vector_iterator &other) const { return !(*this == other); } | ||
| }; | ||
|
|
||
| lambda_vector_range(const std::vector<ValueType> &vec) : vec_(vec) {} | ||
|
|
||
| lambda_vector_iterator begin() { return lambda_vector_iterator(vec_); } | ||
| lambda_vector_iterator end() { return lambda_vector_iterator(vec_, static_cast<unsigned>(vec_.size())); } | ||
| }; | ||
|
|
||
| /// 2D vector: for each node, stores processor assignment info | ||
| std::vector<std::vector<ValueType>> node_lambda_vec; | ||
|
|
||
| /// Number of processors in the system | ||
| unsigned num_procs_ = 0; | ||
|
|
||
| inline void initialize(const vertex_idx_t num_vertices, const unsigned num_procs) { | ||
| node_lambda_vec.assign(num_vertices, std::vector<ValueType>(num_procs)); | ||
| num_procs_ = num_procs; | ||
| } | ||
|
|
||
| inline void reset_node(const vertex_idx_t node) { node_lambda_vec[node].assign(num_procs_, ValueType()); } | ||
|
|
||
| inline void clear() { node_lambda_vec.clear(); } | ||
|
|
||
| inline bool has_proc_entry(const vertex_idx_t node, const unsigned proc) const { | ||
| return HasEntry::has_entry(node_lambda_vec[node][proc]); | ||
| } | ||
|
|
||
| inline ValueType &get_proc_entry(const vertex_idx_t node, const unsigned proc) { | ||
| return node_lambda_vec[node][proc]; | ||
| } | ||
|
|
||
| inline ValueType get_proc_entry(const vertex_idx_t node, const unsigned proc) const { | ||
| return node_lambda_vec[node][proc]; | ||
| } | ||
|
|
||
| inline auto iterate_proc_entries(const vertex_idx_t node) { return lambda_vector_range(node_lambda_vec[node]); } | ||
| }; | ||
|
|
||
| } // namespace osp | ||
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.