Concurrent Models of Computation Edward A Lee Robert
Concurrent Models of Computation Edward A. Lee Robert S. Pepper Distinguished Professor, UC Berkeley EECS 219 D Concurrent Models of Computation Fall 2011 Copyright © 2009 -2011, Edward A. Lee, All rights reserved Week 10: Consistency
Recall: Execution Policy for a Dataflow Actor Suppose s S n is a concatenation of firing rules, s = u 1. u 2. u 3 … Then the output of the actor is the concatenation of the results of a sequence of applications of the firing function: F 0 (s) = n F 1 (s) = ( (F 0 ))(s) = f (u 1) F 2 (s) = ( (F 1 ))(s) = f (u 1). f (u 2) … The problem we address now is scheduling: how to choose which actor to fire when there are choices. Lee 10: 2
Dataflow variants constrain firing rules and trade off expressiveness and analyzability ¢ ¢ ¢ ¢ ¢ Computation graphs [Karp & Miller - 1966] Process networks [Kahn - 1974] Static dataflow [Dennis - 1974] Dynamic dataflow [Arvind, 1981] K-bounded loops [Culler, 1986] Synchronous dataflow [Lee & Messerschmitt, 1986] Structured dataflow [Kodosky, 1986] PGM: Processing Graph Method [Kaplan, 1987] Synchronous languages [Lustre, Signal, 1980’s] Well-behaved dataflow [Gao, 1992] Boolean dataflow [Buck and Lee, 1993] Multidimensional SDF [Lee, 1993] Cyclo-static dataflow [Lauwereins, 1994] Integer dataflow [Buck, 1994] Bounded dynamic dataflow [Lee and Parks, 1995] Heterochronous dataflow [Girault, Lee, & Lee, 1997] Parameterized dataflow [Bhattacharya and Bhattacharyya 2001] Structured dataflow (again) [Thies et al. 2002] … today Lee 10: 3
Recall: Synchronous Dataflow (SDF) production/consumption matrix Actor 1 balance equations Connector 1 firing vector Lee 10: 4
Consistent Models Let a be the number of actors in a connected model. The model is consistent if has rank a - 1. If the rank is a, then the balance equations have only a trivial solution (zero firings). When has rank a - 1, then the balance equations always have a non-trivial solution. Lee 10: 5
Recall: Boolean Dataflow uses Symbolic Production/Consumption Rates Symbolic consumption rate. Imperative equivalent: while (true) { x = f 1(); b = f 7(); if (b) { y = f 3(x); } else { y = f 4(x); } f 6(y); } Symbolic production rate. Production and consumption rates are given symbolically in terms of the values of the Boolean control signals consumed at the control port. Lee 10: 6
Interpretations of Symbolic Rates ¢ ¢ ¢ General interpretation: p is a symbolic placeholder for an unknown. Probabilistic interpretation: p is the probability that a Boolean control input is true. Proportion interpretation: p is the proportion of true values at the control input in one complete cycle. NOTE: We do not need numeric values for p. We always manipulate it symbolically. Lee 10: 7
Symbolic Balance Equations The two connections above imply the following balance equations: q 2 p = q 3 q 2 (1 – p) = q 4 Lee 10: 8
Production/Consumption Matrix for If-Then-Else Symbolic variables: Balance equations: Note that the solution now depends on the symbolic variables Lee 10: 9
Production/Consumption Matrix for If-Then-Else The balance equations have a solution if an only if has rank 6. This occurs if and only if p 7 = p 8 , which happens to be true by construction because signals 7 and 8 come from the same source. The solution is given at the right. Lee 10: 10
Strong and Weak Consistency A strongly consistent dataflow model is one where the balance equations have a solution that is provably valid without concern for the values of the symbolic variables. l The if-then-else dataflow model is strongly consistent. A weakly consistent dataflow model is one where the balance equations cannot be proved to have a solution without constraints on the symbolic variables that cannot be proved. l Note that whether a model is strongly or weakly consistent depends on how much you know about the model. Lee 10: 11
Weakly Consistent Model This production/consumption matrix has full rank unless p = 1. Unless we know f 4 , this cannot be verified at compile time. Lee 10: 12
Another Example of a Weakly Consistent Model This one requires that actor 7 produce half true and half false (that p = 0. 5) to be consistent. This fact is derived automatically from solving the balance equations. Lee 10: 13
Use Boolean Relations Symbolic variables across logical operators can be related as shown. Lee 10: 14
Routing of Boolean Tokens Symbolic variables across switch and select can be related as shown. Lee 10: 15
Recall If-Then-Else Pattern Symbolic consumption rate. Solution to the symbolic balance equations: The if-then-else model is strongly consistent and we can give a quasi -static schedule for it: (1, 7, 2, b? 3, !b? 4, 5, 6) guard Lee 10: 16
Quasi-Static Schedules & Traces A quasi-static schedule is a finite list of guarded firings where: ¢ ¢ ¢ The number of tokens on each arc after executing the schedule is the same as before, regardless of the outcome of the Booleans. If any arc has a Boolean token prior to the execution of the schedule, then it will have a Boolean token with the same value after execution of the schedule. Firing rules are satisfied at every point in the schedule. A trace is a particular execution sequence. Lee 10: 17
Quasi-Static Schedules & Traces Solution to the symbolic balance equations: Quasi-static schedule: (1, 7, 2, b? 3, !b? 4, 5, 6) Possible trace: (1, 7, 2, 3, 5, 6) Another possible trace: (1, 7, 2, 4, 5, 6) Lee 10: 18
Proportion Vectors ¢ ¢ ¢ Let S be a trace. E. g. (1, 7, 2, 3, 5, 6) Let q. S be a repetitions vector for S. E. g. Let ti, S be the number of TRUEs consumed from Boolean stream bi in S. E. g. t 7, S = 1, t 8, S = 1. Let ni, S be the number of tokens consumed from Boolean stream bi in S. E. g. n 7, S = 1, n 8, S = 1. Let proportion vector ¢ We want a quasi-static schedule s. t. for every trace S we have. Lee 10: 19
Proportion Interpretation Recall the balance equations depend on , a vector with one symbolic variable for each Boolean stream that affects consumption production rates: Under a proportion interpretation, for a trace S, represents the proportion of TRUEs in S. We seek a schedule that always yields traces that satisfy Lee 10: 20
Proportion Interpretation for If-Then-Else Quasi-static schedule: (1, 7, 2, b? 3, !b? 4, 5, 6) Possible trace: S = (1, 7, 2, 3, 5, 6) Another possible trace: (1, 7, 2, 4, 5, 6) Both satisfy the balance equations. Lee 10: 21
Limitations of Consistency is necessary but not sufficient for a dataflow graph to have a bounded-memory schedule. Consider: [Gao et al. ’ 92]. This model is strongly consistent. But there is no bounded schedule (e. g. , suppose b 7 = ( F, T, T, T , … ). Lee 10: 22
Limitations of Consistency Even out-of-order execution (as supported by taggedtoken scheduling [Arvind et al. ] doesn’t solve the problem: Lee 10: 23
Gao’s Example has no Quasi-Static Schedule Solution to the symbolic balance equations is A trace S with N firings (N even) of actor 1 must have But this cannot be unless t 7, S is even. There is no assurance of this. Lee 10: 24
Another Example The model is strongly consistent. Solution to symbolic equations: A trace S with N firings (N even) of actor 1 must have: where t is the number of TRUEs consumed. There is no finite N where this is assured of being an integer vector. Lee 10: 25
Clustered Quasi-Static Schedules Consider the clustered schedule: n = 0; do { fire 1; fire 5; fire 2; if (b) { fire 3; } else { n += 1; } } while (n < 2); fire 4; This schedule either fails to terminate or yields an integer vector of the form: Lee 10: 26
Delays Can Also Cause Trouble This model is weakly consistent, where the balance equations have a non-trivial solution only if p 7 = p 8, in which case the solution is: Lee 10: 27
Relating Symbolic Variables Across Delays For the sample delay: What is the relationship between p 1 and p 2? Since consistency is about behavior in the limit, under the probabilistic of the interpretation for the symbolic variables, it is reasonable to assume p 1 = p 2. Is this reasonable under the proportion interpretation? Lee 10: 28
Delays Cause Trouble with the Proportion Interpretation Solution to the symbolic balance equations is A trace S with N firings of actor 1 must have But for no value of N is there any assurance of being able to fire actor 5 N times. This schedule won’t work. Lee 10: 29
Do-While Relies on a Delay Imperative equivalent: while (true) { x = f 1(); b = false; while(!b) { (x, b) = f 3(x); } f 5(x); } Is this model strongly consistent? Weakly consistent? Inconsistent? Lee 10: 30
Checking Consistency of Do-While This model is consistent if and only if p 5 = p 6, which is true under the probabilistic interpretation, but not under the proportion interpretation. Lee 10: 31
Checking Consistency of Do-While Let p = p 5 = p 6, then the solution to the balance equations is: Lee 10: 32
Clustering Solution for Do-While Clustered Schedule: fire 1; do { fire 2; fire 3; fire 4; } while(!b); fire 5; This schedule yields traces S for which p 5 = p 6 = 1/N and compare: Lee 10: 33
Extensions ¢ State enumeration scheduling approach: Seek a finite set of finite guarded schedules that leave the model in a finite set of states (buffer states), and for which there is a schedule starting from each state. ¢ Integer dataflow (IDF [Buck ’ 94]): Allow symbolic variables to have integer values, not just Boolean values. Extension is straightforward in concept, but reasoning about consistency becomes harder. Lee 10: 34
Taking Stock ¢ ¢ ¢ BDF and IDF generalize the idea of balance equations and introduce quasi-static scheduling. BDF and IDF are Turing complete, so existence of quasi-static schedules is undecidable. Can often construct quasi-static schedules anyway. Tricks like clustered schedules make the set of manageable models larger. Are Switch and Select like unrestricted GOTO? Lee 10: 35
Extensions of SDF that Improve Expressiveness Structured Dataflow [Kodosky 86, Thies et al. 02] Boolean dataflow [Buck and Lee, 93] Cyclostatic Dataflow [Lauwereins 94] Multidimensional SDF [Lee & Murthy 96] Heterochronous Dataflow [Girault, Lee, and Lee, 97] Parameterized Dataflow [Bhattacharya et al. 00] Teleport Messages [Thies et al. 05] Many of these remain decidable Lee 10: 36
Structured Dataflow [Kodosky 86] Lab. VIEW uses homogeneous SDF augmented with syntactically constrained forms of feedback and rate changes: While loops Conditionals Sequences Lab. VIEW models are decidable. Lee 10: 37
vs. Dynamic Dataflow, which uses token routing for control flow What consumption rate? Imperative equivalent: while (true) { x = f 1(); b = f 7(); if (b) { y = f 3(x); } else { y = f 4(x); } f 6(y); } What production rate? The if-then-else model is not SDF. But we can clearly give a bounded quasistatic schedule for it: (1, 7, 2, b? 3, !b? 4, 5, 6) guard Lee 10: 38
vs. Dynamic Dataflow, which uses token routing for control flow Select Switch Imperative equivalent: while (true) { x = f 1(); b = false; while(!b) { (x, b) = f 3(x); } f 5(x); } initial token This model uses conditional routing of tokens to iterate a function a data-dependent number of times. Lee 10: 39
Syntax: Graphical or Textual? ¢ component technologies ¢ ¢ ¢ ¢ ¢ Sutherland (66) Prograph (85) Lab. VIEW (86) Gabriel (86) Show and Tell (86) Cantata (91) Ptolemy Classic (94) Ptolemy II (00) Scade (05) … ¢ ¢ ¢ ¢ ¢ Lucid (77) Id (78) VAL (79) Sisal (83) Lustre (86) Signal (90) Granular Lucid (95) Stream. IT (02) Cal (03) … The graphical vs. textual debate obscures a more important question: Are actors and streams a programming language technology or a software component technology? Lee 10: 40
Consistency in Synchronous/Reactive Models SR models are intrinsically bounded, but have related consistency issue: Clock consistency. Lee 10: 41
Two Interpretations of Clocks A clock is a property of a model, and signals may be absent at ticks of the clock (Esterel) The choice between these has profound consequences A clock is a property of a signal, and components impose constraints on clock relationships (Lustre, Signal) Lee 10: 42
The Ptolemy II SR Director realizes Esterelstyle clocks with hierarchical clock domains. In this example, the Count. Down composite issues a “ready” signal to the Enabled. Composite, which then issues a number. The Count. Down composite counts down from that number to 0, then issues another ready. Lee 10: 43
The Ptolemy II SR Director realizes Esterelstyle clocks with hierarchical clock domains. The Enabled. Composite has a clock that ticks only when the enable input is present and true. It issues the sequence 1, 5, 3, 2, followed by absent henceforth. Lee 10: 44
The Clock is a Property of the Model To get a different clock, use opaque hierarchy. This is (roughly) the style of Esterel (with multiclock extensions). Lee 10: 45
Hierarchical clock domains bear some resemblance to structured dataflow Opaque hierarchy can do: ¢ Conditioning an internal tick on an external signal l Like a conditional l If the internal component is an instance of the external, then this amounts to recursion ¢ Multiple internal ticks per external tick l Like ¢ a do-while Iterated internal ticks over a data structure (use Iterate. Over. Array higher-order actor) l Like a for Lee 10: 46
A Consequence: Pre and Non. Strict. Delay have different behaviors! Alternative Semantics: The Clock is a Property of the Signal In Lustre and Signal, a clock is a property of a signal, and Pre and Non. Strict. Delay behave identically by constraining the input clock to be the same as the output clock. They only fire when the clock of the input signal ticks. This leads to a clock consistency problem, which is in general undecidable. Lee 10: 47
Inconsistent clocks In Lustre-style clock systems, the Add. Subtract actor imposes the constraint that all its input signals have the same clock. The above model becomes inconsistent and will not execute. Lee 10: 48
Clock Calculus ¢ ¢ ¢ Let T be a totally ordered set of tags. Let s: T V { } be a signal of type V, where means “absent. ” Let c: T {– 1, 0, 1} be a clock associated with s where s(t) = c(t) = 0 s(t) = true c(t) = 1 s(t) = false c(t) = – 1 If V is not boolean, then when s(t) is present, c(t) has value or 1 or – 1 (we will make no distinction). Lee 10: 49
Operations on Clocks Arithmetic on clocks is in GF-3 (a Galois field with 3 elements), as follows: 0+x=x 0 x = 0 1 + 1 = – 1 1 x = x – 1 + – 1 = 1 – 1 x = – x – 1 + 1 = 0 Lee 10: 50
Clock Relations: Simple Synchrony Most actors require that the clocks on all signals be the same. For example: s 1 s 3 s 2 This means that either all are present, or all are absent. Lee 10: 51
Clock Relations: When Operator Assuming that s 1 is a boolean-valued signal (which it must be), the clocks on signals interacting through the when operator are related as follows: s 3 s 1 s 2 This means: If s 1 is absent, then s 3 is absent. If s 2 is false, then s 3 is absent. If s 2 is true, then s 3 is the same as s 1. Lee 10: 52
Consistency Checking Consider the following model: s 1 s 4 s 2 s 3 These two together imply that: where we have used the fact that: Lee 10: 53
Interpretation of Consistency Result Consistency check implies that: s 1 s 4 s 2 s 3 This means: s 1 is absent if and only if s 2 is absent or false. Lee 10: 54
Logic Operators Affect Clocks The output of the When actor has a clock that depends on the Boolean control signal. Clocks of Boolean-valued signals reflect the signal value as follows: s 1 s 2 s 3 Lee 10: 55
Token Routing Also Affects Clocks Switch and Select affect the clocks as follows: s 1 s 2 s 3 s 4 s 1 s 3 s 4 s 2 Lee 10: 56
Example 1 Using Switch and Select s 1 s 2 s 3 s 6 s 4 s 5 What can you infer about the clock of s 6 ? Lee 10: 57
Example 2 Using Switch and Select s 1 s 2 s 3 What can you infer about the clocks? This means that s 1 is absent and s 3 is either absent or false. Lee 10: 58
What About Delays? s 1 s 2 Clock relations across the delays become dependent on the tags. E. g. , if T is the natural numbers, then we get a nonlinear dynamical system: s 2 This makes clock analysis very difficult, in general. Lee 10: 59
Default Operator Default: The output equals the left input, if it is present, and the bottom input otherwise: s 3 s 1 s 2 This means the clock of s 3 is equal to the clock of s 1 , if it is present, and to the clock of s 2 otherwise. Lee 10: 60
Default Operator in SIGNAL is Nondeterministic In SIGNAL semantics, the following model has many behaviors: The two generated sequences have independent clocks (defined over incomparable values of t T ), and the output sequence is any interleaving that preserves the ordering. Lee 10: 61
Guarded Count in SIGNAL Instead of generating a “ready” signal, in SIGNAL, the count hitting zero can be synchronized with the input being present. Lee 10: 62
Conclusion and Open Issues ¢ When clocks are a property of the model, the result is structured synchronous models, where differences between clocks are explicit and no consistency checks are necessary (and signals may be absent at ticks of the clock). ¢ When clocks are a property of a signal, the result is similar to Boolean Dataflow (BDF). It is arguable that clock operators like “when, ” “default, ” “switch, ” and “select” become analogous to unstructured gotos. Clock consistency checking becomes undecidable. ¢ When further extended as in SIGNAL to partially ordered clock ticks, models easily become nondeterministic. Lee 10: 63
- Slides: 63