GAIL: A DESIGN AND IMPLEMENTATION OF A CONSTRAINED GUARDED ACTION - - PowerPoint PPT Presentation

gail a design and implementation of a constrained guarded
SMART_READER_LITE
LIVE PREVIEW

GAIL: A DESIGN AND IMPLEMENTATION OF A CONSTRAINED GUARDED ACTION - - PowerPoint PPT Presentation

GAIL: A DESIGN AND IMPLEMENTATION OF A CONSTRAINED GUARDED ACTION INTERMEDIATE LANGUAGE SUITABLE FOR REWRITE-BASED OPTIMIZATION Tim Zwiebel Northwestern University 2 Overview GAIL Rewriting Code Generator User Interface Future Work


slide-1
SLIDE 1

GAIL: A DESIGN AND IMPLEMENTATION OF A CONSTRAINED GUARDED ACTION INTERMEDIATE LANGUAGE SUITABLE FOR REWRITE-BASED OPTIMIZATION

Tim Zwiebel Northwestern University

slide-2
SLIDE 2

2

Overview GAIL Rewriting Code Generator User Interface Future Work Conclusion

slide-3
SLIDE 3

Wireless Sensor Networks

3

 Archetype-Based Synthesis  Wireless Communication  Battery Powered  Complex Wireless communication protocols

slide-4
SLIDE 4

ABSYNTH Project

4

Expert System

  • Leads the

user through a series of questions

  • Determine

system-level constraints

  • Assist the

user in generating high-level code System Analysis

  • Optimal

node placement

  • Node-level

constraints

  • Node-level

code GAIL

  • Guarded

Action Intermediate Language

  • Software

and hardware description

  • Rewrite-

Based Optimization

  • Compiled

into C code

slide-5
SLIDE 5

5

Overview GAIL Rewriting Code Generator User Interface Future Work Conclusion

slide-6
SLIDE 6

GAIL

6

 Guarded Action Intermediate Language  Designed for use in Wireless Sensor Networks (runs

  • n constrained hardware platforms)

 Language is constrained to facilitate program

analysis

 Programs contain both hardware and software  Designed to allow rewrite-based optimizations on

both hardware and software

slide-7
SLIDE 7

GAIL Programs

7

 Programs are ( ( Def … ) ( GA … ) )

 Def=Variable & Hardware Definitions  GA = Guarded Actions

 All variables and hardware is defined and

initialized in the hardware definition section

 Types:

 Boolean, Boolean Queues  Scalar, Scalar Queues  Analog and Digital Inputs  Analog and Digital Outputs

slide-8
SLIDE 8

Queues

8

 Queues are statically allocated  Queues can become full, so each queue has a

policy to handle this case

 Policies

 DROP: items added to a full queue are discarded and

the queue remains the same

 DISPLACE: items added to a full queue displace an item

already in the queue (e.g. if an item is added to the front, an item is popped off the back)

slide-9
SLIDE 9

Guarded Actions

9

 Guards are boolean expressions  When guards evaluate to TRUE, the actions are

triggered

 Guarded actions have constraints to determine

when to evaluate the guard

 Example Constraint: (time-constraint 0 3000)  Other Constraints: variable-constraint, guard-

constraint, messages, interrupts

slide-10
SLIDE 10

Evaluation of Guarded Actions

10

 Guards are evaluated according to their constraints  When a guard is evaluated to TRUE, the entire set of

actions is evaluated

 Hardware is sampled once for the entire set of actions  Functions with side effects must be at the top level of an

action

 When evaluating a set of actions, all expressions that

do not have side effects are evaluated before those that do

 Expressions that have side effects are evaluated in

  • rder
slide-11
SLIDE 11

11

Overview GAIL Rewriting Code Generator User Interface Future Work Conclusion

slide-12
SLIDE 12

Rewriting

12

 Optimizations are performed via rewrite rules  Uses PLT Redex, part of PLT Scheme  Rewrite rules are called reduction cases and a set

  • f rewrite rules is a reduction relation
slide-13
SLIDE 13

PLT Redex Example – Language Definition

13

(define-language simple-lang (exp number (+ exp exp) (- exp exp)) (C hole (any ... C any ...)))

slide-14
SLIDE 14

PLT Redex Example – Rewrite Rules

14

(define rewrite (reduction-relation simple-lang (--> (in-hole C (+ number_1 number_2)) (in-hole C ,(+ (term number_1) (term number_2))) "addition") (--> (in-hole C (- number_1 number_2)) (in-hole C ,(- (term number_1) (term number_2))) "subtraction")))

slide-15
SLIDE 15

PLT Redex Example - Traces

15

(traces rewrite (term (+ (- 7 2) (- 4 3))))

slide-16
SLIDE 16

