Integrated Finite State Machine and Dataflow

Integrated Finite State Machine and
Dataflow Modeling
© University of Erlangen-Nuremberg
Christian Haubelt
1
Outline
¾ Introduction
¾ Integrated Modeling
¾ Introduction to SysteMoC Programming
¾ Analysis of Integrated Models
¾ Summary
¾ Hands-on SysteMoC
© University of Erlangen-Nuremberg
Christian Haubelt
2
Dataflow Graphs
¾ Dataflow graphs are widely accepted for modeling DSP
algorithms
ƒ
ƒ
Multimedia
Signal processing
¾ Well known optimization strategies for static dataflow
(SDF) graphs
¾ Modeling complex multimedia applications using SDF
graphs only is challenging or even impossible
© University of Erlangen-Nuremberg
Christian Haubelt
3
Dynamic Dataflow Graphs
¾ Dynamic dataflow (DDF) graphs are well suited for
modeling complex multimedia and signal processing
applications
¾ Ad hoc representation of control flow in DDF graphs
has led to problems in analyses
¾ In summary, neither SDF graphs nor DDF graphs alone
are an appropriate foundation to base a design flow
upon
© University of Erlangen-Nuremberg
Christian Haubelt
4
Integrated FSM and Dataflow Modeling
¾ Actors often model control-dominant behavior
¾ Finite State Machine (FSM) are an appropriate modeling
approach for control-dominant applications
¾ Concurrency models based on hierarchical FSM are
often ambiguous
¾ Consequently: Integrated FSM and Dataflow Modeling
has attracted a lot of attention in the recent years
© University of Erlangen-Nuremberg
Christian Haubelt
5
Finite State Machines
Definition (Finite State Machine): An Finite State
Machine (FSM) is a five-tuple M = (S, Σ, Λ, τ, s0) with
- S being a finite set of states,
- Σ being a set of symbols denoting possible inputs,
- Λ being a set of symbols denoting possible outputs,
- τ : S x Σ → S x Λ being a state transition function, and
- s0 ∈ S being the initial state.
¾ In one reaction, an FSM maps a current state s and an
input symbol σ ∈ Σ to a next state s’ and an output
symbol λ ∈ Λ. Hence, τ (s, σ) = (s’, λ).
¾ Straight forward extension to multiple signals possible
ƒ n input signals: Σ = Σ1 x Σ2 x … x Σn
ƒ m output signals: Λ = Λ1 x Λ2 x … x Λm
© University of Erlangen-Nuremberg
Christian Haubelt
6
State Transition Diagram
¾ Graphical representation of FSMs
¾ Vertices represent states s ∈ S.
¾ Edges represent state transitions τ.
ƒ
ƒ
ƒ
Transitions are labeled with guard/action pairs, where
guard ∈ Σ and action ∈ Λ.
A state transition is selected from all enabled transitions
A transition is enable if it is represented by an outgoing
edge from the vertex representing the current state and
the guard matches the current input symbol
σ1/λ1
s0
s1
σ2/λ2
© University of Erlangen-Nuremberg
Christian Haubelt
current state
s0
s0
s1
s1
…
input symbol
σ2
σ1
σ1
σ2
…
next state
s0
s1
s1
s0
…
output symbol
ε
λ1
ε
λ2
…
7
Outline
¾ Introduction
¾ Integrated Modeling
ƒ
Specify dataflow actors using FSMs
ƒ
Control dataflow graphs by FSMs
¾ Introduction to SysteMoC Programming
¾ Analysis of Integrated Models
¾ Summary
¾ Hands-on SysteMoC
© University of Erlangen-Nuremberg
Christian Haubelt
8
Integrated FSM and Dataflow Modeling
¾ Several options exist how to integrate FSM and
dataflow modeling:
ƒ
ƒ
ƒ
Specify dataflow actors using FSMs,
Control dataflow graphs by FSMs, or
Refine states by dataflow graphs
¾ In this lecture, the first two options are covered
¾ We start with a simple approach
© University of Erlangen-Nuremberg
Christian Haubelt
9
Simple Actors
Definition (Actor): An actor is a three-tuple a = (I, O, M)
containing actor ports, partitioned into actor input
ports I and actor output ports O, and an actor FSM M.
¾ Ports will be used to connect actors to communication
channels
¾ Actors only communicate via channels (Actor-oriented
modeling)
¾ Actor FSM M specifies the behavior of the actor
© University of Erlangen-Nuremberg
Christian Haubelt
10
Example Simple Actor
Actor
i1
i2
Actor FSM
o1
¾ I = {i1, i2}
¾ O = {o1}
¾ Actor FSM … later
© University of Erlangen-Nuremberg
Christian Haubelt
11
Simple Network Graph
Definition (Network Graph): A network graph is a directed
graph G = (A, Q, π) containing a set of actors A, a set of
FIFO channels Q ⊆ A.O x A.I with infinite buffer size, and
a channel parameter function π : Q → V*, which
associates with each channel q ∈ Q a possibly non-empty
sequence v ∈ V* of initial tokens.
¾ Furthermore, all actor ports A.I ⋃ A.O are restricted to
be connected to exactly one channel q ∈ Q.
¾ FIFO channels supporting
ƒ Blocking, destructive reads
ƒ Non-blocking, non-destructive writes
© University of Erlangen-Nuremberg
Christian Haubelt
12
Example Simple Network Graph
a1
a3
a2
¾
¾
¾
¾
A = {a1, a2, a3}
Q = {(a1.o1, a3.i1), (a2.o1, a3.i2), (a3.o1, a1.i1), (a3.o2, a2.i1)}
π(a3.o1, a1.i1) = π(a3.o2, a2.i1) = “1”
Channel parameter functions are omitted for channels
without initial tokens
© University of Erlangen-Nuremberg
Christian Haubelt
13
Simple Actor FSM
Definition (Actor FSM): The actor FSM M of an
actor a ∈ A is an FSM (S, Σ, Λ, τ, s0) with input
alphabet Σ = 2a.I and output alphabet Λ = 2a.O.
¾ a.I denotes the set of input ports of actor a
¾ a.O denotes the set of output ports of actor a
¾ 2X denotes the power set of X
ƒ X = {x1, x2} ⇒ 2X = {Ø, {x1}, {x2}, {x1, x2}}
¾ The input and output symbols specify the consumption
and production of tokens, respectively
© University of Erlangen-Nuremberg
Christian Haubelt
14
Example (Cyclo Static Dataflow)
a1
{i1} / Ø
s0
i1
s1
o1
{i1} / {o1}
a2
i1
i1
i2
{i1} / {o1}
s0
a3
s1
{i2} / {o1, o2}
s0
s1
{i1} / {o1, o2}
o1
o2
o1
{i1} / Ø
© University of Erlangen-Nuremberg
Christian Haubelt
15
Execution Semantics
FOR each actor DO
FOR each state transition originating in the current state DO
Evaluate guard
Non-deterministically select a transition with satisfied guard
Consume tokens according to the guard
Produce tokens according to the action
Update current state
ENDFOR
ENDFOR
a1
i1
{i1} / {o1}
s0
s1
o1
{i1} / Ø
© University of Erlangen-Nuremberg
Christian Haubelt
16
Example (Cyclo Static Dataflow)
a1
{i1} / Ø
s0
i1
s1
o1
{i1} / {o1}
a2
i1
i1
i2
{i1} / {o1}
s0
a3
s1
{i2} / {o1, o2}
s0
s1
{i1} / {o1, o2}
o1
o2
o1
{i1} / Ø
© University of Erlangen-Nuremberg
Christian Haubelt
17
Data-Dependent Behavior
¾ So far introduced simple actor model cannot express
data-dependent behavior
¾ In the following, each token carries a value v ∈ V.
¾ Channels are queues supporting
ƒ
ƒ
Blocking, destructive reads (consumption) and nonblocking, non-destructive writes (production) in FIFO
order
Non-blocking, non-destructive reads (peak) and nonblocking, destructive writes (poke) in random order
© University of Erlangen-Nuremberg
Christian Haubelt
18
Guards (1/3)
¾ Guards (input symbols σ ∈ Σ ) are now given as
formulas in first order logics consisting of a
conjunction of
ƒ
ƒ
ƒ
Consumption rates, where c(i, n) specifies to consume n
∈ ℕ tokens from the channel connected to the input port
i ∈ I,
Production rates, where p(i, m) specifies to produce m ∈
ℕ tokens onto the channel connected to the output port
o ∈ O, and
Comparisons i[k] = v of token values with constant
values v ∈ V. The []-operator returns the value of the k-th
token in the channel connected to the input port i ∈ I.
© University of Erlangen-Nuremberg
Christian Haubelt
19
Guards (2/3)
¾ Only token values from tokens specified in the
consumption rates are allowed to be compared.
¾ Indices start with 0
¾ Example
ƒ
ƒ
Correct: c(i1, 2) ∧ c(i2, 1) ∧ (i2[0] = 2)
Incorrect: c(i1, 2) ∧ c(i2, 1) ∧ (i2[1] = 2)
© University of Erlangen-Nuremberg
Christian Haubelt
20
Guards (3/3)
¾ A guard evaluates to true if
ƒ
ƒ
ƒ
Each specified consumption rate c(i, n) is satisfied, i.e.,
at least n tokens are available from the channel
connected to the input port i,
Each specified production rate p(o, m) is satisfied, i.e, m
additional token can be stored in the channel connected
to output port o (always true in presence of infinite
queues), and
Each specified comparison is true
a2
0 2
© University of Erlangen-Nuremberg
Christian Haubelt
i1
s0
c(i1, 2) ∧ p(o1, 2)
∧ (i1[0] = 2)
∧ (i1[1] = 0) /
o1
3
21
Actions (1/2)
¾ Actions (output symbols δ ∈ ∆) are now given as
sequences of assignments 〈(o1[0] := 1), (o1[1] :=2), …〉
¾ The []-operator returns a reference of the k-th token to
be produced to the channel connected to the output
port o ∈ O.
a2
0 2
© University of Erlangen-Nuremberg
Christian Haubelt
i1
s0
c(i1, 2) ∧ p(o1, 2)
∧ (i1[0] = 2)
∧ (i1[1] = 0) /
〈 (o1[0] := 2),
(o1[1] := 4)〉
o1
3
22
Actions (2/2)
¾ A transition is enabled if its guard evaluates to true
¾ If an enabled transition is executed
ƒ
ƒ
ƒ
ƒ
Additional token are generated according to the
production rates,
The action is performed (values are assigned to the new
tokens according to the action),
Tokens are consumed and produced according to the
consumption and production rates, and
The state of the actor FSM is updated
a2
0 2
© University of Erlangen-Nuremberg
Christian Haubelt
i1
s0
c(i1, 2) ∧ p(o1, 2)
∧ (i1[0] = 2)
∧ (i1[1] = 0) / 4 2
〈 (o1[0] := 2),
(o1[1] := 4)〉
o1
3
23
Example Data-Dependent Behavior
a1
c(i1, 1) ∧ p(o1, 1)
/ o1[0] := 1
s0
i1
c(i1, 1) ∧
p(o1, 1) / o1[0] := 2
a2
i1
o1
s1
a3
i1
i2
c(i1, 1) ∧ p(o1, 1)
s0
1
2
c(i1, 1) ∧ p(o1, 1) ∧
p(o2, 1) ∧ (i1[0] = 1) /
s0
c(i1, 1) ∧
c(i2, 1) ∧ p(o1, 1) ∧
p(o2, 1) ∧ (i1[0] = 2) /
o1
o2
o1
c(i1, 1) /
© University of Erlangen-Nuremberg
Christian Haubelt
24
Outline
¾ Introduction
¾ Integrated Modeling
ƒ
Specify dataflow actors using FSMs
ƒ
Control dataflow graphs by FSMs
¾ Introduction to SysteMoC Programming
¾ Analysis of Integrated Models
¾ Summary
¾ Hands-on SysteMoC
© University of Erlangen-Nuremberg
Christian Haubelt
25
Idea
¾ Refine a single actor by a dataflow graph
¾ Control the firing of the actors of the dataflow graph by
an FSM
¾ A refined actor is called a cluster
¾ The FSM is called the cluster FSM
¾ A cluster without cluster FSM is a network graph
¾ A cluster without refining dataflow graph is an actor
© University of Erlangen-Nuremberg
Christian Haubelt
26
Cluster
Definition (Cluster): A cluster is a six-tuple ac = (I, O, A,
Q, π, M) containing cluster ports, partitioned into
cluster input ports I and cluster output ports O, a set of
actors A, a set of FIFO channels Q ⊆ A.O x A.I with
infinite buffer size, and a channel parameter function π :
Q → V*, which associates with each channel q ∈ Q a
possibly non-empty sequence v ∈ V* of initial tokens,
and a cluster FSM M.
¾ The cluster FSM is an actor FSM where the action is a
static schedule of actors in the refining dataflow graph
© University of Erlangen-Nuremberg
Christian Haubelt
27
Example SDF Cluster (1/2)
2
2
a2
2
1
1
1
a1
a3
1
© University of Erlangen-Nuremberg
Christian Haubelt
2
1
1
28
Example SDF Cluster (2/2)
ac
2
a2
i1
2
1
i2
© University of Erlangen-Nuremberg
Christian Haubelt
2
1
o1
2
1
a1
a3
1
1
1
o2
29
CSDF Schedule (1/2)
ac
2
a2
i1
2
1
i2
2
1
o1
2
1
a1
a3
1
1
1
o2
c(i1, 2) ∧ p(o1, 2) / 〈a2〉
s0
s1
c(i2, 2) ∧ p(o1, 2) / 〈a1, a1, a3, a3〉
© University of Erlangen-Nuremberg
Christian Haubelt
30
CSDF Schedule (2/2)
ac
2
a2
i1
2
1
i2
2
1
o1
2
1
a1
a3
1
1
1
o2
c(i1, 2) ∧ p(o1, 2) / 〈a2〉
s0
s1
c(i2, 2) ∧ p(o1, 2) / 〈a1, a1, a3, a3〉
© University of Erlangen-Nuremberg
Christian Haubelt
31
Outline
¾ Introduction
¾ Integrated Modeling
¾ Introduction to SysteMoC Programming
ƒ
Formal Model
ƒ
Programming
¾ Analysis of Integrated Models
¾ Summary
¾ Hands-on SysteMoC
© University of Erlangen-Nuremberg
Christian Haubelt
32
SysteMoC Actors
¾ So far presented modeling approach not applicable for
real-world applications
¾ Additional abstractions are mandatory
Definition (Actor): An actor is a four-tuple a = (I, O, F, M)
containing actor ports partitioned into actor input ports
I and actor output ports O, the actor functionality F and
an actor FSM M.
¾ The actor functionality can be seen as an actor
refinement not necessarily restricted to dataflow
models
© University of Erlangen-Nuremberg
Christian Haubelt
33
Example SysteMoC Actors
Actor
Actor functionality
i1
Actor FSM
i2
¾
¾
¾
¾
o1
I = {i1, i2}
O = {o1}
Actor functionality … next
Actor FSM … later
© University of Erlangen-Nuremberg
Christian Haubelt
34
SysteMoC Actor Functionality
Definition (Actor Functionality): The actor
functionality is three-tuple F = (Fa, Fg, Z), where Fa
is a finite set of action functions, Fg is a finite set of
guard functions, and Z is a finite set of states.
¾ Action functions and guard functions must terminate
eventually
¾ Action functions are only allowed to change the current
state z ∈ Z of the actor functionality and the token
values to be produced on the output channels
¾ Guard functions are Boolean-valued functions that
must not change the state of the model at all. This
includes
ƒ The current state z ∈ Z of the actor functionality a.F,
ƒ The current state s ∈ S of the actor FSM a.M, and
ƒ The number and the values of tokens in the channels
connected to the actor
© University of Erlangen-Nuremberg
Christian Haubelt
35
Example SysteMoC Actor Functionality
Actor
f1
Z
f2
g1
i1
Actor FSM
i2
o1
¾ Fa = {f1, f2}
¾ Fg = {g1}
¾ Z
¾ Action functions and guard functions are triggered by
the actor FSM
© University of Erlangen-Nuremberg
Christian Haubelt
36
SysteMoC Actor FSM
Definition (Actor FSM): The actor FSM is a threetuple M = (S, T, s0) consisting of a finite set of
states S, a finite set of transitions T, and an initial
state s0 ∈ S.
¾ A transitions t = (s, cons, prod, fg, fa, s’) ∈ T from the
current state s ∈ S to a next state s’ ∈ S defines
ƒ its input consumption rate cons : I → ℕ0
ƒ its output production rate prod : O → ℕ0.
¾ The guard function fg ∈ Fg is a Boolean-valued
expression over the values of the tokens required on
the input ports and the current state z ∈ Z of the actor
functionality.
¾ The action function fa ∈ Fa determines the values of the
tokens, which are to be produced on the outputs.
© University of Erlangen-Nuremberg
Christian Haubelt
37
Example SysteMoC Actor FSM
Actor
f1
f2
Z
g1
i1
i2
c(i1, 1) ∧ p(o1, 1) ∧ g1 / f1
s0
s1
o1
c(i2, 1) ∧ p(o1, 1) / f2
¾ A = {s0, s1}
¾ T = { (s0, ((i1, 1)), ((o1, 1)), g1, f1, s1),
(s1, ((i2, 1)), ((o1, 1)), Ø, f2, s0) }
© University of Erlangen-Nuremberg
Christian Haubelt
38
SysteMoC Actor Behavior
¾ Actors are composed of a Finite State Machine (FSM),
functions, and variables
¾ The FSM controls the function invocation
¾ Functions are executed atomically
¾ Data consumption and production is performed at the
end of an action execution
Actor state
active
passive
Actor FSM
Variables
call
read
modify
Functions
Action Functions
Guard Functions
© University of Erlangen-Nuremberg
Christian Haubelt
39
Simulation Semantics
¾ A transition is active if
ƒ
ƒ
ƒ
All referred input queues have enough tokens,
All referred output queues have enough free space,
And the guard function evaluates to true
¾ An active transition may be fired
ƒ
ƒ
ƒ
The associated action function is atomically executed
Consumption and production of data tokens take place
Dataflow between actors may activate or deactivate
actions
¾ If several transitions of one actor are active
ƒ
One transition is selected non-deterministically
© University of Erlangen-Nuremberg
Christian Haubelt
40
Example Square Root Calculation
0
aapprox
aloop
asrc
asnk
aloop
var
fin { var := i1[0]; o1[0] := var; }
floop { o1[0] := var; }
fout { o2[0] := i1[0]; }
gexact { (i1[0] * i1[0] – var ≤ bound) ? true : false; }
i1
c(i2, 1) ∧ p(o1, 1) / fin
s0
i2
s1
c(i1, 1) ∧
p(o1, 1) ∧
¬gexact / ffoop
c(i1, 1) ∧ p(o2, 1) ∧ gexact / fout
© University of Erlangen-Nuremberg
Christian Haubelt
o1
o2
41
Outline
¾ Introduction
¾ Integrated Modeling
¾ Introduction to SysteMoC Programming
ƒ
Formal Model
ƒ
Programming
¾ Analysis of Integrated Models
¾ Summary
¾ Hands-on SysteMoC
© University of Erlangen-Nuremberg
Christian Haubelt
42
SysteMoC
SysteMoC – SystemC library for Dataflow Modeling
SysteMoC
ƒ Elementary channels separating functionality and communication
ƒ C++ syntax for specifying actor FSMs
ƒ Scheduler for (dynamic) dataflow MoC domain
Elementary Channels
SystemC
Signal, timer, mutex, semaphore, FIFO, etc.
Core Language
Data-Types
ƒ Modules
ƒ Ports
ƒ Processes
ƒ Events
ƒ Interfaces
ƒ Channels
ƒ 4-valued logic types (01zx)
ƒ 4-valued logic vectors
ƒ Bits and bit-vectors
ƒ Arbitrary-precision integers
ƒ Fixed-point numbers
ƒ C++ user-defined types
C++
Event-driven Simulation Kernel
C++ Language Standard
© University of Erlangen-Nuremberg
Christian Haubelt
43
Hello World – Objectives
¾ You will see a state-of-the-art “Hello World” application ...
¾ ... modeled in SysteMoC.
© University of Erlangen-Nuremberg
Christian Haubelt
44
Hello World (hello.cpp)
#include <iostream >
#include <systemoc/smoc_moc.hpp >
class HelloActor: public smoc_actor {
public:
// actor constructor
HelloActor(sc_module_name name)
: smoc_actor(name, start) {
// FSM definition:
// transition from start to end calling action src
start = CALL(HelloActor::src) >> end;
}
private:
smoc_firing_state start , end; // FSM states
void src() { // action
std::cout << "Actor " << this->name()
<< " says :\n„ << "Hello World" << std::endl;
}
© University of Erlangen-Nuremberg
Christian Haubelt
45
SysteMoC Actors
¾ Include SysteMoC library header
#include <systemoc/smoc_moc.hpp>
¾ An actor is a C++ class derived from base class
smoc_actor
class HelloActor: public smoc_actor {
¾ An action function is a method of the actors class
¾ Actions shall be private (prohibit execution by others)
private:
void src() { // action
std::cout << "Actor "
<< this->name () << " says :\n“
<< "Hello World" << std::endl;
}
© University of Erlangen-Nuremberg
Christian Haubelt
46
SysteMoC Actors
¾ An actor has a finite set of states
smoc_firing_state state_a , state_b;
¾ Like objects of a C++ classes, we create instances of an
actor
¾ Constructors are responsible for creating a certain actor
instance
¾ Provide actor name and start state to base class
smoc_actor
HelloActor(sc_module_name name)
: smoc_actor(name , state_a) {
© University of Erlangen-Nuremberg
Christian Haubelt
47
SysteMoC Actors
¾ A finite state machine (FSM) defines transitions between
states
¾ E.g. a transition from state_a to state_b
¾ If this transition is taken, the action HelloActor::src is
executed
HelloActor(sc_module_name name)
: smoc_actor(name , state_a) {
state_a = CALL(HelloActor::src) >> state_b;
}
© University of Erlangen-Nuremberg
Christian Haubelt
48
Hello World (hello.cpp cont‘d)
class HelloNetworkGraph : public smoc_graph {
public:
// network graph constructor (create actor HelloWorld)
HelloNetworkGraph(sc_module_name name)
: smoc_graph(name), helloActor("HalloActor")
{ }
private:
// actors
HelloActor helloActor;
};
int sc_main(int argc , char ** argv) {
// create network graph
HelloNetworkGraph top("top");
smoc_scheduler_top sched(top);
sc_start(); // start simulation (SystemC)
return 0;
}
© University of Erlangen-Nuremberg
Christian Haubelt
49
SysteMoC Graphs
¾ A network graph is derived from base class smoc_graph
class HelloNetworkGraph : public smoc_graph {
¾ Our network graph has an instance of the HelloActor
private:
HelloActor helloActor;
¾ A name for the graph has to be passed to base class
smoc_graph
¾ We need to call HelloActor’s constructor
HelloNetworkGraph(sc_module_name name)
: smoc_graph(name),
helloActor("HelloActor")
{ }
© University of Erlangen-Nuremberg
Christian Haubelt
50
Simulation
¾ Function sc_main is the entry point for simulation (cf.
SystemC)
¾ The network graph is instantiated
¾ Parameters are passed to the graph constructor
(e.g.“top”)
¾ Call sc_start to start simulation (cf. SystemC)
int sc_main(int argc , char ** argv) {
HelloNetworkGraph top("top");
smoc_scheduler_top sched(top);
sc_start();
return 0;
}
© University of Erlangen-Nuremberg
Christian Haubelt
51
Compilation and Execution
¾ Compile the source code (hello.cpp) using e.g., gcc
¾ Run simulation (OSCI SystemC: execute binary for
simulation)
./hello
¾ Simulation output
© University of Erlangen-Nuremberg
Christian Haubelt
52
Ports and Channels – Sink Actor
class Sink: public smoc_actor {
public:
// ports:
smoc_port_in <char> in;
Sink(sc_module_name name) // actor constructor
: smoc_actor(name, start) {
// FSM definition:
start = in(1)
>>
CALL(Sink::sink) >> start;
}
private:
smoc_firing_state start; // FSM states
void sink() {
std::cout << this->name () << " recv: \""
<< in[0] << "\"" << std::endl;
}
};
© University of Erlangen-Nuremberg
Christian Haubelt
53
Ports and Channels – Input Port
¾ Create an input port
¾ Ports have a data type (e.g. char)
smoc_port_in <char> in;
¾ Declare to read one token in FSM transition
start =
in(1)
CALL(Sink::sink)
>>
>> start;
¾ Write data in action
void sink () {
std::cout << this->name () << " recv: \’"
<< in[0] << "\’" << std::endl;
}
© University of Erlangen-Nuremberg
Christian Haubelt
54
Ports and Channels – Source Actor
class Source: public smoc_actor {
public:
// ports:
smoc_port_out <char> out;
Source(sc_module_name name)
: smoc_actor(name , start) {
start = out (1)
>>
CALL(Source::src) >> start;
}
private:
smoc_firing_state start; // FSM states
void src() {
std::cout << this->name ()
<< " send: \’X\’" << std::endl;
out [0] = ’X’;
}
};
© University of Erlangen-Nuremberg
Christian Haubelt
55
Ports and Channels – Output Port
¾ Create an output with data type char
smoc_port_out<char> out;
¾ Declare to write one token in FSM transition
start =
out(1)
CALL(Source::src)
>>
>> start;
¾ Access data within actions
void src() {
std::cout << this->name ()
<< " send: \’X\’" << std::endl;
out[0] = ’X’;
}
© University of Erlangen-Nuremberg
Christian Haubelt
56
Ports and Channels – Connect Actors
class NetworkGraph : public smoc_graph {
public:
NetworkGraph(sc_module_name name) // constructor
: smoc_graph(name),
source("Source"), // create actors
sink("Sink") {
connectNodePorts (source.out , sink.in);
// connect actors
}
private:
Source source; // actors
Sink sink;
};
int sc_main(int argc , char ** argv) {
smoc_top_moc <NetworkGraph> top("top"); // create
network graph
sc_start(); // start simulation (SystemC)
return 0;
}
© University of Erlangen-Nuremberg
Christian Haubelt
57
Ports and Channels – FIFO Queues
¾ Connect a pair of ports (input, output) using a FIFO queue
¾ Connected ports have to use the same data type
¾ Queues have default size “1” (one data token)
connectNodePorts(source.out, sink.in);
¾ Set queue size explicitly
connectNodePorts<23>(source.out, sink.in);
¾ Initial data tokens later
© University of Erlangen-Nuremberg
Christian Haubelt
58
Ports and Channels
¾ Simulation output
¾ Simulation runs infinitely
© University of Erlangen-Nuremberg
Christian Haubelt
59
Multi-Rate Systems – Production Rate
¾ The source actor produces two data tokens per
invocation
¾ We declare to produce n data tokens in a transition
using out(n)
start =
out (2) >>
CALL(Source::src) >> start;
¾ Use the []-operator to write data values
void src () {
out[0] = message[count++];
out[1] = message[count++];
}
¾ Similar to arrays addressing range is 0, . . . ,n−1
© University of Erlangen-Nuremberg
Christian Haubelt
60
Communication Rates – Avoid Deadlocks
¾ Simulation output (using Sink actor from previous
example)
¾ Nothing happens! Why?
¾ Writing two tokens requires free space for (at least)
two tokens
¾ We need to increase the queue size (implicit size was
“1”)
¾ Minimum size of 2 is mandatory (but actors would run
in lockstep)
¾ Using larger sized queues may decouple execution of
actors
connectNodePorts<4>(source.out, sink.in);
© University of Erlangen-Nuremberg
Christian Haubelt
61
Initial Tokens – Syntax
¾ Explicit creation of a FIFO initializer
¾ Give queue size as constructor parameter
smoc_fifo<int> initFifo(1);
¾ Push initial value to initializer
initFifo << 42;
¾ Pass initializer when constructing the queue
connectNodePorts(source.out, sink.in, initFifo);
¾ Initializer may be reused for creating identical
initialized queues
© University of Erlangen-Nuremberg
Christian Haubelt
62
Guards and Actions – Source Actor
static const std :: string MESSAGE = "0123456789";
class Source: public smoc_actor {
public:
smoc_port_out <char> out;
Source(sc_module_name name) : smoc_actor(name, start),
count(0), size(MESSAGE.size()), message(MESSAGE) {
start =
GUARD(Source::hasToken) >>
out(1) >>
CALL(Source::src) >> start;
}
private:
smoc_firing_state start;
unsigned int count, size; // variables (functional
state)
const std::string message; //
bool hasToken() const{ return count < size; } // guard
void src() { out[0] = message[count ++]; } // action
};
© University of Erlangen-Nuremberg
Christian Haubelt
63
Guards and Actions – Guards
¾ A guard is a const member function returning a
Boolean value
bool hasToken() const{
return count < size;
}
¾ Guards enable/disable transitions (true/false)
¾ Guards must (can) not change variable values or token
in channels
¾ Refer to guards via GUARD(..) macro
start =
GUARD(Source::hasToken) >>
out(1) >>
CALL(Source::src) >> start;
¾ Use guards for control flow (see below)
© University of Erlangen-Nuremberg
Christian Haubelt
64
Guards and Actions – Variables
¾ Variables ...
¾ ... are private class member of an actor
¾ ... can be used to store data
¾ ... represent a functional state of an actor (in contrast
to FSM state)
unsigned int count , size;
const std::string message;
© University of Erlangen-Nuremberg
Christian Haubelt
65
Guards and Actions – Actions
¾ Actions ...
¾ ... are used to read/write data on input/output ports
¾ ... modify variables
void src() {
out[0] = message[count ++];
}
¾ Guards access variables read-only (mandatory const
modifier)
¾ Actions are allowed to modify variables
© University of Erlangen-Nuremberg
Christian Haubelt
66
Guards and Actions
¾ Simulation output (using Sink actor from previous
example)
¾ Source actor sends a finite number of characters only
¾ Simulation terminates when no actor can be activated
© University of Erlangen-Nuremberg
Christian Haubelt
67
Outline
¾ Introduction
¾ Integrated Modeling
¾ Introduction to SysteMoC Programming
¾ Analysis of Integrated Models
¾ Summary
¾ Hands-on SysteMoC
© University of Erlangen-Nuremberg
Christian Haubelt
68
Hierarchy of Streaming Models
RPN
BDF and larger: Turing complete
DDF
KPN
BDF
CSDF
SDF
HSDF
RPN: Reactive Process Network
DDF: Dynamic Dataflow
KPN: Kahn Process Network
BDF: Boolean Dataflow
CSDF: Cyclo-Static Dataflow
SDF: Synchronous Dataflow
HSDF: Homogeneous SDF
[Basten@MoCC2008]
© University of Erlangen-Nuremberg
Christian Haubelt
69
Classification
¾ Classify actors by
ƒ Minimizing the communication FSM
ƒ Pattern matching
¾ Note that actor classification in its general form is
undecidable
¾ In the following only static dataflow models are
considered that can be recognized:
ƒ SDF (Synchronous Data Flow)
ƒ CSDF (Cyclo-Static Data Flow)
© University of Erlangen-Nuremberg
Christian Haubelt
70
Simple Example
a
i1
c(i1, 2) ∧ c(i2, 1)
∧ c(o1, 2) /
s0
o1
2
a
2
1
i2
¾ Most basic representation (left figure) of an actor,
which can be classified to be an SDF actor (right
picture)
¾ A single state with one outgoing state transition
© University of Erlangen-Nuremberg
Christian Haubelt
71
Actor state
¾ Problem: Actor FSM describes the possible
communication behavior of the actor
¾ However, only a subset of transitions may be enabled
during the execution of the actor (data dependencies)
¾ To accomodate both, FSM state and functionality state
of an actor, we define an actor state as the pair x = (z, s)
ƒ Z is the (possibly infinite) set of functionality states
ƒ S is the finite set of FSM states
¾ When an enabled transition is executed, the next actor
state x‘ is defined as follows:
ƒ The next FSM state x‘.s is destination state of the
transition
ƒ The next functionality state x‘.z is the new functionality
state after the execution of the associated action
© University of Erlangen-Nuremberg
Christian Haubelt
72
Dynamic state transition diagram
a
i := 0, j := 0
f1 { i = (i + 1) % 2; }
g1 { (i == j) ? true : false; }
p(o1, 1) ∧ ¬g1 / f1
i1
f2 { j = (j + 1) % 2; }
c(i1, 1) ∧ g1 / f1
s0
p(o1, 1) ∧ ¬g1 / f2
o1
c(i1, 1) ∧ g1 / f2
¾ S= { s0 }
¾ Z = { (0,0), (1,0), (0,1), (1,1) }
¾ The actor state space Z x S induces a diagram, which
refines the possible communication behavior described
by the FSM
© University of Erlangen-Nuremberg
Christian Haubelt
73
Dynamic State Transition Diagram
((0,0),s0)
(1),(0)
(0),(1)
(1),(0)
((1,0),s0)
((0,1),s0)
(1),(0)
(0),(1)
(0),(1)
(0),(1)
((1,1),s0)
(1),(0)
¾ For each actor state x = (z, s) and each enabled
transition τ :
ƒ Add edge e to dynamic state transition diagram
connecting x with x‘
ƒ Annotate e with the number of tokens consumed and
produced by τ as vectors
© University of Erlangen-Nuremberg
Christian Haubelt
74
Classification Algorithm
¾ Classification requirements:
ƒ Liveliness, i.e., each actor state must have at least one
enabled outgoing transition (SDF / CSDF actors can always
be activated if enough tokens available)
ƒ Active input / output behavior, i.e., no infinite sequence of
edges, which do not consume or produce any tokens
¾ If requirements are not met, deadlocks could be
introduced by treating the actor as an SDF or CSDF actor
¾ Assume we have a hypothesis γ („classification
candidate“)
ƒ γ.ν : Number of phases
ƒ γ.cons : Maps phase to vector of consumed tokens
ƒ γ.prod : Maps phase to vector of produced tokens
¾ Accept / Reject γ by annotating x., x.cons, x.prod to a
visited state
© University of Erlangen-Nuremberg
Christian Haubelt
75
Example Classification (1/3)
(1),(0)
x0
(1),(0)
(0),(1)
(1),(0)
(0),(1)
x1
x2
(0),(1)
(0),(1)
(1),(0)
x3
(1),(0)
(1),(0)
x2
(0),(1)
(1),(0)
(1),(0)
(0),(1)
x1
(0),(1)
(1),(0)
x0
(1),(0)
(0),(1)
x3
(1),(0)
¾ γ1.ν := 1, γ1.cons(1) := (1), γ1.prod(1) := (0)
ƒ failed
© University of Erlangen-Nuremberg
Christian Haubelt
76
Example Classification (2/3)
(1),(1)
x0
(1),(0)
(0),(1)
(1),(0)
(0),(1)
x1
x2
(0),(1)
(0),(1)
(0),(1)
x3
(1),(0)
(0),(1)
x2
(0),(1)
(1),(0)
(1),(0)
(0),(1)
x1
(0),(1)
(1),(0)
x0
(1),(0)
(0),(1)
(1),(1)
x3
(1),(0)
¾ γ1.ν := 1, γ1.cons(1) := (1), γ1.prod(1) := (0) (discarded)
¾ γ2.ν := 1, γ2.cons(1) := (1), γ2.prod(1) := (1)
© University of Erlangen-Nuremberg
Christian Haubelt
77
Example Classification (3/3)
x0
(1),(0)
(0),(1)
(1),(0)
(0),(1)
x1
(0),(1)
(0),(1)
x2
x3
(1),(0)
x2
(0),(1)
(1),(0)
(1),(0)
(0),(1)
x1
(0),(1)
(1),(0)
x0
(1),(0)
(0),(1)
x3
(1),(0)
¾ γ1.ν := 1, γ1.cons(1) := (1), γ1.prod(1) := (0) (discarded)
¾ γ2.ν := 1, γ2.cons(1) := (1), γ2.prod(1) := (1) (accepted)
¾ γ3.ν := 2, γ3.cons(2) := (1), γ3.prod(2) := (0) (not needed)
© University of Erlangen-Nuremberg
Christian Haubelt
78
Classification Algorithm Limitations
¾ Problem: Functionality state of actor may be
ƒ Not known in advance
ƒ Infinite
ƒ Non-deterministic
¾ Dynamic state transition diagram can not be
constructed / analyzed in such a case
¾ In order to be able to classify those actors anyhow, one
can compute an over-approximation
¾ This leads to a state transition diagram based on the
FSM
¾ Classification algorithm can also be applied to this
diagram
© University of Erlangen-Nuremberg
Christian Haubelt
79
Outline
¾ Introduction
¾ Integrated Modeling
¾ Introduction to SysteMoC Programming
¾ Analysis of Integrated Models
¾ Summary
¾ Hands-on SysteMoC
© University of Erlangen-Nuremberg
Christian Haubelt
80
Summary
¾ Limited expressiveness of static dataflow graphs is
not sufficient to model state-of-the art multimedia or
signal processing applications
¾ Limited analyzability of dynamic dataflow graphs
restricts their usability in automatic design flows
¾ Integrated FSM and dataflow graph model helps to
overcome some of these drawbacks
¾ SysteMoC is an actor-oriented system programming
language based on an integrated FSM and dataflow
graph model
¾ During classification of SysteMoC actors, “hidden”
functionality state must be considered (or abstracted)
© University of Erlangen-Nuremberg
Christian Haubelt
81
© University of Erlangen-Nuremberg
Christian Haubelt
82
Integrated FSM and Dataflow Modeling
¾ Contact information:
Christian Haubelt
Hardware/Software Co-Design
University of Erlangen-Nuremberg, Germany
http://www12.cs.fau.de/people/haubelt
[email protected]
¾ With contributions from
Joachim Falk, Jens Gladigau, Joachim Keinert,
Martin Streubühr, Christian Zebelein, and Jürgen Teich
© University of Erlangen-Nuremberg
Christian Haubelt
83