arXiv is now an independent nonprofit! Learn more
License: arXiv.org perpetual non-exclusive license
arXiv:2609.05419v1 [cs.DC] 15 May 2026

The 2M Multiplication Algorithm for Complex Matrices

Peter Caday
NVIDIA Corporation
pcaday@nvidia.com
Abstract

Complex matrix multiplication is typically computed using 4 real matrix multiplications (GEMMs) of the same size. The well-known 3M multiplication algorithm reduces this cost to 3 real GEMMs, together with quadratic time pre- and post-processing steps.

In this paper, we reduce 3M to 2M for matrices with integer real and imaginary parts, performing complex GEMM with only 2 real GEMMs of the same size, along with quadratic time pre- and post-processing. For floating-point matrices, 2M multiplication combines naturally with the Ozaki-II scheme, yielding a practical, high-performance algorithm for computing a complex floating-point GEMM in roughly twice the time of a real GEMM of the same size. As corollaries, we derive new algorithms for symmetric rank-kk updates (SYRK/HERK) that internally use full rectangular GEMMs.

1 Introduction

The classical approach to multiply complex matrices A=Ar+i​Ai∈Cm×kA=A_{r}+iA_{i}\in\mathbb C^{m\times k} and B=Br+i​Bi∈Ck×nB=B_{r}+iB_{i}\in\mathbb C^{k\times n} is to expand the product into 4 real matrix multiplications:

C=A​B=(Ar​Br−Ai​Bi)+i​(Ar​Bi+Ai​Br).C=AB=(A_{r}B_{r}-A_{i}B_{i})+i(A_{r}B_{i}+A_{i}B_{r}).

Let us call this the 4M algorithm, following [BLISComplex], since it involves 4 real matrix multiplications. 4M multiplication typically forms the backbone of complex floating-point GEMMs in high-performance libraries.

The well-known 3M algorithm reduces this cost to 3 real matrix multiplications, by first computing Ar+AiA_{r}+A_{i} and Br+BiB_{r}+B_{i}:

C=(Ar​Br−Ai​Bi)+i​((Ar+Ai)​(Br+Bi)−Ar​Br−Ai​Bi).C=\big(A_{r}B_{r}-A_{i}B_{i}\big)+i\big((A_{r}+A_{i})(B_{r}+B_{i})-A_{r}B_{r}-A_{i}B_{i}\big). (1)

Note that while (1) is mathematically exact, in floating-point arithmetic the additions Ar+AiA_{r}+A_{i}, Br+BiB_{r}+B_{i} can reduce numerical stability [Higham3M]. Hence, numerical libraries typically offer 3M GEMMs as an opt-in feature.

For scalar complex products, it can be proven that 3 real multiplications is indeed minimal [Winograd2x2]. In this paper, we will show that we can do better for matrix products.

2 2M Complex Multiplication

To start, we consider input matrices A=Ar+i​AiA=A_{r}+iA_{i}, B=Br+i​BiB=B_{r}+iB_{i} with integral real and imaginary parts, and write A​B=C=Cr+i​CiAB=C=C_{r}+iC_{i}. Suppose mm is an integer chosen large enough that \lvert​Re⁡(ci​j)​\rvert,\lvert​Im⁡(ci​j)​\rvert≤m2\lvert\operatorname{Re}(c_{ij})\rvert,\lvert\operatorname{Im}(c_{ij})\rvert\leq\frac{m}{2} for each entry ci​jc_{ij} of CC. Then, if we know CmodmC\bmod m, we can evidently recover CC.

Now suppose that mm is odd and there is an integer ss such that s2=−1(modm)s^{2}=-1\pmod{m}, in effect a “real surrogate” for ii. It can be shown that such an ss exists iff mm is a product of primes congruent to 1 mod 4. We call such an mm a 2M modulus.

Perform the 3M-like preprocessing step

