Counting Affine Calculator and Applications Sven Verdoolaege Team - - PowerPoint PPT Presentation

counting affine calculator and applications
SMART_READER_LITE
LIVE PREVIEW

Counting Affine Calculator and Applications Sven Verdoolaege Team - - PowerPoint PPT Presentation

April 3, 2011 1 / 23 Counting Affine Calculator and Applications Sven Verdoolaege Team ALCHEMY, INRIA Saclay, France Sven.Verdoolaege@inria.fr April 3, 2011 April 3, 2011 2 / 23 Outline Introduction 1 2 Basic Concepts and Operations


slide-1
SLIDE 1

April 3, 2011 1 / 23

Counting Affine Calculator and Applications

Sven Verdoolaege

Team ALCHEMY, INRIA Saclay, France Sven.Verdoolaege@inria.fr

April 3, 2011

slide-2
SLIDE 2

April 3, 2011 2 / 23

Outline

1

Introduction

2

Basic Concepts and Operations Representation Dataflow Analysis Code Generation

3

Transitive Closures Introduction Reachability Analysis

4

Basic Counting

5

Weighted Counting Introduction Dynamic Memory Requirement Estimation

slide-3
SLIDE 3

Introduction April 3, 2011 3 / 23

Outline

1

Introduction

2

Basic Concepts and Operations Representation Dataflow Analysis Code Generation

3

Transitive Closures Introduction Reachability Analysis

4

Basic Counting

5

Weighted Counting Introduction Dynamic Memory Requirement Estimation

slide-4
SLIDE 4

Introduction April 3, 2011 4 / 23

Introduction

What is iscc? ⇒ interactive interface to the barvinok counting library ⇒ also provides interface to the CLooG code generation library and to

some operations of the isl integer set library ⇒ inspired by Omega Calculator from the Omega Project

slide-5
SLIDE 5

Introduction April 3, 2011 4 / 23

Introduction

What is iscc? ⇒ interactive interface to the barvinok counting library ⇒ also provides interface to the CLooG code generation library and to

some operations of the isl integer set library ⇒ inspired by Omega Calculator from the Omega Project

Where to get iscc? ⇒ currently distributed as part of the barvinok distribution ⇒ available from http://freshmeat.net/projects/barvinok/

slide-6
SLIDE 6

Introduction April 3, 2011 4 / 23

Introduction

What is iscc? ⇒ interactive interface to the barvinok counting library ⇒ also provides interface to the CLooG code generation library and to

some operations of the isl integer set library ⇒ inspired by Omega Calculator from the Omega Project

Where to get iscc? ⇒ currently distributed as part of the barvinok distribution ⇒ available from http://freshmeat.net/projects/barvinok/ How to run iscc? ⇒ optionally obtain CLooG from http://www.cloog.org/ ⇒ compile and install barvinok following the instructions in README ⇒ run iscc

Note: iscc currently does not use readline, so you may want to use a readline front-end: rlwrap iscc

slide-7
SLIDE 7

Introduction April 3, 2011 5 / 23

Interaction with Libraries

isl: manipulates parametric affine sets and relations barvinok: counts elements in parametric affine sets and relations CLooG: generates code to scan elements in parametric affine sets GMP isl NTL PolyLib CLooG barvinok iscc

slide-8
SLIDE 8

Introduction April 3, 2011 5 / 23

Interaction with Libraries

isl: manipulates parametric affine sets and relations barvinok: counts elements in parametric affine sets and relations CLooG: generates code to scan elements in parametric affine sets GMP isl NTL PolyLib CLooG barvinok iscc

Future work: remove dependence on PolyLib and NTL

slide-9
SLIDE 9

Introduction April 3, 2011 5 / 23

Interaction with Libraries

isl: manipulates parametric affine sets and relations barvinok: counts elements in parametric affine sets and relations CLooG: generates code to scan elements in parametric affine sets GMP isl CLooG barvinok iscc

Future work: remove dependence on PolyLib and NTL

slide-10
SLIDE 10

Introduction April 3, 2011 5 / 23

Interaction with Libraries

isl: manipulates parametric affine sets and relations barvinok: counts elements in parametric affine sets and relations CLooG: generates code to scan elements in parametric affine sets GMP isl CLooG barvinok iscc

Future work: remove dependence on PolyLib and NTL merge barvinok into isl

slide-11
SLIDE 11

Basic Concepts and Operations April 3, 2011 6 / 23

