Automatic SIMD Vectorization of Chains of Recurrences

Automatic SIMD Vectorization of Chains of Recurrences

Automatic SIMD Vectorization of Chains of Recurrences ∗ Yixin Shou and Robert A. van Engelen Department of Computer Science and School of Computational Science Florida State University Tallahassee, FL 32306 fshou,[email protected] ABSTRACT 1. INTRODUCTION Many computational tasks require repeated evaluation of Many computational tasks in numerical, visualization, and functions over structured grids, such as plotting in a coordi- engineering applications require the repeated evaluation of nate system, rendering of parametric objects in 2D and 3D, functions over structured grids, such as plotting in a coordi- numerical grid generation, and signal processing. In this nate system, rendering of parametric objects in 2D and 3D, paper, we present a method and toolset to speed up closed- numerical grid generation, and signal processing. Thread- form function evaluations over grids by vectorizing Chains level parallelism is typically exploited to speed up the eval- of Recurrences (CR). CR forms of closed-form functions re- uation of closed-form functions across points in a grid. quire fewer operations to evaluate per grid point. However, Another effective optimization that yields good speedups the present CR formalism makes CR forms inherently non- when applicable to structured grids or meshes is short-vector vectorizable due to the dependences carried from one point SIMD execution of arithmetic operations, e.g. \array arith- to the next. To address this limitation, we developed a new metic". Virtually all modern general-purpose processor ar- decoupling method for the CR algebra to translate math chitectures feature instruction sets and instruction set exten- functions into Vector Chains of Recurrences (VCR) forms. sions that support short-vector SIMD floating point and in- The VCR coefficients are packed in short vector registers for teger operations, such as MMX/SSE, 3DNow!, AltiVec, and efficient execution. Performance results of benchmark func- Cell BE SPU SIMD instructions. Coding with these instruc- tions evaluated in single and double precision VCR forms are tion sets is simplified by the use of software, such as state-of- compared to the Intel compiler's auto-vectorized code and the-art compilers that automatically SIMD-vectorize com- the high-performance small vector math library (SVML). putationally intensive loops by restructuring these loops for The results show a significant performance increase of our SIMD vectorization [5] often in combination with highly- VCR method over SVML and scalar CRs, from doubling the optimized vector math library kernels [8]. execution speed to running an order of magnitude faster. An At the hardware level, advances in algorithms for float- auto-tuning tool for VCR is developed for optimal perfor- ing point arithmetic have led to significantly faster execu- mance and accuracy. tion of math library functions in hardware for both scalar and SIMD instructions, such as trigonometric, square root, logarithmic, and exponential functions. For example, the Categories and Subject Descriptors Intel numerics family (8087, 80287, and 80387) use the fast G.4 [Mathematical Software]: Parallel and vector imple- CORDIC (COordinate, Rotation DIgital Computer) meth- mentations|Optimization ods [15, 16]. However, repeated execution of numerics instructions for each grid point over a structured grid is still costly, especially General Terms in loops over the grid points where the execution latency of Algorithms, Performance the iterated floating point instructions cannot be hidden in the instruction pipeline. On an Intel Pentium 4 processor Keywords for example, the execution latency of a numerics instruction typically approaches 200 cycles [9]. Chains of recurrences, vectorization, short vector SIMD, ILP An effective technique to decrease operation counts and reduce instruction latencies of repeated function evaluations ∗ Supported in part by NSF grant CCF-0702435. over regular grids is provided by the Chains of Recurrences (CR) formalism [7, 10, 17], which uses an algebraic approach to translate closed-form functions and math kernels into re- currence forms that in a way implements aggressive loop Permission to make digital or hard copies of all or part of this work for strength reduction [3]. Any floating point expression com- personal or classroom use is granted without fee provided that copies are posed of math library functions and standard arithmetic not made or distributed for profit or commercial advantage and that copies can be transformed into a CR form and then optimized to bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific achieve efficient execution. For example, if two functions permission and/or a fee. f(x) and g(x) have CR forms, then f(x) ± g(x), f(x) ∗ g(x), ICS’08, June 7–12, 2008, Island of Kos, Aegean Sea, Greece. and f(g(i)) have CR forms (with some obvious exceptions). Copyright 2008 ACM 978-1-60558-158-3/08/06 ...$5.00. d CR forms of closed-form functions require fewer opera- Definition 1. A d-dimensional VCR form Φi of a func- tions per grid point by reusing the value computed at a tion f(i) evaluated over i = 0; : : : ; n−1 is denoted by previous point to determine the function value at the next d point. Unfortunately however, this aspect of the CR for- Φi = f~'0; 1; ~'1; 2; ··· ; k; ~'kgi ; malism prohibits loop parallelization and vectorization that where are \+" or \∗" and ~' are vector coefficients require independent operations across the iteration space. 0 1 0 1 0 1 In this paper, we present a vectorization method based on ~'0[0] ~'1[0] ~'k[0] an algebraic transformation to speed up closed-form func- B ~'0[1] C B ~'1[1] C B ~'k[1] C ~' = B C ; ~' = B C ; ··· ~' = B C : tion evaluations over structured grids using vector represen- 0 B . C 1 B . C k B . C @ . A @ . A @ . A tations of CR forms. To this end, we developed a decoupling ~' [d−1] ~' [d−1] ~' [d−1] method for the CR algebra to translate math functions into 0 1 k Vector Chains of Recurrences (VCR) forms. The VCR co- d Hence, a VCR Φi has (k+1) × d scalar values and k opera- efficients are packed into short vector registers for efficient tions ( = + or = ∗) on d-vectors. execution. This approach effectively reduces the instruction d counts for short-vector SIMD execution of functions over Definition 2. The evaluation of a VCR form Φi of a grids. As a result, our method outperforms separately op- function f(i) over i = 0; : : : ; n−1 is defined by the loop timized scalar CR forms and SIMD vectorized closed-form vector[d] ~v0 = ~'0 function evaluation. vector[d] ~v1 = ~'1 We validated the performance gains using several bench- ::: mark functions evaluated in single and double precision and vector[d] ~vk−1 = ~'k−1 compared the results to the Intel compiler's auto-vectorized for i = 0 to n − 1 step d do code with the high-performance small vector math library y[i : i+d−1] = ~v0 (SVML). The results show a dramatic performance increase ~v0 = ~v0 1 ~v1 of our VCR method over SIMD/SVML auto-vectorization ~v1 = ~v1 2 ~v2 and scalar CRs, ranging from doubling the execution speed ::::: to running an order of magnitude faster. In addition, the re- ~vk−1 = ~vk−1 k ~'k sults also show that the VCR code can significantly increase od the level of ILP in modulo scheduling [4] resulting in faster kernels for non-SIMD superscalar processors. Note that the loop computes y[i] = f(i) for i = 0; : : : ; n−1 CR optimizations introduce potential roundoff errors that in vectors of d values per iteration (assuming d divides n). are propagated across the iteration space [19]. Error analysis A method to construct the VCR form of a function is given is required to ensure roundoff errors introduced in CR-based in the next section. Here, we give a simple toy example to evaluation methods are bounded. To address error propa- illustrate VCR evaluation. For d = 2, the VCR form of gation, we combined our VCR method with an auto-tuning f(i) = i! is approach. The VCR code is run to determine error prop- Φ2 = f~' ; ∗; ~' ; +; ~' ; +; ~' g erties and select an optimal vector length for performance. i 0 1 2 3 i „ « „ « „ « „ « This approach ensures optimal performance with high float- 1 2 10 8 = f ; ∗; ; +; ; +; gi : ing point accuracy. 1 6 14 8 The remainder of this paper is organized as follows. Sec- Using Definition 2 we obtain the sequence: tion 2 introduces the VCR notation, semantics, and alge- i = 0 2 4 6 ::: braic construction. An auto-tuning approach for fast and „ y[i] « „1«„2«„ 24 «„ 720 « = ··· safe floating point evaluation is described and implemen- y[i+1] 1 6 120 5040 tation details are given. Performance results showing im- proved SIMD execution and ILP scheduling are presented in where pairs of values are computed in each iteration. In Section 3, followed by a discussion of alternative approaches general, for any d ≥ 2 a speedup is obtained with a vector- and related work in Section 4. Finally, Section 5 summarizes based VCR over scalar CR forms for functions evaluated our conclusions. over structured grids and meshes. 2.2 VCR Construction 2. VECTOR CHAINS OF RECURRENCES We present an algorithm to construct a VCR form of a This section introduces the VCR formalism, which is a function for any d ≥ 1. The case d = 1 degenerates the generalization of the scalar CR formalism [7, 10, 17]. The VCR to a scalar CR form published in [7, 10, 17]. notation and semantics are presented and an algorithm to symbolically construct VCR forms of math functions is given. Algorithm 1. Given a function f(i) represented as a closed-form expression in symbolic form, where f(i) is to 2.1 VCR Notation and Semantics be evaluated over n grid points i = 0; : : : ; n−1, the VCR d The key idea of our VCR method is to translate a math form Φi for d ≥ 1 is constructed in two steps: function or floating point expression into a set of d decoupled Step 1 Construct the symbolic parametric scalar CR form CR forms, where each CR represents the value progression 0 Φi0 (j) of f(d i + j) by substituting index i in f(i) by of the math function at an offset 0; : : : d−1 and stride d ≥ 1.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    11 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us