A±\displaystyle A_{\pm} =Ar±s​Ai(modm),\displaystyle=A_{r}\pm sA_{i}\pmod{m}, B±\displaystyle B_{\pm} =Br±s​Bi(modm).\displaystyle=B_{r}\pm sB_{i}\pmod{m}. (2a)
Next, perform the 2 real multiplications
C±\displaystyle C_{\pm} =A±​B±=(Ar​Br−Ai​Bi)±s​(Ar​Bi+Ai​Br)(modm).\displaystyle=A_{\pm}B_{\pm}=(A_{r}B_{r}-A_{i}B_{i})\pm s(A_{r}B_{i}+A_{i}B_{r})\pmod{m}. (2b)
Then it is not hard to see that
C=2−1​(C−+C+)+i​s⋅2−1​(C−−C+)(modm).\displaystyle C=2^{-1}\big(C_{-}+C_{+}\big)+is\cdot 2^{-1}\big(C_{-}-C_{+}\big)\pmod{m}. (2c)

Here 2−1=(m+1)/22^{-1}=(m+1)/2 is the inverse of 2 modulo mm, explaining why mm must be odd. Together, equations (2a–2c) form the 2M multiplication algorithm. As with 3M, the new algorithm requires (m​n+m​k+n​k)\Theta(mn+mk+nk) scalar operations in addition to the matrix multiplications.

2.1 Algebraic Underpinnings

To understand where 2M multiplication comes from, we borrow some basic ideas from algebraic number theory. Algebraically, AA, BB, CC are matrices over the ring of Gaussian integers Z​[i]={x+y​i|x,y∈Z}\mathbb Z[i]=\{x+yi\,|\,x,y\in\mathbb Z\}. Gaussian integers have a rich algebraic structure. In particular, they form a Euclidean domain, meaning that we have well-defined notion of division with remainder; modular arithmetic and the Chinese remainder theorem (CRT) also extend to Z​[i]\mathbb Z[i].

Suppose now that w=u+v​i∈Z​[i]w=u+vi\in\mathbb Z[i] with gcd⁡(u,v)=1\gcd(u,v)=1, and let m=\lvert​w​\rvert2=u2+v2m=\lvert w\rvert^{2}=u^{2}+v^{2}. Factoring m=w​w¯m=w\overline{w}, the CRT allows us to reconstruct CmodmC\bmod m from CmodwC\bmod w, Cmodw¯C\bmod{\overline{w}}. We can write

Cmodw\displaystyle C\bmod w =(Amodw)​(Bmodw),\displaystyle=(A\bmod w)(B\bmod w), Cmodw¯\displaystyle C\bmod{\overline{w}} =(Amodw¯)​(Bmodw¯).\displaystyle=(A\bmod{\overline{w}})(B\bmod{\overline{w}}).

The crucial step is to convert these complex multiplications to real equivalents. Algebraically speaking, the mapping i↦s=−u​v−1i\mapsto s=-uv^{-1} induces an isomorphism of quotient rings Z​[i]/w​Z​[i]​Z/m​Z\mathbb Z[i]/w\mathbb Z[i]\cong\mathbb Z/m\mathbb Z.111Indeed, we have a trivial homomorphism Z/m​Z↪Z​[i]/m​Z​[i]→Z​[i]/w​Z​[i]\mathbb Z/m\mathbb Z\hookrightarrow\mathbb Z[i]/m\mathbb Z[i]\to\mathbb Z[i]/w\mathbb Z[i], well-defined since w​mw\mid m, and an inverse map induced from i↦smodwi\mapsto s\bmod w by linearity, also well-defined since s2≡1modms^{2}\equiv 1\bmod m. In other words, working in Z​[i]\mathbb Z[i] modulo ww is equivalent to working in Z\mathbb Z modulo mm.

With this isomorphism, the real matrices A±A_{\pm} in (2a) are precisely the residues of AA modulo ww, w¯\overline{w}: A+=AmodwA_{+}=A\bmod w, A−=Amodw¯A_{-}=A\bmod{\overline{w}}, and similarly for B+B_{+}, B−B_{-}. Equation (2b) multiplies these residues modulo ww, w¯\overline{w}, and finally (2c) is the Chinese remainder theorem for recovering CmodmC\bmod m from C+=CmodwC_{+}=C\bmod w, C−=Cmodw¯C_{-}=C\bmod{\overline{w}}, under the same isomorphism.

