Array Dependence Analysis COMP 621 Special Topics By Nurudeen Lameed

Slides:



Advertisements
Similar presentations
Optimizing Compilers for Modern Architectures Copyright, 1996 © Dale Carnegie & Associates, Inc. Dependence Testing Allen and Kennedy, Chapter 3 thru Section.
Advertisements

1 ECE734 VLSI Arrays for Digital Signal Processing Loop Transformation.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
A System to Generate Test Data and Symbolically Execute Programs Lori A. Clarke September 1976.
MATH 224 – Discrete Mathematics
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Parallelism & Locality Optimization.
Course Outline Traditional Static Program Analysis Software Testing
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 Overview 7.1 Introduction to Arrays 7.2 Arrays in Functions 7.3.
Chapter 4 Systems of Linear Equations; Matrices Section 2 Systems of Linear Equations and Augmented Matrics.
Dependence Analysis Kathy Yelick Bebop group meeting, 8/3/01.
Optimizing Compilers for Modern Architectures Preliminary Transformations Chapter 4 of Allen and Kennedy.
Preliminary Transformations Chapter 4 of Allen and Kennedy Harel Paz.
Parallel and Cluster Computing 1. 2 Optimising Compilers u The main specific optimization is loop vectorization u The compilers –Try to recognize such.
Stanford University CS243 Winter 2006 Wei Li 1 Loop Transformations and Locality.
CMPUT680 - Fall 2006 Topic A: Data Dependence in Loops José Nelson Amaral
Chapter 8 Introduction to Arrays Part II Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Complexity Analysis (Part I)
EECC551 - Shaaban #1 Spring 2004 lec# Static Compiler Optimization Techniques We already examined the following static compiler techniques aimed.
Stanford University CS243 Winter 2006 Wei Li 1 Data Dependences and Parallelization.
Complexity Analysis (Part I)
1 Lecture Today’s topic Arrays Reading for this Lecture: –Chaper 11.
A Data Locality Optimizing Algorithm based on A Data Locality Optimizing Algorithm by Michael E. Wolf and Monica S. Lam.
Data Dependences CS 524 – High-Performance Computing.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
Chapter 8 Arrays and Strings
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
Optimizing Compilers for Modern Architectures Dependence: Theory and Practice Allen and Kennedy, Chapter 2 pp
DATA LOCALITY & ITS OPTIMIZATION TECHNIQUES Presented by Preethi Rajaram CSS 548 Introduction to Compilers Professor Carol Zander Fall 2012.
CS0007: Introduction to Computer Programming Introduction to Arrays.
Optimizing Compilers for Modern Architectures Dependence: Theory and Practice Allen and Kennedy, Chapter 2.
5.3 Machine-Independent Compiler Features
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
1 Week 12 Arrays, vectors, matrices and cubes. Introduction to Scientific & Engineering Computing 2 Array subscript expressions n Each subscript in an.
Copyright © 2012 Pearson Education, Inc. Chapter 8 Two Dimensional Arrays.
Multi-Dimensional Arrays
 2006 Pearson Education, Inc. All rights reserved Arrays.
Chapter 8 Arrays and Strings
Toward Efficient Flow-Sensitive Induction Variable Analysis and Dependence Testing for Loop Optimization Yixin Shou, Robert A. van Engelen, Johnnie Birch,
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Carnegie Mellon Lecture 14 Loop Optimization and Array Analysis I. Motivation II. Data dependence analysis Chapter , 11.6 Dror E. MaydanCS243:
1 Partitioning Loops with Variable Dependence Distances Yijun Yu and Erik D’Hollander Department of Electronics and Information Systems University of Ghent,
Slide Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley A set of equations is called a system of equations. The solution.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
System To Generate Test Data: The Analysis Program Syed Nabeel.
H.Melikian/12101 System of Linear Equations and Augmented Matrices Dr.Hayk Melikyan Departmen of Mathematics and CS
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Questions 4) What type of algorithmic problem-solving technique (greedy, divide-and-conquer, dynamic programming)
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison- Wesley Systems of Equations in Three Variables Identifying Solutions Solving Systems.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 3. Time Complexity Calculations.
Dependence Analysis and Loops CS 3220 Spring 2016.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Lecture 9 Symbol Table and Attributed Grammars
Complexity Analysis (Part I)
Constructing Precedence Table
Computer Programming BCT 1113
CS314 – Section 5 Recitation 13
Today’s Material Arrays Definition Declaration Initialization
Data Structures and Algorithms
Data Dependence, Parallelization, and Locality Enhancement (courtesy of Tarek Abdelrahman, University of Toronto)
Preliminary Transformations
EKT150 : Computer Programming
Introduction To Programming Information Technology , 1’st Semester
Lecture 14: Problems with Lots of Similar Data
Complexity Analysis (Part I)
Presentation transcript:

