Fourer Motzkn Elmnaton Logstcs HW10 due Frday Aprl 27 th Today Usng Fourer-Motzkn elmnaton for code generaton Usng Fourer-Motzkn elmnaton for determnng schedule constrants Unversty Fourer-Motzkn Elmnaton 1 Why Transformaton Frameworks? Currently Frameworks used n compler to abstract loops, memory accesses, and data dependences n loop specfy the effect of a sequence of loop transformatons on the loop, ts memory accesses, and ts data dependences generate code from the transformed loop Loop transformatons affect the schedule of the loop Future How can framework technology be exposed n the programmng model? Frameworks Unmodular Polyhedral Presburger Sparse Polyhedral Unversty Fourer-Motzkn Elmnaton 2
Algorthms needed for automaton Operatons on sets and relatons Unon teraton space sets Unon relatons that represent dependences Apply a relaton to a set to model transformng a loop and to check transformaton legalty Compose two relatons to model composng transformatons Schedulng Determne an effcent and legal schedule Determne whch loops should be parallel Storage Mappng If not usng UOV, then need to do ths n coordnaton wth the schedulng Code Generaton Gven a schedule and whch loops to parallelze and/or tle, generate effcent code Code generaton for parameterzed tles Unversty Fourer-Motzkn Elmnaton 3 Code Generaton Goals express outermost loop bounds n terms of symbolc constants and constants express nner loop bounds n terms of any enclosng loop varables, symbolc constants, and constants Approach Proect out nner loop teraton varables to determne loop bounds for outer loops Fourer Motzkn elmnaton s the algorthm that proects a varable out of a polyhedron CS553 Lecture 4
Fourer-Motzkn Elmnaton: The Idea Polyhedron convex ntersecton of a set of nequaltes model for teraton spaces <=5 1 >= Problem gven a polyhedron how do we generate loop bounds that scan all of ts ponts? example: two possble loop orders (, ) (, ) <= CS553 Lecture 5 Fourer-Motzkn Elmnaton: The Algorthm FM( P, _k ) => P Input: Output: Algorthm: for each lower bound of for each upper bound of CS553 Lecture 6
Dstngushng Upper and Lower Bounds Smple Algorthm gven that the polyhedron s represented as follows: any constrant wth a postve coeffcent for _k s a lower bound any constrant wth a negatve coeffcent for _k s an upper bound <=5 <= CS553 Lecture 7 1 >= Trangular Iteraton Space Example (, ) for target teraton space <=5 <= (, ) for target teraton space 1 >= CS553 Lecture 8
General Algorthm for Generatng Loop Bounds Input: where the vector s the desred loop order Output: Algorthm: for k = d to 1 by -1 CS553 Lecture 9 Loop Skewng and Permutaton Orgnal code do = 1,6 do = 1,5 A(,) = A(-1,+1)+1 Dstance vector: (1, -1) Skewng followed by Permutaton: CS553 Lecture 10
Transformng the Dependences and Array Accesses Orgnal code do = 1,6 do = 1,5 A(,) = A(-1,+1)+1 Dependence vector: New Array Accesses: CS553 Lecture 11 Transformng the Loop Bounds Orgnal code do = 1,6 do = 1,5 A(,) = A(-1,+1)+1 Bounds: Transformed code (use general loop bound alg) do = 2,11 do = max( -5,1), mn(6, -1) A(, - ) = A( -1, - +1)+1 CS553 Lecture 12
Fourer Motzkn for Schedulng Recall We need to proect out the lambdas Now we know how to do that automatcally CS553 Lecture 13 Usng the Farkas lemma Assume the followng dependence polyhedron Assume a schedule functon of the form We need Unversty Fourer-Motzkn Elmnaton 14
The process of determnng set of legal schedules (1) Change all of the equalty constrants n to nequalty constrants. (2) Use the Farkas lemma to create a set of constrants for the schedule. θ S () θ R () 1=λ 0 + λ T (A λ 0 0 and λ 0 θ R () =v T + b θ S () = w T + c (3) Solve for v, w, b, and c vector constrants by proectng out lambdas. p 1 ) Unversty Fourer-Motzkn Elmnaton 15 Example of usng the Farkas lemma Orgnal code do = 1,6 do = 1,5 A(,) = A(-1,+1)+1 (1) Dependence polyhedron (2) Farkas lemma to set up constrants (3) Proect out lambdas to determne set of legal schedules Unversty Fourer-Motzkn Elmnaton 16
Next Tme Lecture Code generaton for parameterzed tlng Schedule HW10 due Frday Aprl 27 th Unversty Fourer-Motzkn Elmnaton 17