Algorithms for Weighted Counting over Parametric Polytopes - Lirias

3 downloads 0 Views 93KB Size Report
tion call in each iteration of a loop; and pointer conversion or array recovery [vE01,Fran03], where pointer .... Algorithmica, 48(1):37–66, June 2007. [Verd08] S.
Algorithms for Weighted Counting over Parametric Polytopes: A Survey and a Practical Comparison Sven Verdoolaege∗,1,2 , Maurice Bruynooghe∗,1 ∗

Katholieke Universiteit Leuven, Celestijnenlaan 200A, B-3001 Leuven, Belgium

ABSTRACT The polytope model is widely used in compiler analysis for representing a certain class of programs. Many counting problems that occur in the analysis of such programs can be solved by counting the number of integer points in a parametric polytope. In other counting problems, polynomial weights are assigned to the integer points of a parametric polytope and the objective is to find the sum of these weights over all integer points. This paper briefly surveys a number of algorithms for solving such problems. The paper also serves to document some of the algorithms implemented in the freely available barvinok library. KEYWORDS :

Barvinok’s decomposition; Laurent expansion; local Euler-Maclaurin formula; nested sums; piecewise quasi-polynomial; polytope model

1 Introduction Counting the number of integer points in a parametric polytope is the driving force behind many compiler optimization techniques. Counting examples include the number of memory locations touched by a loop, the number of operations performed by a loop or the amount of cache misses generated by a loop. Program transformations and optimizations exploiting these numbers include parallelization, memory size optimization and cache effectiveness optimization. For a more extensive overview, we refer to [Verd07]. 1 2

E-mail: {sven,maurice}@cs.kuleuven.be This author was supported by FWO-Vlaanderen.

p = a; for (i = 0; i < N; ++i) for (j = i; j < N; ++j) { p += j * ((j-i)/4); *p = 0; } Listing 1: Artificial pointer conversion example.

For some compiler techniques, we are not interested simply in the number of integer points satisfying some constraints, but in the sum of some (quasi)polynomial evaluated in each integer point satisfying the constraints. Examples include the amount of memory dynamically allocated by a piece of code [Brab03], where we need to sum the amount of memory allocated in each iteration of a loop; the estimation of the worst case execution time [Lisp03, vE06], where we need to sum the time required by an operation or a function call in each iteration of a loop; and pointer conversion or array recovery [vE01, Fran03], where pointer manipulations are transformed into array indexing. As an example of array recovery, consider the slightly contrived code in Listing 1 and suppose we want to replace accesses to array a through pointer p by explicit accesses to a. To obtain an explicit indexation in terms of the iterators, we need to accumulate the increments to pointer p over all previous iterations. That is, we need to sum the increment over all 0 ≤ i′ < N and i′ ≤ j ′ < N such that (i′ , j ′ ) 4 (i, j), where 4 denotes the lexicographical order. Note that “(j-i)/4” is an integer division, i.e., the increment is  ′  ′ ′ ′ ′ j −i c(i , j ) = j . 4 The accumulated increment is therefore d(i, j) =

X

c(i′ , j ′ ),

(i′ ,j ′ )∈S,(i′ ,j ′ )4(i,j)

with S = { (i′ , j ′ ) ∈ Z2 | 0 ≤ i′ < N ∧ i′ ≤ j ′ < N }.

2

Weighted Counting

We consider the computation of s(s) =

X

t∈P (s)∩Zn

q(s, t) =

X i

X

t∈Pi

qi (s, t),

(1)

(s)∩Zn

where q(s, t) is a piecewise quasi-polynomial function, i.e., a function that, within each of a finite set of polyhedra Pi that form a subdivision of P and for each residue class modulo a lattice in Pi , behaves as a polynomial. The period of q( s, t) is the index of this lattice. We may assume, w.l.o.g. that q(s, t) is a quasi-polynomial. A quasi-polynomial can be represented by a “step-polynomial”, i.e., a polynomial expression in greatest integer parts (floors), or by a table of polynomials. We will focus on the step-polynomial representation.

Since only one of the techniques discussed below has any (very limited) support for handling quasi-polynomials directly, we will need various reductions, depending on the applied counting algorithm. A quasi-polynomial can be written as polynomial by introducing a new variable for each distinct floor expressions. This reduction is best performed on each monomial individually, to reduce the number of variables introduced in each counting problem. For methods that only directly support unweighted counting, we need a further reduction. If t1 attains only non-negative values throughout the domain P (s), we can remove t1 from any given monomial by introducing as many new variables as the exponent of t1 in the monomial, expressing this power of t1 as the number of integer points in a cube. If negative values are possible, we have to split P (s) and apply transformations on the parts such that only non-negative values remain. We briefly describe six methods here. For more information, we refer to [Verd08]. • Nested sums [Sake96]: an incremental weighted method based on  m−1 k  X 1 X k+1 k t = Bn mk+1−n n k + 1 n=0 t=0

