CS671 Parallel Programming in the Many-Core Era

Similar documents
Tiling: A Data Locality Optimizing Algorithm

Polyhedral Compilation Foundations

The Polyhedral Model (Transformations)

Math 414 Lecture 2 Everyone have a laptop?

Polyhedral Operations. Algorithms needed for automation. Logistics

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

Program transformations and optimizations in the polyhedral framework

Loop Transformations, Dependences, and Parallelization

The Challenges of Non-linear Parameters and Variables in Automatic Loop Parallelisation

maximize c, x subject to Ax b,

C&O 355 Lecture 16. N. Harvey

Iterative Optimization in the Polyhedral Model

The Polyhedral Compilation Framework

Modeling and Analysis of Hybrid Systems

Modeling and Analysis of Hybrid Systems

COMP331/557. Chapter 2: The Geometry of Linear Programming. (Bertsimas & Tsitsiklis, Chapter 2)

Linear programming and duality theory

The Polyhedral Model (Dependences and Transformations)

Applied Integer Programming

Convex Geometry arising in Optimization

Combinatorial Geometry & Topology arising in Game Theory and Optimization

Lecture 3. Corner Polyhedron, Intersection Cuts, Maximal Lattice-Free Convex Sets. Tepper School of Business Carnegie Mellon University, Pittsburgh

Chapter 4 Concepts from Geometry

Polyhedral Compilation Foundations

Integer Programming Theory

POLYHEDRAL GEOMETRY. Convex functions and sets. Mathematical Programming Niels Lauritzen Recall that a subset C R n is convex if

Computing the Integer Points of a Polyhedron

Lecture 4: Rational IPs, Polyhedron, Decomposition Theorem

Lecture 9 Basic Parallelization

Lecture 9 Basic Parallelization

Convex Hull Representation Conversion (cddlib, lrslib)

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

Linear Programming in Small Dimensions

In this chapter we introduce some of the basic concepts that will be useful for the study of integer programming problems.

Integer Programming Chapter 9

Legal and impossible dependences

Data Dependences and Parallelization

Louis-Noël Pouchet

CS675: Convex and Combinatorial Optimization Spring 2018 Convex Sets. Instructor: Shaddin Dughmi

FACES OF CONVEX SETS

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

Applications of Linear Programming

Theory of Integers. CS389L: Automated Logical Reasoning. Lecture 13: The Omega Test. Overview of Techniques. Geometric Description

Minimizing Memory Strides using Integer Transformations of Parametric Polytopes

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

MATH 890 HOMEWORK 2 DAVID MEREDITH

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

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

ORIE 6300 Mathematical Programming I September 2, Lecture 3

Array Dependence Analysis as Integer Constraints. Array Dependence Analysis Example. Array Dependence Analysis as Integer Constraints, cont

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

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

Convex Optimization Lecture 2

Lecture 12: Feasible direction methods

Basic Algorithms for Periodic-Linear Inequalities and Integer Polyhedra

The Chvátal-Gomory Closure of a Strictly Convex Body is a Rational Polyhedron

CS 293S Parallelism and Dependence Theory

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

Lesson 17. Geometry and Algebra of Corner Points

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

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

arxiv: v1 [math.co] 15 Dec 2009

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

UNIVERSITÉ DE PARIS-SUD 11 U.F.R. SCIENTIFIQUE D ORSAY

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

Alan LaMielle, Michelle Strout Colorado State University March 16, Technical Report CS

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

Systems of Inequalities

TOBIAS GROSSER Parkas Group, Computer Science Department, Ècole Normale Supèrieure / INRIA 45 Rue d Ulm, Paris, 75005, France

Conic Duality. yyye

An Overview to. Polyhedral Model. Fangzhou Jiao

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

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

Mathematical and Algorithmic Foundations Linear Programming and Matchings

Lecture 2 - Introduction to Polytopes

Cuts from Proofs: A Complete and Practical Technique for Solving Linear Inequalities over Integers

Lecture 2. Topology of Sets in R n. August 27, 2008

ACTUALLY DOING IT : an Introduction to Polyhedral Computation

Submodularity Reading Group. Matroid Polytopes, Polymatroid. M. Pawan Kumar

Polar Duality and Farkas Lemma

The Simplex Algorithm

CS522: Advanced Algorithms

Investigating Mixed-Integer Hulls using a MIP-Solver

CS675: Convex and Combinatorial Optimization Spring 2018 The Simplex Algorithm. Instructor: Shaddin Dughmi

Solving the Live-out Iterator Problem, Part I

Polyhedral-Based Data Reuse Optimization for Configurable Computing

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

Fourier-Motzkin and Farkas Questions (HW10)

UNIVERSITÉ DE PARIS-SUD 11 U.F.R. SCIENTIFIQUE D ORSAY

Using Facets of a MILP Model for solving a Job Shop Scheduling Problem

The Polyhedral Model Is More Widely Applicable Than You Think

