CAL Implementation in GraalVM
Lakshya A Agrawal
Advisor: Dr. Endri Bezati
Supervisor: Prof. James Larus
CAL Implementation in GraalVM
CAL
Dataflow Programming Language
Actor Model of Computation
GraalVM
Universal Virtual Machine
Support for Polyglot and Native image
Problem
Decrease in performance gains for general purpose processors
Potential Solution
Explore use of FPGAs as reconfigurable accelerators
Challenge!
Determine division of work between processor and FPGA
Context of the problem
3
4
Context of the problem
Finding Division of Labour
StreamBlocks
Solution
Aim of the project
Extend StreamBlocks with a development environment
Debugger support
Polyglot support
CAL implementation over GraalVM
Truffle Framework
Faster language extension experiments
Native Image Compilation
5
Philosophy: Writing AST Interpreter is easy
Profiling info from interpreter used for optimized partial evaluations
Implementations of languages like TruffleRuby have faster than native performance
Compiles to native image
Saves the warming up time of the JVM
Uses AST metadata to power development tools
Debugger using Chrome Dev Tools and Debugger Adapter Protocol
IDE support through Language Server Protocol
Background
Truffle Programming Language Implementation Framework
6
Background
CAL Programming Language
The Actor Model
A Program consists of different Actors
Actors have point to point connections with each other through data-pipes
Communicate discrete data packets (tokens)
7
Background
CAL Programming Language
8
Background
CAL Programming Language
9
Background
CAL Programming Language
10
Background
CAL Programming Language
In each firing, one action may execute, which can:
Consume tokens from Actor's input ports
Modify the Actors' internal state
Produce tokens at its output ports
Rules can be specified to determine when an action is fired
Actors perform their computation in a sequence of steps called firings
11
How does an Actor execute?
Action Selection
Action Execution
12
Action Selection
Which Action to execute next?
What if data arrives at both the ports?
Scenario
13
Action Selection
Which Action to execute next?
Actors can have multiple actions
The order of action execution can affect the results of the computation
CAL Provides a powerful set of Action-Selection constructs
What is the need?
14
Each action can be provided a tag in the form of X.Y.Z
The action can then be referred to by any of its tag prefixes
An action tagged X.Y.Z can be referred by X, X.Y and X.Y.Z
Action Selection
Which Action to execute next?
Naming Actions
15
Action Selection Primitives
Input port constraints
Guards
Schedules
Priorities
…but it is driven by relatively few simple “atomic” conditions
16
Action Selection Primitives
…but it is driven by relatively few simple “atomic” conditions
Input port constraints
17
Action Selection Primitives
…but it is driven by relatively few simple “atomic” conditions
Input port constraints
Guards
18
Action Selection Primitives
…but it is driven by relatively few simple “atomic” conditions
Input port constraints
Guards
Schedules
19
Action Selection Primitives
Input port constraints
Guards
Schedules
Priorities
…but it is driven by relatively few simple “atomic” conditions
20
Action Selection Primitives – Language Specification
An Action may execute if it satisfies the following:
2. All input patterns are satisfied
3. Guard conditions satisfied
4. No higher-priority action is enabled
1. The Action Tag may follow from the Action Schedule
actor Add () A, B ==> X:
action A:[a], B:[b] ==> X:[a+b] end
end
actor Split() A ==> P, N:
action A:[a] ==> P:[a]
guard a >= 0 end
action A:[a] ==> N:[a]
guard a < 0 end
end
actor BiasedMerge() A, B ==> X:
CopyA: action A:[a] ==> X:[a] end
CopyB: action B:[b] ==> X:[b] end
priority CopyA > CopyB; end
end
actor AlmostFairMerge () Input1, Input2 ==> Output:
A: action Input1: [x] ==> [x] end
B: action Input2: [x] ==> [x] end
schedule fsm s1:
s1 (A) --> s2;
s2 (B) --> s1;
end
end
21
Action Selection Implementation
Priorities and Schedules
Priorities induce a partial order on the set of actions
Implementation:
DAG generated from partial order induced by priority relations
Topological sorting of the DAG using DFS
This ordering is used to execute actions sequentially for firing
Schedules
Implementation:
Regex converted to FSMs
FSM transitions stored in AST nodes
Actions checked before execution
State change after action execution
22
Fanout of tokens from FIFOs
Same port of an Actor can have multiple outgoing connections
Implementation
Fanout Node for every output port
References to all outgoing buffers stored
On token push to fanout, tokens are pushed to all references
23
Initializer Actions
Special Actions which only execute once at the beginning
Implementation
Initializers follow all action scheduling rules
ActorInitializer calls action-selection for initializers
24
List Comprehensions
List Comprehension Expressions, which can bind variables from generators, filter bindings by boolean expressions and collect values generated by expression evaluation
Implementation
Each Generator introduces a Lexical Scope
Currently RootNodes are used to create lexical scope
Inefficient Implementation�Will be improved with better support for lexical scoping
25
Action input and output expressions
Support for reading(or writing) multiple tokens from a port during one firing of the action
Implementation
Repeat expressions are created as for-loops in the AST
Multiple expressions are created as enumerated AST nodes
26
CAL Runtime: Running actors to conclusion
The Root entity can be executed user input number of times
Or can be specified to be run till conclusion
Run the root entity till conclusion
Each entity reports if any action executed
Invoke root entity till it returns true
27
Current State of Implementation
What works?
CAL Programs based on Language Spec
Working JPEG Decoder Program
Experimental Debugger support with code stepping
Native Image Compilation Support
28
Working Chrome Dev Tools based Debugger
29
Work achieved over Summer
Action Priorities
Guards over bound tokens
Action Schedule FSM
Action Schedule Regex
List Comprehensions
Native Image Compilation
Initializer Actions
Basic Type System
Multiple Input ports in Actors
Fanout of tokens
List size operator
Execution of entities to conclusion
Import all and Namespaces
Complex input and output expressions
While loops
Procedures
Invariant port ordering in Actors
GitHub Actions CI for release and testing
30
Non-preemptive Actor Scheduling
Network Language
Polyglot
Partition of actors into multiple cores
Network Visuali-�zation
Proper Lexical Scoping
Compiler Support
Working language server protocol
Lots of Exciting Development going as Open Source on GitHub
Work in Progress
32
CAL Implementation in GraalVM
Acknowledgements:
Tibor Vaughan, Initial Contributor
Petar Dekanovic, Antlr Parser
Thank You!
Gaps in current implementation
Performance
Partial support for Lexical Scoping
Partial support for Types
31