3 2M Multiplication In Floating Point

3.1 The Ozaki-II Scheme

To apply 2M to non-integer GEMMs, we employ the Ozaki-II scheme [Ozaki2], a family of algorithms for computing floating-point matrix multiplication (GEMM) to arbitrary accuracy. Ozaki-II works by quantizing its inputs to integers, then performing fast integer matrix multiplication with modular arithmetic. By leveraging the dedicated narrow-precision matrix multipliation units available on modern GPUs, Ozaki-II can often significantly outperform standard floating-point GEMM while maintaining the same level of accuracy. Moreover, the level of accuracy may be tuned: either reduced, for additional performance; or increased, to provide additional accuracy beyond that available with a standard floating-point implementation.

We briefly restate the method here. Given real matrices 𝐀=(𝐚i​k)∈Rm×k\mathbf{A}=(\mathbf{a}_{ik})\in\mathbb R^{m\times k}, 𝐁=(𝐛k​j)∈Rk×n\mathbf{B}=(\mathbf{b}_{kj})\in\mathbb R^{k\times n}, we choose per-row and per-column scaling factors σ∈Rm\sigma\in\mathbb R^{m}, τ∈Rn\tau\in\mathbb R^{n} for 𝐀\mathbf{A} and 𝐁\mathbf{B}, respectively, and quantize to integer matrices