Outline

1

Introduction

2

Basic Concepts and Operations Representation Dataflow Analysis Code Generation

3

Transitive Closures Introduction Reachability Analysis

4

Basic Counting

5

Weighted Counting Introduction Dynamic Memory Requirement Estimation

slide-12
SLIDE 12

Basic Concepts and Operations Representation April 3, 2011 7 / 23

Representation

Simple program with temporary array t:

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

slide-13
SLIDE 13

Basic Concepts and Operations Representation April 3, 2011 7 / 23

Representation

Simple program with temporary array t:

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

Iteration domains:

D := [N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N };

slide-14
SLIDE 14

Basic Concepts and Operations Representation April 3, 2011 7 / 23

Representation

Simple program with temporary array t:

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

Iteration domains:

D := [N parameters ] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N };

slide-15
SLIDE 15

Basic Concepts and Operations Representation April 3, 2011 7 / 23

Representation

Simple program with temporary array t:

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

Iteration domains:

D := [N parameters ] -> { S1 (optional) name of space [i] : 0 <= i < N; S2[i] : 0 <= i < N };

slide-16
SLIDE 16

Basic Concepts and Operations Representation April 3, 2011 7 / 23

Representation

Simple program with temporary array t:

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

Iteration domains:

D := [N parameters ] -> { S1 (optional) name of space [i] : 0 <= i < N; disjunction S2[i] : 0 <= i < N };

slide-17
SLIDE 17

Basic Concepts and Operations Representation April 3, 2011 7 / 23

Representation

Simple program with temporary array t:

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

Iteration domains:

D := [N parameters ] -> { S1 (optional) name of space [i] : 0 <= i < N; disjunction S2[i] : 0 <= i < N };

Read accesses:

R := [N] -> { S1[i] -> a[i]; S2[i] -> t[N-i-1] } * D;

slide-18
SLIDE 18

Basic Concepts and Operations Representation April 3, 2011 7 / 23

Representation

Simple program with temporary array t:

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

Iteration domains:

D := [N parameters ] -> { S1 (optional) name of space [i] : 0 <= i < N; disjunction S2[i] : 0 <= i < N };

Read accesses:

R := [N] -> { S1[i] -> a[i]; S2[i] -> t[N-i-1] } * intersect domain of map on the left with set on the right D;

slide-19
SLIDE 19

Basic Concepts and Operations Representation April 3, 2011 7 / 23

Representation

Simple program with temporary array t:

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

Iteration domains:

D := [N parameters ] -> { S1 (optional) name of space [i] : 0 <= i < N; disjunction S2[i] : 0 <= i < N };

Read accesses:

R := [N] -> { S1[i] -> a[i]; S2[i] -> t[N-i-1] } * intersect domain of map on the left with set on the right D;

Write accesses:

W := { S1[i] -> t[i]; S2[i] -> b[i] } * D;

slide-20
SLIDE 20

Basic Concepts and Operations Representation April 3, 2011 7 / 23

Representation

Simple program with temporary array t:

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

Iteration domains:

D := [N parameters ] -> { S1 (optional) name of space [i] : 0 <= i < N; disjunction S2[i] : 0 <= i < N };

Read accesses:

R := [N] -> { S1[i] -> a[i]; S2[i] -> t[N-i-1] } * intersect domain of map on the left with set on the right D;

Write accesses:

W := { S1[i] -> t[i]; S2[i] -> b[i] } * D;

Schedule:

S := { S1[i] -> [0,i]; S2[i] -> [1,i] };

slide-21
SLIDE 21

Basic Concepts and Operations Dataflow Analysis April 3, 2011 8 / 23

Dataflow Analysis

dep1,dep2

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

slide-22
SLIDE 22

Basic Concepts and Operations Dataflow Analysis April 3, 2011 8 / 23

Dataflow Analysis

dep1,dep2

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

individual pair of accesses

A1:=[N] -> { S1[i] -> t[i] : 0 <= i < N }; A2:=[N] -> { S2[i] -> t[N-i-1] : 0 <= i < N };

slide-23
SLIDE 23

Basic Concepts and Operations Dataflow Analysis April 3, 2011 8 / 23

Dataflow Analysis

dep1,dep2

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

individual pair of accesses

A1:=[N] -> { S1[i] -> t[i] : 0 <= i < N }; A2:=[N] -> { S2[i] -> t[N-i-1] : 0 <= i < N };