Polyhedral Search Space Exploration in the ExaStencils Code Generator

Introducing the GCC to the Polyhedron Model

1 Linear Programming. 1.1 Optimizion problems and convex polytopes 1 LINEAR PROGRAMMING

AMS : Combinatorial Optimization Homework Problems - Week V

GRAPHITE: Polyhedral Analyses and Optimizations

Lecture 5: Properties of convex sets

11 Linear Programming

Introduction to Modern Control Systems

Artificial Intelligence

Transcription:

1 CS671 Parallel Programming in the Many-Core Era Polyhedral Framework for Compilation: Polyhedral Model Representation, Data Dependence Analysis, Scheduling and Data Locality Optimizations December 3, 2013

Table of Contents 2 Polyhedral Program Optimizations Code to Model: Polyhedral Model Polyhedral Model Overview Modeling Dependence Transformations in the Model Classical Affine Transformations Affine Scheduling - One Dimensional Time Affine Scheduling - Multi-Dimensional Time Model To Code The Problem Definition Polyhedral Code Generation Approaches References

Polyhedral Program Optimization: A three-stage process 1. Analysis: from code to model Existing prototype tools PoCC (Clan-Candl-LetSee-Pluto-Cloog-Polylib-PIPLib-ISL-FM) URUK, Omega, Loopo GCC GRAPHITE Reservoir Labs R-Stream, IBM XL/Poly 2. Transformation in the model Build and select a program transformation 3. Code generation: from model to code Apply the transformation in the model Regenerate syntactic (AST-based) code 3

Lecture 7 Table of Contents 4 Polyhedral Program Optimizations Code to Model: Polyhedral Model Polyhedral Model Overview Modeling Dependence Transformations in the Model Classical Affine Transformations Affine Scheduling - One Dimensional Time Affine Scheduling - Multi-Dimensional Time Model To Code The Problem Definition Polyhedral Code Generation Approaches References

Motivation 5 An Example of Loop for ( i = 0; i < 3; ++i ) for ( j = 0; j < 3; ++j ) A[i][j] = i j; Loop execution: A[0][0]=0*0 A[0][1]=0*1 A[0][2]=0*2 A[1][0]=1*0 A[1][1]=1*1 A[1][2]=1*2 A[2][0]=2*0 A[2][1]=2*1 A[2][2]=2*2

Capture Loop Characteristics 6 What will be needed? Need to indicate total number of iterations Need to distinguish every different iteration Need to imply an order on these different iterations Challenges Compact (memory space consumption) Parametric loop bound / unbounded loop Non-unit loop stride Conditionals

Overview of Polyhedral Model 7 Iteration domain: A set of n-dimensional vectors Iteration Vector: x = (i, j) Iteration domain: the set of values of x Polytopes model sets of totally ordered n-dimensional vectors The set must be convex Example: Code for ( i=0; i < 5; i++ ) for ( j=0; j < 5; j++ )... endfor endfor Iter. Domain Graph J I

Convexity 8 Definition: Convex Set Let R be a vector space over the real numbers. A set S in R is convex iff, µ, λ S and given any t [0,1], the point (1 t) µ + t λ S In words: Drawing a line segment between any two points of S, each point of this segment is also in S.

Convexity in Loop Iteration Domains 9 A statement surrounded by loops with unit-stride, no conditional and constant loop bounds has a convex iteration domain, if the iteration domain exists. In general, in loops for ( i=0; i < N; i++ )... The polytope set must be convex Convexity is the central concept of polyhedral optimization J J I I

Affine Function I 10 Definition A function f : K m K n is affine if there exists a vector b K n and matrix A K n m such that: x K m, f ( x) = A x + b Affine half-space definition An affine half-space of K m is defined as the set of points: { x K m a x b}

Affine Function II x 2 Example of an affine half-space: 11 3x 1 + 2x 2 11 3x 1 + 2x 2 11 (0, 0) x 1 3x 1 + 2x 2 = 11

Polyhedron I 12 Polyhedron definition A set S K n is a polyhedron if there exists a system of a finite number of inequalities A x b such that: P = { x K n A x b} Equivalently, it is the intersection of finitely many half-spaces.

Polyhedron II Example of a polyhedron generated by intersection of three half-spaces: 13 x 2 3x 1 + 4x 2 = 4 2x 1 x 2 = 5 (0, 0) x 1 3x 1 + 2x 2 = 11

Polyhedron III A polytope is a bounded polyhedron Integer Polyhedron (Z-polyhedron) It is a polyhedron where all its extreme points are integer valued 14 Integer Hull The integer hull of a rational polyhedron P is the largest set of integer points such that each of these points is in P.

Polyhedron Example 15 Example of a Polytope and an Integer Hull x 2 3x 1 + 4x 2 = 4 3x 1 + 2x 2 = 11 2x 1 x 2 = 5 (0, 0) x 1