A=(roundZ(𝐚i​kσi−1)∈Zm×k,B=(roundZ(𝐛k​jτj−1))∈Zk×n.A=\big(\operatorname{round}Z(\mathbf{a}_{ik}\sigma_{i}^{-1}\big)\in\mathbb Z^{m\times k},\qquad B=\big(\operatorname{round}Z(\mathbf{b}_{kj}\tau_{j}^{-1})\big)\in\mathbb Z^{k\times n}.

Here, roundS⁡(⋅)\operatorname{round}_{S}(\cdot) represents rounding to a nearest element of a set SS. Next, we choose a collection of coprime moduli m1,…,mN∈Z+m_{1},\dotsc,m_{N}\in\mathbb Z_{+} whose product MM is large enough that each element of the integer product C=A​BC=AB has absolute value at most M/2M/2. Then C=(ci​j)C=(c_{ij}) can be uniquely recovered from its residue modulo MM, and we do so by computing the products

Cℓ=(Amodmℓ)​(Bmodmℓ),ℓ=1,…,N,C_{\ell}=\left(A\bmod m_{\ell}\right)\left(B\bmod m_{\ell}\right),\qquad\ell=1,\dotsc,N, (3)

and applying the Chinese remainder theorem (CRT) elementwise:

C=\slimits@ℓ=1N​Cℓ⋅(Mmℓmodmℓ)−1​Mmℓ.C=\sumop\slimits@_{\ell=1}^{N}C_{\ell}\cdot\left(\frac{M}{m_{\ell}}\bmod m_{\ell}\right)^{-1}\frac{M}{m_{\ell}}.

Then 𝐂=𝐀𝐁≈(ctildei​j​σi​τj)\mathbf{C}=\mathbf{A}\mathbf{B}\approx(\tilde{c}_{ij}\sigma_{i}\tau_{j}). The accuracy of the approximation is determined primarily by MM, with relative elementwise error (ci​j−ctildei​j​σi​τj)/ci​j(c_{ij}-\tilde{c}_{ij}\sigma_{i}\tau_{j})/c_{ij} roughly O​(M−1/2)O(M^{-1/2}). Achieving full accuracy also requires a proper choice of scaling factors σ\sigma, τ\tau; for more detail, see [O2Error, ESC].

Ozaki-II derives its speed from computing the products (3) using dedicated narrow-precision matrix multiplication hardware, which guides the choice of the moduli mim_{i} (e.g. mi≤28m_{i}\leq 2^{8} for 8-bit integer GEMMs).

3.2 Complex Ozaki-II With 2M

Ozaki-II extends readily to complex-valued inputs 𝐀=𝐀r+i​𝐀i∈Cm×k\mathbf{A}=\mathbf{A}_{r}+i\mathbf{A}_{i}\in\mathbb C^{m\times k}, 𝐁=𝐁r+i​𝐁i∈Ck×n\mathbf{B}=\mathbf{B}_{r}+i\mathbf{B}_{i}\in\mathbb C^{k\times n}. In Uchino et al.’s algorithm [Uchino], they first choose (real) scaling factors σ\sigma, τ\tau and quantize 𝐀r\mathbf{A}_{r}, 𝐀i\mathbf{A}_{i}, 𝐁r\mathbf{B}_{r}, 𝐁i\mathbf{B}_{i} to integer matrices as above. The resulting integer matrices are reduced modulo each mℓm_{\ell}, multiplied, and then the real and imaginary parts of CC are reconstructed separately using CRT. Scaling factors may be chosen using straightforward extensions of any of the existing real algorithms [Ozaki2, ESC].

For better performance, Uchino et al. apply 3M to each small integer multiplication, after modular reduction; since 3M is an algebraic identity, it is valid modulo any mℓm_{\ell}.222It is also possible to apply 3M prior to modular reduction, but this has the disadvantage of requiring high-precision integer arithmetic in 3M’s pre- and post-proessing steps. By substituting 2M multiplication for 3M, we immediately derive a 2M Ozaki-II algorithm for complex floating-point GEMMs (Algorithm 1).

Algorithm 1 2M Ozaki-II
1: Fix a set of coprime 2M moduli m1,…,mNm_{1},\dotsc,m_{N}; let M=\slimits@​miM=\prodop\slimits@m_{i}.
2: Choose scaling factors σ∈Rm\sigma\in\mathbb R^{m}, τ∈Rn\tau\in\mathbb R^{n}.
3: Quantize input matrices: A=(roundZ​[i]⁡(σi−1​𝐚i​k))A=\big(\operatorname{round}_{\mathbb Z[i]}(\sigma_{i}^{-1}\mathbf{a}_{ik})\big), B=(roundZ​[i]⁡(τj−1​𝐛k​j))B=\big(\operatorname{round}_{\mathbb Z[i]}(\tau_{j}^{-1}\mathbf{b}_{kj})\big).
4: For each i=1,…,Ni=1,\dotsc,N, reduce AA, BB modulo mim_{i} and multiply with (2a–2c).
5: Determine CmodMC\bmod M via CRT.
6: Lift CC to Z​[i]m×n\mathbb Z[i]^{m\times n} by choosing representatives with real and imaginary parts in [−M/2,M/2)[-M/2,M/2).
7: Reconstruct 𝐂≈(ci​j​σi​τj)∈Cm×n\mathbf{C}\approx(c_{ij}\sigma_{i}\tau_{j})\in\mathbb C^{m\times n}.

Note also that we can readily hybridize the 2M and 3M Ozaki-II methods, using 2M multiplication for moduli mℓm_{\ell} that satisfy the 2M conditions (odd, with a square root of −1-1), and 3M multiplication for the remaining moduli. For a practical implementation, such a hybrid approach allows reaching higher precision in cases where insufficient 2M moduli are available.

3.3 Other 2M Ozaki-II Variants

Algebraically, we may interpret Uchino et al.’s algorithm as the usual Ozaki-II scheme operating over the Gaussian integers, with real integer moduli mim_{i}. 2M Ozaki-II works similarly, but with conjugate pairs of complex integer moduli.

We note in passing that 2M multiplication and Algorithm 1 have analogues where we replace Z​[i]\mathbb Z[i] by another imaginary quadratic number ring. A natural choice is the Eisenstein integers Z​[e2​π​i/3]={a+b​e2​π​i/3|a,b∈Z}\mathbb Z[e^{2\pi i/3}]=\{a+be^{2\pi i/3}\,|\,a,b\in\mathbb Z\}, which form a hexagonal grid in the complex plane. By varying the number ring, we vary the set of valid 2M moduli. Asymptotically speaking, half of all primes are 2M moduli w.r.t. any given imaginary quadratic number ring by quadratic reciprocity and Dirichlet’s theorem. In practice, however, since moduli are generally bounded by the input range of hardware matrix multiplication units, specific rings may perform slightly better than others, as we will see in the next section.

4 ZGEMM with 8-bit Integer GEMMs

As a concrete example of Algorithm 1, let us consider complex double-precision GEMM (ZGEMM) with 8-bit integer GEMMs underneath. We enumerate a set of coprime 2M moduli in the range [1,256][1,256], chosen using a greedy algorithm:

ℳ2M={241,233,229,221,205,197,193,181,173,157,149,137,113,109,…,37,29}.\mathcal{M}_{\text{2M}}=\{241,233,229,221,205,197,193,181,173,157,149,137,113,109,\ldots,37,29\}.

Recall that the accuracy of an Ozaki-II method is determined primarily by MM, the product of the chosen moduli. The first N=16N=16 moduli of the above sequence, with product M≈2117M\approx 2^{117}, is sufficient in many cases to achieve accuracy comparable to a standard ZGEMM implementation in double-precision arithmetic.

Note that by comparison Ozaki-II real GEMMs, which are not restricted to 2M moduli, have access to a larger set of moduli

ℳreal={256,255,253,251,247,241,239,233,229,227,…}.\mathcal{M}_{\text{real}}=\{256,255,253,251,247,241,239,233,229,227,\ldots\}.

Because these moduli decrease less rapidly than 2M moduli, we require only 15 moduli to achieve the same level of accuracy M≈2117M\approx 2^{117}.

The relative sparsity of ℳ2​M\mathcal{M}_{2M} w.r.t. ℳreal\mathcal{M}_{\text{real}} reflects the fact that asymptotically only half of the prime numbers are valid 2M moduli, as observed in Section 3.3. Furthermore, the product of all moduli in ℳ2M\mathcal{M}_{\text{2M}} is M≈2152M\approx 2^{152}, much lower than for real Ozaki-II (M≈2342M\approx 2^{342}). If additional precision is required, e.g. due to a large exponent span in the input matrices [ESC], we may potentially exhaust available 2M moduli. In this case, additional non-2M moduli may be added to the set of moduli using the hybrid 2M/3M algorithm described in Section 3.2.

As mentioned previously, the set of 2M moduli may be varied by discretizing to different imaginary quadratic number rings. Indeed, for 8-bit integer moduli, the Eisenstein integers have a slight advantage over Gaussian integers: we can achieve M≈2154.5M\approx 2^{154.5} with 2M moduli. However, this advantage is offset by slightly more complicated quantization/dequantization steps; in particular, quantization involves rounding each point in the complex plane to the nearest point on a hexagonal lattice.

5 2M Rank-kk Updates333The author thanks Robert Parrish for pointing out this method of reducing SYRK to 2M GEMM.

The 2M method also yields computationally efficient methods for the real and complex BLAS-3 rank-kk and rank-2​k2k update routines (SYRK, HERK, SYR2K, HER2K). We recall these routines’ definitions, omitting alpha and beta scaling for simplicity:

  • •

    SYRK: C=A​ATC=AA^{T},  A∈Rn×kA\in\mathbb R^{n\times k}.

  • •

    HERK: C=A​AHC=AA^{H},  A∈Cn×kA\in\mathbb C^{n\times k}.

  • •

    SYR2K: C=A​BT+B​ATC=AB^{T}+BA^{T},  A,B∈Rn×kA,B\in\mathbb R^{n\times k}.

  • •

    HER2K: C=A​BH+B​AHC=AB^{H}+BA^{H},  A,B∈Cn×kA,B\in\mathbb C^{n\times k}.

In each case CC is (Hermitian) symmetric, so only the lower or upper triangle of CC is computed and stored. In theory, the symmetry of CC reduces the operation count in half (e.g. n2​k+o​(n2​k)n^{2}k+o(n^{2}k) flops for SYRK vs. 2​n2​k2n^{2}k for a same-sized GEMM), but library implementations generally cannot obtain the full 2×2\times speedup. The reason is that SYRK-like routines are typically implemented with a modified GEMM kernel that masks its output to the lower or upper triangle of the output matrix CC [GotoBLAS3]. Each kernel operates on a fixed-size tile of CC, leading to wasted computation near the diagonal, where tiles lie partly outside the desired triangle.

With 2M, it is possible to implement symmetric products using full, unmasked GEMMs, while still maintaining the expected 2x speedup. The key idea is that Hermitian symmetry in the problem induces a symmetry relation in the real integer products C±C_{\pm}, allowing us to compute only half as many integer GEMMs. We outline the methods below, which may be applied in either the integer domain (modulo mm) or in floating point, in conjuction with Ozaki-II.

HERK:

Writing A=Ar+i​AiA=A_{r}+iA_{i} and applying 2M, we have

C+\displaystyle C_{+} =(Ar+s​Ai)​(Ar−s​Ai)Tmodm,\displaystyle=(A_{r}+sA_{i})(A_{r}-sA_{i})^{T}\bmod m,
C−\displaystyle C_{-} =(Ar−s​Ai)​(Ar+s​Ai)Tmodm.\displaystyle=(A_{r}-sA_{i})(A_{r}+sA_{i})^{T}\bmod m.

In particular C−=C+TC_{-}=C_{+}^{T}, so we only need to compute a single real multiplication C+C_{+} for each mm, providing the expected 2x speedup while still computing full GEMMs.

HER2K:

Apply 2M to each multiplication. If we use the same scaling factors for AA and BB (i.e. σ=τ\sigma=\tau), we can bring the matrix addition into the residue domains:

C+\displaystyle C_{+} =(Ar+s​Ai)​(Br−s​Bi)T+(Br+s​Bi)​(Ar−s​Ai)Tmodm,\displaystyle=(A_{r}+sA_{i})(B_{r}-sB_{i})^{T}+(B_{r}+sB_{i})(A_{r}-sA_{i})^{T}\bmod m,
C−\displaystyle C_{-} =(Ar−s​Ai)​(Br+s​Bi)T+(Br−s​Bi)​(Ar+s​Ai)Tmodm.\displaystyle=(A_{r}-sA_{i})(B_{r}+sB_{i})^{T}+(B_{r}-sB_{i})(A_{r}+sA_{i})^{T}\bmod m.

Again C−=C+TC_{-}=C_{+}^{T}, reducing four real multiplications (per modulus) to two.

SYRK, SYR2K:

We convert (real) SYRK to an n×(k/2)n\times(k/2) HERK. Assuming for simplicity kk is even, split AA evenly in the k dimension: A=[A1A2]A=\left[\begin{array}[]{c|c}A_{1}&A_{2}\end{array}\right] and form Z=A1+i​A2Z=A_{1}+iA_{2}. Then

Z​ZH\displaystyle ZZ^{H} =(A1​A1T+A2​A2T)+i​(A2​A1T−A1​A2T)=A​AT+i​(A2​A1T−A1​A2T).\displaystyle=(A_{1}A_{1}^{T}+A_{2}A_{2}^{T})+i(A_{2}A_{1}^{T}-A_{1}A_{2}^{T})=AA^{T}+i(A_{2}A_{1}^{T}-A_{1}A_{2}^{T}).

Hence A​AT=Re⁡(Z​ZH)AA^{T}=\operatorname{Re}(ZZ^{H}), which we compute using 2M HERK. The same method converts SYR2K to a HER2K problem of half the kk dimension.

6 Computational Results

To demonstrate the efficacy of the 2M method, we present in Figure 1 performance and accuracy results for int8-emulated 2M ZGEMM on a single NVIDIA B200 GPU. All results are with α=1\alpha=1, β=0\beta=0, and use the Gaussian integer version of 2M.

Refer to caption
(a) Accuracy as a function of modulus count, NN, measured as the maximum relative error over all entries of the product matrix CC.
Refer to caption
(b) Performance at varying square sizes, with fixed precision (log2⁡M≈117\log_{2}M\approx 117). TFLOP/s values are calculated using the number of floating-point operations required by reference GEMM.
Figure 1: Performance and accuracy of 2M ZGEMM. All results measured on an NVIDIA B200 GPU. Reference implementation: cublasZgemm from cuBLAS 13.1, with emulation disabled.

Figure 1(a) confirms that 2M ZGEMM reaches the expected accuracy results for Ozaki-II. We measure accuracy as the maximum relative error over each entry of CC, on a test case with m=n=k=4096m=n=k=4096, while varying the number of moduli NN. Input matrices are chosen using Uchino et al.’s data distribution [Ozaki2] with ϕ=0.5\phi=0.5. Overall, convergence matches the overall trend of real Ozaki-II DGEMM. Note that the choice of complex multiplication method (2M, 3M, or 4M) does not affect accuracy as multiplications are always performed in exact integer arithmetic, and for this reason we do not undertake a detailed accuracy study here, instead referring the reader to [O2Error, ESC, Uchino, Ozaki2].

Figure 1(b) shows 2M ZGEMM performance across a range of square problem sizes, using N=16N=16 moduli. Performance is measured in effective teraflops per second, calculated using the floating point operation count from the baseline algorithm: 8​m​n​k8mnk operations for ZGEMM, 2​m​n​k2mnk for DGEMM. The modulus count NN is chosen to achieve accuracy similar to native-floating point ZGEMM; in fact, Ozaki-II 2M ZGEMM is approximately 10×\times more accurate than native floating-point ZGEMM for this input data (cf. Figure 1(a)).

With N=16N=16, 2M ZGEMM is up to 8×8\times faster than reference 4M fp64 ZGEMM (cuBLAS 13.1), and 1.4–1.5×\times faster than Uchino et al.’s 3M-based GEMMul8 library.555Tested version: https://github.com/RIKEN-RCCS/GEMMul8/commit/3115e709 2M also achieves an average 1.84×1.84\times speedup in effective TF/s compared to Ozaki-II DGEMM at the same accuracy. That is, in absolute time a single ZGEMM costs approximately 4/1.84≈2.164/1.84\approx 2.16 DGEMMs, close to theoretical expectations. The cost is not exactly 2 DGEMMs primarily because 2M requires slightly more moduli than the other Ozaki-II methods (16 vs. 15) to achieve a similar accuracy level. Again, this is due to the restricted set of moduli available for 2M.

Refer to caption
(a) Performance vs. precision, m=n=k=16384m=n=k=16384. Marked data points show modulus count NN. The dotted vertical line marks the approximate precision of reference floating-point GEMM.
Refer to caption
(b) Ozaki-II 2M ZGEMM speedups over reference ZGEMM.
Figure 2: Additional 2M ZGEMM performance data.

In Figure 2(a) we fix the problem size to m=n=k=16384m=n=k=16384 and vary NN to show the tradeoff between performance and accuracy. 2M shows similar speedups over GEMMul8’s 3M ZGEMM and Ozaki-II DGEMM across the range of NN, with performance up to 570 TF/s (15×\times reference ZGEMM) at N=8N=8. Figure 2(b) provides a more detailed heatmap of speedups over reference ZGEMM at a range of sizes and accuracy settings.

7 Conclusion

With each successive generation of CPU and GPU hardware, narrow-precision GEMM throughput continues to outpace traditional single and double precision arithmetic. The Ozaki-II scheme and other emulation methods take advantage of this trend, using integer quantization and small integer GEMMs to accelerate floating-point GEMMs.

In this paper, we have shown that this integer-quantized approach opens up new algorithms for complex GEMMs that leverage the algebraic structure of quadratic integer rings. In particular, 2M multiplication reduces a complex GEMM to two real GEMMs of the same size, instead of the three or four real GEMMs required by previous algorithms. For rank-kk updates, 2M reduces a complex rank-kk update (C=A​AHC=AA^{H}) to a real GEMM of the same, and a real rank-kk update (C=A​ATC=AA^{T}) to a real GEMM of half the size. The new 2M algorithm is easy to implement, and achieves practical speedups that closely match these theoretical predictions.

Acknowledgements

The author is grateful for helpful reviews from numerous colleagues, which greatly improved this paper.

References