Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/osp/auxiliary/io/DotFileWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class DotFileWriter {
}

write_graph_structure(
os, g2, VertexWriterDuplicateRecompSchedule_DOT<Graph_t>(g2, names, node_to_proc, node_to_superstep));
os, g2, VertexWriterDuplicateRecompSchedule_DOT<graph_t>(g2, names, node_to_proc, node_to_superstep));
}

template<typename Graph_t>
Expand Down
2 changes: 1 addition & 1 deletion include/osp/bsp/model/BspInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class BspInstance {
explicit BspInstance(const BspInstance<Graph_t_other> &other)
: architecture(other.getArchitecture()),
nodeProcessorCompatibility(other.getNodeProcessorCompatibilityMatrix()) {
construct_computational_dag(other.getComputationalDag(), cdag);
constructComputationalDag(other.getComputationalDag(), cdag);
}

BspInstance(const BspInstance<Graph_t> &other) = default;
Expand Down
2 changes: 1 addition & 1 deletion include/osp/coarser/StepByStep/StepByStepCoarser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ std::vector<vertex_idx_t<Graph_t>> StepByStepCoarser<Graph_t>::generate_vertex_c
G_coarse.remove_vertex(node);
}

construct_computational_dag(G_full, G_coarse);
constructComputationalDag(G_full, G_coarse);

contractionHistory.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,52 @@ limitations under the License.

#pragma once

#include <numeric>

#include "osp/concepts/computational_dag_concept.hpp"
#include "osp/concepts/constructable_computational_dag_concept.hpp"
#include "directed_graph_top_sort.hpp"

