Acceleration of Tensor-Product Operations with Tensor Cores
Paper · 2024 · Cu Cui
Summary
A finite element solver can spend much of its time applying the same differential operator to new vectors. For high-order elements, storing the operator as a matrix can be expensive because each unknown interacts with many others. A matrix-free solver evaluates those interactions when needed, using small calculations that repeat across the mesh. Cu Cui asks whether those calculations can run efficiently on the specialized matrix hardware of an NVIDIA A100. The paper studies Poisson’s equation in three dimensions and uses the structure of the finite element basis to turn parts of each operator application into small matrix multiplications. This is a question about both arithmetic and data movement in GPU and parallel computing.
The paper compares two ways to program Tensor Cores. NVIDIA’s Warp Matrix Multiply and Accumulate interface handles much of the work of loading a matrix tile and distributing its entries across GPU threads. Its layout requirements, however, leave one coordinate direction of Cui’s implementation on conventional CUDA Cores. Inline instructions in NVIDIA’s Parallel Thread Execution language let the kernel use Tensor Cores in every direction. They also let it rearrange data in shared memory so that simultaneous requests go to distinct memory banks. With that rearrangement, the best double-precision kernel reaches a reported 8 TFLOPS/s, about 45% of the Tensor Core peak cited in the conclusion, and delivers a 2.3-fold speedup over a tuned CUDA Core implementation.
The paper also tests how much numerical accuracy is needed at different points in an iterative solve. Half-precision inputs make the matrix multiplications faster, but a direct conversion from single to half precision produces larger errors in the operator output. An error correction scheme retains an approximation to the discarded part of each input and uses it in supplementary products. This recovers the accuracy observed with single precision in the operator test. For the Poisson solve, the outer flexible GMRES iteration stays in double precision, while a multigrid preconditioner uses lower precision. The corrected half-precision version cuts solution time by approximately a factor of four and retains the discretization accuracy observed in the double-precision comparison.
The findings connect performance at different scales. At the kernel level, the gains depend on getting data to the arithmetic units in the right layout, and some problem sizes pay for padding or heavy use of on-chip memory. At the solver level, a fast preconditioner helps only if it still gives useful corrections. The operator comparisons, hardware profiles and convergence tests show how the implementation meets both conditions for the cases studied.
Deep dive: Acceleration of Tensor-Product Operations with Tensor Cores
Cu Cui shows how Tensor Cores speed up matrix-free finite element operations and how mixed precision reduces the time needed to solve Poisson’s equation. · about 39 minutes to read
The problem and its context
The cost of applying a high-order operator
Poisson’s equation relates a function to the sum of its second spatial derivatives. Given a source throughout a domain and values along its boundary, the task is to find the function inside. The paper uses a finite element method, which divides the domain into cells and represents the unknown function on each cell by polynomials. Raising the polynomial degree gives each cell more freedom to represent a varying solution. It also gives the solver more coefficients to work with and increases the number of interactions among them.
A degree of freedom is an independent quantity in the discrete representation. In the formulation studied here, local degrees of freedom are the coefficients of a polynomial basis associated with interpolation points. Applying the discrete Laplacian takes a vector of those coefficients and returns a vector of responses. An iterative solver performs that operation repeatedly, using the responses to decide how to improve its current approximation. A faster operator can therefore matter throughout the solve, provided that the rest of the solver makes effective use of it.
An assembled implementation puts the discrete couplings in a matrix ahead of time. A matrix application then reads those couplings and the input values they multiply. The paper explains that this becomes unattractive at higher polynomial degrees, where many local degrees of freedom are coupled. In a matrix-free implementation, the solver keeps the operations that define the couplings and evaluates them on demand. For instance, it can compute the gradient of a polynomial at integration points and use those values to form the response. The discrete operator still has a matrix representation, which is convenient for deriving its action, even though the kernel can evaluate that action without assembling the matrix.
The paper places this choice in the history of GPU-based finite element computation. It traces early work on elliptic problems in two-dimensional domains and then describes studies of higher-order discretizations and more complicated equations, including Navier–Stokes. Among the earlier studies it cites is Nodal discontinuous Galerkin methods on graphics processors. It also points to work on high-order discretizations for large parallel systems and uses the incompressible flow simulator NekRS as an example of what tuned GPU implementations made possible. GPU Algorithms for Efficient Exascale Discretizations.
Matrix-free evaluation already had a performance advantage that Cui could build on. When a basis function is a product of functions of separate coordinates, an operation on the full cell can often be decomposed into successive operations along individual coordinates. These smaller operations can reuse the same one-dimensional matrices for many lines of values through the cell. The paper cites implementations that had already tuned this strategy for CUDA Cores and studies in which local operators approached performance bounds. The contribution therefore starts from an established decomposition and asks what must change to execute it efficiently on different hardware.
Why matrix hardware needs a different implementation
A Tensor Core performs a matrix multiply-and-accumulate operation on a tile. Multiple threads cooperate on the tile, supplying the pieces of the input matrices and holding the pieces of the output. The hardware has prescribed tile shapes and expects particular values in particular thread registers. For a finite element kernel, the arithmetic fits naturally once a directional contraction has been written as a matrix product. The required distribution of entries across threads can be harder to arrange.
The paper describes Tensor Cores as hardware that originated with NVIDIA’s Volta architecture and was developed for deep learning. Earlier work examined their precision and programming behavior and applied them to a range of other numerical tasks. Matrix libraries such as cuBLAS and CUTLASS provided ready-made ways to use them for general matrix multiplication. Cui’s workload calls for a different degree of control because a cell calculation contains a sequence of small products, and the result of one product becomes the input to the next in a different coordinate direction. An earlier study cited in this context is NVIDIA Tensor Core Programmability, Performance & Precision.
The layout problem follows directly from the shape of the data. A cell’s coefficients have several coordinate indices, but memory is addressed along a line. Entries next to each other in one coordinate can be consecutive in memory. Entries next to each other in another coordinate can be separated by a stride. By changing the indexing, the kernel can present either set as a matrix of coordinate lines. Whether it can load that matrix directly into the arithmetic unit depends on the programming interface and on how its requests distribute across shared memory.
Poisson’s equation gives the study a way to connect this implementation problem with the behavior of an actual solver. The paper describes an earlier Poisson study on lower-precision accelerator hardware that used an assembled approach. Cui instead works with a matrix-free discontinuous Galerkin operator, investigates its kernels separately, and then uses the accelerated calculations in multigrid preconditioning. This separates the question of how quickly the GPU can evaluate an operator from the question of how much time the iterative method takes to find a solution.
The method, step by step
From the differential equation to cell and face contributions
The calculation starts with a boundary-value problem. The interior equation specifies the relation between the unknown and the forcing term. The boundary condition, called a Dirichlet condition, supplies values of the unknown along the edge of the domain.
−Δu = f in Ω, u = g on ∂Ω
Here u is the function to find, Δ is the Laplacian, and f is the prescribed forcing. Ω is the spatial domain, ∂Ω is its boundary, and g is the prescribed boundary value. The minus sign fixes the sign convention for the operator. In the paper, the domain lies in three-dimensional space.
The mesh consists of hexahedral cells. Every cell has its own copy of a polynomial space defined first on a reference cube. A map carries points of that cube to points in the physical cell. The basis on the reference cube comes from Lagrange interpolation at Gauss–Lobatto points. Each one-dimensional basis polynomial has value one at its own interpolation point and zero at the other interpolation points. Multiplying such functions across coordinates produces a basis for the cell.
φ̂ᵢⱼₖ(ξ) = φᵢ(ξ₁) φⱼ(ξ₂) φₖ(ξ₃)
The hat identifies a basis function on the reference cube. ξ denotes its coordinate tuple, and ξ₁, ξ₂ and ξ₃ are the individual coordinates. The indices i, j and k select the one-dimensional Lagrange polynomials φᵢ, φⱼ and φₖ. In this expression k is a basis index. Elsewhere the paper also uses k to denote polynomial degree. The product gives the value of the reference basis function at ξ.
φᴋ,ᵢ(x) = φ̂ᵢ(Fᴋ⁻¹(x))
K denotes a physical cell, x is a point in it, and Fᴋ is the map from the reference cube to K. Its inverse, Fᴋ⁻¹, supplies the reference coordinates of x. The index i now collects the basis indices for a single basis function. φ̂ᵢ is the function on the reference cube, and φᴋ,ᵢ is the corresponding function on K.
Vₕ = {v ∈ L²(Ω) | v|ᴋ ∈ V(K) for every K ∈ Tₕ}
Vₕ is the finite element space. Tₕ is the mesh, h labels that mesh, and K ranges over its cells. V(K) is the local space spanned by the mapped polynomials. The symbol v|ᴋ means the restriction of v to K. L²(Ω) denotes the space of square-integrable functions on Ω, and ∈ means membership. There is no continuity condition in this definition across the faces of adjoining cells.
That last property gives the method its name, discontinuous Galerkin. At an interior face, evaluating a function from one cell can give a different value from evaluating it at the same point from the adjoining cell. The values reached from each side are called traces. The symmetric interior penalty formulation brings these traces into the discrete equation so that the cell solutions are coupled. Its face terms also include traces of derivatives.
{v}(x) = ½(v⁺(x) + v⁻(x))
The braces denote averaging on an interior face. The superscripts + and − identify the traces from the two adjacent cells. v is the finite element function under consideration and x is a point on the face. The factor ½ is the averaging weight. At a boundary face the paper uses the single available trace. When the average is applied to a product of a function and a normal, each trace uses the outward normal of its own cell.
∫ₜₕ ∇uₕ · ∇v dx + ∫ₑₕ (γₑ {uₕn} · {vn} − {∇uₕ} · {vn} − {uₕn} · {∇v}) dσ(x) = ∫ₜₕ fv dx
Here uₕ is the discrete solution, and the equation is tested against every v in Vₕ. The notation ∫ₜₕ abbreviates integration over the cells of Tₕ, while ∫ₑₕ abbreviates integration over the mesh faces in Eₕ. The symbol ∇ denotes a gradient, the centered dot is a vector inner product, and n is the outward unit normal for the relevant trace. The measure dx is for cell volume, and dσ(x) is for face area. γₑ is the penalty on face e. The braces use the trace convention just described, and f is the forcing. The volume integral on the left accounts for the gradients within cells. The face integral adds a penalty term and a pair of gradient and trace couplings. The displayed right-hand side is the volume forcing term in the paper’s variational expression. The numerical experiment specifies its Dirichlet data separately through a known solution.
γₑ = k(k + 1)(1/h⁺ + 1/h⁻)
γₑ is the penalty parameter at face e. Here k is the degree of the polynomial basis, and h⁺ and h⁻ are the cell-size quantities associated with the two sides. The expression combines the degree-dependent factor with reciprocal lengths. This use of k is distinct from the basis index in the reference-cube product.
For an operator application, the input is a vector of coefficients. The kernel gathers the values needed for a local calculation, evaluates the cell and face terms, and accumulates the resulting coefficients in the output vector. Numerical quadrature, which replaces an integral by a weighted sum of values at selected points, is used to carry out the local integrals. The paper expresses the bookkeeping through restriction maps.
v = Au = ∑ᴋ∈ₜₕ Pᴋᵀ Aᴋ Pᴋ u
u is the input coefficient vector, A is the global discrete operator, and v is the result. In this operator notation v denotes an output vector. In the variational equation it denotes a test function. The sum runs over the cells K of Tₕ. Pᴋ gathers coefficients into the local indexing, Aᴋ denotes the corresponding local contribution, and Pᴋᵀ scatters that result back to the global indexing. The superscript ᵀ denotes transpose. The sum describes the overall action, with the appropriate traces supplied where faces couple neighboring cells.
Turning cell integrals into directional products
The volume calculation gives a concrete view of the arithmetic. For a pair of basis functions, the corresponding stiffness entry integrates the inner product of their gradients. A matrix entry therefore describes how one basis function contributes when the result is tested against another.
Aᴷᵢⱼ = ∫ᴋ ∇φᴋ,ᵢ · ∇φᴋ,ⱼ dx
Aᴷᵢⱼ is the local volume stiffness entry for basis indices i and j on K. φᴋ,ᵢ and φᴋ,ⱼ are the physical-cell basis functions. ∇ gives their physical gradients, · denotes the inner product, and dx is the physical volume measure. The integration is over K.
The operation is easier to organize in reference coordinates because every cell uses the same reference basis. The Jacobian of the cell map describes how changes in reference coordinates are stretched and reoriented in the physical cell. Its inverse transforms the derivative information, and its volume factor changes the weight of the integral. The paper combines these geometric quantities with quadrature weights.
Aᴷᵢⱼ ≈ ∑q w(q) ∇φ̂ᵢ(q)ᵀ Jᴋ(q)⁻¹ Jᴋ(q)⁻ᵀ ∇φ̂ⱼ(q) |det Jᴋ(q)|
Here q denotes a reference quadrature point, and the sum includes the tensor grid of such points. w(q) is the associated reference weight. φ̂ᵢ and φ̂ⱼ are the reference basis functions, so the gradients in this expression are taken in reference coordinates. Jᴋ(q) is the Jacobian of the map to cell K at q. The superscripts ⁻¹ and ⁻ᵀ denote inverse and inverse transpose. The determinant magnitude supplies the volume factor, and ᵀ on a gradient makes it a row for the inner product. The symbol ≈ indicates quadrature of the volume integral. The order of the inverse factors here follows the convention that the reference gradients are columns and the Jacobian maps reference coordinate increments to physical ones.
A direct evaluation could multiply every coefficient by the value of its full basis function at every quadrature point. The product structure gives a shorter route. Fix the coordinates transverse to a chosen direction and combine the input coefficients along that direction. Repeating the operation for the remaining directions gives the same interpolation through nested sums. Taking a reference derivative changes the one-dimensional basis factor in the direction being differentiated.
u(q) = ∑ₖ₌₀ᵖ φₖ(ξₖq) [∑ⱼ₌₀ᵖ φⱼ(ξⱼq) [∑ᵢ₌₀ᵖ uᵢⱼₖ φᵢ(ξᵢq)]]
u(q) is the evaluated polynomial at quadrature point q. The point has coordinate entries ξᵢq, ξⱼq and ξₖq, where the subscripts label the three directions of the quadrature multi-index as in the paper. uᵢⱼₖ are the input coefficients, φᵢ, φⱼ and φₖ are one-dimensional basis functions, and p is the degree bound for each basis index. The indices in the sums run from 0 to p. The brackets mark the nesting, so an inner sum can be computed once and used by later sums.
The paper calls this organization sum factorization. A useful way to picture a directional pass is to hold two coordinates fixed and read the values along the remaining coordinate as a column. The same one-dimensional matrix acts on every such column. Putting the columns side by side turns many applications of a small matrix to vectors into one matrix product. For dimension d, the paper describes a factor of shape N × N and a reshaped array of shape N × Nᵈ⁻¹. Here N is the one-dimensional matrix dimension, and the power counts the combinations of transverse indices. In the three-dimensional case the second shape becomes N × N².
The same idea can express the gradient more compactly. The paper uses interpolation matrices for directions where it evaluates a basis function and derivative matrices where it evaluates its slope.
Gφ = [S₂ ⊗ S₁ ⊗ D₀; S₂ ⊗ D₁ ⊗ S₀; D₂ ⊗ S₁ ⊗ S₀]
Gφ is the map from local coefficients to the stacked reference-gradient components at quadrature points. Sᵢ is the one-dimensional interpolation matrix for direction i, and Dᵢ is its derivative counterpart. The subscripts 0, 1 and 2 label the directions. The symbol ⊗ is the Kronecker product, expressing an operation built from independent factors on different coordinates. The semicolons inside the brackets separate the rows of operators for the gradient components.
Aᴋ = Gφᵀ W Gφ
Aᴋ here denotes the local volume operator. Gφ evaluates the gradients of the input, W contains geometry and integration weights at the quadrature points, and Gφᵀ integrates the weighted values back against the test basis. Multiplication is read from right to left when applying the expression to a coefficient vector. This is a factorization of the action of Aᴋ. The implementation uses the factors without forming the expanded stiffness matrix.
Face quadrature has a similar organization. At a face the normal coordinate is fixed at an endpoint, while the tangential coordinates still run across quadrature points. A one-dimensional endpoint evaluation takes the place of a full interpolation matrix along the fixed direction. The derivative in that direction uses an endpoint derivative evaluation.
[∂₀Φ; ∂₁Φ; ∂₂Φ] = [S₂ ⊗ Sꜰ ⊗ D₀; S₂ ⊗ Dꜰ ⊗ S₀; D₂ ⊗ Sꜰ ⊗ S₀] Φ
Φ is the local polynomial represented by its coefficient array on the right. ∂₀Φ, ∂₁Φ and ∂₂Φ are the directional derivative values at the face quadrature points. Sꜰ and Dꜰ are the endpoint value and derivative rows for the face in the illustrated orientation. They have shape 1 × N. S₀, S₂, D₀ and D₂ are the corresponding full interpolation or derivative matrices in the tangential directions. The symbol ⊗ again joins the directional factors, and the separators stack the gradient components vertically. The position of the endpoint row marks which coordinate is fixed in this example.
Grouping contributions into patches
The general derivation allows geometry and integration weights to be applied at each quadrature point. The benchmarks use a more specific setting. The mesh is Cartesian, and the coefficient in the differential operator is constant. These conditions let the implementation group cell and face contributions in patches and express the resulting calculation using one-dimensional stiffness and mass matrices. A mass matrix captures weighted products of basis values. A stiffness matrix captures the directional derivative contribution. The patch construction incorporates the relevant interfaces, so the one-dimensional factors describe more than interpolation inside a single cell.
Aᴋ = L₂ ⊗ M₁ ⊗ M₀ + M₂ ⊗ L₁ ⊗ M₀ + M₂ ⊗ M₁ ⊗ L₀
Aᴋ now denotes the patch operator used in the benchmarks. Lᵢ is the stiffness factor and Mᵢ is the mass factor along direction i. The subscripts 0, 1 and 2 distinguish the coordinate directions. Each + adds one directional contribution to the Laplacian and ⊗ forms the product of the coordinate factors. The three terms put the stiffness factor in different positions because each accounts for differentiation along a different axis.
A patch can include parts of the cell and face integrals in a single calculation. The paper illustrates interior, boundary and corner patches to show how the contributions included in a patch depend on where it sits. An interior patch has a different arrangement of neighboring cells and faces from a corner patch. The computational benefit is that the local matrices are larger than for a single cell at the same degree. The paper gives N = 8 as an example that corresponds to degree k = 7 for a cell calculation and k = 3 for a patch calculation. A larger local matrix can use a Tensor Core tile more fully even when the underlying element degree is relatively low.
Matrix-free operator application with Tensor Cores
The steps in order.
The directional passes use the same coefficient array in different ways. A pass groups values with the same transverse coordinates and varying coordinates along its own axis. The GPU code can accomplish the corresponding reshape by changing indices. For the layout discussed in the double-precision benchmark, the direction-dependent strides are 1, N and N². A new interpretation of the indices changes which entries make up a matrix column. How those entries reach registers is then a separate question, even when the reshape itself needs no explicit copy.
Loading tiles and executing the multiply
A Tensor Core instruction implements a product with an accumulating term. That accumulating term lets the warp build an output tile across a sequence of products when the inner dimension of the full calculation spans several hardware tiles.
D = A × B + C
A and B are the input matrix tiles, × is matrix multiplication, C is the incoming accumulator, and D is the output tile. The same storage may serve as C and D when a result is updated in place. These letters describe the hardware operation, so A here is a tile operand and should be distinguished from the global finite element operator.
Both programming approaches use a warp, a group of 32 threads working together. The kernel organizes the workload in thread blocks for local mesh operations. Its two-dimensional thread structure assigns threads to columns of degrees of freedom, with each direction determining how values along such a column are visited. The workload assigned to a warp can encompass several slices of a local array, or several warps can share the processing of a slice. The assignment depends on the shape of the local operation and the instructions used.
The C++ Warp Matrix Multiply and Accumulate interface, called WMMA, represents tiles as fragments distributed over registers. It provides collective functions to load fragments, multiply them with an accumulator and store the result. The paper’s double-precision example starts with an empty accumulator, loads tiles of the operands from shared memory, performs the multiplication, and writes the accumulator back to shared memory. The interface handles the distribution of entries to the threads that need them.
This abstraction comes with alignment and layout requirements. The paper specifies 256-bit pointer alignment for the WMMA matrix references it discusses, and the values in the relevant rows or columns must be consecutive in memory. All threads in the warp must participate in the collective operation. In Cui’s layout, WMMA can accelerate the passes along x₀ and x₁. The pass along x₂ stays on CUDA Cores, so the paper assigns 2/3 of the directional arithmetic in this version to Tensor Cores.
The inline Parallel Thread Execution approach exposes the mma.sync.aligned instruction directly. The instruction still expects the warp to supply each matrix entry in the appropriate register. The programmer now decides how to load those registers. For the basic double-precision kernel, individual threads use ld.shared to fetch their entries from shared memory. As long as they supply the required register operands, the memory locations themselves can follow the contraction’s layout. This allows the Tensor Core to perform all directional products.
Shared memory is the on-chip working store used to stage the input and the intermediate results. It is divided into banks that can service accesses in parallel. When requests issued together need different data from the same bank, the requests contend for that bank. The paper identifies this problem when the basic inline kernel loads parts of its operand tiles. The matrix arithmetic can be ready to run while the warp is still waiting for its operands.
Cui addresses the conflict by permuting shared-memory indices with a bitwise exclusive-or operation, commonly called XOR. The change is in where an entry is stored and how the matching load finds it. Its role in the product and its assignment to a thread register stay the same. In the illustrated double-precision layout, the simultaneous requests within each shown submatrix go to distinct banks. The paper calls the resulting kernel MMA CF, with CF standing for conflict free. Its example for one direction shows the permutation for both operands and illustrates how the output is stored for later use.
The half-precision version follows the same organization with a layout adapted to smaller entries. A physical bank covers a different set of entries when their size changes, so simply keeping the double-precision index permutation would give a different access pattern. The paper also uses ldmatrix, a collective load that supplies a matrix fragment to registers across a warp. Wider loads let the half-precision kernel move more of its operands per instruction. The input entries are in FP16, the half-precision format, while the instruction accumulates in FP32, the single-precision format. In the double-precision path both are in FP64.
Handling dimensions and recovering precision
Tensor Core tiles have prescribed shapes. The double-precision instruction illustrated in the paper uses the tile tuple 8 × 8 × 4, while the half-precision instruction illustrated uses 16 × 8 × 16 with a single-precision accumulator. The tuple describes the output row and column dimensions and the inner dimension over which the products are summed. A local finite element dimension can fit the relevant instructions well or leave part of the issued tile without useful work. This is a property of the directional matrix dimensions even though the larger operation is a finite element application.
The paper considers adding threads so that the warp can still execute the prescribed tile when some of its positions lie outside the actual array. One arrangement lets the added threads skip certain reads. It avoids reserving extra shared memory, but it can split threads into different execution paths and makes the banking pattern harder to arrange. The other arrangement pads memory and threads together. For the three-dimensional case described, the padding is needed along x₀ and x₁. A regular array then supports the established loading pattern, at the cost of processing additional entries.
Numerical precision raises a separate issue. FP16 can represent a less finely spaced set of input values than FP32. If the operands are rounded to FP16 before multiplication, some information is lost before the FP32 accumulator sees any products. The correction scheme used in the paper makes a second FP16 array for an approximation to that missing information. It first converts the main operands to FP16.
(Aₕ, Bₕ) = (float2half(Aₛ), float2half(Bₛ))
Aₛ and Bₛ are the original single-precision matrices. Aₕ and Bₕ are their half-precision versions. float2half is the conversion to FP16, applied to each entry. The parentheses pair the two operands and their corresponding results.
δAₕ = float2half((Aₛ − half2float(Aₕ)) × 2¹¹)
δAₕ is the half-precision correction array for A. half2float converts Aₕ back to FP32 so that the subtraction from Aₛ measures what was lost in the first conversion. The multiplication by 2¹¹ scales that residual before float2half converts it to the correction format. All operations in this expression are entrywise.
δBₕ = float2half((Bₛ − half2float(Bₕ)) × 2¹¹)
δBₕ is the correction array for the other operand. Bₛ is its original single-precision matrix and Bₕ is the rounded half-precision matrix. half2float gives the rounded values in single precision for subtraction, 2¹¹ is the same residual scale, and float2half stores the scaled residual in FP16. This supplies correction information for the second input tile.
Cₛ = AₕBₕ + (δAₕBₕ + AₕδBₕ)/2¹¹
Cₛ is the corrected product in single precision. Adjacent matrix symbols denote matrix multiplication. AₕBₕ is the product of the main half-precision operands. δAₕBₕ and AₕδBₕ compensate for rounding in the first and second operands, respectively. Dividing by 2¹¹ undoes the residual scaling in these products. The expression retains terms that are linear in the residuals. It omits the product of the two residual arrays, so the scheme is an approximation to the single-precision input product.
This arrangement calls for extra conversions and matrix multiplications. Its purpose is to keep much of the matrix arithmetic on the high-throughput half-precision path while recovering a useful level of input accuracy. The paper tests that recovery first on an isolated operator application. It also points out that the scheme could be applied to either operand individually if an application had different accuracy or cost requirements. The experimental correction formula uses both.
Putting the kernel inside the Poisson solver
The application uses multigrid as a preconditioner for flexible GMRES, abbreviated FGMRES. A preconditioner takes information about the current error, represented through the residual, and returns a correction that helps the outer iteration. Multigrid works with a hierarchy of meshes. A smoothing operation improves an approximation on the current mesh. A coarser mesh is then used to address error that remains after smoothing, and its correction is brought back to the finer mesh.
The paper’s smoother works on vertex patches and is multiplicative. A vertex patch groups contributions around a mesh vertex. In a multiplicative method, an update can use the result of earlier updates, so the operations form a sequence of local improvements. The V-cycle starts with a smoothing pass on the current level. It then finds the residual, restricts it to the next coarser level, and repeats the procedure. After returning from the coarse level, it applies the transferred correction and smooths again.
x₀ ← A₀⁻¹ b₀
x₀ is the approximation on the coarsest level, indexed by 0. b₀ is that level’s right-hand side. A₀⁻¹ denotes solution with the coarsest-level operator A₀, and ← means assignment. Once there is no coarser level in the hierarchy, the algorithm returns the result of this solve.
rℓ = bℓ − Aℓ xℓ
ℓ labels the current level. rℓ is its residual, bℓ is the right-hand side, and Aℓ is the discrete operator on that level. xℓ is the current approximation after presmoothing. The subtraction expresses how far the current approximate solution falls short of satisfying the discrete equation.
rℓ₋₁ = I↓ℓ₋₁ rℓ
rℓ₋₁ is the residual represented on the next coarser level. I↓ℓ₋₁ is the restriction operation from level ℓ to level ℓ − 1, as indicated by the downward arrow. rℓ is the residual on the current level. The restricted residual supplies the right-hand side for the coarse correction problem.
xℓ ← xℓ + I↑ℓ₋₁ Vcycleℓ₋₁(Aℓ₋₁, 0, rℓ₋₁)
Vcycleℓ₋₁ denotes a recursive application of the procedure on the coarser level. Aℓ₋₁ is the operator there, 0 is the initial coarse correction, and rℓ₋₁ is its right-hand side. I↑ℓ₋₁ is prolongation, which transfers that correction back to level ℓ. The arrow after xℓ denotes assignment, and the upward arrow on I marks the direction of transfer. The method adds the returned correction and then applies its smoother again before returning xℓ.
In the mixed-precision runs, the outer iteration operates in double precision. Data is converted at entry to and exit from the lower-precision V-cycle. The paper stores data within the cycle in single precision. In the half-precision path, the operands are converted during computation and accumulated in single precision, consistent with the requirements of the Tensor Core instruction and the error correction scheme. The distinction between storage and arithmetic precision matters because the half-precision preconditioner still uses single-precision quantities.
The paper gives two reasons for choosing FGMRES. First, the parallel multiplicative smoother gives a nonsymmetric preconditioner, which rules out the conjugate gradient alternatives Cui discusses. Second, FGMRES allows the effective preconditioner to vary between iterations. This flexibility is relevant when the preconditioner itself is evaluated with rounding and truncation in low precision. Keeping the outer iteration in FP64 lets the experiment test whether lower-precision work produces an adequate correction without requiring every intermediate value in the solve to have double-precision accuracy.
Experiments and results
Benchmark problems and measurements
The experiments use a single NVIDIA Ampere A100 SXM4 GPU running at 1.27 GHz, with 80GB of HBM2e device memory. The paper gives its peak device-memory bandwidth as 2TB/s and uses NVIDIA Nsight Compute for hardware profiling. The workload in the double-precision benchmark is the full discrete Laplace operator in three dimensions, including face terms and data access. The reported problem-size range is 10³ to 10⁸. The double-precision implementation comparisons feature local matrix dimensions N = 8 and N = 16. The main half-precision comparison uses N = 16.
There are two main kinds of inputs. The operator benchmarks take finite element coefficient vectors, and the numerical accuracy test generates the entries of a test vector in FP64 from a normal distribution with μ = 0 and σ = 1. Here μ is the mean and σ is the standard deviation. The solver experiment uses Poisson forcing and boundary values derived from a known smooth solution. This gives the paper an independent function against which to measure the final discretization error as well as a residual to monitor during iteration.
The baseline is a tuned matrix-free CUDA Core implementation. Earlier work cited by Cui had placed the performance of this implementation lineage near 40% of peak. The paper compares it with the WMMA route, basic inline MMA, and inline MMA with a shared-memory permutation. The implementations use the same type of directional tensor operations. Their differences concern where the products run, how the threads load operands and how the data is arranged to meet the hardware’s requirements.
The paper reports arithmetic throughput in TFLOPS/s, using that spelling for its floating-point operation rate. It also reports degrees of freedom processed per second, or DoF/s. These metrics answer different questions. Arithmetic throughput reflects the amount of work issued relative to elapsed time. DoF/s relates elapsed time to the size of the discrete problem. If a method adds products for error correction or processes extra entries because of padding, a higher operation count can increase its arithmetic rate while delivering a smaller improvement in useful throughput.
Double precision
The WMMA implementation improves on the original CUDA Core program. Moving all coordinate directions to Tensor Cores through the inline MMA route gives a further gain. The strongest double-precision result comes from combining that route with the permuted shared-memory layout. The paper’s headline figure is 8 TFLOPS/s, which its conclusion describes as about 45% of peak Tensor Core FP64 performance. It reports a 2.3-fold improvement over the tuned CUDA Core implementation and gives a best-case useful throughput approaching 10 BDoF/s in the double-precision analysis.
The paper also reports 7.6 TFLOPS/s for the optimized FP64 kernel in its device-memory roofline analysis. The headline value and the roofline value appear in different parts of its reporting. The device-memory roofline result lies near the transition between bandwidth-limited and arithmetic-limited behavior. The comparison with CUDA Cores also gives some context for the headline speedup. The A100 capability table describes a nominal 2× advantage for FP64 Tensor Core operations over standard fused multiply-add. The measured 2.3x is a ratio to the performance of an implemented CUDA Core kernel. Cui attributes the additional gain to reuse of data already loaded into registers as the warp performs tile operations.
The profiling gives a more specific view of what changed when the shared-memory permutation was applied. A wavefront in this discussion is a unit of work into which the memory pipeline divides a request. Fewer wavefronts are needed when requests can be handled together. The paper reports that their count fell by almost half and that the measured stalls associated with the memory input/output pipeline also fell. Once the conflicts were reduced, the principal stalls were attributed to dependencies in execution. A directional pass can require values produced by an earlier pass, so speeding up loads leaves some waiting that follows from the sequence of the calculation.
Memory input/output pipeline stalls in the double-precision 3D Laplace operator benchmark at N = 8
The permuted shared-memory layout reduces stalls associated with the memory pipeline.
The numbers
| System or setting | reported MIO stall value |
|---|---|
| Basic inline MMA | 11.58 |
| Conflict-free inline MMA (this paper) | 2.11 |
Half precision and operator accuracy
The best half-precision kernel accelerates the original CUDA Core program by a factor of 3.5 in the lower-precision benchmark. Its arithmetic performance surpasses the theoretical single-precision CUDA Core performance discussed in the paper. The stated reasons are the higher arithmetic capacity available in the FP16 path and the reduction in memory instruction pressure from wider loads. This is the kernel comparison for the operator. The Poisson solver comparison includes the outer iteration, the rest of the multigrid cycle and the accuracy needed to reach the stopping condition.
To test operator accuracy, the paper applies the same discrete operator to the random input vector using different precision paths. It compares each result with the result from double precision. It takes the Euclidean norm of their difference and normalizes it by the norm of the double-precision output.
E = √(∑ᵢ (vᵢᶠᵖ⁶⁴ − vᵢˡ)²) / √(∑ᵢ (vᵢᶠᵖ⁶⁴)²)
E is the relative ℓ² error in the operator output. vᵢᶠᵖ⁶⁴ is entry i of the FP64 output, and vᵢˡ is the matching entry from the lower-precision path. The sums are over entries of the output vectors. The square roots and squares give Euclidean norms. The denominator scales the discrepancy by the magnitude of the reference result.
Across the tested sizes the errors generally rise with vector size. Direct FP16 inputs give much larger discrepancies than FP32 calculations. The FP16 path with residual correction recovers the error level observed with FP32. The paper also compares useful throughput for these paths at N = 16. Correction adds work through conversions and supplementary products, so it lowers the efficiency relative to what the half-precision kernel can achieve without that work. The Tensor Core versions still show a throughput advantage over the conventional CUDA Core results discussed in that comparison.
The highest reported arithmetic rate for the corrected half-precision path is 70 TFLOPS/s in the device-memory roofline analysis. The calculation of that rate includes arithmetic performed for error correction. The paper estimates that the extra products bring the operation count to about three times the count for the corresponding uncorrected work. The useful-throughput comparison answers how fast a given number of degrees of freedom is processed after the correction cost is included. This is particularly relevant when comparing operator paths at different accuracy levels.
The solve with a known answer
For the application test, the paper chooses the forcing and boundary values so that Poisson’s equation has the following analytical solution.
u(x, y, z) = sin(πx) sin(πy) sin(πz)
u is the exact solution being represented. x, y and z are spatial coordinates, π is the circular constant, and sin is the sine function. The product gives the exact value at each point. The numerical solution is compared with this function to assess error from the discretization and the finite-precision solve together.
The outer FGMRES iteration stops when its ℓ² residual norm has fallen to 10⁻⁸ of its initial norm. The convergence plot for degree k = 7, corresponding to N = 16 in the patch calculation, shows coincident curves for FP64, FP32 and FP16 with error correction in the preconditioner. The paper also describes larger iteration counts for single precision in its discussion of solver efficiency. These statements have different scopes. The overlapping curves describe the specific plotted comparison, while the discussion of timings describes iteration behavior across the experiments. The plot establishes close agreement for the displayed case.
Using Tensor Cores in the double-precision solve reduces solution time to about half that of the corresponding CUDA Core solve, with a larger effect described at larger problem sizes. For lower-precision multigrid with a double-precision outer iteration, the conclusion reports more than a fourfold increase in solution efficiency and retention of accuracy and convergence rates. This application-level comparison includes the cost of supplying the preconditioner’s correction at each iteration. A faster V-cycle can have a smaller effect on time to solution if its correction requires more outer iterations. The observed agreement in convergence is therefore part of the speed result.
The paper reports that a relative error diagnostic for FGMRES remains stable at 10⁻¹⁰. Its discussion also contrasts FGMRES with ordinary GMRES under mesh refinement, reporting increases in the L² and H¹ errors for GMRES. L² measures error in function values in an integrated norm, while H¹ includes first derivatives. This comparison concerns the solver’s ability to maintain accuracy as the discrete problem changes. It is separate from the relative ℓ² operator-output error measured on random vectors and from the residual threshold used to stop the Poisson solve.
What the ablations show
Instruction choice and shared-memory layout
The progression from CUDA Cores through WMMA to basic inline MMA and then to the conflict-free kernel is the main implementation comparison. WMMA already moves much of the arithmetic to specialized hardware, which tests the payoff from using Tensor Cores through the more constrained interface. The basic inline route tests what can be gained by also moving the remaining direction to Tensor Cores. Its stalls show that making the arithmetic instruction available throughout the kernel leaves a substantial cost when threads contend for access to shared memory.
The comparison between basic and conflict-free inline MMA is more focused because the matrix instruction is already in use for each directional pass. The permutation changes how simultaneous loads map to banks, and the profiler supplies a mechanism for the observed improvement. The reduction in wavefronts and memory-pipeline stalls is consistent with requests being served more efficiently. The shift towards execution dependencies in the optimized kernel also gives the remaining stalls a different interpretation. They are associated with calculations that need previous results as the operation proceeds through its coordinate passes.
These comparisons help explain why changing an instruction alone does not deliver the full gain. The WMMA result depends on the directions compatible with its loading requirements. The basic inline result depends on the bank accesses created by independently chosen loads. The conflict-free inline result depends on giving those loads a layout suitable for their joint access pattern. The gain reported for the optimized kernel comes from this combination in the finite element operation, including the need to pass intermediate results from one direction to the next.
Storage choices and loop unrolling
The paper also asks where to store the small directional matrices. Its comparison uses a CUDA Core implementation in single precision at N = 16. Constant memory can hold the data, but the accesses become inefficient when threads in a warp request different addresses. The authors report that utilization of the address unit pipeline rises from almost 0% to 45% for the constant-memory experiment. The texture path handles divergent addresses better in the test. It also increases register pressure enough to cause spills, moving some values out of the register allocation and generating additional memory operations. For these small, repeatedly read matrices, shared memory gives the strongest result in the comparison.
Loop unrolling changes how much work is visible to the instruction scheduler. A scheduler may be able to overlap more operations when several iterations are exposed at once. The additional live values can also require more registers per thread. The paper measures these competing effects for its kernels, where threads already hold matrix operands and intermediate results while the warp processes multiple tiles.
In its double-precision MMA CF case at N = 16, the original version uses 216 registers per thread and achieves 12. Occupancy is 5%, and each multiprocessor has one active thread block. Occupancy measures the proportion of supported warp activity present on a multiprocessor. Unrolling raises register use to 254 per thread and introduces spills with 16-byte loads and stores. The profiler records 476,656 local load and store instructions. The paper reports a 5% increase in L1 and L2 hit rates alongside a 10% increase in execution time. Caches serve a greater share of the accesses while the total amount of traffic and the instruction count increase.
In the half-precision example, the original kernel uses 128 registers per thread, with 2 resident blocks per multiprocessor and 25% occupancy. The unrolled version uses 147 registers per thread, and the multiprocessor can hold only one block. The timing comparison gives the combined effect of the change in instruction scheduling and the change in available parallel work.
Execution time with and without loop unrolling in the half-precision finite element kernel
The kernel with its original loops finishes sooner.
The numbers
| System or setting | ms |
|---|---|
| Inner loop unrolled | 2.02 |
| Original loop structure (this paper) | 1.42 |
The two precision cases illustrate different resource effects. The double-precision measurements show extra traffic from values that no longer fit in registers. The half-precision comparison shows how a larger allocation per thread can reduce the number of blocks that run together. Both effects matter for the sequence of local matrix operations because any scheduling benefit from unrolling must be large enough to offset the new resource costs.
Padding and accuracy correction
The matrix-size experiment varies how closely the local dimensions fit the hardware tile. Cui considers padding threads alone and padding both threads and shared memory. With thread-only padding, the threads corresponding to added positions need a separate load behavior. This can cause branch divergence, meaning threads in the same warp follow different paths. The original, irregular memory layout also makes it harder to find a permutation that distributes requests over banks. Padding memory as well lets the computation keep a regular access pattern and gives the best Tensor Core results used in the size comparison.
The cost of that regularity is visible over dimensions 10 to 16. The paper states that sizes from 10 to 14 execute the same operations as N = 16 after padding. The measured disadvantage is particularly noticeable at N = 10. The full hardware tile is issued even though a smaller share of its arithmetic corresponds to values in the actual operator. This comparison qualifies the generality of the implementation. Padding makes the instruction usable at a wider set of sizes, and the fraction of useful work varies across those sizes.
The correction experiment varies a different part of the kernel while keeping the discrete operator being tested. The direct FP16 calculation shows the size of the error after rounding the operands to half precision. The corrected calculation shows that supplementary products recover much of the accuracy lost at that conversion. The FP32 calculation gives a reference level for this recovery, and FP64 supplies the output against which all discrepancies are measured. In the solver, the corrected path’s convergence also shows that the added work can preserve the effectiveness of the multigrid correction in the tested case.
The error correction tests and padding tests both benefit from measuring DoF/s. Padding can raise the number of operations needed to cover a fixed problem, and correction deliberately adds products to improve accuracy. A throughput comparison in floating-point operations alone cannot tell how these changes affect the time to apply the operator at the required accuracy. The paper’s use of both rates lets the reader see why a kernel that executes more arithmetic can still be worthwhile, and why that arithmetic must be assessed against the work the solver needs.
Locating the performance limit
A roofline relates a kernel’s arithmetic rate to the amount of data it needs to move. The ratio of floating-point work to transferred bytes is its arithmetic intensity at the chosen level of memory. A bandwidth limit bounds the rate at low intensity because the arithmetic units must wait for data. At higher intensity a hardware arithmetic limit can take over. The paper examines the performance against device-memory traffic and then asks whether shared-memory traffic explains the results more closely.
The device-memory comparison places the traditional matrix-free CUDA Core Laplacian in a typically compute-bound regime. The optimized double-precision Tensor Core kernel falls near the transition between compute and bandwidth limits. The lower-precision kernels discussed in the device-memory analysis fall on the bandwidth-limited side. These changes are consistent with arithmetic having become faster relative to the rate at which data can be supplied. The paper then estimates the capacity of shared memory from the parallel resources available on the GPU.
B = (#SMs) × (#banks) × word length × clock speed
B is the estimated shared-memory bandwidth. #SMs is the number of streaming multiprocessors, the GPU units on which thread blocks execute. #banks is the number of shared-memory banks per multiprocessor. Word length gives the number of bytes transferred per bank for the estimate, and clock speed gives the cycle rate. The multiplication states the bandwidth available when the banks can be used in parallel.
The paper uses 108 multiprocessors, 32 banks, a word length of 4 and a clock figure of 1.27 in its A100 estimate, giving a reported 17.145TB/s. It relates that estimate to an earlier measured shared bandwidth of 127.7 bytes/clk/SM. For a particular kernel, the resulting throughput bound uses the work and the read and write traffic associated with it.
R = B × F/(dᵣ + d𝓌)
R is the arithmetic rate allowed by the shared-memory bandwidth estimate B. F is the number of floating-point operations attributable to the traffic being counted. For shared memory, dᵣ counts the bytes read and d𝓌 counts the bytes written. Their sum gives the volume of shared-memory traffic for those operations. The ratio of F to that sum is the arithmetic intensity relative to shared memory.
Most of the optimized results approach the shared-memory bound in the paper’s comparison. Cui highlights the double-precision conflict-free kernel at N = 16 as an exception. It uses 143.36 Kbyte/block of dynamic shared memory, leaving only one thread block on each multiprocessor. The achieved occupancy drops from 24.2% at N = 8 to 12.4% at N = 16 in that analysis. The resource figures explain how a kernel can remove bank conflicts and still fail to reach the estimated bandwidth bound. The bank assignment lets simultaneous accesses proceed efficiently when issued. Limited block residency reduces the parallel work available to issue those accesses and to cover other delays.
Limitations
Limits identified by Cui
The paper’s fastest operator is built for constant coefficients on a Cartesian mesh. That setting permits the patch operator to be written as a sum of products of one-dimensional mass and stiffness factors. The more general derivation using the gradient map and quadrature weights gives a way to describe other geometries, but the reported fastest kernel is evaluated on the simpler structure. Cui identifies other differential operators and other element families as subjects for further work, giving Raviart–Thomas elements used for Stokes problems as an example.
The author also identifies irregular and anisotropic tensor products as open implementation problems. Anisotropic elements can have different approximation requirements along different axes. The local matrix products could then have different shapes from direction to direction. The padding experiment demonstrates the penalty when sizes fit the hardware poorly even in the scalar benchmark. It provides a way to cover additional sizes, with a varying cost in wasted arithmetic and shared storage. Efficient handling of those sizes remains a separate question from whether the operation can be executed.
Global memory access receives less attention than shared memory in the optimization. The kernel first stages its data from device memory into shared memory. The study concentrates on the later transfers and matrix arithmetic, and Cui mentions pipelining and alternative global numbering as possible improvements to the earlier stage. The conclusion also points to vector-valued problems, where each location may carry several unknown quantities and more data has to be brought on chip. The profile of the present scalar operator gives no measured cost for that larger data movement.
The author notes that the patch formulation evaluates some cell contributions only in part. As a result, the arithmetic per useful degree of freedom for the patch-wise 3D Laplacian at N = 16 is higher than in some earlier operator implementations. This affects both the reported operation rate and comparisons across discretizations. The paper’s DoF/s measurements provide the more direct measure of operator speed within its benchmark, where the discretization and the useful work being counted are specified.
Limits of the evidence
All measured performance comes from the same A100 configuration. Tile shapes, register allocation and bank mappings drive several of the findings, and the paper supplies implementation examples tailored to that hardware. The conflict-free access pattern demonstrates what that layout can achieve for the instructions and precisions studied. Transferring the kernel to a different architecture would require checking those relationships again. The reported speedups are for the observed GPU and the selected CUDA Core baseline.
The numerical tests address a particular random-vector operator experiment and a particular Poisson problem with a smooth exact solution. They show that error correction reaches the FP32 error level for the tested operator inputs and that the mixed-precision preconditioner preserves the reported Poisson accuracy. They give no error guarantee for all possible input ranges, different coefficient fields or other boundary-value problems. The reported agreement in discretization error applies to the mixed-precision arrangement actually used, including the double-precision outer iteration and the single-precision accumulators.
The application test also evaluates the precision split as a whole. It shows what happens when the multigrid cycle uses the studied lower-precision path inside FGMRES. It does not isolate a separate time or convergence contribution for every operation in restriction, prolongation, smoothing and the coarse solve. The kernel tests explain part of the application gain, and the convergence measurements show whether the complete preconditioner remained effective. Assigning the whole solver speedup to a single instruction or a single memory optimization would exceed those comparisons.
Finally, the paper’s precision comparisons use several error measures with different roles. The random-vector experiment measures an operator-output discrepancy against an FP64 reference. The solver residual measures how well the discrete equations are satisfied. The L² and H¹ solution errors assess agreement with the analytical solution. The paper reports the stable 10⁻¹⁰ relative FGMRES diagnostic in its narrative, while the accompanying figure caption describes an iteration residual plot. The numerical value can be attributed to that narrative claim, with the convergence curves providing separate evidence about iteration behavior.
What came after
No later citing work is documented here. Cui’s conclusion identifies the extensions left open by the study, including mixed or vector-valued finite elements, anisotropic tensor products and the cost of bringing more degrees of freedom from device memory into shared memory. These directions follow from specific features of the experiments. The Cartesian patch operator supplies the clean directional factors used in the fast kernel, the padding comparisons show the cost of mismatched dimensions, and the resource measurements show how an increase in on-chip storage can reduce the work a multiprocessor can run concurrently.
Cite
Cite as Cu Cui. 2024. Acceleration of Tensor-Product Operations with Tensor Cores. arXiv:2407.09621.
@misc{cui2024acceleration,
title = {{Acceleration of Tensor-Product Operations with Tensor Cores}},
author = {Cu Cui},
year = {2024},
doi = {10.48550/arxiv.2407.09621},
eprint = {2407.09621},
archivePrefix = {arXiv},
url = {https://doi.org/10.48550/arxiv.2407.09621}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/cui-2024-acceleration-tensor-product-operations-tensor/