128
A Unified Framework for Schedule and Storage Optimization William Thies, Frédéric Vivien*, Jeffrey Sheldon, and Saman Amarasinghe MIT Laboratory for Computer Science * ICPS/LSIIT, Université Louis Pasteur http://compiler.lcs.mit.edu/aov

A Unified Framework for Schedule and Storage Optimization

  • Upload
    alijah

  • View
    40

  • Download
    0

Embed Size (px)

DESCRIPTION

A Unified Framework for Schedule and Storage Optimization. William Thies, Frédéric Vivien*, Jeffrey Sheldon, and Saman Amarasinghe MIT Laboratory for Computer Science * ICPS/LSIIT, Université Louis Pasteur http://compiler.lcs.mit.edu/aov. Motivating Example. - PowerPoint PPT Presentation

Citation preview

Page 1: A Unified Framework for Schedule and Storage Optimization

A Unified Framework forSchedule and Storage

Optimization

William Thies, Frédéric Vivien*, Jeffrey Sheldon, and Saman

Amarasinghe

MIT Laboratory for Computer Science

* ICPS/LSIIT, Université Louis Pasteur

http://compiler.lcs.mit.edu/aov

Page 2: A Unified Framework for Schedule and Storage Optimization

Motivating Example

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2]) j

Page 3: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 1

(i, j) = (1, 1)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 4: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 2

(i, j) = (1, 2)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 5: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 3

(i, j) = (1, 3)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 6: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 4

(i, j) = (1, 4)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 7: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 5

(i, j) = (1, 5)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 8: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 6

(i, j) = (2, 1)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 9: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 7

(i, j) = (2, 2)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 10: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 8

(i, j) = (2, 3)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 11: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 9

(i, j) = (2, 4)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 12: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 10

(i, j) = (2, 5)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 13: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

t = 25

(i, j) = (5, 5)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

Page 14: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

init A[0][j] for i = 1 to n for j = 1 to n A[i][j] = f(A[i-1][j], A[i][j-2])

Array Expansion

i

j

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

t = 25

(i, j) = (5, 5)

Page 15: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

Array Expansion

t = 1

(i, j) = (1, 1)i

j

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

t = 25

(i, j) = (5, 5)

init A[0][j] for i = 1 to n for j = 1 to n A[i][j] = f(A[i-1][j], A[i][j-2])

Page 16: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

Array Expansion

t = 2

(i, j) = {(1, 2), (2, 1)}

i

j

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

t = 25

(i, j) = (5, 5)

init A[0][j] for i = 1 to n for j = 1 to n A[i][j] = f(A[i-1][j], A[i][j-2])

Page 17: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

Array Expansion

i

j

t = 3

(i, j) = {(1, 3), (2, 2), (3, 1)}

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

t = 25

(i, j) = (5, 5)

init A[0][j] for i = 1 to n for j = 1 to n A[i][j] = f(A[i-1][j], A[i][j-2])

Page 18: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

Array Expansion

i

j

t = 4

(i, j) = {(1, 4), (2, 3), (3, 2), (4, 1)}

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

t = 25

(i, j) = (5, 5)

init A[0][j] for i = 1 to n for j = 1 to n A[i][j] = f(A[i-1][j], A[i][j-2])

Page 19: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

Array Expansion

i

j

t = 5

(i, j) = {(1, 5), (2, 4), (3, 3), (4, 2), (5, 1)}

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

t = 25

(i, j) = (5, 5)

init A[0][j] for i = 1 to n for j = 1 to n A[i][j] = f(A[i-1][j], A[i][j-2])

Page 20: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

Array Expansion

i

j

t = 6

(i, j) = {(2, 5), (3, 4), (4, 3), (5, 2)}

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

t = 25

(i, j) = (5, 5)

init A[0][j] for i = 1 to n for j = 1 to n A[i][j] = f(A[i-1][j], A[i][j-2])

Page 21: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

Array Expansion

i

j

t = 7

(i, j) = {(3, 5), (4, 4), (5, 3)}

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

t = 25

(i, j) = (5, 5)

init A[0][j] for i = 1 to n for j = 1 to n A[i][j] = f(A[i-1][j], A[i][j-2])

Page 22: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

Array Expansion

i

j

t = 8

(i, j) = {(4, 5), (5, 4)}

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

t = 25

(i, j) = (5, 5)

init A[0][j] for i = 1 to n for j = 1 to n A[i][j] = f(A[i-1][j], A[i][j-2])