namespace osp {

/**
* @brief Constructs a computational DAG from another graph.
*
* This function copies the structure and properties of a source graph into a target graph structure.
* Assumes that the vertices of the source graph are indexed from 0 to N-1. If the target graph is empty, indices are sequentially assigned starting from 0.
* If the target graph is not empty, new vertices will be added to the target graph and their indices will be sequentially assigned starting from the index N.
*
* @tparam Graph_from The type of the source graph. Must satisfy `is_computational_dag`.
* @tparam Graph_to The type of the target graph. Must satisfy `is_constructable_cdag_vertex`.
* @param from The source graph.
* @param to The target graph.
*/
template<typename Graph_from, typename Graph_to>
bool construct_computational_dag(const Graph_from &from, Graph_to &to) {

void constructComputationalDag(const Graph_from &from, Graph_to &to) {
static_assert(is_computational_dag_v<Graph_from>, "Graph_from must satisfy the computational_dag concept");
static_assert(is_constructable_cdag_vertex_v<Graph_to>,
"Graph_to must satisfy the constructable_cdag_vertex concept");
static_assert(is_constructable_cdag_vertex_v<Graph_to>, "Graph_to must satisfy the constructable_cdag_vertex concept");

for (const auto &v_idx : from.vertices()) {
std::vector<vertex_idx_t<Graph_to>> vertex_map;
vertex_map.reserve(from.num_vertices());

for (const auto &v_idx : from.vertices()) {
if constexpr (has_typed_vertices_v<Graph_from> and has_typed_vertices_v<Graph_to>) {
to.add_vertex(from.vertex_work_weight(v_idx), from.vertex_comm_weight(v_idx),
from.vertex_mem_weight(v_idx), from.vertex_type(v_idx));
vertex_map.push_back(to.add_vertex(from.vertex_work_weight(v_idx), from.vertex_comm_weight(v_idx),
from.vertex_mem_weight(v_idx), from.vertex_type(v_idx)));
} else {
to.add_vertex(from.vertex_work_weight(v_idx), from.vertex_comm_weight(v_idx),
from.vertex_mem_weight(v_idx));
vertex_map.push_back(to.add_vertex(from.vertex_work_weight(v_idx), from.vertex_comm_weight(v_idx),
from.vertex_mem_weight(v_idx)));
}
}

if constexpr (has_edge_weights_v<Graph_from> and has_edge_weights_v<Graph_to>) {

for (const auto &e : edges(from)) {
to.add_edge(source(e, from), target(e, from), from.edge_comm_weight(e));
to.add_edge(vertex_map.at(source(e, from)), vertex_map.at(target(e, from)), from.edge_comm_weight(e));
}

} else {
for (const auto &v : from.vertices()) {
for (const auto &child : from.children(v)) {
to.add_edge(v, child);
to.add_edge(vertex_map.at(v), vertex_map.at(child));
}
}
}

return true;
}

} // namespace osp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
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

namespace osp {

/**
* @brief Implementation of a computational DAG vertex.
*
* This struct holds the properties of a vertex in a computational DAG, including its ID,
* weights (work, communication, memory), and type.
*
* @tparam vertex_idx_t Type for vertex indices.
* @tparam workw_t Type for work weights.
* @tparam commw_t Type for communication weights.
* @tparam memw_t Type for memory weights.
* @tparam vertex_type_t Type for vertex types.
*/
template<typename vertex_idx_t, typename workw_t, typename commw_t, typename memw_t, typename vertex_type_t>
struct cdag_vertex_impl {

using vertex_idx_type = vertex_idx_t;
using work_weight_type = workw_t;
using comm_weight_type = commw_t;
using mem_weight_type = memw_t;
using cdag_vertex_type_type = vertex_type_t;

cdag_vertex_impl() = default;

cdag_vertex_impl(const cdag_vertex_impl &other) = default;
cdag_vertex_impl(cdag_vertex_impl &&other) noexcept = default;
cdag_vertex_impl &operator=(const cdag_vertex_impl &other) = default;
cdag_vertex_impl &operator=(cdag_vertex_impl &&other) noexcept = default;

/**
* @brief Constructs a vertex with specified properties.
*
* @param vertex_idx_ The unique identifier for the vertex.
* @param work_w The computational work weight.
* @param comm_w The communication weight.
* @param mem_w The memory weight.
* @param vertex_t The type of the vertex.
*/
cdag_vertex_impl(vertex_idx_t vertex_idx_, workw_t work_w, commw_t comm_w, memw_t mem_w,
vertex_type_t vertex_t)
: id(vertex_idx_), work_weight(work_w), comm_weight(comm_w), mem_weight(mem_w),
vertex_type(vertex_t) {}

vertex_idx_t id = 0;

workw_t work_weight = 0;
commw_t comm_weight = 0;
memw_t mem_weight = 0;

vertex_type_t vertex_type = 0;
};

/**
* @brief A vertex implementation with integer weights. Indexed by size_t. Node types are unsigned.
*
* This struct implements a vertex with integer weights for work, communication, and memory.
*/
using cdag_vertex_impl_int = cdag_vertex_impl<size_t, int, int, int, unsigned>;

/**
* @brief A vertex implementation with unsigned weights. Indexed by size_t. Node types are unsigned.
*
* This struct implements a vertex with unsigned weights for work, communication, and memory.
*/
using cdag_vertex_impl_unsigned = cdag_vertex_impl<size_t, unsigned, unsigned, unsigned, unsigned>;

} // namespace osp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ limitations under the License.
#pragma once

#include "osp/auxiliary/hash_util.hpp"
#include "computational_dag_vector_impl.hpp"
#include "cdag_vertex_impl.hpp"
#include "edge_iterator.hpp"
#include "osp/graph_implementations/integral_range.hpp"
#include "osp/graph_algorithms/computational_dag_construction_util.hpp"
#include <vector>

Expand Down Expand Up @@ -123,7 +124,7 @@ class computational_dag_edge_idx_vector_impl {

static_assert(is_computational_dag_v<Graph_t>, "Graph_t must satisfy the is_computation_dag concept");

construct_computational_dag(other, *this);
constructComputationalDag(other, *this);
}

computational_dag_edge_idx_vector_impl &operator=(const computational_dag_edge_idx_vector_impl &other) = default;
Expand Down
Loading