The Polyhedral Model (Transformations)

Similar documents
Review. Loop Fusion Example

The Polyhedral Model (Dependences and Transformations)

Polyhedral Operations. Algorithms needed for automation. Logistics

Loop Transformations, Dependences, and Parallelization

CS671 Parallel Programming in the Many-Core Era

Tiling: A Data Locality Optimizing Algorithm

Loop Transformations! Part II!

Tiling: A Data Locality Optimizing Algorithm

Outline. L5: Writing Correct Programs, cont. Is this CUDA code correct? Administrative 2/11/09. Next assignment (a homework) given out on Monday

Autotuning. John Cavazos. University of Delaware UNIVERSITY OF DELAWARE COMPUTER & INFORMATION SCIENCES DEPARTMENT


Legal and impossible dependences

CS 293S Parallelism and Dependence Theory

Iterative Optimization in the Polyhedral Model: Part I, One-Dimensional Time

Tiling: A Data Locality Optimizing Algorithm

Linear Programming in Small Dimensions

A Crash Course in Compilers for Parallel Computing. Mary Hall Fall, L2: Transforms, Reuse, Locality

Compiling for Advanced Architectures

CS 372: Computational Geometry Lecture 10 Linear Programming in Fixed Dimension

Linear programming and duality theory

Integer Programming Theory

Data Dependence Analysis

An Overview to. Polyhedral Model. Fangzhou Jiao

maximize c, x subject to Ax b,

Advanced Operations Research Techniques IE316. Quiz 1 Review. Dr. Ted Ralphs

6.189 IAP Lecture 11. Parallelizing Compilers. Prof. Saman Amarasinghe, MIT IAP 2007 MIT

Transforming Imperfectly Nested Loops

Coarse-Grained Parallelism

Lecture 11 Loop Transformations for Parallelism and Locality

Polar Duality and Farkas Lemma

Louis-Noël Pouchet

Lecture 9 Basic Parallelization

Lecture 9 Basic Parallelization

Introduction to Modern Control Systems

R n a T i x = b i} is a Hyperplane.

16.410/413 Principles of Autonomy and Decision Making

Discrete Optimization 2010 Lecture 5 Min-Cost Flows & Total Unimodularity

Module 18: Loop Optimizations Lecture 35: Amdahl s Law. The Lecture Contains: Amdahl s Law. Induction Variable Substitution.

Essential constraints: Data Dependences. S1: a = b + c S2: d = a * 2 S3: a = c + 2 S4: e = d + c + 2

Polyhedral Compilation Foundations

15-451/651: Design & Analysis of Algorithms October 11, 2018 Lecture #13: Linear Programming I last changed: October 9, 2018

Dual-fitting analysis of Greedy for Set Cover

Module 18: Loop Optimizations Lecture 36: Cycle Shrinking. The Lecture Contains: Cycle Shrinking. Cycle Shrinking in Distance Varying Loops

Linear Programming Duality and Algorithms

MATH 890 HOMEWORK 2 DAVID MEREDITH

Math 414 Lecture 2 Everyone have a laptop?

