Commit b1ecc318 by Marcus Winter

dataflow_cpp: added support for priorities and affinities

parent ae4813ec
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <cstddef> #include <cstddef>
#include <embb/base/exceptions.h> #include <embb/base/exceptions.h>
#include <embb/mtapi/execution_policy.h>
#include <embb/dataflow/internal/scheduler.h> #include <embb/dataflow/internal/scheduler.h>
#include <embb/dataflow/internal/clock_listener.h> #include <embb/dataflow/internal/clock_listener.h>
...@@ -58,10 +59,14 @@ class Node { ...@@ -58,10 +59,14 @@ class Node {
SetSlices(0); SetSlices(0);
} }
} }
void SetPolicy(embb::mtapi::ExecutionPolicy const & policy) {
policy_ = policy;
}
protected: protected:
Scheduler * sched_; Scheduler * sched_;
static int next_process_id_; static int next_process_id_;
embb::mtapi::ExecutionPolicy policy_;
static int GetNextProcessID() { return next_process_id_++; } static int GetNextProcessID() { return next_process_id_++; }
virtual void SetSlices(int /*slices*/) {} virtual void SetSlices(int /*slices*/) {}
......
...@@ -146,7 +146,7 @@ class Process< Serial, Inputs<I1, I2, I3, I4, I5>, ...@@ -146,7 +146,7 @@ class Process< Serial, Inputs<I1, I2, I3, I4, I5>,
for (int ii = clk; ii < clk_res; ii++) { for (int ii = clk; ii < clk_res; ii++) {
const int idx = ii % slices_; const int idx = ii % slices_;
action_[idx] = Action(this, ii); action_[idx] = Action(this, ii);
sched_->Enqueue(queue_id_, action_[idx]); sched_->Enqueue(queue_id_, action_[idx], policy_);
} }
queued_clock_.Store(clk_res); queued_clock_.Store(clk_res);
retry = false; retry = false;
...@@ -158,7 +158,7 @@ class Process< Serial, Inputs<I1, I2, I3, I4, I5>, ...@@ -158,7 +158,7 @@ class Process< Serial, Inputs<I1, I2, I3, I4, I5>,
} else { } else {
const int idx = clock % slices_; const int idx = clock % slices_;
action_[idx] = Action(this, clock); action_[idx] = Action(this, clock);
sched_->Start(action_[idx]); sched_->Start(action_[idx], policy_);
} }
} }
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#ifndef EMBB_DATAFLOW_INTERNAL_SCHEDULER_H_ #ifndef EMBB_DATAFLOW_INTERNAL_SCHEDULER_H_
#define EMBB_DATAFLOW_INTERNAL_SCHEDULER_H_ #define EMBB_DATAFLOW_INTERNAL_SCHEDULER_H_
#include <embb/mtapi/execution_policy.h>
namespace embb { namespace embb {
namespace dataflow { namespace dataflow {
namespace internal { namespace internal {
...@@ -37,8 +39,13 @@ class Scheduler { ...@@ -37,8 +39,13 @@ class Scheduler {
public: public:
Scheduler() {} Scheduler() {}
virtual ~Scheduler() {} virtual ~Scheduler() {}
virtual void Start(Action & action) = 0; virtual void Start(
virtual void Enqueue(int process_id, Action & action) = 0; Action & action,
embb::mtapi::ExecutionPolicy const & policy) = 0;
virtual void Enqueue(
int process_id,
Action & action,
embb::mtapi::ExecutionPolicy const & policy) = 0;
virtual void WaitForSlice(int slice) = 0; virtual void WaitForSlice(int slice) = 0;
virtual int GetSlices() = 0; virtual int GetSlices() = 0;
}; };
......
...@@ -96,14 +96,25 @@ class SchedulerMTAPI : public Scheduler { ...@@ -96,14 +96,25 @@ class SchedulerMTAPI : public Scheduler {
embb::base::Allocation::Free(group_); embb::base::Allocation::Free(group_);
embb::base::Allocation::Free(queue_); embb::base::Allocation::Free(queue_);
} }
virtual void Start(Action & action) { virtual void Start(
Action & action,
embb::mtapi::ExecutionPolicy const & policy) {
const int idx = action.GetClock() % slices_; const int idx = action.GetClock() % slices_;
group_[idx].Start(job_, &action, static_cast<void*>(NULL)); embb::mtapi::TaskAttributes task_attr;
task_attr.SetPolicy(policy);
group_[idx].Start(job_, &action, static_cast<void*>(NULL),
task_attr);
} }
virtual void Enqueue(int process_id, Action & action) { virtual void Enqueue(
int process_id,
Action & action,
embb::mtapi::ExecutionPolicy const & policy) {
const int idx = action.GetClock() % slices_; const int idx = action.GetClock() % slices_;
const int queue_id = process_id % queue_count_; const int queue_id = process_id % queue_count_;
queue_[queue_id].Enqueue(&action, static_cast<void*>(NULL), group_[idx]); embb::mtapi::TaskAttributes task_attr;
task_attr.SetPolicy(policy);
queue_[queue_id].Enqueue(&action, static_cast<void*>(NULL),
task_attr, group_[idx]);
} }
virtual void WaitForSlice(int slice) { virtual void WaitForSlice(int slice) {
group_[slice].WaitAll(MTAPI_INFINITE); group_[slice].WaitAll(MTAPI_INFINITE);
......
...@@ -38,10 +38,15 @@ class SchedulerSequential : public Scheduler { ...@@ -38,10 +38,15 @@ class SchedulerSequential : public Scheduler {
public: public:
SchedulerSequential() {} SchedulerSequential() {}
virtual ~SchedulerSequential() {} virtual ~SchedulerSequential() {}
virtual void Start(Action & action) { virtual void Start(
Action & action,
embb::mtapi::ExecutionPolicy const &) {
action.RunSequential(); action.RunSequential();
} }
virtual void Enqueue(int, Action & action) { virtual void Enqueue(
int,
Action & action,
embb::mtapi::ExecutionPolicy const &) {
action.RunSequential(); action.RunSequential();
} }
virtual void WaitForSlice(int /*slice*/) {} virtual void WaitForSlice(int /*slice*/) {}
......
...@@ -113,7 +113,7 @@ class Sink< Inputs<I1, I2, I3, I4, I5> > ...@@ -113,7 +113,7 @@ class Sink< Inputs<I1, I2, I3, I4, I5> >
for (int ii = clk; ii < clk_res; ii++) { for (int ii = clk; ii < clk_res; ii++) {
const int idx = ii % slices_; const int idx = ii % slices_;
action_[idx] = Action(this, ii); action_[idx] = Action(this, ii);
sched_->Enqueue(queue_id_, action_[idx]); sched_->Enqueue(queue_id_, action_[idx], policy_);
} }
queued_clock_.Store(clk_res); queued_clock_.Store(clk_res);
retry = false; retry = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment