A dataflow graph is a representation of how compute blocks are connected to implement a processing.
Here is an example with 3 nodes:
Each node is producing and consuming some amount of samples. For instance, the source node is producing 5 samples each time it is run. The filter node is consuming 7 samples each time it is run.
The FIFOs lengths are represented on each edge of the graph : 11 samples for the leftmost FIFO and 5 for the other one.
In blue, the amount of samples generated or consumed by a node each time it is called.
When the processing is applied to a stream of samples then the problem to solve is :
how the blocks must be scheduled and the FIFOs connecting the block dimensioned
The general problem can be very difficult. But, if some constraints are applied to the graph then some algorithms can compute a static schedule.
When the following constraints are satisfied we say we have a Synchronous Dataflow Graph (SDF):
The CMSIS-DSP SDF Tools are a set of Python scripts and C++ classes with following features:
Without any scheduling tool for a dataflow graph, there is a problem of modularity : a change on a node may impact other nodes in the graph. For instance, if the number of samples consumed by a node is changed:
With the CMSIS-DSP SDF Tools you don't have to think about those details while you are still experimenting with your data processing pipeline. It makes it easier to experiment, add or remove blocks, change their parameters.
The tools will generate a schedule and the FIFOs. Even if you don't use this at the end for a final implementation, the information could be useful : is the schedule too long ? Are the FIFOs too big ?
Let's look at an (artificial) example:
Without a tool, the user would probably try to modify the sample values so that the number of sample produced is equal to the number of samples consumed. With the SDF Tools we know that such a graph can be scheduled and that the FIFO sizes need to be 11 and 5.
The periodic schedule generated for this graph has a length of 19. It is big for such a small graph and it is because, indeed 5 and 7 are not very well chosen values. But, it is working even with those values.
The schedule is (the size of the FIFOs after the execution of the node displayed in the brackets):
source [ 5 0]
source [10 0]
filter [ 3 5]
sink [ 3 0]
source [ 8 0]
filter [ 1 5]
sink [ 1 0]
source [ 6 0]
source [11 0]
filter [ 4 5]
sink [ 4 0]
source [ 9 0]
filter [ 2 5]
sink [ 2 0]
source [ 7 0]
filter [ 0 5]
sink [ 0 0]
At the end, both FIFOs are empty so the schedule can be run again : it is periodic !
First, you must install the CMSIS-DSP
PythonWrapper:
pip install cmsisdsp
In folder SDFTools/example/build
, type the cmake
command:
cmake -DHOST=YES -DDOT="path to dot tool" -DCMSIS="path to cmsis" -G "Unix Makefiles" ..
The Graphviz dot tool is requiring a recent version supporting the HTML-like labels.
The path to cmsis must be the root folder containing CMSIS and Device folders.
If cmake is successful, you can type make
to build the examples. It will also build CMSIS-DSP for the host.
If you don't have graphviz, the option -DDOT can be removed.
If for some reason it does not work, you can go into an example folder (for instance example1), and type the commands:
python graph.py dot -Tpdf -o test.pdf test.dot
It will generate the C++ files for the schedule and a pdf representation of the graph.
Note that the Python code is relying on the CMSIS-DSP PythonWrapper which is now also containing the Python scripts for the Synchronous Data Flow.
To build the C examples:
sdf/src
must be addedFor example3
which is using an input file, cmake should have copied the input test pattern input_example3.txt
inside the build folder. The output file will also be generated in the build folder.
example4
is like example3
but in pure Python and using the CMSIS-DSP Python wrapper (which must already be installed before trying the example). example4
is not built by the cmake. You'll need to go to the example4
folder and type:
python graph.py python main.py
The first line is generating the schedule in Python. The second line is executing the schedule.
example7
is communicating with OpenModelica
. You need to install the VHTModelica blocks from the VHT-SystemModeling project on our GitHub
It is a first version and there are lots of limitations and probably bugs:
sdf/templates
. They must be cleaned to be more readable. You can modify the templates according to your needs ;Here is a list of the nodes supported by default. More can be easily added:
void function(T* src, T* dst, int nbSamples)
void function(T* srcA, T* srcB, T* dst, int nbSamples)
Dsp("mult",CType(F32),NBSAMPLES)
to use arm_mult_f32
Examples 5 and 6 are showing how to use the CMSIS-DSP MFCC with a synchronous data flow.
Example 7 is communicating with OpenModelica. The Modelica model (PythonTest) in the example is implementing a Larsen effect.