Map to all writes: R := A2 . (A1ˆ-1);

slide-24
SLIDE 24

Basic Concepts and Operations Dataflow Analysis April 3, 2011 8 / 23

Dataflow Analysis

dep1,dep2

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

individual pair of accesses

A1:=[N] -> { S1[i] -> t[i] : 0 <= i < N }; A2:=[N] -> { S2[i] -> t[N-i-1] : 0 <= i < N };

Map to all writes: R := A2 . (A1ˆ-1); Last write: lexmax R;

slide-25
SLIDE 25

Basic Concepts and Operations Dataflow Analysis April 3, 2011 8 / 23

Dataflow Analysis

dep1,dep2

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

individual pair of accesses

A1:=[N] -> { S1[i] -> t[i] : 0 <= i < N }; A2:=[N] -> { S2[i] -> t[N-i-1] : 0 <= i < N };

Map to all writes: R := A2 . (A1ˆ-1); Last write: lexmax R; globally

D := [N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }; R := [N] -> { S1[i] -> a[i]; S2[i] -> t[N-i-1] } * D; W := { S1[i] -> t[i]; S2[i] -> b[i] } * D; S := { S1[i] -> [0,i]; S2[i] -> [1,i] }; last W before R under S;

slide-26
SLIDE 26

Basic Concepts and Operations Code Generation April 3, 2011 9 / 23

Code Generation

codegen1,codegen2

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

Original schedule

D := [N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }; S := { S1[i] -> [0,i]; S2[i] -> [1,i] }; codegen (S * D);

slide-27
SLIDE 27

Basic Concepts and Operations Code Generation April 3, 2011 9 / 23

Code Generation

codegen1,codegen2

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

Original schedule

D := [N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }; S := { S1[i] -> [0,i]; S2[i] -> [1,i] }; codegen (S * D);

Alternative schedule

D := [N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }; S2 := [N] -> { S1[i] -> [i,0]; S2[i] -> [N-i-1,1] }; codegen (S2 * D);

slide-28
SLIDE 28

Transitive Closures April 3, 2011 10 / 23

Outline

1

Introduction

2

Basic Concepts and Operations Representation Dataflow Analysis Code Generation

3

Transitive Closures Introduction Reachability Analysis

4

Basic Counting

5

Weighted Counting Introduction Dynamic Memory Requirement Estimation

slide-29
SLIDE 29

Transitive Closures Introduction April 3, 2011 11 / 23

Transitive Closures

trans

Given a directed graph (represented as an affine map)

M := { A[i] -> A[i+1] : 0 <= i <= 3; B[] -> A[2] };

A B What are the paths in the graph (transitive closure of map)?

slide-30
SLIDE 30

Transitive Closures Introduction April 3, 2011 11 / 23

Transitive Closures

trans

Given a directed graph (represented as an affine map)

M := { A[i] -> A[i+1] : 0 <= i <= 3; B[] -> A[2] };

A B What are the paths in the graph (transitive closure of map)? ⇒ Mˆ+; A B

slide-31
SLIDE 31

Transitive Closures Introduction April 3, 2011 11 / 23

Transitive Closures

trans

Given a directed graph (represented as an affine map)

M := { A[i] -> A[i+1] : 0 <= i <= 3; B[] -> A[2] };

A B What are the paths in the graph (transitive closure of map)? ⇒ Mˆ+; A B Result:

({ B[] -> A[o0] : o0 <= 4 and o0 >= 3; B[] -> A[2]; A[i] -> A[o0] : i >= 0 and i <= 3 and o0 >= 1 and

  • 0 <= 4 and o0 >= 1 + i }, True)
slide-32
SLIDE 32

Transitive Closures Introduction April 3, 2011 11 / 23

Transitive Closures

trans

Given a directed graph (represented as an affine map)

M := { A[i] -> A[i+1] : 0 <= i <= 3; B[] -> A[2] };

A B What are the paths in the graph (transitive closure of map)? ⇒ Mˆ+; A B Result:

({ B[] -> A[o0] : o0 <= 4 and o0 >= 3; B[] -> A[2]; A[i] -> A[o0] : i >= 0 and i <= 3 and o0 >= 1 and

  • 0 <= 4 and o0 >= 1 + i }, True

exact transitive closure )

slide-33
SLIDE 33

Transitive Closures Reachability Analysis April 3, 2011 12 / 23

Reachability Analysis

reach

double x[2][10]; int old = 0, new = 1, i, t; for(t = 0; t<1000; t++) { for(i = 0; i<10;i++) x[new][i] = g(x[old][i]); new = (new+1) %2; old = (old+1) %2; }

Invariant between new and old?

slide-34
SLIDE 34

Transitive Closures Reachability Analysis April 3, 2011 12 / 23

Reachability Analysis

reach

double x[2][10]; int old = 0, new = 1, i, t; for(t = 0; t<1000; t++) { for(i = 0; i<10;i++) x[new][i] = g(x[old][i]); new = (new+1) %2; old = (old+1) %2; }

Invariant between new and old?

T := {[new,old] -> [(new+1)%2,(old+1)%2]}; S0 := {[0,1]}; (Tˆ+)(S0);

slide-35
SLIDE 35

Basic Counting April 3, 2011 13 / 23

Outline

1

Introduction

2

Basic Concepts and Operations Representation Dataflow Analysis Code Generation

3

Transitive Closures Introduction Reachability Analysis

4

Basic Counting

5

Weighted Counting Introduction Dynamic Memory Requirement Estimation

slide-36
SLIDE 36

Basic Counting April 3, 2011 14 / 23

Maximal Number of Live Memory elements

live1

S1: A = 0; S2: B = A; S3: A = 1; S4: C = A; S5: C = B; S6: B = A; S7: f(B,C);

slide-37
SLIDE 37

Basic Counting April 3, 2011 14 / 23

Maximal Number of Live Memory elements

live1

S1: A = 0; S2: B = A; S3: A = 1; S4: C = A; S5: C = B; S6: B = A; S7: f(B,C);

W:={S1[]->A[];S2[]->B[];S3[]->A[];S4[]->C[];S5[]->C[];S6[]->B[]}; R:={S2[]->A[];S4[]->A[];S5[]->B[];S6[]->A[];S7[]->B[];S7[]->C[]}; S:={S1[]->[1];S2[]->[2];S3[]->[3];S4[]->[4];S5[]->[5];S6[]->[6];S7[]->[7]}; D := dom S;

slide-38
SLIDE 38

Basic Counting April 3, 2011 14 / 23

Maximal Number of Live Memory elements

live1

S1: A = 0; S2: B = A; S3: A = 1; S4: C = A; S5: C = B; S6: B = A; S7: f(B,C);

W:={S1[]->A[];S2[]->B[];S3[]->A[];S4[]->C[];S5[]->C[];S6[]->B[]}; R:={S2[]->A[];S4[]->A[];S5[]->B[];S6[]->A[];S7[]->B[];S7[]->C[]}; S:={S1[]->[1];S2[]->[2];S3[]->[3];S4[]->[4];S5[]->[5];S6[]->[6];S7[]->[7]}; D := dom S; Dep := (last W before R under S)[0];

slide-39
SLIDE 39

Basic Counting April 3, 2011 14 / 23

Maximal Number of Live Memory elements

live1

S1: A = 0; S2: B = A; S3: A = 1; S4: C = A; S5: C = B; S6: B = A; S7: f(B,C);

W:={S1[]->A[];S2[]->B[];S3[]->A[];S4[]->C[];S5[]->C[];S6[]->B[]}; R:={S2[]->A[];S4[]->A[];S5[]->B[];S6[]->A[];S7[]->B[];S7[]->C[]}; S:={S1[]->[1];S2[]->[2];S3[]->[3];S4[]->[4];S5[]->[5];S6[]->[6];S7[]->[7]}; D := dom S; Dep := (last W before R under S)[0]; LR := (lexmax (Dep . S)) . Sˆ-1;

slide-40
SLIDE 40

Basic Counting April 3, 2011 14 / 23

Maximal Number of Live Memory elements

live1

S1: A = 0; S2: B = A; S3: A = 1; S4: C = A; S5: C = B; S6: B = A; S7: f(B,C);

W:={S1[]->A[];S2[]->B[];S3[]->A[];S4[]->C[];S5[]->C[];S6[]->B[]}; R:={S2[]->A[];S4[]->A[];S5[]->B[];S6[]->A[];S7[]->B[];S7[]->C[]}; S:={S1[]->[1];S2[]->[2];S3[]->[3];S4[]->[4];S5[]->[5];S6[]->[6];S7[]->[7]}; D := dom S; Dep := (last W before R under S)[0]; LR := (lexmax (Dep . S)) . Sˆ-1; LLT := S << S; LGE := S >>= S; After_Write := domain_map(LR) . LLT;

slide-41
SLIDE 41

Basic Counting April 3, 2011 14 / 23

Maximal Number of Live Memory elements

live1

S1: A = 0; S2: B = A; S3: A = 1; S4: C = A; S5: C = B; S6: B = A; S7: f(B,C); domain_map { S2[] -> S5[] }; { [S2[] -> S5[]] -> S2[] }

W:={S1[]->A[];S2[]->B[];S3[]->A[];S4[]->C[];S5[]->C[];S6[]->B[]}; R:={S2[]->A[];S4[]->A[];S5[]->B[];S6[]->A[];S7[]->B[];S7[]->C[]}; S:={S1[]->[1];S2[]->[2];S3[]->[3];S4[]->[4];S5[]->[5];S6[]->[6];S7[]->[7]}; D := dom S; Dep := (last W before R under S)[0]; LR := (lexmax (Dep . S)) . Sˆ-1; LLT := S << S; LGE := S >>= S; After_Write := domain_map(LR) . LLT;

slide-42
SLIDE 42

Basic Counting April 3, 2011 14 / 23

Maximal Number of Live Memory elements

live1

S1: A = 0; S2: B = A; S3: A = 1; S4: C = A; S5: C = B; S6: B = A; S7: f(B,C); domain_map { S2[] -> S5[] }; { [S2[] -> S5[]] -> S2[] }

W:={S1[]->A[];S2[]->B[];S3[]->A[];S4[]->C[];S5[]->C[];S6[]->B[]}; R:={S2[]->A[];S4[]->A[];S5[]->B[];S6[]->A[];S7[]->B[];S7[]->C[]}; S:={S1[]->[1];S2[]->[2];S3[]->[3];S4[]->[4];S5[]->[5];S6[]->[6];S7[]->[7]}; D := dom S; Dep := (last W before R under S)[0]; LR := (lexmax (Dep . S)) . Sˆ-1; LLT := S << S; LGE := S >>= S; After_Write := domain_map(LR) . LLT;

slide-43
SLIDE 43

Basic Counting April 3, 2011 14 / 23

Maximal Number of Live Memory elements

live1

S1: A = 0; S2: B = A; S3: A = 1; S4: C = A; S5: C = B; S6: B = A; S7: f(B,C); domain_map { S2[] -> S5[] }; { [S2[] -> S5[]] -> S2[] }

W:={S1[]->A[];S2[]->B[];S3[]->A[];S4[]->C[];S5[]->C[];S6[]->B[]}; R:={S2[]->A[];S4[]->A[];S5[]->B[];S6[]->A[];S7[]->B[];S7[]->C[]}; S:={S1[]->[1];S2[]->[2];S3[]->[3];S4[]->[4];S5[]->[5];S6[]->[6];S7[]->[7]}; D := dom S; Dep := (last W before R under S)[0]; LR := (lexmax (Dep . S)) . Sˆ-1; LLT := S << S; LGE := S >>= S; After_Write := domain_map(LR) . LLT; Before_Read := range_map(LR) . LGE; N_Live := card number of image elements ((After_Write * Before_Read)ˆ-1);

slide-44
SLIDE 44

Basic Counting April 3, 2011 14 / 23

Maximal Number of Live Memory elements

live1

S1: A = 0; S2: B = A; 1 S3: A = 1; 1 S4: C = A; 2 S5: C = B; 2 S6: B = A; 2 S7: f(B,C); 2 domain_map { S2[] -> S5[] }; { [S2[] -> S5[]] -> S2[] }

W:={S1[]->A[];S2[]->B[];S3[]->A[];S4[]->C[];S5[]->C[];S6[]->B[]}; R:={S2[]->A[];S4[]->A[];S5[]->B[];S6[]->A[];S7[]->B[];S7[]->C[]}; S:={S1[]->[1];S2[]->[2];S3[]->[3];S4[]->[4];S5[]->[5];S6[]->[6];S7[]->[7]}; D := dom S; Dep := (last W before R under S)[0]; LR := (lexmax (Dep . S)) . Sˆ-1; LLT := S << S; LGE := S >>= S; After_Write := domain_map(LR) . LLT; Before_Read := range_map(LR) . LGE; N_Live := card number of image elements ((After_Write * Before_Read)ˆ-1);

slide-45
SLIDE 45

Basic Counting April 3, 2011 14 / 23

Maximal Number of Live Memory elements

live1

S1: A = 0; S2: B = A; 1 S3: A = 1; 1 S4: C = A; 2 S5: C = B; 2 S6: B = A; 2 S7: f(B,C); 2 domain_map { S2[] -> S5[] }; { [S2[] -> S5[]] -> S2[] }

W:={S1[]->A[];S2[]->B[];S3[]->A[];S4[]->C[];S5[]->C[];S6[]->B[]}; R:={S2[]->A[];S4[]->A[];S5[]->B[];S6[]->A[];S7[]->B[];S7[]->C[]}; S:={S1[]->[1];S2[]->[2];S3[]->[3];S4[]->[4];S5[]->[5];S6[]->[6];S7[]->[7]}; D := dom S; Dep := (last W before R under S)[0]; LR := (lexmax (Dep . S)) . Sˆ-1; LLT := S << S; LGE := S >>= S; After_Write := domain_map(LR) . LLT; Before_Read := range_map(LR) . LGE; N_Live := card number of image elements ((After_Write * Before_Read)ˆ-1); ub N_Live;

slide-46
SLIDE 46

Basic Counting April 3, 2011 15 / 23

Maximal Number of Live Memory elements

live2,live3

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

D := [N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }; R := [N] -> { S1[i] -> a[i]; S2[i] -> t[N-i-1] } * D; W := { S1[i] -> t[i]; S2[i] -> b[i] } * D; S := { S1[i] -> [0,i]; S2[i] -> [1,i] } * D; Dep := (last W before R under S)[0]; LR := (lexmax (Dep . S)) . Sˆ-1; LLT := S << S; LGE := S >>= S; After_Write := domain_map(LR) . LLT; Before_Read := range_map(LR) . LGE; N_Live := card ((After_Write * Before_Read)ˆ-1); ub N_Live;

slide-47
SLIDE 47

Basic Counting April 3, 2011 15 / 23

Maximal Number of Live Memory elements

live2,live3

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

D := [N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }; R := [N] -> { S1[i] -> a[i]; S2[i] -> t[N-i-1] } * D; W := { S1[i] -> t[i]; S2[i] -> b[i] } * D; S := { S1[i] -> [0,i]; S2[i] -> [1,i] } * D; Dep := (last W before R under S)[0]; LR := (lexmax (Dep . S)) . Sˆ-1; LLT := S << S; LGE := S >>= S; After_Write := domain_map(LR) . LLT; Before_Read := range_map(LR) . LGE; N_Live := card ((After_Write * Before_Read)ˆ-1); ub N_Live; Result: ([N] -> { max(N) : N >= 2; max(N) : N = 1 }, True)

slide-48
SLIDE 48

Basic Counting April 3, 2011 15 / 23

Maximal Number of Live Memory elements

live2,live3

for (i = 0; i < N; ++i) S1: t[i] = f(a[i]); for (i = 0; i < N; ++i) S2: b[i] = g(t[N-i-1]);

D := [N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }; R := [N] -> { S1[i] -> a[i]; S2[i] -> t[N-i-1] } * D; W := { S1[i] -> t[i]; S2[i] -> b[i] } * D; S := { S1[i] -> [0,i]; S2[i] -> [1,i] } * D; Dep := (last W before R under S)[0]; LR := (lexmax (Dep . S)) . Sˆ-1; LLT := S << S; LGE := S >>= S; After_Write := domain_map(LR) . LLT; Before_Read := range_map(LR) . LGE; N_Live := card ((After_Write * Before_Read)ˆ-1); ub N_Live; Result: ([N] -> { max(N) : N >= 2; max(N) : N = 1 }, True bound is tight )

slide-49
SLIDE 49

Weighted Counting April 3, 2011 16 / 23

Outline

1

Introduction

2

Basic Concepts and Operations Representation Dataflow Analysis Code Generation

3

Transitive Closures Introduction Reachability Analysis

4

Basic Counting

5

Weighted Counting Introduction Dynamic Memory Requirement Estimation

slide-50
SLIDE 50

Weighted Counting Introduction April 3, 2011 17 / 23

Weighted Counting

sum1,sum2

y

x2+y2 4

x

F := { [x,y] -> 1/4*xˆ2+1/4*yˆ2 : 1 <= x,y <= 2 };

slide-51
SLIDE 51

Weighted Counting Introduction April 3, 2011 17 / 23

Weighted Counting

sum1,sum2

y

x2+y2 4

x

F := { [x,y] -> 1/4*xˆ2+1/4*yˆ2 : 1 <= x,y <= 2 }; D := dom F;

slide-52
SLIDE 52

Weighted Counting Introduction April 3, 2011 17 / 23

Weighted Counting

sum1,sum2

y

x2+y2 4

x

F := { [x,y] -> 1/4*xˆ2+1/4*yˆ2 : 1 <= x,y <= 2 }; D := dom F; F(D); ⇒ sum of F over points in D

slide-53
SLIDE 53

Weighted Counting Introduction April 3, 2011 17 / 23

Weighted Counting

sum1,sum2

y

x2+y2 4

x x M : x → (x, y)

F := { [x,y] -> 1/4*xˆ2+1/4*yˆ2 : 1 <= x,y <= 2 }; D := dom F; F(D); ⇒ sum of F over points in D M := { [x] -> [x,y] };

slide-54
SLIDE 54

Weighted Counting Introduction April 3, 2011 17 / 23

Weighted Counting

sum1,sum2

y

x2+y2 4

x x

5+2x2 4

M : x → (x, y)

F := { [x,y] -> 1/4*xˆ2+1/4*yˆ2 : 1 <= x,y <= 2 }; D := dom F; F(D); ⇒ sum of F over points in D M := { [x] -> [x,y] }; F(M); ⇒ sum of F over image of M

(alternative notation: M . F)

slide-55
SLIDE 55

Weighted Counting Introduction April 3, 2011 18 / 23

Compositions with Piecewise (Folds of) Quasipolynomials

f . g; f: D1 → D2 is a map g: D2 → Q may be

◮ piecewise quasipolynomial

(result of counting problems) ⇒ take sum over intersection of ran f and dom g

◮ piecewise fold of quasipolynomials

(result of upper bound computation) ⇒ compute bound over intersection of ran f and dom g

(f . g): D1 → Q of same type as g Note: if f is single-valued, then sum/bound is computed over a single point

slide-56
SLIDE 56

Weighted Counting Dynamic Memory Requirement Estimation April 3, 2011 19 / 23

Dynamic Memory Requirement Estimation [CFGV2006]

mem1

How much memory is needed to execute the following program? void m0(int m) { for (c = 0; c < m; c++) { m1(c); /*S1*/ B[] m2Arr = m2(2*m-c); /*S2*/ } } void m1(int k) { for (i = 1; i <= k; i++) { A a = new A(); /*S3*/ B[] dummyArr = m2(i); /*S4*/ } } B[] m2(int n) { B[] arrB = new B[n]; /*S5*/ for (j = 1; j <= n; j++) B b = new B(); /*S6*/ return arrB; }

slide-57
SLIDE 57

Weighted Counting Dynamic Memory Requirement Estimation April 3, 2011 19 / 23

Dynamic Memory Requirement Estimation [CFGV2006]

mem1

How much memory is needed to execute the following program? void m0(int m) { for (c = 0; c < m; c++) { m1(c); /*S1*/ B[] m2Arr = m2(2*m-c); /*S2*/ } } void m1(int k) { for (i = 1; i <= k; i++) { A a = new A(); /*S3*/ B[] dummyArr = m2(i); /*S4*/ } } B[] m2(int n) { B[] arrB = new B[n]; /*S5*/ for (j = 1; j <= n; j++) B b = new B(); /*S6*/ return arrB; } D := { m0[m]->S1[c] : 0<=c<m; m0[m]->S2[c] : 0<=c<m; m1[k]->S3[i] : 1<=i<=k; m1[k]->S4[i] : 1<=i<=k; m2[n]->S5[]; m2[n]->S6[j] : 1<=j<=n }; DM := (domain_map D)ˆ-1;

slide-58
SLIDE 58

Weighted Counting Dynamic Memory Requirement Estimation April 3, 2011 20 / 23

Dynamic Memory Requirement Estimation [CFGV2006]

mem2

How much (scoped) memory is needed?

⇒ compute for each method retm size of memory returned by m capm size of memory “captured” (not returned) by m reqm total memory requirements of m reqm = capm +

max

p called by m reqp

slide-59
SLIDE 59

Weighted Counting Dynamic Memory Requirement Estimation April 3, 2011 20 / 23

Dynamic Memory Requirement Estimation [CFGV2006]

mem2

How much (scoped) memory is needed?

⇒ compute for each method retm size of memory returned by m capm size of memory “captured” (not returned) by m reqm total memory requirements of m reqm = capm +

max

p called by m reqp B[] m2(int n) { B[] arrB = new B[n]; for (j=1; j<=n; j++) B b = new B(); return arrB; }

slide-60
SLIDE 60

Weighted Counting Dynamic Memory Requirement Estimation April 3, 2011 20 / 23

Dynamic Memory Requirement Estimation [CFGV2006]

mem2

How much (scoped) memory is needed?

⇒ compute for each method retm size of memory returned by m capm size of memory “captured” (not returned) by m reqm total memory requirements of m reqm = capm +

max

p called by m reqp B[] m2(int n) { B[] arrB = new B[n]; for (j=1; j<=n; j++) B b = new B(); return arrB; }

ret_m2 := DM . { [m2[n] -> S5[]] -> n : n >= 0 }; cap_m2 := DM . { [m2[n] -> S6[j]] -> 1 }; req_m2 := cap_m2 + { m2[n] -> max(0) };

slide-61
SLIDE 61

Weighted Counting Dynamic Memory Requirement Estimation April 3, 2011 21 / 23

Dynamic Memory Requirement Estimation [CFGV2006]

void m1(int k) { for (i = 1; i <= k; i++) { A a = new A(); /* S3 */ B[] dummyArr = m2(i); /* S4 */ } } capm1(k) =

  • 1≤i≤k

(1 + retm2(i)) ret_m2 is a function of the arguments of m2

We want to use it as a function of the arguments and local variables of m1

slide-62
SLIDE 62

Weighted Counting Dynamic Memory Requirement Estimation April 3, 2011 21 / 23

Dynamic Memory Requirement Estimation [CFGV2006]

void m1(int k) { for (i = 1; i <= k; i++) { A a = new A(); /* S3 */ B[] dummyArr = m2(i); /* S4 */ } } capm1(k) =

  • 1≤i≤k

(1 + retm2(i)) ret_m2 is a function of the arguments of m2

We want to use it as a function of the arguments and local variables of m1

⇒ define parameter binding CB_m1 := { [m1[k] -> S4[i]] -> m2[i] }; cap_m1 := DM . ({ [m1[k]->S3[i]] -> 1 } + (CB_m1 . ret_m2));

slide-63
SLIDE 63

Weighted Counting Dynamic Memory Requirement Estimation April 3, 2011 22 / 23

Dynamic Memory Requirement Estimation [CFGV2006]

mem3

void m1(int k) { for (i = 1; i <= k; i++) { A a = new A(); /* S3 */ B[] dummyArr = m2(i); /* S4 */ } } reqm = capm +

max

p called by m reqp CB_m1 := { [m1[k] -> S4[i]] -> m2[i] }; ret_m1 := { m1[k] -> 0 }; cap_m1 := DM . ({ [m1[k]->S3[i]] -> 1 } + (CB_m1 . ret_m2)); req_m1 := cap_m1 + (DM . CB_m1 . req_m2);

slide-64
SLIDE 64

Weighted Counting Dynamic Memory Requirement Estimation April 3, 2011 23 / 23

Dynamic Memory Requirement Estimation [CFGV2006]

mem4

void m0(int m) { for (c = 0; c < m; c++) { m1(c); /* S1 */ B[] m2Arr = m2(2 * m - c); /* S2 */ } } CB_m0 := { [m0[m] -> S1[c]] -> m1[c]; [m0[m] -> S2[c]] -> m2[2 * m - c] }; ret_m0 := { m0[m] -> 0 }; cap_m0 := DM . CB_m0 . (ret_m1 + ret_m2); req_m0 := cap_m0 + (DM . CB_m0 . (req_m1 . req_m2));

slide-65
SLIDE 65

Weighted Counting Dynamic Memory Requirement Estimation April 3, 2011 23 / 23

Dynamic Memory Requirement Estimation [CFGV2006]

mem4

void m0(int m) { for (c = 0; c < m; c++) { m1(c); /* S1 */ B[] m2Arr = m2(2 * m - c); /* S2 */ } } CB_m0 := { [m0[m] -> S1[c]] -> m1[c]; [m0[m] -> S2[c]] -> m2[2 * m - c] }; ret_m0 := { m0[m] -> 0 }; cap_m0 := DM . CB_m0 . (ret_m1 + ret_m2); req_m0 := cap_m0 + (DM . CB_m0 . (req_m1 . combine reductions req_m2));