Skip to content

Commit ee8a787

Browse files
committed
Started implementing support for engine mode selection. Done for ELM, todo for remaining.
1 parent 7cec3a7 commit ee8a787

20 files changed

Lines changed: 153 additions & 93 deletions

include/react/propagation/ELMEngine.h

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ using tbb::spin_mutex;
2525
////////////////////////////////////////////////////////////////////////////////////////
2626
/// Turn
2727
////////////////////////////////////////////////////////////////////////////////////////
28-
class Turn :
29-
public TurnBase,
30-
public ExclusiveTurnManager::ExclusiveTurn
28+
class Turn : public TurnBase
3129
{
3230
public:
3331
Turn(TurnIdT id, TurnFlagsT flags);
@@ -53,47 +51,59 @@ class Node : public IReactiveNode
5351
};
5452

5553
////////////////////////////////////////////////////////////////////////////////////////
56-
/// ELMEngine
54+
/// Engine
5755
////////////////////////////////////////////////////////////////////////////////////////
58-
class ELMEngine :
59-
public IReactiveEngine<Node,Turn>,
60-
public ExclusiveTurnManager
56+
template <typename TTurn>
57+
class EngineBase : public IReactiveEngine<Node,TTurn>
6158
{
6259
public:
6360
using NodeShiftMutexT = Node::ShiftMutexT;
6461
using NodeSetT = set<Node*>;
6562

66-
void OnNodeCreate(NodeInterface& node);
67-
void OnNodeDestroy(NodeInterface& node);
63+
void OnNodeCreate(Node& node);
64+
void OnNodeDestroy(Node& node);
6865

6966
void OnNodeAttach(Node& node, Node& parent);
7067
void OnNodeDetach(Node& node, Node& parent);
7168

72-
void OnTurnAdmissionStart(Turn& turn);
73-
void OnTurnAdmissionEnd(Turn& turn);
74-
void OnTurnEnd(Turn& turn);
69+
void OnTurnInputChange(Node& node, TTurn& turn);
70+
void OnTurnPropagate(TTurn& turn);
7571

76-
void OnTurnInputChange(Node& node, Turn& turn);
77-
void OnTurnPropagate(Turn& turn);
72+
void OnNodePulse(Node& node, TTurn& turn);
73+
void OnNodeIdlePulse(Node& node, TTurn& turn);
7874

79-
void OnNodePulse(Node& node, Turn& turn);
80-
void OnNodeIdlePulse(Node& node, Turn& turn);
81-
82-
void OnNodeShift(Node& node, Node& oldParent, Node& newParent, Turn& turn);
75+
void OnNodeShift(Node& node, Node& oldParent, Node& newParent, TTurn& turn);
8376

8477
private:
85-
void processChild(Node& node, bool update, Turn& turn);
86-
void nudgeChildren(Node& parent, bool update, Turn& turn);
78+
void processChild(Node& node, bool update, TTurn& turn);
79+
void nudgeChildren(Node& parent, bool update, TTurn& turn);
8780

8881
task_group tasks_;
8982
NodeSetT inputNodes_;
9083
};
9184

85+
class BasicEngine :
86+
public EngineBase<Turn>
87+
{
88+
};
89+
90+
class QueuingEngine :
91+
public DefaultQueuingEngine<EngineBase,Turn>
92+
{
93+
};
94+
9295
} // ~namespace elm
9396
REACT_IMPL_END
9497

9598
REACT_BEGIN
9699

97-
using REACT_IMPL::elm::ELMEngine;
100+
struct parallel;
101+
struct parallel_queuing;
102+
103+
template <typename TMode = parallel_queuing>
104+
class ELMEngine;
105+
106+
template <> class ELMEngine<parallel> : public REACT_IMPL::elm::BasicEngine {};
107+
template <> class ELMEngine<parallel_queuing> : public REACT_IMPL::elm::QueuingEngine {};
98108

99109
REACT_END

include/react/propagation/EngineBase.h

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313
#include "react/common/Concurrency.h"
1414

1515
////////////////////////////////////////////////////////////////////////////////////////
16-
REACT_BEGIN
17-
18-
enum class ETransactionMode
19-
{
20-
none,
21-
exclusive
22-
};
23-
24-
REACT_END
25-
2616
REACT_IMPL_BEGIN
2717

2818
////////////////////////////////////////////////////////////////////////////////////////
@@ -55,6 +45,9 @@ struct IReactiveEngine
5545
void OnNodeIdlePulse(NodeInterface& node, TurnInterface& turn) {}
5646

5747
void OnNodeShift(NodeInterface& node, NodeInterface& oldParent, NodeInterface& newParent, TurnInterface& turn) {}
48+
49+
template <typename F>
50+
bool TryMerge(F&& f) { return false; }
5851
};
5952

6053
////////////////////////////////////////////////////////////////////////////////////////
@@ -100,20 +93,20 @@ class TurnBase
10093
};
10194

