Multiword Arithmetic and Parallel Computing


Abstract

In many applications, the precision by the available hardware arithmetic is insufficient to guarantee accurate results. Multiword arithmetic is a special type of multiprecision arithmetic where a multiple double is an unevaluated sum of 64-bit doubles, or where a multiple integer is an unevaluated sum of 64-bit integers. Parallel computing is applied to compensate for the cost overhead of multiword arithmetic. This type of arithmetic exploits naturally the optimized hardware, allows for efficient type conversions, memory layouts, all favorable for parallel computing. For example, storing a multiword in registers rather than arrays is beneficial to parallel computing by tasking and acceleration by graphics processing units. Code for multiword arithmetic is available in the software PHCpack, written mainly in Ada, publicly available at github, and as an Alire crate, released under the GNU GPL v3.0 license.

1 Introduction↩︎

An algorithm is robust if it does not fail for small perturbations of degenerate inputs [1]. Software can be made more robust by the application of multiprecision arithmetic. The algorithms [2] to extend 32-bit floating-point arithmetic using originated in the late sixties [3] and available software packages are QDlib [4] and CAMPARY [5].

A multiple double is an unevaluated sum of nonoverlapping doubles. The multiple double arithmetic multiplies the accuracy of the results, from 16 decimal places to 32 and 64, respectively for double doubles and quad doubles. However, the cost overhead is significant, and parallel computing allows to compensate for this cost overhead. The overhead factors are summarized in Table ¿tbl:tabOverhead?.

The number of operations with doubles for a multipledouble addition (add), multiplication (mul),and division (div), required for \(m\)-double arithmetic,for \(m = 2, 4, 8, 16\).
add mul div avg
2 20 23 70 37.7
4 89 336 893 439.3
8 269 1742 5126 2379.0
16 925 11499 33041 15155.0

This paper describes some recent additions to PHCpack [6], extending contributions described in [7] and [8]. One application is the computation of power series [9]. As the errors in the leading coefficients propagate to the trailing coefficients, the leading coefficients must be computed at higher accuracy than what can be computed in 64-bit double precision.

The code described in this paper serves as a computational preparation for use of tensor cores on a graphic processing unit, in a stepping stone to implement the Ozaki scheme [10].

2 An Error Free Summation↩︎

Assuming all 64-bit doubles have the same exponent, we work with 52-bit integers (fractions of the doubles). The idea for an error free summation is introduced in Figure 1.

Figure 1: Split a vector of doubles, add the parts, fuse the result.

If the number of additions does not exceed some threshold, then we have sufficiently many zero bits left at the end of the numbers to represent the result exactly, without any error.

The idea in Figure 1 will be applied to computing inner products with double double arithmetic. Given are vectors \({\boldsymbol{x}}\) and \({\boldsymbol{y}}\) both of length \(n\), of double double numbers, we compute \(\displaystyle \sum_{k=1}^n x_k \star y_k\), where \(\star\) is the double double multiplication.

The double double \(x_k\) is represented by \((x^{hi}_k, x^{lo}_k)\), where the high double \(x^{hi}_k\) and the low double \(x^{lo}_k\) of \(x_k\) are splitted in quarters:

\[(\overbracket[1.2pt][6pt]{x_{k,0},x_{k,1},x_{k,2},x_{k,3}}^{x^{hi}_k}, \overbracket[1.2pt][6pt]{x_{k,4},x_{k,5},x_{k,6},x_{k,7}}^{x^{lo}_k}).\] After splitting also \(y_k\), we compute in double arithmetic: \[s_0 = \sum_{k=1}^n x_{k,0} y_{k,0}, ~ s_1 = \sum_{k=1}^n x_{k,1} y_{k,0} + x_{k,0} y_{k,1},\] and \[s_i = \sum_{k=1}^n \sum_{j=0}^i x_{k,j} y_{k,i-j},\] for \(i=2,\ldots,7\). Then, add \(s_0 + s_1 + \cdots + s_7\) in double double arithmetic.

To examine the computational efficiency, random 64-bit doubles are generated with a fraction of 52 bits in following pattern:

\[1 \underbrace{b b \cdots b}_{12 bits} 1 \underbrace{b b \cdots b}_{12 bits} 1 \underbrace{b b \cdots b}_{12 bits} 1 \underbrace{b b \cdots b}_{12 bits}, \quad b \in \{0, 1\}.\]

Splitting such double into four leads to doubles with fractions

\[\begin{array}{c} 1 b \cdots b ~ 0 0 \cdots 0 ~ 0 0 \cdots 0 ~ 0 0 \cdots 0, \\ 0 0 \cdots 0 ~ 1 b \cdots b ~ 0 0 \cdots 0 ~ 0 0 \cdots 0, \\ 0 0 \cdots 0 ~ 0 0 \cdots 0 ~ 1 b \cdots b ~ 0 0 \cdots 0, \\ 0 0 \cdots 0 ~ 0 0 \cdots 0 ~ 0 0 \cdots 0 ~ 1 b \cdots b. \end{array}\]