Array Dependence Analysis COMP 621 Special Topics By Nurudeen Lameed

Outline Introduction Basic concepts – Affine functions – Iteration Space – Data Space – Affine Array-Index functions – Matrix formulation Array Data-Dependence Analysis Questions?

Introduction – Why? The traditional data flow model is inadequate for parallelization. For instance, it does not distinguish between different executions of the same statement in a loop. Array dependence analysis enables optimization for parallelism in programs involving arrays.

Affine functions A function of one or more variables, i 1, i 2, …, i n is affine, if it can be expressed as a sum of a constant, plus constant multiples of the variables. i.e. n f = c 0 + ∑ c i x i i = 1 Array subscript expressions are usually affine functions involving loop induction variables.

Affine functions(2) Sometimes, affine functions are called linear functions. Examples: – a[ i ]affine – a[ i+j -1 ] affine – a[ i*j ] non-linear, not affine – a[ 2*i+1, i*j ] linear, non-linear; not affine – a[ b[i] + 1 ] ? Non linear (indexed subscript), not affine

Iteration Space(1) Iteration space is the set of iterations, whose ID’s are given by the values held by the loop index variables. for (i = 2; i <= 100; i= i+3) Z[i] = 0; The iteration space for the loop is the set {2, 5, 8, 11, …, 98} – the set contains the value of the loop index i at each iteration of the loop.

Iteration Space(2) The iteration space can be normalized. For example, the loop in the previous slide can be written as for (i n = 0; i n <= 32; i n ++) Z[2 + 3* i n ] = 0; In general, i n = (i – lowerBound) / i step

Iteration Space(3) How about nested loops? for (i = 3; i <= 7; i++) for (j = 6; j >= 2; j = j – 2 ) Z[i, j] = Z[i, j+2] + 1 The iteration space is given by the set of vectors: {[3,6], [3,4], [3,2], [4,6], [4,4], [4,2], [5,6], [5,4], [5,2], [6,6], [6,4], [6,2], [7,6], [7,4], [7,2]} Q1: Rewrite the loop using normalized iteration vectors?

Iteration Space(4) Sol1:Normalized form for (i = 0; i <= 4; i++) for (j = 0; j <= 2; j++ ) Z[3 + i, 6 - j*2] = Z[3 + i, 6 - j*2+2] + 1

Dependence types We consider three kinds of dependence. – Flow dependence (true dependence) A variable assigned in one statement is used subsequently in another statement. – Anti-dependence A variable is used in one statement and reassigned in a subsequently executed statement. – Output dependence A variable is assigned in one statement and subsequently reassigned in another statement.

Dependence Graph Graph can be drawn to show data dependence between statements within a loop. S 1 :for (i = 2; i<= 5; ++i){ S 2 : X[i] = Y[i] + Z[i] S 3 : A[i] = X[i-1] + 1 } i=2i=3i=4i=5 S 2 : X[2] X[3] X[4] X[5] S 3 : X[1] X[2] X[3] X[4] 1 1 1

Iteration space dependence Graph for (i = 3; i <= 7; i++) for (j = 6; j >= 2; j = j – 2 ) Z[i, j] = Z[i, j+2] + 1 Iteration space dependence graph (normalized)

Data Space Array declaration specifies the data space. float Z[50]; declares an array whose elements are indexed by 0, 1, Note that iteration space is different from data space

Matrix formulation (Iteration space) We can represent iterations in a d-deep loop mathematically as { i in Z d | Bi + b ≥ 0} Where Z = set of integers; B is a d x d integer matrix; b is an integer vector of length d, and 0 is a vector of d 0’s for ( i = 0; i <= 5; i++)  i ≥ 0, i ≤ 5; for ( j = i; j <= 7; j++)  j ≥ i, j ≤ 7; Z[j, i] = 0;// express this in the form // c i.i + c j.j + c ≥ 0