10295
////////////////////////////////////////////////////////////////////////////////////////
103-
/// ExclusiveTurnManager
96+
/// TurnQueueManager
10497
////////////////////////////////////////////////////////////////////////////////////////
105-
class ExclusiveTurnManager
98+
class TurnQueueManager
10699
{
107100
public:
108-
class ExclusiveTurn
101+
class QueueEntry
109102
{
110103
public:
111-
explicit ExclusiveTurn(TurnFlagsT flags) :
104+
explicit QueueEntry(TurnFlagsT flags) :
112105
isMergeable_{ (flags & enable_input_merging) != 0 }
113106
{
114107
}
115108

116-
inline void Append(ExclusiveTurn& tr)
109+
inline void Append(QueueEntry& tr)
117110
{
118111
successor_ = &tr;
119112
tr.blockCondition_.Block();
@@ -158,7 +151,7 @@ class ExclusiveTurnManager
158151
using MergedDataVectT = std::vector<std::pair<std::function<void()>,BlockingCondition*>>;
159152

160153
bool isMergeable_;
161-
ExclusiveTurn* successor_ = nullptr;
154+
QueueEntry* successor_ = nullptr;
162155
MergedDataVectT merged_;
163156
BlockingCondition blockCondition_;
164157
};
@@ -183,7 +176,7 @@ class ExclusiveTurnManager
183176
return merged;
184177
}
185178

186-
inline void StartTurn(ExclusiveTurn& turn)
179+
inline void StartTurn(QueueEntry& turn)
187180
{
188181
{// seqMutex_
189182
SeqMutexT::scoped_lock lock(seqMutex_);
@@ -197,7 +190,7 @@ class ExclusiveTurnManager
197190
turn.WaitForUnblock();
198191
}
199192

200-
inline void EndTurn(ExclusiveTurn& turn)
193+
inline void EndTurn(QueueEntry& turn)
201194
{// seqMutex_
202195
SeqMutexT::scoped_lock lock(seqMutex_);
203196

@@ -211,7 +204,64 @@ class ExclusiveTurnManager
211204
using SeqMutexT = tbb::queuing_mutex;
212205

213206
SeqMutexT seqMutex_;
214-
ExclusiveTurn* tail_ = nullptr;
207+
QueueEntry* tail_ = nullptr;
208+
};
209+
210+
////////////////////////////////////////////////////////////////////////////////////////
211+
/// DefaultQueueableTurn
212+
////////////////////////////////////////////////////////////////////////////////////////
213+
template
214+
<
215+
typename TTurnBase
216+
>
217+
class DefaultQueueableTurn :
218+
public TTurnBase,
219+
public TurnQueueManager::QueueEntry
220+
{
221+
public:
222+
DefaultQueueableTurn(TurnIdT id, TurnFlagsT flags) :
223+
TTurnBase(id, flags),
224+
TurnQueueManager::QueueEntry(flags)
225+
{
226+
}
227+
};
228+
229+
////////////////////////////////////////////////////////////////////////////////////////
230+
/// DefaultQueuingEngine
231+
////////////////////////////////////////////////////////////////////////////////////////
232+
template
233+
<
234+
template <typename Turn_> class TTEngineBase,
235+
typename TTurnBase
236+
>
237+
class DefaultQueuingEngine : public TTEngineBase<DefaultQueueableTurn<TTurnBase>>
238+
{
239+
public:
240+
using TurnT = DefaultQueueableTurn<TTurnBase>;
241+
242+
void OnTurnAdmissionStart(TurnT& turn)
243+
{
244+
queueManager_.StartTurn(turn);
245+
}
246+
247+
void OnTurnAdmissionEnd(TurnT& turn)
248+
{
249+
turn.RunMergedInputs();
250+
}
251+
252+
void OnTurnEnd(TurnT& turn)
253+
{
254+
queueManager_.EndTurn(turn);
255+
}
256+
257+
template <typename F>
258+
bool TryMerge(F&& f)
259+
{
260+
return queueManager_.TryMerge(std::forward<F>(f));
261+
}
262+
263+
private:
264+
TurnQueueManager queueManager_;
215265
};
216266

217267
REACT_IMPL_END

include/react/propagation/FloodingEngine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using tbb::spin_mutex;
2727
////////////////////////////////////////////////////////////////////////////////////////
2828
class Turn :
2929
public TurnBase,
30-
public ExclusiveTurnManager::ExclusiveTurn
30+
public TurnQueueManager::QueueEntry
3131
{
3232
public:
3333
Turn(TurnIdT id, TurnFlagsT flags);
@@ -67,7 +67,7 @@ class Node : public IReactiveNode
6767
////////////////////////////////////////////////////////////////////////////////////////
6868
class FloodingEngine :
6969
public IReactiveEngine<Node,Turn>,
70-
public ExclusiveTurnManager
70+
public TurnQueueManager
7171
{
7272
public:
7373
void OnNodeAttach(Node& node, Node& parent);

include/react/propagation/PulseCountEngine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using tbb::spin_rw_mutex;
2424
////////////////////////////////////////////////////////////////////////////////////////
2525
struct Turn :
2626
public TurnBase,
27-
public ExclusiveTurnManager::ExclusiveTurn
27+
public TurnQueueManager::QueueEntry
2828
{
2929
public:
3030
Turn(TurnIdT id, TurnFlagsT flags);
@@ -53,7 +53,7 @@ class Node : public IReactiveNode
5353
////////////////////////////////////////////////////////////////////////////////////////
5454
class PulseCountEngine :
5555
public IReactiveEngine<Node,Turn>,
56-
public ExclusiveTurnManager
56+
public TurnQueueManager
5757
{
5858
public:
5959
typedef Node::ShiftMutexT NodeShiftMutexT;

include/react/propagation/PulseCountO1Engine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Node : public IReactiveNode
6969
////////////////////////////////////////////////////////////////////////////////////////
7070
class Turn :
7171
public TurnBase,
72-
public ExclusiveTurnManager::ExclusiveTurn
72+
public TurnQueueManager::QueueEntry
7373
{
7474
public:
7575
Turn(TurnIdT id, TurnFlagsT flags);
@@ -82,7 +82,7 @@ class Turn :
8282
////////////////////////////////////////////////////////////////////////////////////////
8383
class PulseCountO1Engine :
8484
public IReactiveEngine<Node,Turn>,
85-
public ExclusiveTurnManager
85+
public TurnQueueManager
8686
{
8787
public:
8888
PulseCountO1Engine();

include/react/propagation/SourceSetEngine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using tbb::spin_mutex;
3030
////////////////////////////////////////////////////////////////////////////////////////
3131
class Turn :
3232
public TurnBase,
33-
public ExclusiveTurnManager::ExclusiveTurn
33+
public TurnQueueManager::QueueEntry
3434
{
3535
public:
3636
using SourceIdSetT = SourceIdSet<ObjectId>;
@@ -104,7 +104,7 @@ class Node : public IReactiveNode
104104
////////////////////////////////////////////////////////////////////////////////////////
105105
class SourceSetEngine :
106106
public IReactiveEngine<Node,Turn>,
107-
public ExclusiveTurnManager
107+
public TurnQueueManager
108108
{
109109
public:
110110
void SourceSetEngine::OnNodeCreate(Node& node);

include/react/propagation/TopoSortEngine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct ShiftRequestData
5454
////////////////////////////////////////////////////////////////////////////////////////
5555
class Turn :
5656
public TurnBase,
57-
public ExclusiveTurnManager::ExclusiveTurn
57+
public TurnQueueManager::QueueEntry
5858
{
5959
public:
6060
Turn(TurnIdT id, TurnFlagsT flags);
@@ -65,7 +65,7 @@ class Turn :
6565
////////////////////////////////////////////////////////////////////////////////////////
6666
class TopoSortEngine :
6767
public IReactiveEngine<Node,Turn>,
68-
public ExclusiveTurnManager
68+
public TurnQueueManager
6969
{
7070
public:
7171
using NodeSetT = set<Node*>;

src/benchmark/Main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ REACTIVE_DOMAIN(PulseCountDomain, PulseCountEngine, EventLog);
3333
REACTIVE_DOMAIN(SourceSetDomain, SourceSetEngine, EventLog);
3434
REACTIVE_DOMAIN(TopoSortSTDomain, TopoSortSTEngine, EventLog);
3535
REACTIVE_DOMAIN(PulseCountO1Domain, PulseCountO1Engine, EventLog);
36-
REACTIVE_DOMAIN(ELMDomain, ELMEngine, EventLog);
36+
REACTIVE_DOMAIN(ELMDomain, ELMEngine<>, EventLog);
3737

3838
REACTIVE_DOMAIN(BFloodingDomain, FloodingEngine);
3939
REACTIVE_DOMAIN(BTopoSortDomain, TopoSortEngine);
@@ -42,7 +42,7 @@ REACTIVE_DOMAIN(BPulseCountDomain, PulseCountEngine);
4242
REACTIVE_DOMAIN(BSourceSetDomain, SourceSetEngine);
4343
REACTIVE_DOMAIN(BTopoSortSTDomain, TopoSortSTEngine);
4444
REACTIVE_DOMAIN(BPulseCountO1Domain, PulseCountO1Engine);
45-
REACTIVE_DOMAIN(BELMDomain, ELMEngine);
45+
REACTIVE_DOMAIN(BELMDomain, ELMEngine<>);
4646

4747
void runBenchmarkGrid(std::ostream& out)
4848
{

0 commit comments

Comments
 (0)