Page 23: A Unified Framework for Schedule and Storage Optimization

Motivating Example

j

Array Expansion

i

j

t = 9

(i, j) = (5, 5)

for i = 1 to n for j = 1 to n A[j] = f(A[j], A[j-2])

t = 25

(i, j) = (5, 5)

init A[0][j] for i = 1 to n for j = 1 to n A[i][j] = f(A[i-1][j], A[i][j-2])

Page 24: A Unified Framework for Schedule and Storage Optimization

• Increasing storage can enable parallelism– But storage can be expensive

• Phase ordering problem– Optimizing for storage restricts parallelism– Maximizing parallelism restricts storage options– Too complex to consider all combinations

Need efficient framework to integrate schedule and storage optimization

Parallelism/Storage Tradeoff

CacheRAMDisk

Page 25: A Unified Framework for Schedule and Storage Optimization

Outline

• Abstract problem• Simplifications• Concrete problem• Solution Method• Conclusions

Page 26: A Unified Framework for Schedule and Storage Optimization

• Given DAG of dependent operations

– Must execute producers before consumers– Must store a value until all consumers

execute

Abstract Problem

• Two parameters control execution:1. A scheduling function

• Maps each operation to execution time• Parallelism is implicit

2. A fully associative store of size m

Page 27: A Unified Framework for Schedule and Storage Optimization

• We can ask three questions:

Abstract Problem

• Two parameters control execution:1. A scheduling function

• Maps each operation to execution time• Parallelism is implicit

2. A fully associative store of size m

Page 28: A Unified Framework for Schedule and Storage Optimization

• We can ask three questions: 1. Given , what is the smallest m?

Abstract Problem

• Two parameters control execution:1. A scheduling function

• Maps each operation to execution time• Parallelism is implicit

2. A fully associative store of size m

Page 29: A Unified Framework for Schedule and Storage Optimization

• We can ask three questions: 1. Given , what is the smallest m? 2. Given m, what is the “best” ?

Abstract Problem

• Two parameters control execution:1. A scheduling function

• Maps each operation to execution time• Parallelism is implicit

2. A fully associative store of size m

Page 30: A Unified Framework for Schedule and Storage Optimization

• We can ask three questions: 1. Given , what is the smallest m? 2. Given m, what is the “best” ? 3. What is the smallest m that is valid for all

legal ?

Abstract Problem

• Two parameters control execution:1. A scheduling function

• Maps each operation to execution time• Parallelism is implicit

2. A fully associative store of size m

Page 31: A Unified Framework for Schedule and Storage Optimization

Outline

• Abstract problem• Simplifications• Concrete problem• Solution Method• Conclusions

Page 32: A Unified Framework for Schedule and Storage Optimization

Simplifying the Schedule

• Real programs aren’t DAG’s– Dependence graph is parameterized by loops– Too many nodes to schedule

• Size could even be unknown (symbolic constants)

• Use classical solution: affine schedules– Each statement has a scheduling function – Each is an affine function of the enclosing

loop counters and symbolic constants– To simplify talk, ignore symbolic constants:

(i) = B • i

Page 33: A Unified Framework for Schedule and Storage Optimization

Simplifying the Storage Mapping

• Programs use arrays, not associative maps– If size decreases, need to specify which

elements are mapped to the same location

Page 34: A Unified Framework for Schedule and Storage Optimization

Simplifying the Storage Mapping

• Programs use arrays, not associative maps– If size decreases, need to specify which

elements are mapped to the same location

Page 35: A Unified Framework for Schedule and Storage Optimization

Simplifying the Storage Mapping

• Programs use arrays, not associative maps– If size decreases, need to specify which

elements are mapped to the same location

?

Page 36: A Unified Framework for Schedule and Storage Optimization

Simplifying the Storage Mapping

• Specifies unit of overwriting within an array

• Locations collapsed if separated by a multiple of v

j

i

v = (1, 1)

Occupancy Vectors (Strout et al.)

Page 37: A Unified Framework for Schedule and Storage Optimization

Simplifying the Storage Mapping

• Specifies unit of overwriting within an array

• Locations collapsed if separated by a multiple of v

j

i

v = (1, 1)

Occupancy Vectors (Strout et al.)

Page 38: A Unified Framework for Schedule and Storage Optimization

Simplifying the Storage Mapping

• Specifies unit of overwriting within an array

• Locations collapsed if separated by a multiple of v

j

i

v = (1, 1)