Polyhedron Example 15 Example of a Polytope and an Integer Hull x 2 3x 1 + 4x 2 = 4 3x 1 + 2x 2 = 11 2x 1 x 2 = 5 (0, 0) x 1

Polyhedron Example 15 Example of a Polytope and an Integer Hull x 2 3x 1 + 4x 2 = 4 3x 1 + 2x 2 = 11 2x 1 x 2 = 5 (0, 0) x 1

Define Affine Loops A special class of loop: The lowerbound and upper bound of the loop are expressed as affine expressions of the surrounding loop variables and symbolic constants. 16 Given do i 1 = L 1, U 1... do i n S 1 :... S 2 :... = L n, U n where L m = f m (i 1, i 2,..., i m 1 ) and f m (...) are all affine functions of variables (i 1,..., i m 1 ).

Modeling Affine Loop Iteration Domains Corresponding loop constructs: unit stride, no conditionals Polytope dimension: number of surrounding loops Constraints: set by loop bounds Let s all formulate it in this way: A * x - b 0 Add symbolic constants if necessary 17 Previous Loop Example for ( i = 0; i 5; ++i ) for ( j = 0; j 5; ++j ) A[i][j] = i j; D R : 1 0 1 0 0 1 0 1 ( i j ) + 0 5 0 5 = 0 i 5 0 j 5 1 0 0 1 0 5 0 1 0 0 1 5. i j 1 0

Lexicographical Order of Affine Index Given I = (i 1, i 2,..., i n ) and I = (i 1, i 2,..., i n), I < I iff (i 1, i 2,..., i k ) = (i 1, i 2,..., i k ) & i k+1 < i k+1 An Example of Loop for ( i = 0; i < 3; ++i ) for ( j = 0; j < 3; ++j ) A[i][j] = i j; Loop execution: 18 (0,0) (0,1) (0,2) (1,0) (1,1) (1,2)...

Another Iteration Space Example for ( i = 0; i 4; ++i ) for ( j = i + 1; j 10 - i; ++j ) A[i][j] = i j; Inequalities set by loop bounds: i 0 i 4 i 4 j i + 1 j 10 i j 10 + i 19 D R : 1 0 1 0 1 1 1 1 ( i j ) + 0 4 1 10 = 1 0 0 1 0 4 1 1 1 1 1 10. i j 1 0

The loop iteration space in graph: 20 Inequalities set by loop bounds: i 0 i 4 j i + 1 j 10 i i j i = 1 i = 4 (0, 0) j j + i = 10

Scan the Loop Iteration Space 21 Loop code generation: Using the lexicographical order: Assume no dependence: what if we want to sweep the space using another order? i j i = 1 i = 4 (0, 0) j j + i = 10 Scan the iteration space from loop i first. What will be the loop bounds?

Fourier-Motzkin elimination: Input: A polyhedron S with variables x 1, x 2, x 3,..., x n. Output: A polyhedron S with variables x 1, x 2,..., x m 1, x m+1,..., x n Generally speaking, find a projection onto dimensions other than x m Take all pairs of inequalities with opposite sign coefficients of x m, and for each generate a new valid inequality that eliminates x m Also take all inequalities from the original set which do not depend on x m Fourier-Motzkin Theorem: The above collection of inequalities defines exactly the projection of S onto x m = 0. 22

Assignment (2) I More examples: Example I 23 for ( i = 10; i 1000; ++i ) for ( j = i; j i + 10; ++j ) A[i,j] = 0; Example II for ( i = 0; i 100; ++i ) for ( j = 0; j i+100; ++j ) for ( k = i+j; k 100 - i - j; k++ ) X[i, j, k] = 0;

Assignment (2) II Example III 24 for ( i = 0; i < N; ++i ) for ( j = 0; j < i; ++j ) if ( i > M ) A[j] = 0;

More complicated loops I Unbounded domains: use polyhedra! Parametric loop bounds: use parametric polyhedra! Non-unit loop bounds: normalize the loop! Conditionals: Those which preserve convexity Problem remain for those which do not preserve convexity 25

Examples 26 Example I for ( i = 0; i < N; i += 2 ) for ( j = 0; j < N; ++j ) A[i] = 0; Example II for ( i = 0; i < N; i += 2 ) for ( j = 0; j < N; ++j ) if ( i % 3 == 1 && j % 5 == 0 ) A[i] = 0;

Generalized Conditionals 27 Different categories: Conjunctions ( a && b ) Disjunctions ( a b ) Non-affine ( i * j < 2 ) Data-dependent ( a[i] == 0 )

Relation with Operations on Polyhedra 28 Conjunction: Definition: intersection The intersection of two convex sets P 1 and P 2 is a convex set P. P = { x K m x P 1 x P 2 } Disjunction: Definition: union The union of two convex sets P 1 and P 2 is a set P: P = { x K m x P 1 x P 2 } The union of two convex sets may not be a convex set.