with Bn the Bernoulli numbers; requires splintering to obtain polynomials from quasipolynomials and is therefore exponential in the input size.

• Interpolation [Clau98]: based on the structure of the resulting formula; exponential in the input size. • Barvinok’s algorithm [Barv99]: an unweighted method based on a decomposition into P unimodular cones and a generating function representation fP (x) = t∈Zd [t ∈ P ] xt , whence #P = fP (1); polynomial in input size, exponential in dimension and degree (due to conversion). • Local Euler-Maclaurin formula [Berl06]: a weighted method based on Barvinok’s decomposition and the local Euler-Maclaurin formula Z X X p(s)(t) = DP (s),F (s) · p(s); t∈P (s)∩Λ

F (s)∈F (P (s))

F (s)

exponential in the dimension.

• Iterated Laurent Series [Bald08]: a weighted method based on Barvinok’s decomposition and the observation ! X X t X X tn yn X yn n y y = , t f (e ) = e = n! n! n≥0 t∈P ∩Zd t∈P ∩Zd t∈P ∩Zd n≥0 P i.e., t∈P ∩Zd tn is n! times the coefficient of yn in f (ey ); exponential in the dimension.

• Derivation [DL06]: a weighted method based on Barvinok’s decomposition and the observation n1 nd   X ∂ ∂ x1 fP (z) = · · · xd [t ∈ P ] tn xt ; ∂x1 ∂xd d t∈Z

exponential in the dimension, increasing the “dimension” by the degree.

All but the interpolation and derivation methods have been (partially) implemented in barvinok.

References [Bald08]

V. B ALDONI , N. B ERLINE , AND M. V ERGNE. Sum over lattice points of a polygon with iterated Laurent series. User’s guide. Available from URL http://www.math.polytechnique.fr/~berline/, March 2008.

[Barv99]

A. B ARVINOK AND J. P OMMERSHEIM. An algorithmic theory of lattice points in polyhedra. New Perspectives in Algebraic Combinatorics, 38:91–147, 1999.

[Berl06]

N. B ERLINE AND M. V ERGNE. Local Euler-Maclaurin formula for polytopes, July 2006. http://arXiv.org/abs/math/0507256.

[Brab03]

V. B RABERMAN , D. G ARBERVETSKY, AND S. Y OVINE. On synthesizing parametric specifications of dynamic memory utilization. Technical Report TR-2004-03, VERIMAG, October 2003.

[Clau98] P. C LAUSS AND V. L OECHNER. Parametric analysis of polyhedral iteration spaces. Journal of VLSI Signal Processing, 19(2):179–194, July 1998. [DL06]

J. D E L OERA , R. H EMMECKE , M. K ÖPPE , AND R. W EISMANTEL. Integer Polynomial Optimization in Fixed Dimension. Mathematics of Operations Research, 31(1):147–153, Februari 2006.

[Fran03]

B. F RANKE AND M. O’B OYLE. Array Recovery and High-Level Transformations for DSP Applications. ACM Transactions on Embedded Computing Systems, 2(2):132– 162, May 2003.

[Lisp03]

B. L ISPER. Fully Automatic, Parametric Worst-Case Execution Time Analysis. In J. Gustafsson, eds., Proceedings of the Third International Workshop on Worst-Case Execution Time (WCET) Analysis, pages 77–80, Porto, July 2003.

[Sake96]

R. S AKELLARIOU. On the Quest for Perfect Load Balance in Loop-Based Parallel Computations. PhD. Thesis, University of Manchester, October 1996.

[vE01]

R. VAN E NGELEN AND K. G ALLIVAN. An efficient algorithm for pointer-to-array access conversion for compiling and optimizing DSP applications. In Innovative Archs. for Future Gen. High-Perf. Processors and Systems, pages 80–89. IEEE, 2001.

[vE06]

R. VAN E NGELEN , K. G ALLIVAN , AND B. WALSH. Parametric Timing Estimation With the Newton-Gregory Formulae. Journal of Concurrency and Computation: Practice and Experience, 18(10):1434–1464, September 2006.

[Verd07] S. V ERDOOLAEGE , R. S EGHIR , K. B EYLS , V. L OECHNER , AND M. B RUYNOOGHE. Counting integer points in parametric polytopes using Barvinok’s rational functions. Algorithmica, 48(1):37–66, June 2007. [Verd08] S. V ERDOOLAEGE AND M. B RUYNOOGHE. Algorithms for Weighted Counting over Parametric Polytopes: A Survey and a Practical Comparison. In M. Beck and T. Stoll, eds., The 2008 International Conference on Information Theory and Statistical Learning, July 2008.