23
A Dynamic Programming Approach to Optimal Integrated Code Generation Christoph Keßler Andrzej Bednarski Linköping University (Sweden)

A Dynamic Programming Approach to Optimal Integrated Code Generation

  • Upload
    alden

  • View
    22

  • Download
    0

Embed Size (px)

DESCRIPTION

A Dynamic Programming Approach to Optimal Integrated Code Generation. Christoph Ke ßler Andrzej Bednarski Linköping University (Sweden). Outline. Code generation Our integrated approach Implementation and results Current and future work Conclusion. Code Generation. IR-level - PowerPoint PPT Presentation

Citation preview

Page 1: A Dynamic Programming Approach to Optimal Integrated Code Generation

A Dynamic Programming Approach to Optimal

Integrated Code Generation

Christoph KeßlerAndrzej Bednarski

Linköping University (Sweden)

Page 2: A Dynamic Programming Approach to Optimal Integrated Code Generation

Outline Code generation Our integrated approach Implementation and results Current and future work Conclusion

Page 3: A Dynamic Programming Approach to Optimal Integrated Code Generation

Code Generation

Instru

ctio

n s

ele

ctio

n

Instru

ctio

n s

ele

ctio

n

Instru

ctio

n s

ele

ctio

n

Instru

ctio

n s

ele

ctio

n

IR

Targetcode

IR-levelInstruction scheduling

Target-levelInstruction scheduling

IR-levelInstruction scheduling

Target-levelInstruction scheduling

Targ

et-le

vel

Reg. A

lloc

Targ

et-le

vel

Reg. A

lloc

IR-le

vel

Reg. A

lloc

IR-le

vel

Reg. A

lloc

Page 4: A Dynamic Programming Approach to Optimal Integrated Code Generation

Related Work Heuristics Optimal approaches

ILP Dynamic programming Branch-and-bound Enumeration Constraint logic programming

Page 5: A Dynamic Programming Approach to Optimal Integrated Code Generation

Integrated Code Generation

Instru

ctio

n s

ele

ctio

n

Instru

ctio

n s

ele

ctio

n

Instru

ctio

n s

ele

ctio

n

Instru

ctio

n s

ele

ctio

n

IR

Targetcode

IR-levelInstruction scheduling

Target-levelInstruction scheduling

IR-levelInstruction scheduling

Target-levelInstruction scheduling

Targ

et-le

vel

Reg. A

lloc

Targ

et-le

vel

Reg. A

lloc

IR-le

vel

Reg. A

lloc

IR-le

vel

Reg. A

lloc

Integrated

Code generation

Page 6: A Dynamic Programming Approach to Optimal Integrated Code Generation

Integrated Approach Christoph Keßler’s previous work

Scheduling by topological sorting Dynamic programming Selection DAG

Time profile Extended selection DAGBasic block scope of code generation

Page 7: A Dynamic Programming Approach to Optimal Integrated Code Generation

Topological Sorting

u

v

scheduled(z)

z

scheduled(z’)

u

v

z’

Page 8: A Dynamic Programming Approach to Optimal Integrated Code Generation

Selection Tree

h

f g

d e

a b c

{a,b,c}

{b,c} {a,c} {a,b}

a cb

{c,d} {b} {c,d} {a,e} {b} {a,e}

… … … … … …

b c a c a b

Page 9: A Dynamic Programming Approach to Optimal Integrated Code Generation

Selection DAG Merge multiple instances of same

zero indegree set z in one selection node

Selection DAG Selection DAG is leveled in n+1 levels Each schedule S corresponds to one

path in the selection DAG

Page 10: A Dynamic Programming Approach to Optimal Integrated Code Generation

Selection DAG

h

f g

d e

a b c

{a,b,c}

{b,c} {a,c} {a,b}

a cb

{c,d} {b} {a,e}

… … …

b c ca ab

Page 11: A Dynamic Programming Approach to Optimal Integrated Code Generation

Towards Time Optimization Machine model

Generic superscalar/VLIW architecture Single/Multiple issue

From IR level to target level Instruction selection Register allocation (homogenous) Imitate instruction dispatcher

behaviour

Page 12: A Dynamic Programming Approach to Optimal Integrated Code Generation

Time Profile Window of the instructions scheduled

last for each unit that may still influence future scheduling decisions

e f -

c

t

d

- -

--a

b

-

time

u3u2u1

Page 13: A Dynamic Programming Approach to Optimal Integrated Code Generation

Extended Selection Node An extended selection node (z, t,

P), summarizes all schedules of scheduled(z) that end with the time profile (t, P).

Pruning (formal proof in the paper)time e f -

c

t

d

- -

--a

b

-

u3u2u1

e f -

c

t’

d

- -b

a

u3u2u1

a f -

c

t’

d

- -b

e

u3u2u1

Page 14: A Dynamic Programming Approach to Optimal Integrated Code Generation

Extended Selection DAGLevel 0

Level 1

Level 2

...

Page 15: A Dynamic Programming Approach to Optimal Integrated Code Generation

Solution Space Group the extended

selection nodes in each level according to execution time

Construct solution space in order of increasing time

Postpones the combinatorial explosion

Page 16: A Dynamic Programming Approach to Optimal Integrated Code Generation

Implementation C++ LEDA XML based architecture description

language LCC as C–front-end

Page 17: A Dynamic Programming Approach to Optimal Integrated Code Generation

Results – Random DAGs

Page 18: A Dynamic Programming Approach to Optimal Integrated Code Generation

Results – Random DAGs

Page 19: A Dynamic Programming Approach to Optimal Integrated Code Generation

Results – FIR Filter

Basic Block

DAG#node

sTime

archi. 1Time

archi. 2

BB1 16 3.5s 4.0s

BB2 16 8.0s 9.5s

BB3 303:21:50.

2s4:40:44.9

s

Page 20: A Dynamic Programming Approach to Optimal Integrated Code Generation

Results – Matrix Multiplication

Basic Block

DAG#node

sTime

archi. 1Time

archi. 2

BB2 30 1:05.0s 1:41.8s

BB2 (unrolle

d)40 6:08.5s 9:47.2s

Page 21: A Dynamic Programming Approach to Optimal Integrated Code Generation

Results – Jacobi Grid Relax.

Basic Block

DAG#node

sTime

archi. 1Time

archi. 2

Loop body (5)

40 1:15.8s 1:31.8s

Loop body (9)

531:36:13.2

s2:00:51.5

s

Page 22: A Dynamic Programming Approach to Optimal Integrated Code Generation

Current and Future Work Time-space profile for irregular

register sets Speculative instruction selection Extensions of architecture

description language Beyond basic block level

Time-space profiles as connector descriptions

Page 23: A Dynamic Programming Approach to Optimal Integrated Code Generation

Conclusion Goal: fully integrated code generation Dynamic programming approach Time profiles to compress the solution space Improved order of solution space construction Feasible for medium sized basic blocks Potential for extensions Alternative to ILP Home page: www.ida.liu.se/~chrke/optimist