Implementation of Orc William Cook and Jayadev Misra f cook,misra g - - PowerPoint PPT Presentation

implementation of orc
SMART_READER_LITE
LIVE PREVIEW

Implementation of Orc William Cook and Jayadev Misra f cook,misra g - - PowerPoint PPT Presentation

D EPARTMENT OF C OMPUTER S CIENCES Implementation of Orc William Cook and Jayadev Misra f cook,misra g @cs.utexas.edu Department of Computer Science University of Texas at Austin Email: web: http://www.cs.utexas.edu/users/psp U NIVERSITY OF T


slide-1
SLIDE 1

DEPARTMENT OF COMPUTER SCIENCES

Implementation of Orc

William Cook and Jayadev Misra Department of Computer Science University of Texas at Austin Email:

fcook,misrag@cs.utexas.edu

web: http://www.cs.utexas.edu/users/psp

UNIVERSITY OF TEXAS AT AUSTIN

slide-2
SLIDE 2

DEPARTMENT OF COMPUTER SCIENCES

Status of Implementation

Implementation coded in Java. An Orc program can call Java programs as sites. A Java program can call an Orc program.

Another implementation by Galen Menzel using Concurrent Haskell.

UNIVERSITY OF TEXAS AT AUSTIN 1

slide-3
SLIDE 3

DEPARTMENT OF COMPUTER SCIENCES

Java Calling Orc

Include in the main (Java) program

z :2 E (L)

where

z is a variable of the main program, E an Orc expression, L a list of actual parameters,

constants and variables of the main program. The effect is: assign to

z the first value published by E and terminate.

UNIVERSITY OF TEXAS AT AUSTIN 2

slide-4
SLIDE 4

DEPARTMENT OF COMPUTER SCIENCES

Implementation Using the Semantic Rules

f l , ! f f j g l , ! f j g

(SYM1)

f y , ! f f > x > g
  • ,