By virtue of the placement of the ones in the random fractions, all quarters have fixed exponents, e.g.: 0, \(-13\), \(-26\), \(-39\). All doubles in a multiple double are generated according this pattern.

3 Computational Results↩︎

The results on computing 1,024 times \(\displaystyle \sum_{k=1}^{6144} a_k \star b_k\) in increasing precision is shown in Table ¿tbl:tabResults?.

Rows for double (1d), double double (2d), quad double (4d),octo double (8d), and hexa double (16d), comparing the new vectorizedinner products to the ordinary ones.Times are in milliseconds (ms).The column next to the times are the cost overhead factors.
ordinary speedup vectorized
16d 40s 780ms 6.3x 4.3x  9s 491ms 6.2x
8d 6s 428ms 3.3x 4.2x 1s 520ms 4.8x
4d 1s 977ms 12.x 6.2x 318ms 4.6x
2d 158ms 13.x 2.3x 69ms 2.3x
1d 12ms 0.4x 30ms

Times in Table ¿tbl:tabResults? were obtained on an Intel Xeon 5318Y Ice Lake-SP, up to 3.40GHz, 256GB of internal memory at 3200MHz, GNU/Linux, Microway 2024, compiled with GNAT 12.2.0, flags -O3 -gnatp -gnatf.

It takes 9 seconds for 1,024 inner products in hexa double precision (16d). The wall clock time is 9s 308ms, with 85ms for generating the vectors.

In a high level multithread computation, every thread does one inner product. On two 24-core Intel Xeon 5318Y Ice Lake-SP, up to 3.40GHz, 256GB of internal memory at 3200MHz, GNU/Linux, Microway 2024, compiled with GNAT 12.2.0, flags -O3 -gnatp -gnatf, the wall clock time drops to 293 milliseconds, using 96 threads.

Comparing the 293 milliseconds to the 318 milliseconds with one thread in quad double precision, we can quadruple the precision and compute as fast as in quad double precision, using 96 threads, achieving quality up.

4 Conclusions↩︎

Postponing renormalizations of multiple doubles benefits the efficiency.

The convolutions \(\displaystyle \sum_{k=1}^n \sum_{j=0}^i x_{k,j} y_{k,i-j}\) allow to rewrite the inner products in multiple double arithmetic as matrix multiplications in double precision floating-point arithmetic, to prepare for better acceleration with graphics processing units, in particular tensor cores.

References↩︎

[1]
J. R. Shewchuk. Adaptive precision floating-point arithmetic and fast robust geometric predicates. Discrete Comput. Geom., 18(3):305–363, 1997.
[2]
J.-M. Muller, N. Brunie, F. de Dinechin, C.-P. Jeannerod, M. Joldes, V. Lefèvre, G. Melquiond, N. Revol, and S. Torres. Handbook of Floating-Point Arithmetic. Springer-Verlag, second edition, 2018.
[3]
T. J. Dekker. A floating-point technique for extending the available precision. Numerische Mathematik, 18(3):224–242, 1971.
[4]
Y. Hida, X. S. Li, and D. H. Bailey. Algorithms for quad-double precision floating point arithmetic. In 15th IEEE Symposium on Computer Arithmetic (Arith-15 2001), pages 155–162. IEEE Computer Society, 2001.
[5]
M. Joldes, J.-M. Muller, V. Popescu, and Tucker. W. : Cuda Multiple precision arithmetic library and applications. In Mathematical Software – ICMS 2016, the 5th International Conference on Mathematical Software, pages 232–240. Springer-Verlag, 2016.
[6]
J. Verschelde. Algorithm 795: PHCpack: A general-purpose solver for polynomial systems by homotopy continuation. ACM Trans. Math. Softw., 25(2):251–276, 1999.
[7]
J. Verschelde. Parallel software to offset the cost of higher precision. ACM SIGAda Ada Letters, 40(2):59–64, 2020.
[8]
J. Verschelde. Exporting Ada software to Python and Julia. ACM SIGAda Ada Letters, 42(1):76–78, 2022.
[9]
J. Verschelde. accelerated Newton for Taylor series solutions of polynomial homotopies in multiple double precision. In F. Boulier, C. Mou, T. M. Sadykov, and E. V. Vorozhtsov, editors, Proceedings of the 26th International Workshop on Computer Algebra in Scientific Computing (CASC 2024), volume 14938 of Lecture Notes in Computer Science, pages 328–348. Springer-Verlag, 2024.
[10]
K. Ozaki, T. Ogita, S. Oishi, and S. M. Rump. Error-free transformations of matrix multiplication by using fast routines of matrix multiplication and its applications. Numerical Algorithms, 59:95–118, 2012.

  1. Supported by a 2023 Simons Travel Award. University of Illinois at Chicago, Department of Mathematics, Statistics, and Computer Science, 851 S. Morgan St. (m/c 249), Chicago, IL 60607-7045, Email: janv@uic.edu, URL: http://www.math.uic.edu/\(\sim\)jan.↩︎