Skip to content

Commit 14624b8

Browse files
authored
Revision bsp schedule (#73)
* revision Ibsp schedule and set schedule * member encapsulation * setschedule revision * satisfiesLocalConstraint revision * removed local_in_out memconstraint
1 parent a76c4a2 commit 14624b8

13 files changed

Lines changed: 161 additions & 394 deletions

File tree

include/osp/bsp/model/BspArchitecture.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ enum class MemoryConstraintType {
4646
GLOBAL, /** The memory bounds apply to the sum of memory weights of the nodes assigned to the same processor. */
4747
PERSISTENT_AND_TRANSIENT, /** Memory bounds apply to the sum of memory weights of nodes assigned to the same processor plus
4848
the maximum communication weight of a node assigned to a processor. */
49-
LOCAL_IN_OUT, /** Memory constraints are local in-out. Experimental. */
5049
LOCAL_INC_EDGES, /** Memory constraints are local incident edges. Experimental. */
5150
LOCAL_SOURCES_INC_EDGES /** Memory constraints are local source incident edges. Experimental. */
5251
};
@@ -65,8 +64,6 @@ inline const char *ToString(MemoryConstraintType type) {
6564
return "GLOBAL";
6665
case MemoryConstraintType::PERSISTENT_AND_TRANSIENT:
6766
return "PERSISTENT_AND_TRANSIENT";
68-
case MemoryConstraintType::LOCAL_IN_OUT:
69-
return "LOCAL_IN_OUT";
7067
case MemoryConstraintType::LOCAL_INC_EDGES:
7168
return "LOCAL_INC_EDGES";
7269
case MemoryConstraintType::LOCAL_SOURCES_INC_EDGES:

include/osp/bsp/model/BspSchedule.hpp

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,6 @@ class BspSchedule : public IBspSchedule<GraphT>, public IBspScheduleEval<GraphT>
457457
case MemoryConstraintType::GLOBAL:
458458
return SatisfiesGlobalMemoryConstraints();
459459

460-
case MemoryConstraintType::LOCAL_IN_OUT:
461-
return SatisfiesLocalInOutMemoryConstraints();
462-
463460
case MemoryConstraintType::LOCAL_INC_EDGES:
464461
return SatisfiesLocalIncEdgesMemoryConstraints();
465462

@@ -605,16 +602,17 @@ class BspSchedule : public IBspSchedule<GraphT>, public IBspScheduleEval<GraphT>
605602
* @return True if local memory constraints are satisfied, false otherwise.
606603
*/
607604
bool SatisfiesLocalMemoryConstraints() const {
608-
SetSchedule setSchedule = SetSchedule(*this);
605+
std::vector<std::vector<VMemwT<GraphT>>> memory(numberOfSupersteps_,
606+
std::vector<VMemwT<GraphT>>(instance_->NumberOfProcessors(), 0));
607+
608+
for (const auto &node : instance_->Vertices()) {
609+
memory[nodeToSuperstepAssignment_[node]][nodeToProcessorAssignment_[node]]
610+
+= instance_->GetComputationalDag().VertexMemWeight(node);
611+
}
609612

610613
for (unsigned step = 0; step < numberOfSupersteps_; step++) {
611614
for (unsigned proc = 0; proc < instance_->NumberOfProcessors(); proc++) {
612-
VMemwT<GraphT> memory = 0;
613-
for (const auto &node : setSchedule.stepProcessorVertices_[step][proc]) {
614-
memory += instance_->GetComputationalDag().VertexMemWeight(node);
615-
}
616-
617-
if (memory > instance_->GetArchitecture().MemoryBound(proc)) {
615+
if (memory[step][proc] > instance_->GetArchitecture().MemoryBound(proc)) {
618616
return false;
619617
}
620618
}
@@ -671,32 +669,6 @@ class BspSchedule : public IBspSchedule<GraphT>, public IBspScheduleEval<GraphT>
671669
return true;
672670
}
673671

674-
bool SatisfiesLocalInOutMemoryConstraints() const {
675-
SetSchedule setSchedule = SetSchedule(*this);
676-
677-
for (unsigned step = 0; step < numberOfSupersteps_; step++) {
678-
for (unsigned proc = 0; proc < instance_->NumberOfProcessors(); proc++) {
679-
VMemwT<GraphT> memory = 0;
680-
for (const auto &node : setSchedule.stepProcessorVertices_[step][proc]) {
681-
memory += instance_->GetComputationalDag().VertexMemWeight(node)
682-
+ instance_->GetComputationalDag().VertexCommWeight(node);
683-
684-
for (const auto &parent : instance_->GetComputationalDag().Parents(node)) {
685-
if (nodeToProcessorAssignment_[parent] == proc && nodeToSuperstepAssignment_[parent] == step) {
686-
memory -= instance_->GetComputationalDag().VertexCommWeight(parent);
687-
}
688-
}
689-
}
690-
691-
if (memory > instance_->GetArchitecture().MemoryBound(proc)) {
692-
return false;
693-
}
694-
}
695-
}
696-
697-
return true;
698-
}
699-
700672
bool SatisfiesLocalIncEdgesMemoryConstraints() const {
701673
SetSchedule setSchedule = SetSchedule(*this);
702674

@@ -705,7 +677,7 @@ class BspSchedule : public IBspSchedule<GraphT>, public IBspScheduleEval<GraphT>
705677
std::unordered_set<VertexIdxT<GraphT>> nodesWithIncomingEdges;
706678

707679
VMemwT<GraphT> memory = 0;
708-
for (const auto &node : setSchedule.stepProcessorVertices_[step][proc]) {
680+
for (const auto &node : setSchedule.GetProcessorStepVertices()[step][proc]) {
709681
memory += instance_->GetComputationalDag().VertexCommWeight(node);
710682

711683
for (const auto &parent : instance_->GetComputationalDag().Parents(node)) {
@@ -735,7 +707,7 @@ class BspSchedule : public IBspSchedule<GraphT>, public IBspScheduleEval<GraphT>
735707
std::unordered_set<VertexIdxT<GraphT>> nodesWithIncomingEdges;
736708

737709
VMemwT<GraphT> memory = 0;
738-
for (const auto &node : setSchedule.stepProcessorVertices_[step][proc]) {
710+
for (const auto &node : setSchedule.GetProcessorStepVertices()[step][proc]) {
739711
if (IsSource(node, instance_->GetComputationalDag())) {
740712
memory += instance_->GetComputationalDag().VertexMemWeight(node);
741713
}

include/osp/bsp/model/IBspSchedule.hpp

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,77 @@ limitations under the License.
2222

2323
namespace osp {
2424

25-
/// @class IBspSchedule
26-
/// @brief Interface for a BSP (Bulk Synchronous Parallel) schedule.
25+
/**
26+
* @class IBspSchedule
27+
* @brief Pure interface class to organize the interaction with a BSP schedule.
28+
*
29+
* A BSP schedule assigns nodes to processors and supersteps, is based on an instance, and has a number of supersteps.
30+
* It provides unified access for different data implementations.
31+
*
32+
* - The class `BspSchedule` implements the assignments as vectors.
33+
* - The class `SetBspSchedule` implements containers that contain all nodes assigned to a pair of processor and superstep.
34+
*
35+
* @tparam GraphT The type of the computational DAG, which must satisfy `is_computational_dag_v`.
36+
* @see BspInstance
37+
* @see BspSchedule
38+
* @see SetBspSchedule
39+
*/
2740
template <typename GraphT>
2841
class IBspSchedule {
2942
using VertexIdx = VertexIdxT<GraphT>;
3043

44+
static_assert(isComputationalDagV<GraphT>, "IBspSchedule can only be used with computational DAGs.");
45+
3146
public:
32-
/// @brief Destructor.
3347
virtual ~IBspSchedule() = default;
3448

35-
virtual const BspInstance<GraphT> &GetInstance() const = 0;
36-
37-
/// @brief Set the assigned superstep for a node.
38-
/// @param node The node index.
39-
/// @param superstep The assigned superstep.
49+
/**
50+
* @brief Get the BSP instance associated with this schedule.
51+
*
52+
* @return The BSP instance.
53+
*/
54+
[[nodiscard]] virtual const BspInstance<GraphT> &GetInstance() const = 0;
55+
56+
/**
57+
* @brief Set the assigned superstep for a node.
58+
*
59+
* @param node The node index.
60+
* @param superstep The assigned superstep.
61+
*/
4062
virtual void SetAssignedSuperstep(VertexIdx node, unsigned int superstep) = 0;
4163

42-
/// @brief Set the assigned processor for a node.
43-
/// @param node The node index.
44-
/// @param processor The assigned processor.
64+
/**
65+
* @brief Set the assigned processor for a node.
66+
*
67+
* @param node The node index.
68+
* @param processor The assigned processor.
69+
*/
4570
virtual void SetAssignedProcessor(VertexIdx node, unsigned int processor) = 0;
4671

47-
/// @brief Get the assigned superstep of a node.
48-
/// @param node The node index.
49-
/// @return The assigned superstep of the node.
50-
/// If the node is not assigned to a superstep, this.NumberOfSupersteps() is returned.
51-
virtual unsigned AssignedSuperstep(VertexIdx node) const = 0;
52-
53-
/// @brief Get the assigned processor of a node.
54-
/// @param node The node index.
55-
/// @return The assigned processor of the node.
56-
/// If the node is not assigned to a processor, this.GetInstance().NumberOfProcessors() is returned.
57-
virtual unsigned AssignedProcessor(VertexIdx node) const = 0;
58-
59-
/// @brief Get the number of supersteps in the schedule.
60-
/// @return The number of supersteps in the schedule.
61-
virtual unsigned NumberOfSupersteps() const = 0;
72+
/**
73+
* @brief Get the assigned superstep of a node.
74+
*
75+
* @param node The node index.
76+
* @return The assigned superstep of the node.
77+
* If the node is not assigned to a superstep, this.NumberOfSupersteps() is returned.
78+
*/
79+
[[nodiscard]] virtual unsigned AssignedSuperstep(VertexIdx node) const = 0;
80+
81+
/**
82+
* @brief Get the assigned processor of a node.
83+
*
84+
* @param node The node index.
85+
* @return The assigned processor of the node.
86+
* If the node is not assigned to a processor, this.GetInstance().NumberOfProcessors() is returned.
87+
*/
88+
[[nodiscard]] virtual unsigned AssignedProcessor(VertexIdx node) const = 0;
89+
90+
/**
91+
* @brief Get the number of supersteps in the schedule.
92+
*
93+
* @return The number of supersteps in the schedule.
94+
*/
95+
[[nodiscard]] virtual unsigned NumberOfSupersteps() const = 0;
6296
};
6397

6498
} // namespace osp

0 commit comments

Comments
 (0)