! (f > x > g ) j [ =x℄g

(SEQ1V) The expression structure has to change.

[[ E (q )
  • f
℄℄ 2 D E (p)
  • ,
! [p=q ℄f

(DEF) Each expression has to be instantiated whenever it is called.

UNIVERSITY OF TEXAS AT AUSTIN 3

slide-5
SLIDE 5

DEPARTMENT OF COMPUTER SCIENCES

A simpler strategy

Compile a fixed structure for each expression.

– Compile each expression to a directed acyclic graph (dag). – Each node of the dag has an instruction.

Runtime Dag Traversal: Place tokens at dag nodes.

In each step, – Pick an appropriate token. – Execute the corresponding instruction, which may

make site/expression call create new tokens publish a value

UNIVERSITY OF TEXAS AT AUSTIN 4

slide-6
SLIDE 6

DEPARTMENT OF COMPUTER SCIENCES

Compiler

For each defined expression and the goal expression build a dag. Each dag has a root and a sink node. Each node has an instruction:

for expression

  • for silent transition
r etur n

to publish a value

M (L)

site call

E (L)

expression call

assig n(x)

assign to variable

x w her e(x)

for starting a where expression

hok e

for ending a where expression

UNIVERSITY OF TEXAS AT AUSTIN 5

slide-7
SLIDE 7

DEPARTMENT OF COMPUTER SCIENCES

Recursive Construction of Dag

assign(x) f>x>g τ τ τ f g τ f | g τ f g f>>g E f g where(x) choke τ M f g g f where x :ε M E

UNIVERSITY OF TEXAS AT AUSTIN 6

slide-8
SLIDE 8

DEPARTMENT OF COMPUTER SCIENCES

Notes on Dag construction

There is a unique root and sink for each dag. The instruction at each sink is .

UNIVERSITY OF TEXAS AT AUSTIN 7

slide-9
SLIDE 9

DEPARTMENT OF COMPUTER SCIENCES

Dag Finalization

Change the instruction at each sink, from

to: hok e, if this is the goal dag (i.e., for expression in the main program) r etur n, for all other dags.

Hence, a sink does not have a

instruction, i.e.,

Every

  • node has a successor.

UNIVERSITY OF TEXAS AT AUSTIN 8

slide-10
SLIDE 10

DEPARTMENT OF COMPUTER SCIENCES

Construction of Example Dag

τ M N(x) τ τ τ τ choke τ τ assign(y) G(y) τ choke where(x) S

Figure 1:

(M j N (x) where x:2 S
  • 0)
> y > G(y )

UNIVERSITY OF TEXAS AT AUSTIN 9

slide-11
SLIDE 11

DEPARTMENT OF COMPUTER SCIENCES

Dag Optimization (

  • node Elimination)

Eliminate any non-root

  • node:

τ A B C D A B C D

Restriction

A where node has a left and a right successor. A site/expression call node has exactly one successor.

UNIVERSITY OF TEXAS AT AUSTIN 10

slide-12
SLIDE 12

DEPARTMENT OF COMPUTER SCIENCES

Reconstruction of Example Dag

τ M N(x) choke assign(y) G(y) where(x) S choke

Figure 2:

(M j N (x) where x:2 S
  • 0)
> y > G(y )

UNIVERSITY OF TEXAS AT AUSTIN 11

slide-13
SLIDE 13

DEPARTMENT OF COMPUTER SCIENCES

Dag Traversal:

(M j N ) > x > (R j S (x))

τ M N R S(x) choke assign(x)

UNIVERSITY OF TEXAS AT AUSTIN 12

slide-14
SLIDE 14

DEPARTMENT OF COMPUTER SCIENCES

τ M N R S(x) choke assign(x) (1) assign(x) τ M N R choke S(x)

x x

(4) assign(x) τ M N R choke S(x) (5)

x x

assign(x) τ M N R choke S(x) (6)

x x

assign(x) τ M N R choke S(x) (2) assign(x) τ M N R choke S(x) (3) : ready token : suspended token

UNIVERSITY OF TEXAS AT AUSTIN 13

slide-15
SLIDE 15

DEPARTMENT OF COMPUTER SCIENCES

Fields of a token

position: the node in the dag. context: values of variables (such as x in the example) val: token’s value, which may be returned to the caller. state: ready, pending, or suspended.

UNIVERSITY OF TEXAS AT AUSTIN 14

slide-16
SLIDE 16

DEPARTMENT OF COMPUTER SCIENCES

Initialization

Given

z := E (p; 3) in the Main program and goal dag E (x; y ) Create token t where t: ontext = f(x; p’s value); (y ; 3)g.
  • t:v
al = ?.
  • t:state
= r eady. Put t on the root node of the goal dag.

UNIVERSITY OF TEXAS AT AUSTIN 15

slide-17
SLIDE 17

DEPARTMENT OF COMPUTER SCIENCES

Process token

t’s instruction
  • 0: skip.
  • : put copies of
t at all successor nodes. Site call M (x):

– call

M with parameter value x from t: ontext.

– put suspended copy of

t at the successor node.
  • assig
n(x):

– add

(x; t:v al ) to t: ontext.

– put copies of

t at all successor nodes.
  • hok
e:

– return

t:v al to the caller. (This will be generalized.)

– Terminate this computation. Delete

t after processing.

UNIVERSITY OF TEXAS AT AUSTIN 16

slide-18
SLIDE 18

DEPARTMENT OF COMPUTER SCIENCES

Processing expression call: caller’s dag

M On receiving value v v’ M E(p) Expression Call E(p) Initially t M v E(p) E(p)

For ready token t at E (p):

– put

v, a pending copy of t, at M .

– Delete

t. On receiving value from E :

– create ready copy

v 0 of v to get the value.

v remains pending, to receive more values.

UNIVERSITY OF TEXAS AT AUSTIN 17

slide-19
SLIDE 19

DEPARTMENT OF COMPUTER SCIENCES

Processing expression call

E (x): callee’s dag when token t at caller dag calls E (p): put token u at E ’s root.

u is ready .

u: ontext has (x; p’s value from t: ontext).

u: al l er := v

al l er is a field of a token. To process token t at the sink of the dag, with instruction r etur n:

v := t: al l er;

v :v al := t:v al; v :state := r eady

– delete

t

UNIVERSITY OF TEXAS AT AUSTIN 18

slide-20
SLIDE 20

DEPARTMENT OF COMPUTER SCIENCES

Example:

Metr
  • nome

Signal Rtimer(1) return τ Metronome

Figure 3:

Metr
  • nome
  • S
ig nal j R timer (1)
  • Metr
  • nome

UNIVERSITY OF TEXAS AT AUSTIN 19

slide-21
SLIDE 21

DEPARTMENT OF COMPUTER SCIENCES

Signal Rtimer(1) return τ Metronome Signal Rtimer(1) return τ Metronome Signal Rtimer(1) return τ Metronome Signal Rtimer(1) return τ Metronome Signal Rtimer(1) return τ Metronome Signal Rtimer(1) return τ Metronome Signal Rtimer(1) return τ Metronome Signal Rtimer(1) return τ Metronome 0’ 0’’ 0’’ 0’’ responds to Main 0’ 0’’ 0’’ 0’’ 1 1’ 0’’ 1’’ 1’’ 0’’0’’ returns to 1’ 0’’

i’: on the left, always ready

receives from Rtimer

: on the right, ready :on the right, suspended i’’ i’’

0’

UNIVERSITY OF TEXAS AT AUSTIN 20

slide-22
SLIDE 22

DEPARTMENT OF COMPUTER SCIENCES

Token structure in Metronome

  • 0 and
00 return signals to Main.
  • i
0 and i 00, i > 0, return signals to (i
  • 1)
00.
  • i
00 is permanently pending; copy i 00 created when it receives a signal.

UNIVERSITY OF TEXAS AT AUSTIN 21

slide-23
SLIDE 23

DEPARTMENT OF COMPUTER SCIENCES

Summary (so far)

Compile dag for each expression. A token has: position, context, val, caller, state. Put a ready token with parameter values as context at the root of goal

dag.

Process any ready token, with instruction: 0, , Site/Expr call, assig n(x), r etur n, hok e

UNIVERSITY OF TEXAS AT AUSTIN 22

slide-24
SLIDE 24

DEPARTMENT OF COMPUTER SCIENCES

where expression

f g where(x) choke τ

Figure 4:

f where x:2 g Compute f as far as possible. Call to M (x) may wait. Compute g: At hok e

– assign value to

x.

– terminate

g

UNIVERSITY OF TEXAS AT AUSTIN 23

slide-25
SLIDE 25

DEPARTMENT OF COMPUTER SCIENCES

For ready token

t at w her e(x)

f g where(x) choke τ u v

Create ready tokens u and v at left and right successors. Create cell where the value of x will be stored. :v al := ? Add (x; ) to u: ontext.

UNIVERSITY OF TEXAS AT AUSTIN 24

slide-26
SLIDE 26

DEPARTMENT OF COMPUTER SCIENCES

Site/Expr call in the left subgraph

For ready token t at site call M (x) where (x; ) is in t: ontext:

if

:v al 6= ? then call M ( :v al ); put copy u of t at successor.

– immediate site: receive response

r; u:v al := r; u:state := r eady

– deferred site:

u:state := suspended

if

:v al = ? then t is pending waiting for . For token t at expr call E (x): proceed as before

delete

t.

UNIVERSITY OF TEXAS AT AUSTIN 25

slide-27
SLIDE 27

DEPARTMENT OF COMPUTER SCIENCES

For token

t at w her e(x), contd.

f g where(x) choke τ u v Given that cell

is created at w her e(x): All tokens in g are killed at hok e. Identify all such tokens by cell ; kill all tokens of of cell .
  • v
: el l :=

el l is a new field of a token.

UNIVERSITY OF TEXAS AT AUSTIN 26

slide-28
SLIDE 28

DEPARTMENT OF COMPUTER SCIENCES

Processing

hok e

f g where(x) choke τ u v For token

t at hok e: := t: el l :v al := t:v al

now no token waits for

;

any token waiting only for

is made ready;

delete all tokens of cell

UNIVERSITY OF TEXAS AT AUSTIN 27

slide-29
SLIDE 29

DEPARTMENT OF COMPUTER SCIENCES

Cell within cell:

h where y :2 (f where x:2 g )

g where(x) choke1 where(y) h τ τ choke2 f

Suppose y is assigned at hok e2 before x is assigned. Need to kill f where x:2 g’s computation, i.e, both f and g. Tokens in f and g have different cells.

UNIVERSITY OF TEXAS AT AUSTIN 28

slide-30
SLIDE 30

DEPARTMENT OF COMPUTER SCIENCES

Cell Tree

f g where(x) choke τ u v

In processing token t at w her e(x):

create cell

; :par ent := t: el l In processing token s at hok e:

kill all tokens of

s: el l and descendant cells.

UNIVERSITY OF TEXAS AT AUSTIN 29

slide-31
SLIDE 31

DEPARTMENT OF COMPUTER SCIENCES

RootCell

The initial token has cell R
  • tCel
l . The cells form a tree with root R
  • tCel
l .

UNIVERSITY OF TEXAS AT AUSTIN 30

slide-32
SLIDE 32

DEPARTMENT OF COMPUTER SCIENCES

Summary of Runtime structure

Fields of a token: position, context, val, caller, state, cell. Fields of a cell: val, parent, waitList.

UNIVERSITY OF TEXAS AT AUSTIN 31

slide-33
SLIDE 33

DEPARTMENT OF COMPUTER SCIENCES

Overall algorithm

R
  • tCel
l :v al 6= ? ! return R
  • tCel
l :v al to main; terminate. t:r eady ! process instruction at t; delete t t:suspended ^ :(9s :: s:r eady ) ! on receiving response r: t:v al := r ; t:state := r eady

else

! “No value will be published” Round-based Execution: Response from a deferred site is processed
  • nly if there is no ready token.
else is same as (8t :: t:pending ). There may be no token at all (for 0). else is executed for M (x) where x:2 The algorithm may not terminate: there are suspended tokens, but no

deferred site responds.

UNIVERSITY OF TEXAS AT AUSTIN 32