Occupancy Vectors (Strout et al.)

Page 39: A Unified Framework for Schedule and Storage Optimization

Simplifying the Store

• Specifies unit of overwriting within an array

• Locations collapsed if separated by a multiple of v

j

i

v = (1, 1)

Occupancy Vectors (Strout et al.)

Page 40: A Unified Framework for Schedule and Storage Optimization

Simplifying the Store

• Specifies unit of overwriting within an array

• Locations collapsed if separated by a multiple of v

j

i

v = (1, 1)

Occupancy Vectors (Strout et al.)

Page 41: A Unified Framework for Schedule and Storage Optimization

Simplifying the Store

• Specifies unit of overwriting within an array

• Locations collapsed if separated by a multiple of v

j

i

v = (1, 1)

Occupancy Vectors (Strout et al.)

Page 42: A Unified Framework for Schedule and Storage Optimization

Simplifying the Store

• Specifies unit of overwriting within an array

• Locations collapsed if separated by a multiple of v

j

i

v = (1, 1)

Occupancy Vectors (Strout et al.)

Page 43: A Unified Framework for Schedule and Storage Optimization

Simplifying the Store

• Specifies unit of overwriting within an array

• Locations collapsed if separated by a multiple of v

j

i

v = (1, 1)

Occupancy Vectors (Strout et al.)

Page 44: A Unified Framework for Schedule and Storage Optimization

Simplifying the Store

• Specifies unit of overwriting within an array

• Locations collapsed if separated by a multiple of v

j

i

v = (1, 1)

Occupancy Vectors (Strout et al.)

Page 45: A Unified Framework for Schedule and Storage Optimization

Simplifying the Store

• Specifies unit of overwriting within an array

• Locations collapsed if separated by a multiple of v

j

i

v = (1, 1)

2 :Original

n2 :dTransforme

n

Occupancy Vectors (Strout et al.)

Page 46: A Unified Framework for Schedule and Storage Optimization

Simplifying the Store

• For a given schedule, v is valid if semantics are unchanged using transformed array

• Shorter vectors require less storage

j

i

v = (1, 1)

2 :Original

n2 :dTransforme

n

Occupancy Vectors (Strout et al.)

Page 47: A Unified Framework for Schedule and Storage Optimization

Outline

• Abstract problem• Simplifications• Concrete problem• Solution Method• Conclusions

Page 48: A Unified Framework for Schedule and Storage Optimization

Answering Question #1

• Given (i, j) = i + j, what is the shortest valid occupancy vector v?

i

j

Page 49: A Unified Framework for Schedule and Storage Optimization

Answering Question #1

• Given (i, j) = i + j, what is the shortest valid occupancy vector v?

i

j

Page 50: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 51: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 52: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 53: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 54: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 55: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 56: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 57: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 58: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 59: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 60: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 61: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 62: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Solution: v = (1, 1)

i

j

Page 63: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Why not v = (0, 1)?

i

j

Page 64: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Why not v = (0, 1)?

i

j

Page 65: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Why not v = (0, 1)?

i

j

Page 66: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Why not v = (0, 1)?

i

j

Page 67: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Why not v = (0, 1)?

i

j

Page 68: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Why not v = (0, 1)?

i

j

Page 69: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Why not v = (0, 1)?

i

j

Page 70: A Unified Framework for Schedule and Storage Optimization

Answering Question #1• Given (i, j) = i + j, what is the shortest valid

occupancy vector v? Why not v = (0, 1)?

i

j

???

Page 71: A Unified Framework for Schedule and Storage Optimization

Answering Question #2

• Given v = (0, 1), what is the range of valid schedules ?

i

j

Page 72: A Unified Framework for Schedule and Storage Optimization

Answering Question #2

• Given v = (0, 1), what is the range of valid

schedules ? (i, j) is between:

(i, j) = 2 i + j (inclusive)(i, j) = i (exclusive)

i

j

Page 73: A Unified Framework for Schedule and Storage Optimization

j

i

Answering Question #2

• Given v = (0, 1), what is the range of valid schedules ? (i, j) is between:

(i, j) = 2 i + j (inclusive)(i, j) = i (exclusive)

Page 74: A Unified Framework for Schedule and Storage Optimization

j

i

Answering Question #2

• Given v = (0, 1), what is the range of valid schedules ? (i, j) is between:

(i, j) = 2 i + j (inclusive)(i, j) = i (exclusive)

Page 75: A Unified Framework for Schedule and Storage Optimization

j

i