Matrix formulation(2) i ≥ 0 1.i + 0.j + 0 ≥ 0 i ≤ 5 -1.i + 0.j + 5 ≥ 0 j ≥ i -1.i + 1.j + 0 ≥ 0 j ≤ 7 0.i - 1.j + 7 ≥ 0 Thus, i j + 0 ≥

Affine Array Access Affine functions provide a mapping from the iteration space to data space; they make it easier to identify iterations that map to the same data. An array access is affine if: – the bounds of the loop and the index of each dimension of the array are affine expressions of loop variables and symbolic constants. Affine access can also be represented as matrix-vector calculation.

Matrix formulation(Array Access) Like iteration space, array access can be represented as Fi + f; F and f represent the functions of the loop-index variables. Formally, an array access, A= ; where i = index variable vector; A maps i within the bounds Bi + b ≥ 0 to the array element location Fi + f

Matrix formulation (Array Access-2) AccessAffine Expression X[i, j] 1 0 i j 0 X[6 – j*2] i 0 2 j 6 X[1,5] 0 0 i j 5 X[0, i-5, 2*i + j] 0 0 i j

Array Dependence Analysis(1) Consider two static accesses A in a d-deep loop nest and A’ in a d’-deep loop nest respectively defined as A= and A’ = A and A’ are data dependent if – Bi ≥ 0 ; B’i’ ≥ 0 and – Fi + f = F’i’ + f’ – (and i ≠ i’ for dependencies between instances of the same static access)

Array Dependence Analysis(2) for (i = 1; i < 10; i++) { X[i] = X[i-1] } To find all the data dependences, we check if 1.X[i-1] and X[i] refer to the same location; 2.different instances of X[i] refer to the same location. For 1, we solve for i and i’ in 1 ≤ i ≤ 10, 1 ≤ i’ ≤ 10 and i – 1 = i’

Array Dependence Analysis(3) For 2, we solve for i and i’ in 1 ≤ i ≤ 10, 1 ≤ i’ ≤ 10, i = i’ and i ≠ i’ (between different dynamic accesses) There is a dependence since there exist integer solutions to 1. e.g. (i=2, i’=1), (i=3,i’=2). 9 solutions exist. There is no dependences among different instances of X[i] because 2 has no solutions!

Array Dependence Analysis(4) Array data dependence basically requires finding integer solutions to a system( often refers to as dependence system) consisting of equalities and inequalities. Equalities are derived from array accesses. Inequalities from the loop bounds. It is an integer linear programming problem. ILP is an NP-Complete problem. Several Heuristics have been developed.

Question 2 Q2: Rewrite this loop using normalized iteration space? for (i = 2; i <= 50; i= i+5) Z[i] = 0;

Solution Q2 The iteration space for the loop is the set { 2, 7, 12, …, 47} – the set contains the value of the loop index i at different iteration of the loop. The normalized version of the loop is for (i n = 0; i n <= 9; i n ++) Z[5*i n + 2] = 0;

Question 3 For the following loop for (i = 1; i <= 6; i= i++) X[i] = X[6-i]; indicate all the 1.Flow dependences (True dependences) 2.Anti-dependences 3.Output dependences

Solution Q3 Flow dependence: – { (X[1], 1  5), (X[2], 2  4) } Anti-dependence: – { (X[5], 1  5), (X[4], 2  4), (X[3], 3  3) } Output-dependence: – {} i=1i=2i=3i=4i=5i=6 X[1] = X[5]X[2] = X[4]X[3] = X[3]X[4] = X[2]X[5] = X[1]X[6] = X[0]

References Alfred V. Aho, Monica S. Lam, Ravi Sethi and Jeffrey D. Ullman, “Compilers: Principles, Techniques, and Tools”. (2nd Edition). Addison-Wesley, CA. Michael Wolfe, “Optimizing Super- compilers for Supercomputers”.MIT Press. Michael Wolfe, “High Performance Compilers for Parallel Computing“. Addison- Wesley, CA.