1 / 88

Jörn W. Janneck The Ptolemy Group University of California at Berkeley

Actors, actor composition, and an actor language describing the semantics of (some) visual languages. Jörn W. Janneck The Ptolemy Group University of California at Berkeley. credits. Johan Eker, Lund University language design, C code generation Yang Zhao, UCB action-level scheduling

Download Presentation

Jörn W. Janneck The Ptolemy Group University of California at Berkeley

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Actors, actor composition, and an actor language describing the semantics of (some) visual languages Jörn W. Janneck The Ptolemy GroupUniversity of California at Berkeley

  2. credits Johan Eker, Lund University • language design, C code generation Yang Zhao, UCB • action-level scheduling Chris Chang, UCB • type system, program transformations Lars Wernli, ETH Zurich • Java code generation, generic code generation infrastructure

  3. What's an actor? • entity that has ... • state • ports • ... and is defined by ... • outputs in response to inputs • state transition in response to inputs • data packaged into tokens

  4. 42 41 ‘P’ 42 What's an actor? parameters input ports output ports 99 12 ‘\’ 1 3 N FIRE Actor tokens tokens ‘A’ ‘L’ Data ‘C’ state Actorsdecoupledataandcontrol

  5. 45 42 2 4 41 ‘P’ ‘L’ ‘A’ ‘C’ What's an actor? parameters input ports output ports 99 12 ‘\’ 1 N Actor token tokens Data state 45 Actorsdecoupledataandcontrol

  6. A C B networks of actors • actors are usually composed with other actors into networks • conceptually concurrent • What does a network mean? • model of computation (coordination model) • model of computation defines • meaning of connections • 'sequence' of actor firings • state transition

  7. actors and visual languages • actor networks are often represented using visual languages • actor models of computation natural match for (many) VL semantics

  8. specifying VL semantics • semantics of an actor • define an actor syntax first! • then describe what it means • semantics of an actor composition • again, syntax first • composition operator actors + network  actor • the composition operator is the model of computation!

  9. semantics of actor compositions • the operational approach • describe a generic abstract machine • actors are 'machines' that interact with their generic environment • a special instance of that environment is a model of computation • examples: Ptolemy, Metropolis • two issues: • generic machine needs to anticipate the facilities needed by models of computation • actors become specific to models of computation

  10. 2 3 operational actor interpretation • examples: • the Kahn process story • the CSP story Adder 1 A S B

  11. semantics of actor composition • the language approach • consider an actor description a constraint on all possible behaviors • models of computation compose those descriptions • they may interpret an actor specification • thereby adding constraints to it, specializing it actor Adder () Double A, Double B ==> Double S: action [a], [b] ==> [a + b] end end

  12. What is CAL? CAL is a (textual) language for writing actors. • supports a variety of platforms and models of computation • by supporting a variety of interpretations • by proserving lots of static structure in the actor description • token rates • dependencies • designed as a domain-specific language • it is intentionally incomplete • part of the Ptolemy project

  13. a simple example actor A (Double k) Double Input1, Double Input2 ==> Double Output: action [a], [b] ==> [k * (a + b)] end end

  14. another example actor B () Double Input ==> Double Output: Integer n := 0; Double sum := 0; action [a] ==> [sum / n] do n := n + 1; sum := sum + a; end end

  15. the CAL vision • provide flexible platform for expressing a wide range of actor functionality • generate (operational) implementations for specific platforms • Ptolemy/Java, C, Moses, ... • bridge between modeling environments and implementation • serve as platform for composing actors • express models of computation as syntactic transformations in CAL • this makes models of computation portable to any CAL platform! • profiles for portability

  16. Some language features

  17. multiple actions, action conditions actor C () Double Input ==> Double Output: action [a] ==> [a] guard a >= 0 end action [a] ==> [-a] guard a < 0 end end actor D () Double Input ==> Double Output: action [a] ==> [abs(a)] end end

  18. nondeterminism • More than one action may be firable. • Caltrop does not specify how this is resolved. • It allows deterministic as well as non-deterministic implementations. • Often, determinism can be ascertained statically. actor E () Double Input ==> Double Output: action [a] ==> [a] end action [a] ==> [-a] end end

  19. port patterns • examples • [a, b, c] • [a, b, c | s] • [| s] actor PairwiseSwap [T] () T Input ==> T Output: action[a, b]==> [b, a] end end

  20. repeated patterns actor ReversePrefix [T] (Integer n) T Input ==> T Output: action [a] repeat n==> [reverse(a)] repeat nend end

  21. multiports, channel selectors actor Switch [T] () multi T Data, Integer Select ==> T Output: action [a] i, [i] ==> [a] end end

  22. port tags actor Switch [T] () multi T Data, Integer Select ==> T Output: actionData: [a] i, Select: [i] ==> [a] end end actor Switch [T] () multi T Data, Integer Select ==> T Output: actionSelect: [i], Data: [a] i ==> [a] end end

  23. action tags, action selectors actor FairMerge [T] () T Input1, T Input2 ==> T Output: A:action Input1: [a] ==> [a] end B:action Input2: [a] ==> [a] end selector (AB)* end end • other selectors are conceivable, e.g. • (AB)* | (BA)* • ( (AB) | (BA) )*

  24. action conditions, state actor FairMerge [T] () T Input1, T Input2 ==> T Output: Integer s := 1; action Input1: [a] ==> [a] guards = 1 do s := 2; end action Input2: [a] ==> [a] guards = 2 do s := 1; end end

  25. CAL compilation—the big picture. parsing CAL transformation,annotation source text CAL(0) code generation Caltrop AST CAL(1) Java platforms target platform C platforms CAL(n) CalCore Pålsjö/Koala LegOS Ptolemy II Moses JGrafChart

  26. code generation infrastructure CALCORE generic Java generic C Palsjo/Koala(Lund) LegOS(UCB) Pt/Java(UCB) JGrafChart(Lund) Moses(ETH)

  27. CAL A C CALcomposition CAL B codegeneration CAL CAL direct codegeneration CAL actor composition

  28. project status • We have... • the language definition • including an informal semantics • Java code generator • generic + Ptolemy • usable, but not complete • ongoing work on porting Ptolemy actor library • C code generator • generic + Palsjo • usable, but not complete • Lund University uses it for writing control software for robot • Swedish company wants to use the language for writing DSP applications • some work on static scheduling of actor networks • some work on actor composition

  29. project status • We would like... • formal actor semantics • composition and composition language • more extensive code generation • more complete • more platforms • more languages • larger function libraries • larger actor libraries • ... but most of all ... Collaborators!

  30. Thanks. www.gigascale.org/caltrop

  31. Motivation Writing simple actors should be simple. • But: The Ptolemy API is very rich, and writing actors in it requires considerable skill. • However: Many Ptolemy actors have considerable commonalities - they are written in a stylized format.

  32. Motivation We should generate many actors from a more abstract description. • Benefits: • reduces amount of code to be written • makes writing actors more accessible • reduces error probability • makes code more versatile • actors may be retargeted to other platforms, or new versions of the Ptolemy API

  33. Overview of the implementation general architecture aspects of the Pt/Java implementation

  34. Caltrop implementation—the big picture. source text parsing Caltrop transformation,annotation Caltrop AST Caltrop(0) code generation target platform Caltrop(1) Caltrop(n) split-phase CalCore Ì CalCore Matlab? DSP/FPGA? Pt/Java TinyOS/C? ???

  35. Caltrop implementation • many small modules • transformers, annotaters, checkers • transforming Caltrop into some language subset • CalCore • small, semantically complete subset • minimal language for code generation, analysis, transformation • built on functional and procedural closures

  36. Transformers & annotators • replace control structures • replace port patterns • sort variable declarations • replace operators • propagate type information • check static properties • tag port patterns • ...

  37. Caltrop implementation • Benefits: • Much of the ‘hard’ stuff can be done on the same data structure, exploiting the regularities of the Caltrop/CalCore semantics and the existing software infrastructure. • Code generators becomes relatively small, thus making retargeting easier. • Intermediate results are valid Caltrop programs, making debugging a lot easier. • We can look at them easily. • We can use the parser and the well-formedness/type checkers themselves as debugging tools!

  38. Switch in CalCore* actor Switch [T] () multi T Data, Integer Select ==> T Output : action Select::[|G0], Data::[|G2] all ==> Output::[a] where G1, G3 with Boolean G1 := available(G0, 1), Integer i := if G1 then G0[0] else null end, Integer G4 := i, Boolean G3 := available(G2[G4], 1), Integer a := if G3 then G2[G4][0] else null end end end *Actually, we are cheating here; CalCore is in fact even more primitive. And even less readable...

  39. CalCore ==> Pt/Java • different programming models • single atomic action vs prefire/firen/postfire • referentially transparent access to channels vs. token consuming read methods • stateful computation vs state-invariant fire

  40. CalCore ==> Pt/Java • mapping Caltrop notions to Pt/Java concepts • parameters ==> attributes + attribute changes • types and type checking • ...

  41. What goes into prefire()? actor Switch [T] () multi T Data, Integer Select ==> T Output : action Select::[|G0], Data::[|G2] all ==> Output::[a] where G1, G3 with Boolean G1 := available(G0, 1), Integer i := if G1 thenG0[0]else null end, Integer G4 := i, Boolean G3 := available(G2[G4], 1), Integer a := if G3 then G2[G4][0] else null end end end All computation that is required in order to decide firability? Just the part of it before the first token access?

  42. prefire/fire • aggressive vs defensive condition evaluation • incrementally computing conditions • reusing computation done in prefire • Should tokens read in prefire be kept if prefire returns false?

  43. fire/postfire action Input1:: [a] ==> [a] where s = 1 : s := 2;end action Input1::[|G0] ==> Output::[a] whereequals(s,1), G1 with Boolean G1 := available(G0, 1), T a := if G1 then G0[0] else null end : s := 2; end prefire fire postfire Computation that does not affect the output can be done in postfire.

  44. State management If state needs to be changed in order to compute output, it needs to be shadowed. • safe state management • referentially transparent expressions • no aliasing of stateful structures

  45. State management actor B () Double Input ==> Double Output: Integer n := 0; Double sum := 0; action [a] ==> [sum / n] : n := n + 1; sum := sum + a; end end The division between fire and postfire can be expressed in Caltrop (btw, this is a non-CalCore transformation) using action tags and selectors.

  46. State management actor B () Double Input ==> Double Output: Integer n := 0; Integer n$shadow; Double sum := 0; Double sum$shadow; fire: action [a] ==> [sum$shadow / n$shadow] : n$shadow := n; sum$shadow := sum; n$shadow := n$shadow + 1; sum$shadow := sum$shadow + a; end postfire: action ==> : n := n$shadow; sum := sum$shadow; end selector (fire+ postfire)* end end

  47. Things we need to do...

  48. Short term “grunt” work  • well-formedness checks • type system, type checking • split-phase analyses • interpreter (+ wrapper for Pt/Java) • optimizations, big and small • other transformers, annotators

  49. Fun mid-term projects  • static analysis of actor properties (data rates, dependency on state, parameters, input, ...) • relation to MoC (e.g. BDF) • computing interface automata from actor descriptions • code generators to other platforms and languages • code generation for composite actors?

More Related