Answering Question #2

• Given v = (0, 1), what is the range of valid schedules ? (i, j) is between:

(i, j) = 2 i + j (inclusive)(i, j) = i (exclusive)

Page 76: A Unified Framework for Schedule and Storage Optimization

j

i

Answering Question #2

• Given v = (0, 1), what is the range of valid schedules ? (i, j) is between:

(i, j) = 2 i + j (inclusive)(i, j) = i (exclusive)

Page 77: A Unified Framework for Schedule and Storage Optimization

j

i

Answering Question #2

• Given v = (0, 1), what is the range of valid schedules ? (i, j) is between:

(i, j) = 2 i + j (inclusive)(i, j) = i (exclusive)

Page 78: A Unified Framework for Schedule and Storage Optimization

j

i

Answering Question #2

• Given v = (0, 1), what is the range of valid schedules ? (i, j) is between:

(i, j) = 2 i + j (inclusive)(i, j) = i (exclusive)

Page 79: A Unified Framework for Schedule and Storage Optimization

j

i

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

Page 80: A Unified Framework for Schedule and Storage Optimization

j

i

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

Page 81: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 82: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 83: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 84: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 85: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 86: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 87: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 88: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 89: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 90: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 91: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 92: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 93: A Unified Framework for Schedule and Storage Optimization

Answering Question #2• Given v = (0, 1), what is the range of valid

schedules ? Lets try (i, j) = 2 i + j

j

i

Page 94: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules?

i

j

Page 95: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal

i

j

Page 96: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal

i

j

Page 97: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal

i

j

Page 98: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal

i

j

Page 99: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal

i

j

Page 100: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal

i

j

Page 101: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal

i

j

Page 102: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal

i

j

Page 103: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal

i

j

Page 104: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal v = (2, 1)

i

j

Page 105: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal v = (2, 1)

i

j

Page 106: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal v = (2, 1)

i

j

Page 107: A Unified Framework for Schedule and Storage Optimization

Answering Question #3

• What is the shortest v that is valid for all legal affine schedules? Range of legal v = (2, 1)

• Def: v is an affine occupancy vector (AOV)

i

j

Page 108: A Unified Framework for Schedule and Storage Optimization

Outline

• Abstract problem• Simplifications• Concrete problem• Solution Method• Conclusions

Page 109: A Unified Framework for Schedule and Storage Optimization

i

Schedule Constraints

• Dependence analysis yields:– iteration i depends on iteration h(i)– h is an affine function

• Consumer must executeafter producer

i1

h(i)

Schedule Constraint

(i) (h(i)) + 1

i2

Page 110: A Unified Framework for Schedule and Storage Optimization

Storage Constraints

i

i1

i2

h(i)

Page 111: A Unified Framework for Schedule and Storage Optimization

Storage Constraints

i

i1

i2

h(i)

vv

dynamic single assignmentfor i = 1 to n for j = 1 to n A[i][j] = … B[i][j] = …

Page 112: A Unified Framework for Schedule and Storage Optimization

Storage Constraints

i

i1

i2

h(i)

v

Consumer: i

Producer: h(i)h(i).+.v Consumer: i

Producer: h(i)

Overwriting producer: h(i) + v

Consumer must execute before producer is overwritten Storage Constraint

(i) (h(i) + v)

Page 113: A Unified Framework for Schedule and Storage Optimization

The Constraints

• A given (, v) combination is valid if– For all dependences h,– For all iterations i in the program:

(i) (h(i)) + 1 schedule constraint(i) (h(i) + v) storage constraint

• Given , want to find v satisfying

constraints– Might look simple, but it is not– Too many i’s and n’s to enumerate!– Need to reduce the number of constraints

Page 114: A Unified Framework for Schedule and Storage Optimization

The Constraints

• A given (, v) combination is valid if– For all dependences h,– For all iterations i in the program:

(i) (h(i)) + 1 schedule constraint(i) (h(i) + v) storage constraint

• Given , want to find v satisfying

constraints– Might look simple, but it is not– Too many i’s to enumerate!– Need to reduce the number of constraints

Page 115: A Unified Framework for Schedule and Storage Optimization

The Vertex Method (1-D)

• An affine function is non-negative within an interval [x1, x2] iff it is non-negative at x1 and x2

x1 x2

Page 116: A Unified Framework for Schedule and Storage Optimization

The Vertex Method (1-D)

• An affine function is non-negative over an unbounded interval [x1, ) iff it is non-negative at x1 and is non-decreasing along the interval