Joint Hardware-Software Optimization

16

(--> (in-hole C (+ (read di-exp_1) number_1)) (in-hole C (read (d+ di-exp_1 number_1)) “read d+”) (--> (in-hole C (+ (read ai_exp_1) number_1)) (in-hole C (read (a+ ai-exp_1 (dac number_1)))) “read a+”)

slide-17
SLIDE 17

Example Rewriting

17

This graph is unreadable since it won’t fit on one slide

slide-18
SLIDE 18

Objective Functions

18

 The rewrite system generates equivalent programs  An objective function is used to determine the “best”

program

 GAIL is constrained, so program analysis is easier

 Maximum stack depth  Memory usage  Program code size  Estimates of power/energy use

slide-19
SLIDE 19

19

Overview GAIL Rewriting Code Generator User Interface Future Work Conclusion

slide-20
SLIDE 20

Code Generator: LISA

20

 LISA is a Java-based compiler generator  It uses attribute-based grammars  Generates a scanner, parser, and evaluator  Attributes are Java types  Java assignment statements in the formal grammar

determine the values for the attributes

 LISA can automatically determine inherited vs.

synthesized attributes

slide-21
SLIDE 21

C Code

21

 Initialize variables  Main Loop

 Wait on a semaphore

 Constraints place a function pointer in a task queue,

then post on the semaphore

slide-22
SLIDE 22

LISA Example - Scanner

22

language SimpleLang { lexicon { NUMBER \-?[0-9]+(.[0-9]+)? PLUS \+ MINUS \- LP \( RP \) //space, tab, line feed, carriage return WHITESPACE [\ \0x09\0x0A\0x0D] ignore #WHITESPACE } ...

slide-23
SLIDE 23

LISA Example - Attributes

23

... attributes String PROG.code, EXP.val, EXP.code; rule Program { PROG ::= EXP compute { PROG.code = "#include <stdio.h>\n\nint main() {\n" + EXP.code + "\nprintf(\"%f\\n\", " + EXP.val + ");\n\nreturn 0;\n}"; }; } ...

slide-24
SLIDE 24

LISA Example - Grammar

24

... rule Expression { EXP ::= #NUMBER compute { EXP.val = getTemp(); EXP.code = "float " + EXP.val + " = " + #NUMBER.value() + ";\n"; }; EXP ::= ( #PLUS EXP EXP ) compute { EXP[0].val = getTemp(); EXP[0].code = EXP[1].code + EXP[2].code + "float " + EXP[0].val + " = " + EXP[1].val + " + " + EXP[2].val + ";\n"; }; EXP ::= ( #MINUS EXP EXP ) compute { EXP[0].val = getTemp(); EXP[0].code = EXP[1].code + EXP[2].code + "float " + EXP[0].val + " = " + EXP[1].val + " - " + EXP[2].val + ";\n"; }; } ...

slide-25
SLIDE 25

LISA Example - Methods

25

... method Conversions { double stringToDouble(String s) { return Double.parseDouble(s); } } method Temps { static int tempCount = 1; String getTemp() { return "temp" + tempCount++; } } }

slide-26
SLIDE 26

LISA Tree

26

slide-27
SLIDE 27

LISA Example – C Code

27

#include <stdio.h> int main() { float temp3 = 7; float temp4 = 2; float temp2 = temp3 - temp4; float temp6 = 4; float temp7 = 3; float temp5 = temp6 - temp7; float temp1 = temp2 + temp5; printf("%f\n", temp1); return 0; }

slide-28
SLIDE 28

28

Overview GAIL Rewriting Code Generator User Interface Future Work Conclusion

slide-29
SLIDE 29

User Interface

29

 Java Applet  Webcam  Demo

slide-30
SLIDE 30

Future UI Work

30

 Graphics to see LEDs, etc.  Buttons to actuate sensors  Improved editor

 Syntax highlighting, line numbers, code completion

slide-31
SLIDE 31

31

Overview GAIL Rewriting Code Generator User Interface Future Work Conclusion

slide-32
SLIDE 32

Future Work

32

 Implementation of data types

 Scalars  Queues

 Communication

 Multi-hop

 Optimizations

 More of them  Directed search

slide-33
SLIDE 33

Future Work

33

 Verification

 Accuracy maintained?  Power/energy consumption

 Runtime Errors

slide-34
SLIDE 34

34

Overview GAIL Rewriting Code Generator User Interface Future Work Conclusion

slide-35
SLIDE 35

Conclusion

35

 Guarded Action Intermediate Language  Runs in a constrained hardware environment  Rewrite system allows joint hardware-software

  • ptimization

 Constrained nature of language allows easier

program analysis

slide-36
SLIDE 36

QUESTIONS?

36