A code generator for the CAL actor language Lars Wernli Supervisor: Joern Janneck, UC Berkeley Professor: Lothar Thiele, ETH Zuerich.

Slides:



Advertisements
Similar presentations
Introduction to Compilation of Functional Languages Wanhe Zhang Computing and Software Department McMaster University 16 th, March, 2004.
Advertisements

Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
Rule Based Operational Semantics Specification in Ptolemy Yanwar Asrigo COMP 763B - Modeling and Simulation Based Design 30 th April 2008.
Component Technologies for Embedded Systems Johan Eker.
5 th Biennial Ptolemy Miniconference Berkeley, CA, May 9, 2003 Java Code Generation Steve Neuendorffer UC Berkeley.
Type System, March 12, Data Types and Behavioral Types Yuhong Xiong Edward A. Lee Department of Electrical Engineering and Computer Sciences University.
7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
5 th Biennial Ptolemy Miniconference Berkeley, CA, May 9, 2003 C AL - An actor language Jörn W. Janneck The Ptolemy Group University of California, Berkeley.
Welco me. Bart’s Operating System Structure B.Visscher Aug 2001.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
February 12, 2009 Center for Hybrid and Embedded Software Systems Encapsulated Model Transformation Rule A transformation.
3/12/ Modeling and controlling the Caltech Ducted Fan Vehicle Steve Neuendorffer, Ptolemy Group, UC Berkeley.
An Extensible Type System for Component-Based Design
The Ptolemy Group University of California at Berkeley Jörn W. Janneck Actors, actor composition, and an actor language describing the semantics of (some)
MoBIES PI-Meeting, July 2001, Jackson Hole Controller Design Using Multiple Models of Computation Edward Lee Johan Eker with thanks to Paul Griffiths,
Computer Science 1620 Programming & Problem Solving.
SEC PI Meeting Annapolis, May 8-9, 2001 Component-Based Design of Embedded Control Systems Edward A. Lee & Jie Liu UC Berkeley with thanks to the entire.
Department of Electrical Engineering and Computer Sciences University of California at Berkeley System-Level Types for Component-Based Design Edward A.
February 12, 2009 Center for Hybrid and Embedded Software Systems Model Transformation Using ERG Controller Thomas H. Feng.
MoBIES Working group meeting, September 2001, Dearborn Ptolemy II The automotive challenge problems version 4.1 Johan Eker Edward Lee with thanks.
The Caltrop Actor Language Johan Eker UC Berkeley MoBIES group, Carnegie Mellon, November 30, 2001.
5 th Biennial Ptolemy Miniconference Berkeley, CA, May 9, 2003 JHDL Hardware Generation Mike Wirthlin and Matthew Koecher
5 th Biennial Ptolemy Miniconference Berkeley, CA, May 9, 2003 MESCAL Application Modeling and Mapping: Warpath Andrew Mihal and the MESCAL team UC Berkeley.
System-Level Types for Component-Based Design Paper by: Edward A. Lee and Yuhong Xiong Presentation by: Dan Patterson.
Models of Computation as Program Transformations Chris Chang
Department of Electrical Engineering and Computer Sciences University of California at Berkeley The Ptolemy II Framework for Visual Languages Xiaojun Liu.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Computer Science 209 The Strategy Pattern II: Emulating Higher-Order Functions.
I. Pribela, M. Ivanović Neum, Content Automated assessment Testovid system Test generator Module generators Conclusion.
Compilation (Chapter 3) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Composing Models of Computation in Kepler/Ptolemy II
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved ADT Implementation:
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
CSC 338: Compiler design and implementation
1 Introduction Modules  Most computer programs solve much larger problem than the examples in last sessions.  The problem is more manageable and easy.
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
1 CSC 222: Computer Programming II Spring 2004 See online syllabus at: Course goals:
1 5 Nov 2002 Risto Pohjonen, Juha-Pekka Tolvanen MetaCase Consulting AUTOMATED PRODUCTION OF FAMILY MEMBERS: LESSONS LEARNED.
UHD::3320::CH121 DESIGN PHASE Chapter 12. UHD::3320::CH122 Design Phase Two Aspects –Actions which operate on data –Data on which actions operate Two.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
Design Languages in 2010 Chess: Center for Hybrid and Embedded Software Systems Edward A. Lee Professor UC Berkeley Panel Position Statement Forum on Design.
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Algorithms Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin,
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Wei-Tek Tsai who’s.
Incremental Checkpointing with Application to Distributed Discrete Event Simulation Thomas Huining Feng and Edward A. Lee {tfeng,
Actor Oriented Programming with CAL -designing embedded system components Johan Eker Department of Automatic Control, Lund University Chris Chang, Jörn.
CS 5991 Presentation Ptolemy: A Framework For Simulating and Prototyping Heterogeneous Systems.
Linear Analysis and Optimization of Stream Programs Masterworks Presentation Andrew A. Lamb 4/30/2003 Professor Saman Amarasinghe MIT Laboratory for Computer.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
ECE 587 Hardware/Software Co- Design Lecture 23 LLVM and xPilot Professor Jia Wang Department of Electrical and Computer Engineering Illinois Institute.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Lecture #5 מבוא מורחב.
Advanced Computer Systems
CSC 222: Computer Programming II
Key Ideas from day 1 slides
Ptolemy II - Heterogeneous Concurrent Modeling and Design in Java
Code Generation for Ptolemy II
Advanced Programming Behnam Hatami Fall 2017.
Higher-Order Procedures
Retargetable Model-Based Code Generation in Ptolemy II
Lecture #5 מבוא מורחב.
Jörn W. Janneck The Ptolemy Group University of California, Berkeley
Algorithms and Problem Solving
The Caltrop Actor Language a short introduction
Presentation transcript:

A code generator for the CAL actor language Lars Wernli Supervisor: Joern Janneck, UC Berkeley Professor: Lothar Thiele, ETH Zuerich

What is Ptolemy II? continuous time finite-state machine discrete time Hierarchical, heterogeneous model

Actor oriented design input portsoutput ports parameters Actor tokens ‘C’ 31 ‘L’ ‘A’ tokens 42 ‘P’ 9912‘\’ state 42 Actors decouple data and control N Data 41 FIRE

Actor oriented design Actors decouple data and control input portsoutput ports parameters Actor token 1 tokens 2 ‘P’ 9912‘\’ state 45 N Data ‘C’‘A’‘L’

Actors in Ptolemy II Firing is divided into three phases: prefire()1 time –checks whether action can fire or not fire()n times –calculates output tokens postfire() 0 or 1 times –updates persistent state

Writing a Ptolemy actor int sum = 0, _sum; prefire() { return N.hasToken(); } fire() { _sum = sum; int n = N.getToken(); if (Data.hasTokens(n)) { _sum = _sum + n; for (int i = 0; i < n; i++) Out2.putToken(Data.getToken()); Out1.putToken(_sum); } else { // what to do with the value of n? } postfire() { sum = _sum; }

Writing a Ptolemy actor int sum = 0, _sum; prefire() { return N.hasToken(); } fire() { _sum = sum; int n = N.getToken(); if (Data.hasTokens(n)) { _sum = _sum + n; for (int i = 0; i < n; i++) Out2.putToken(Data.getToken()); Out1.putToken(_sum); } else { // what to do with the value of n? } postfire() { sum = _sum; }

What is CAL? CAL is a textual language for writing dataflow actors. Integer sum := 0; action N:[n], Data:[d] repeat n ==> Out1:[sum], Out2:[d] repeat n do sum := sum + n; end The actor just introduced written in CAL:

Motivation for using CAL makes writing actors more accessible reduces amount of code to be written reduces error probability allows information extraction for model analysis CAL actors may be reused by other platforms, or new versions of Ptolemy

Design goal for CAL CAL is intended to be retargeted to a variety of platforms make retargeting as simple as possible –modular compiler design –modular code generation

CAL compilation —the big picture. CAL CalCore CAL (0) CAL (n) parsing CAL (1) transformation, annotation code generation source text Caltrop AST target platform Ptolemy IIMosesPålsjö/KoalaJGrafChartLegOS Java platforms C platforms

Generic and specific actor CalCore generic code generator platform specific code generator Code generator is easy to retarget Actor core can be reused by other platforms

Code generator and target code design Design goals 1.Make retargeting the code generator as simple as possible 2.Reusability of generated code 3.Optimize for speed Challenges -specify an interface for generic part of the actor -matching the generic actor interface to Ptolemy API

State shadowing Problem: state changing firing in CAL vs state-invariant fire() in Ptolemy generic variable interface Ptolemy specific variable object State:Shadow State: fire() { listener.rollbackAll(); … } postfire() { … listener.commitAll(); } change listener 42 assign(45) 45 markAsChanged(this)

State shadowing Problem: state changing firing in CAL vs state-invariant fire() in Ptolemy generic variable interface Ptolemy specific variable object State:Shadow State: fire() { listener.rollbackAll(); … } postfire() { … listener.commitAll(); } change listener 4245 rollbackAll()rollback()

State shadowing Problem: state changing firing in CAL vs state-invariant fire() in Ptolemy generic variable interface Ptolemy specific variable object State:Shadow State: fire() { listener.rollbackAll(); … } postfire() { … listener.commitAll(); } change listener 42 assign(47) 47 markAsChanged(this)

State shadowing Problem: state changing firing in CAL vs state-invariant fire() in Ptolemy generic variable interface Ptolemy specific variable object State:Shadow State: fire() { listener.rollbackAll(); … } postfire() { … listener.commitAll(); } change listener 4247

State shadowing Problem: state changing firing in CAL vs state-invariant fire() in Ptolemy generic variable interface Ptolemy specific variable object State:Shadow State: fire() { listener.rollbackAll(); … } postfire() { … listener.commitAll(); } change listener 4247 commitAll() 47 commit()

State shadowing Problem: state changing firing in CAL vs state-invariant fire() in Ptolemy generic variable interface Ptolemy specific variable object State:Shadow State: fire() { listener.rollbackAll(); … } postfire() { … listener.commitAll(); } change listener 4247

Achievements code generation for full-fledged language -higher-order function closures -procedural closures -set/list/map comprehensions -input port patterns -regular action selectors -… reusability of generated code code generator easy to retarget to other Java platforms

Achievements generated actors run with acceptable speed facilitate retargeting to other languages (such as C) –design template for code generators Pålsjö/Koala LTH –reusable infrastructure

Future work –Implement type checking –Describe the transformations on the AST in XML –Retarget the code generator to other platforms (LegOS UCB, Moses ETH?) –Model compilation using CAL actor Network + actors  schedule Network + actors + schedule  actor

It’s time for a demo

Atomic actors in Ptolemy implemented in Java domain polymorph ports parameters split-phase-firing: –prefire() –fire() –postfire()

Atomic actors in Ptolemy implemented in Java domain polymorph ports parameters split-phase-firing: –prefire() –fire() –postfire()

The Ptolemy II GUI

Models in Ptolemy II actor based heterogeneous systems hierarchical composite actors treated like atomic directors decouple behavior & control flow

Writing Ptolemy actors in Java....requires certain knowledge about the Ptolemy II API..results in platform specific classes..is error-prone..is often redundant..makes it hard to extract information from the actors Specifying actors in Java is problematic

Writing Ptolemy actors in Java....requires certain knowledge about the Ptolemy II API..results in platform specific classes..is error-prone..is often redundant..makes it hard to extract information from the actors Specifying actors in Java is problematic

A better approach We should be able to generate actors from a more abstract description. Benefits: –makes writing actors more accessible –actors may be retargeted to other platforms, or new versions of Ptolemy –reduces error probability –reduces amount of code to be written –actors get more readable and analyzable

Can you guess what this does? actor B () Double Input ==> Double Output: Integer n := 0; Double sum := 0; action [a] ==> [sum / n] DO n := n + 1; sum := sum + a; end

Can you guess what this does? actor B () Double Input ==> Double Output: Integer n := 0; Double sum := 0; action [a] ==> [sum / n] : n := n + 1; sum := sum + a; end

What about this? actor PrimeSieve () Integer Input ==> Integer Output: [Integer --> Boolean] filter := lambda (Integer a) --> Boolean : false end; function divides (Integer a, Integer b) --> Boolean : b mod a = 0 end action [a] ==> [] guard filter(a) end action [a] ==> [a] guard not filter(a) var [Integer --> Boolean] f = filter do filter := lambda(Integer b) --> Boolean: f(b) or divides(a, b) end; end

ActorCore vs Ptolemy API state management –fire vs fire n / postfire –state changing computation vs state-invariant fire input ports –random access to input channels vs sequential read methods

The runtime environment 1.Variable objects & change listener –Support state shadowing –Provide a generic interface to the Ptolemy Token and Parameter objects 2.Port wrappers –Emulate random access input ports –Provide a generic interface to the Ptolemy TypedIOPorts  Factory –Creates wrapping objects –facilitates decoupling between ActorCore and Ptolemy API

Three implementation details Actors at runtime 1.How the PtActor passes Ptolemy objects to the ActorCore via factory 2.How CAL scopes are represented in the ActorCore The code generator 3.How the code generator uses the visitor pattern to traverse the AST

1. Actors and the Factory

actor DeadlockPrimeSieve () Integer Input ==> Integer Output: [Integer --> Boolean] filter := lambda (Integer a) --> Boolean : false end; action [a] ==> [a] guard not filter(a) var [Integer --> Boolean] f = filter do filter := lambda(Integer b) --> Boolean: f(b) or (lambda (Integer a, Integer b)--> Boolean : b mod a = 0; end)(a, b) end 2. CAL scopes

2. Structure of the ActorCore

accept(this) 3. The visitor pattern e.argTuple.accept(this); // generate some code … e.function.accept(this); // generate more code … visitApplication(this) visitor.visitTuple(this);visitor.visitApplication(this);

Problems solved matching CAL to Ptolemy –single atomic action vs prefire / fire n / postfire –state changing computation vs state-invariant fire –CalCore scopes vs Java scopes –random access to channels vs sequential read methods

Further work –Implement type checking –Describe the transformations on the AST in XML –Network + actors  schedule –Network + actors + schedule  actor –Retarget the code generator to other platforms (Moses ETH)

continuous time finite-state machine discrete time Hierarchical, heterogeneous model

Generic and specific code generator

The CAL compiler