Title: Dynamic Data Flow Primitives
1Dynamic Data Flow Primitives
- William I. LundgrenGedae, Inc.Telephone 856
231 4458Fax 856 231 1403Email
gedae_at_gedae.comWebsite www.gedae.com
2Overview(continued)
- branch illustrates
- Dynamic outputs
- Use of consume function
- merge illustrates
- Variable threshold inputs
- Use of amount function to set threshold
- Use of produce function
3Example branch_c
- Name branch_c
- Type static
- Comment "Complete Branch on Stream
- if (c0)
- input is branched to out0
- else
- input is branched to out1"
- Keyword "meta logic","meta conditional",branch
- Intrinsic
Key Informational fields Data fields
Include field Methods
4Example branch_c(continued)
- Input
- stream float in
- stream int c
-
- Output
- dynamic stream float out0
- dynamic stream float out1
Key Informational fields Data fields
Include field Methods
5Example branch_c(continued)
- Apply
- int i, n_out00, n_out10
- for (i0 iltsize(in) i)
- if (ci0)
- out0n_out0 ini
- else
- out1n_out1 ini
-
-
- produce(out0,n_out0)
- produce(out1,n_out1)
-
Key Informational fields Data fields
Include field Methods
6Data Fieldsbranch_c
- Output both outputs are marked as dynamic.
- The default threshold is 1
- Example
- Input
- stream float in
- stream int c
-
- Output
- dynamic stream float out0
- dynamic stream float out1
Key Informational fields Data fields
Include field Methods
7Methodbranch_c
- Apply We count the number of tokens placed on
each output and then call produce() to set the
produce amount - produce(name of output, number of tokens)
- Apply
- int i, n_out00, n_out10
- for (i0 iltsize(in) i)
- if (ci0)
- out0n_out0 ini
- else
- out1n_out1 ini
-
-
- produce(out0,n_out0)
- produce(out1,n_out1)
-
Key Informational fields Data fields
Include field Methods
8Example merge_c
- Name merge_c
- Type static
- Comment "Complete Merge on Stream
- if (c0)
- copy and consume token from in0 to out
- else
- copy and consume token from in1 to out"
- Keyword "meta logic","meta conditional",merge
- Intrinsic
Key Informational fields Data fields
Include field Methods
9Example merge(continued)
- Input
- nondet stream float in0
- nondet stream float in1
- stream int c
-
- Local
- int c_examined
- int n0
- int n1
-
- Output
- stream float out
-
Key Informational fields Data fields
Include field Methods
10Example merge_c
Key Informational fields Data fields
Include field Methods
11Example merge_c
- Apply
- int i
- if (!c_examined)
- n0 n1 0
- for (i0 iltgranularity i)
- if (ci0) n0
- else n1
-
- c_examined 1
-
-
Key Informational fields Data fields
Include field Methods
12Example merge_c(continued)
- amount(in0,n0)
- amount(in1,n1)
- if (queues_ready)
- int j00, j10
- for (i0 iltgranularity i)
- if (ci0) outi in0j0
- else outi in1j1
-
- consume(in0,n0)
- consume(in1,n1)
- c_examined 0
-
-
Key Informational fields Data fields
Include field Methods
13Data Fieldsmerge_c
- Input the inputs are variable threshold
(nondet) because the required amount depends on
the control input c - Example
- Input
- nondet stream float in0
- nondet stream float in1
- stream int c
-
- Local
- int c_examined
- int n0
- int n1
Key Informational fields Data fields
Include field Methods
14Data Fieldsmerge_c (continued)
- Output the output is statically related to the
control input so there will be one output for
every control input - Example
- Output
- stream float out
Key Informational fields Data fields
Include field Methods
15Methodmerge_c
- Apply The first in the apply method is to
determine the number of tokens required on each
of the inputs. Use flag, c_examied, to avoid
checking the control input 2 times. - Example
- Apply
- int i
- if (!c_examined)
- n0 n1 0
- for (i0 iltgranularity i)
- if (ci0) n0
- else n1
-
- c_examined 1
-
Key Informational fields Data fields
Include field Methods
16Methodmerge_c (continued)
- Apply Declare the number of required tokens to
the thread scheduler effectively setting the
threshold. - Example
- amount(in0,n0)
- amount(in1,n1)
Key Informational fields Data fields
Include field Methods
17Methodmerge_c (continued)
- Apply If the thread scheduler has set the
queues_ready flag indicating that both amount()
functions are met move the data to the output as
appropriate and consume from the inputs. - if (queues_ready)
- int j00, j10
- for (i0 iltgranularity i)
- if (ci0) outi in0j0
- else outi in1j1
-
- consume(in0,n0)
- consume(in1,n1)
- c_examined 0 / reset local flag /
-
Key Informational fields Data fields
Include field Methods
18Laboratory
- The objective of this laboratory is to become
familiar with the functional interface required
to implement primitives with dynamic and variable
threshold behavior. You should become familiar
with the following functions - void embSuspendQueueWait(char reason)
- int avail(Identifier id)
- void amount(Identifier id, int tokens)
- Void consume(Identifier id, int tokens)
19Laboratory
- Open the graph named run_primitiveLab. In it you
will find a place for a function box named
f_umerge. You will create this function boxes. It
has 2 variable threshold (nondet) inputs and 1
static output. All of them are scalars. You will
want to check the inputs for the number of tokens
available using the avail() function. If there
are enough tokens to populate the output you will
prepare the queues with the amount() function and
set the output values. If there are insufficient
tokens you will cal the embSuspendQueueWait()
function. Once you have used the tokens you will
indicate to the thread manager they are used with
the function consume().
20Laboratory
- We will allow 45 minutes for this laboratory.
21Solution
- The primitive f_umerge is shown in the next few
charts. The solution graph is below.
22f_umerge
- Name f_umerge
- Type static
- Comment "This box takes data from in0 or in1 if
available. It passes granularity tokens to the
output. If there are not enough tokens on the
inputs combined it informs the thread manager by
calling embSuspendQueueWait(). It preferentially
takes tokens from in0. "
Key Informational fields Data fields
Include field Methods
23f_umerge
- Input
- nondet stream float in0
- nondet stream float in1
-
- Output
- stream float out
Data flow modifier for variable threshold is
nondet.
Key Informational fields Data fields
Include field Methods
24f_umerge Check Token Availability and Note Success
- Apply
- int g
- int a0 avail(in0)
- int a1 avail(in1)
- int a a0 a1 / The number of input tokens
available / - if (a gt granularity)
- lt see next charts gt
- else
- embSuspendQueueWait("need more tokens on the
inputs") -
No information function call means the Apply was
successful
Key Informational fields Data fields
Include field Methods
See Gedae Primitive Function Reference Manual
for a complete list of functions.
25f_umerge Prepare Queues
- if (a granularity)
- amount(in0,a0)
- amount(in1,a1)
- else if (a0 gt granularity)
- amount(in0, granularity) / prepare the
queue / - a0 granularity
- a1 0
- else
- amount(in0, a0)
- amount(in1, granularity - a0)
- a1 granularity - a0
-
3 input state conditions must be handled
Key Informational fields Data fields
Include field Methods
26f_umerge Move and Consume Inputs
- for (g0 glta0 g)
- out in0
-
- for (g0 glta1 g)
- out in1
-
- consume(in0,a0)
- consume(in1,a1)
Move the data from in0 and in1 to out
Consume the tokens moved to the output
Key Informational fields Data fields
Include field Methods
27Trace of Execution
Dependning on which buttons are pushed tokens
arrive on and are consumed from different queues