x1

Page 117: A Unified Framework for Schedule and Storage Optimization

The Vertex Method

• The same result holds in higher dimensions– An affine function is nonnegative over a

bounded polyhedron D iff it is nonnegative at vertices of D

Page 118: A Unified Framework for Schedule and Storage Optimization

Applying the Method (Quinton87)• Recall the storage constraints

– For all iterations i in the program:(i) (h(i) + v)

– Re-arrange:0 (h(i) + v) - (i)

• The right hand side is:1. An affine function of i2. Nonnegative over the domain D of iterations We can apply the vertex method

Page 119: A Unified Framework for Schedule and Storage Optimization

Applying the Method

• Replace i with the vertices w of its domain:

i1

i2

w1 w2

w3 w4

(h(i) + v) - (i)

iteration space

iD, (h(i) + v) - (i) 0

(h(w1) + v) - (w1) 0(h(w2) + v) - (w2) 0(h(w3) + v) - (w3) 0(h(w4) + v) - (w4) 0

Page 120: A Unified Framework for Schedule and Storage Optimization

The Reduced Constraints

• Apply same method to schedule constraints• Now a given (, v) combination is valid if

– For all dependences h,– For all vertices w of the iteration domain:

(w) (h(w)) + 1 schedule constraint(w) (h(w) + v) storage constraint

• These are linear constraints and v are variables; h and w are constants – Given , constraints are linear in v (& vice-

versa)

Page 121: A Unified Framework for Schedule and Storage Optimization

(w(z)) (h(w(z))) + 1 schedule constraint

(h(w(z)) + v) (w(z)) storage constraint

(w) (h(w)) + 1 schedule constraint

(w) (h(w) + v) storage constraint

Answering the Questions

1. Given , we can “minimize” |v|- Linear programming problem

2. Given v, we can find a “good” - Feautrier, 1992

3. To find an AOV... still too many constraints!- For all satisfying the schedule

constraints:v must satisfy the storage constraints

Page 122: A Unified Framework for Schedule and Storage Optimization

(w(z)) (h(w(z))) + 1 schedule constraint

(h(w(z)) + v) (w(z)) storage constraint

(w) (h(w)) + 1 schedule constraint

(w) (h(w) + v) storage constraint

Finding an AOV

• Apply the vertex method again!• Schedule constraints define domain of valid

• Storage constraints can be written as a non-

negative affine function of components of :– Expand (i) = B • i

B • w B • (h(w) + v)– Simplify

(h(w) + v – w) • B 0

Page 123: A Unified Framework for Schedule and Storage Optimization

Finding an AOV

• Our constraints are now as follows:– For all dependences h,– For all vertices w of the iteration domain,– For all vertices t of the space of valid

schedules:

t • w t • (h(w) + v) AOV constraint

• Can find “shortest” AOV with linear program – Finite number of constraints– h, w, and t are known constants

Page 124: A Unified Framework for Schedule and Storage Optimization

The Big PictureInput program

Affine Dependences

dependence analysis

Schedule & Storage ConstraintsConstraintswithout i

vertex method

Constraintswithout

vertex method

Given , find vGiven v, find Find an AOV, valid for all

linearprogram

linearprogram

Page 125: A Unified Framework for Schedule and Storage Optimization

Details in Paper

• Symbolic constants• Inter-statement dependences across

loops• Farkas’ Lemma for improved efficiency

Page 126: A Unified Framework for Schedule and Storage Optimization

Related Work

• Universal Occupancy Vector (Strout et al.)– Valid for all schedules, not just affine ones– Stencil of dependences in single loop nest

• Storage for ALPHA programs (Quilleré, Rajopadhye, Wilde)– Polyhedral model, with occupancy vector

analog– Assume schedule is given

• PAF compiler (Cohen, Lefebvre, Feautrier)– Minimal expansion scheduling contraction– Storage mapping A[i mod x][j mod y]

Page 127: A Unified Framework for Schedule and Storage Optimization

Future Work

• Allow affine left hand side references– A[2j][n-i] = …

• Consider multi-dimensional time schedules

• Collapse multiple dimensions of storage

Page 128: A Unified Framework for Schedule and Storage Optimization

Conclusions

• Unified framework for determining:1. A good storage mapping for a given schedule2. A good schedule for a given storage mapping3. A good storage mapping for all valid

schedules

• Take away: representations and techniques- Occupancy vectors- Affine schedules- Vertex method