4 LINEAR PROGRAMMING (LP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1

Loop Nest Optimizer of GCC. Sebastian Pop. Avgust, 2006

be a polytope. has such a representation iff it contains the origin in its interior. For a generic, sort the inequalities so that

Chapter 4 Concepts from Geometry

Compiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7

Elementary maths for GMT. Algorithm analysis Part II

Convex Optimization. Convex Sets. ENSAE: Optimisation 1/24

Lecture notes on the simplex method September We will present an algorithm to solve linear programs of the form. maximize.

Enhancing Parallelism

AMS : Combinatorial Optimization Homework Problems - Week V

Mathematical Programming and Research Methods (Part II)

CS599: Convex and Combinatorial Optimization Fall 2013 Lecture 14: Combinatorial Problems as Linear Programs I. Instructor: Shaddin Dughmi

IE 5531: Engineering Optimization I

On Demand Parametric Array Dataflow Analysis

Computing and Informatics, Vol. 36, 2017, , doi: /cai

CSE 373 APRIL 3 RD ALGORITHM ANALYSIS

Parallel Processing: October, 5, 2010

Ranking Functions. Linear-Constraint Loops

Programming, numerics and optimization

Integer Programming ISE 418. Lecture 7. Dr. Ted Ralphs

Introduction to optimization

CMPSCI611: The Simplex Algorithm Lecture 24

Introduction to Linear Programming

Outline. Why Parallelism Parallel Execution Parallelizing Compilers Dependence Analysis Increasing Parallelization Opportunities

LECTURE 6: INTERIOR POINT METHOD. 1. Motivation 2. Basic concepts 3. Primal affine scaling algorithm 4. Dual affine scaling algorithm

Efficient Polynomial-Time Nested Loop Fusion with Full Parallelism

10/11/2017. Constraint Satisfaction Problems II. Review: CSP Representations. Heuristic 1: Most constrained variable

The Simplex Algorithm

Lecture 2 - Introduction to Polytopes

Compiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7

15.082J and 6.855J. Lagrangian Relaxation 2 Algorithms Application to LPs

Graphs and Network Flows IE411. Lecture 20. Dr. Ted Ralphs

Polyèdres et compilation

DM545 Linear and Integer Programming. Lecture 2. The Simplex Method. Marco Chiarandini

CS599: Convex and Combinatorial Optimization Fall 2013 Lecture 4: Convex Sets. Instructor: Shaddin Dughmi

Outline. CS38 Introduction to Algorithms. Linear programming 5/21/2014. Linear programming. Lecture 15 May 20, 2014

Parallelization. Saman Amarasinghe. Computer Science and Artificial Intelligence Laboratory Massachusetts Institute of Technology

Polyhedral Computation Today s Topic: The Double Description Algorithm. Komei Fukuda Swiss Federal Institute of Technology Zurich October 29, 2010

Conic Duality. yyye

ECE 5730 Memory Systems

2. Convex sets. x 1. x 2. affine set: contains the line through any two distinct points in the set

Advanced Compiler Construction Theory And Practice

1. Lecture notes on bipartite matching February 4th,

Lecture 4: Linear Programming

Loops and Locality. with an introduc-on to the memory hierarchy. COMP 506 Rice University Spring target code. source code OpJmizer

AMATH 383 Lecture Notes Linear Programming

Convex Geometry arising in Optimization

Chapter 15 Introduction to Linear Programming

CS 188: Artificial Intelligence Fall 2008

Announcements. CS 188: Artificial Intelligence Fall Large Scale: Problems with A* What is Search For? Example: N-Queens

Linear Optimization. Andongwisye John. November 17, Linkoping University. Andongwisye John (Linkoping University) November 17, / 25

Control flow graphs and loop optimizations. Thursday, October 24, 13

Introduction to Optimization Problems and Methods

General Methods and Search Algorithms

Transcription:

The Polyhedral Model (Transformations) Announcements HW4 is due Wednesday February 22 th Project proposal is due NEXT Friday, extension so that example with tool is possible (see resources website for Today Polyhedral definitions Direction/distance vectors and dependence relations Polyhedral model (two notations and ways of viewing shared schedule) Multi-dimensional schedule and statement order Mapping with constant elements for statement order (K&P) Legality for both Fusion and fission using K&P Polyhedral model (Transformations) 1 Polyhedron (source: http://www.cse.ohio-state.edu/~pouchet/lectures/888.11.lect1.html) Affine functions A function is affine if there exists a vector and a matrix such that Affine half spaces An affine half-space of (affine constraint) is defined as a set of points Polyhedron A set is a polyhedron if there exists a system of finite inequalities such that Equivalently it is the intersection of finitely many half-spaces. Intersection between polyhedral sets When you intersect two convex polyhedral sets the results is a convex polyhedral set. P = {x K m x P 1 x P 2 } Polyhedral model (Transformations) 2

Convexity for Reals Reals Given S a subset of R n. S is convex iff, µ, λ S and given c [0, 1] (1 c)µ + cλ S IOW, drawing a line segment between any two points of S, each point on this segment is also in S. Integers (Z polyhedron) Lattice: A subset L in is a lattice if it is generated by an integral combination of finitely many vectors: If the vectors have integral coordinates, L is an integer lattice. A Z-polyhedron is the intersection of a polyhedron and an affine itegral full dimensional lattice. (source: http://www.cse.ohio-state.edu/~pouchet/lectures/888.11.lect1.html) Polyhedral model (Transformations) 3 Convexity for Integers Lattice Lattice: A subset L in is a lattice if it is generated by an integral combination of finitely many vectors: If the vectors have integral coordinates, L is an integer lattice. a i Z-polyhedron A Z-polyhedron is the intersection of a polyhedron and an affine integral full dimensional lattice. Iteration domains are in fact Z-polyhedra with a unit lattice Q = {[i, j] 0 i, j 10} L = {[i, j] i, j Z} Z = Q L K n a 1, a 2,..., a n (a i K n ) Intersection of Z-polyhedra is not convex in general (source: http://www.cse.ohio-state.edu/~pouchet/lectures/888.11.lect1.html) Polyhedral model (Transformations) 4

Checking whether a set is empty Many questions we need to automate check whether a polyhedral set or sets are empty or not. Is there a dependence at a certain loop level? Is a transformation legal? Determining whether a set is feasible If constraints conflict then the set is empty, or infeasible. For real polyhedrons there are polynomial time algorithms. For Z-polyhedron there are worst-case exponential time algorithms, but these algorithms are reasonable for most problems related to loop transformations. Polyhedral model (Transformations) 5 Dependence Testing in General General code do i 1 = l 1,h 1!!...!! do i n = l n,h n!... A(f(i 1,...,i n ))!... A(g(i 1,...,i n ))!!!!...!! There exists a dependence between iterations I=(i 1,..., i n ) and J=(j 1,..., j n ) when at least one of the accesses is a write and f(i) = g(j) (l 1,...l n ) < I,J < (h 1,...,h n ) I << J or J << I, where << is lexicographically less Polyhedral model (Transformations) 6

Direction/Dependence Vectors do i = 1,5 do j = 1,6 A(i+1,j-1) = A(i-2,j+1)+exp(j,j) Set up the dependence problem Subtract the source from the target iteration Polyhedral model (Transformations) 7 Dependence Relations do i = 1,5 do j = 1,6 A(i+1,j-1) = = A(i-2,j+1)+exp(j,j) Possible notations Feautrier Kelly and Pugh Polyhedral model (Transformations) 8

Recall Automatic Parallelization Input program has a set of operations E with a strict order Find a partial order on E that is deterministic and results in the same output as the original strict total order. Overall process Translate the code to a model Select a transformation/schedule Determination of partial order on E, data dependence analysis Specify a transformation/schedule Ensure that the loop transformation/schedule is legal Transform the model and generate the transformed code Polyhedral model (Transformations) 9 Specifying Loop Transformations Unimodular Polyhedral/Affine Transformations (also called a schedule or Change of Basis) Kelly and Pugh (Presburger in general case) Polyhedral model (Transformations) 10

Loop Fusion Idea Combine multiple loop nests into one Example A(i) = A(i-1) do j = 1,n B(j) = A(j)/2 A(i) = A(i-1) B(i) = A(i)/2 Pros May improve data locality Reduces loop overhead Cons May hurt data locality May hurt icache performance Enables array contraction (opposite of scalar expansion) May enable better instruction scheduling Polyhedral model (Transformations) 11 Legality of Loop Fusion Basic Conditions Both loops must have same structure Same loop depth Same loop bounds Same iteration directions Can we relax any of these restrictions? Dependences must be preserved e.g., Flow dependences must not become anti dependences body1 body2 All cross-loop dependences flow from body1 to body2 body1 body2 Ensure that fusion does not introduce dependences from body2 to body1 Polyhedral model (Transformations) 12

Loop Fusion Example What are the dependences? s 2 C(i) = A(i)/2 s 2! f s 3 What are the dependences? s 2 C(i) = A(i)/2 s 3! a s 2 Fusion changes the dependence between s 2 and s 3, so fusion is illegal Is there some transformation that will enable fusion of these loops? Polyhedral model (Transformations) 13 Loop Fusion Example (cont) Loop reversal is legal for the original loops Does not change the direction of any dep in the original code Will reverse the direction in the fused loop: s 3! a s 2 will become s 2! f s 3 do i = n,1 do i = n,1 s 2 C(i) = A(i)/2 s 2! f s 3 do i = n,1 do i = n,1,-1 s 2 C(i) = A(i)/2 s 2! f s 3 After reversal and fusion all original dependences are preserved Polyhedral model (Transformations) 14

Kelly and Pugh Transformation Framework Specify iteration space as a set of integer tuples Specify data dependences as relations between integer tuples (i.e., data dependence relations) {[i 1,j 1 ] [i 2,j 2 ] (i 1 = i 2 1) (j 1 = j 2 1) (1 i 1,j 1,i 2,j 2 n) i 1 <i 2 } {[i 1,j 1 ] [i 2,j 2 ] (i 1 = i 2 1) (j 1 = j 2 1) (1 i 1,j 1,i 2,j 2 n) i 1 = i 2 j 1 <j 2 } Specify transformations as relations/mappings between integer tuples Execute iterations in transformed iteration space in lexicographic order Polyhedral model (Transformations) 15 Specifying Loop Fusion in Kelly and Pugh Framework Specify iteration space as a set of integer tuples Specify data dependences as mappings between integer tuples (i.e., data dependence relations) Specify transformations as mappings between integer tuples Polyhedral model (Transformations) 16

Checking Legality in Kelly & Pugh Framework For each dependence, [I] -> [J]the transformed I iteration must be executed after the transformed J iteration. Polyhedral model (Transformations) 17 Loop Fusion Example (cont) Loop reversal is legal for the original loops Does not change the direction of any dep in the original code Will reverse the direction in the fused loop: s 3! a s 2 will become s 2! f s 3 do i = n,1,-1 do i = n,1,-1 s 2 C(i) = A(i)/2 do i = n,1,-1 s 2! f s 3 do i = n,1,-1 s 2 s 3 C(i) = A(i)/2 s 2! f s 3 D(i) = 1/C(i+1) After reversal and fusion all original dependences are preserved Polyhedral model (Transformations) 18

Fusion Example Can we fuse these loop nests? Fusion of these loops would violate this dependence X(i) = 0! f do j = 1,n do k = 1,n X(k) = X(k)+A(k,j)*Y(j) X(i) = 0 do k = 1,n X(k) = X(k)+A(k,i)*Y(i) Polyhedral model (Transformations) 19 Fusion Example (cont) Use loop interchange to preserve dependences X(i) = 0! f X(i) = 0! do k = 1,n f do j = 1,n do j = 1,n X(i) = X(i)+A(i,j)*Y(j) X(k) = X(k)+A(k,j)*Y(j) Polyhedral model (Transformations) 20

Loop Fission (Loop Distribution) Idea Split a loop nest into multiple loop nests (the inverse of fusion) Example A(i) = B(i) + 1 C(i) = A(i)/2 Motivation? Produces multiple (potentially) less constrained loops May improve locality Enable other transformations, such as interchange A(i) = B(i) + 1 C(i) = A(i)/2 Legality? Polyhedral model (Transformations) 21 Loop Fission (cont) Legality Fission is legal when the loop body contains no cycles in the dependence graph body1 body2 body1 body2 Cycles cannot be preserved because after fission all cross-loop dependences flow from body1 to body2 Polyhedral model (Transformations) 22

Loop Fission Example Recall our fusion example s 2 C(i) = A(i)/2 s 2! f s 3 Can we perform fission on this loop? s 2 C(i) = A(i)/2 s 3! a s 2 Polyhedral model (Transformations) 23 Loop Fission Example (cont) If there are no cycles, we can reorder the loops with a topological sort s 3! a s 2 s 2 C(i) = A(i)2 Can we perform fission on this loop? s 2 C(i) = A(i)/2 s 3! a s 2 Polyhedral model (Transformations) 24

Two different ways to deal with imperfect loop nesting Add dimensionality to the schedule for statement order Approach taken by Kelly and Pugh Embed all statements in same iteration space Use initial statement order as the tie breaker Difference Has an effect on the scheduling algorithms Has an effect on the code generation algorithms Polyhedral model (Transformations) 25 Next Time Reading No reading assignment this week, should be reading about possible benchmarks and automation tools Homework HW4 is due Wednesday 2/22/12 Project proposal pushed to next Friday, 2/24/12 Lecture Tools for specifying and transforming polyhedra: Omega Polyhedral model (Transformations) 26