What Is Matrix Multiply-Accumulate (MMA)? Understand Inputs and Accumulation Precision
MMA computes a matrix product and adds it to an existing accumulator: D = A×B + C. Learn how this differs from scalar FMA, why input, compute, and output precision are separate choices, and how to validate a CUDA library mode against an application-specific error tolerance.
What Is Matrix Multiply-Accumulate (MMA)? Understand Inputs and Accumulation Precision
Matrix multiply-accumulate (MMA) multiplies matrix elements, adds the products, and adds them to an existing accumulator. Its basic form is D = A×B + C: each output element is the dot product of one row of A and one column of B, plus the corresponding value in C. MMA names the operation shape; whether a GPU runs it on dedicated hardware such as a Tensor Core depends on that GPU, its API, and its supported data types.
This article uses the CUDA matrix-operation and cuBLAS precision modes documented in the CUDA Programming Guide 13.2 and cuBLAS 13.5, checked on November 22, 2026. Do not assume that other GPU APIs or devices support the same type combinations or behavior.
What does MMA calculate?
In an ordinary matrix product, one output element is the dot product of a row of A and a column of B. MMA can produce that dot product as a new result or accumulate it into an existing output fragment.
D[i,j] = C[i,j] + A[i,0]×B[0,j] + A[i,1]×B[1,j] + ... + A[i,K-1]×B[K-1,j]
The same calculation can be expressed for several output elements together, so a programming interface can treat small matrix fragments as one operation. For example, CUDA WMMA’s mma_sync uses warp cooperation to perform the matrix multiply-accumulate D=A×B+C. That describes the API operation. It does not mean every GPU executes it as the same single hardware instruction.
How are MMA, FMA, and matrix multiplication different?
All three involve multiplication and addition, but they operate at different scales.
| Operation | Unit handled at a time | Meaning |
|---|---|---|
| FMA (fused multiply-add) | Three scalar values | Computes a×b+c with one rounding step |
| Matrix product A×B | Two matrices | Adds the products needed for each output element |
| MMA | Matrix fragments and an accumulator fragment | Computes A×B, adds the existing C fragment, and produces D |
Starting a matrix product with C=0 is one way to express the MMA accumulation form. When a later K segment adds a partial result to an output fragment already computed, C is a nonzero accumulator. FMA handles one product and one scalar accumulator; MMA expresses products and accumulation for multiple outputs at matrix scale. The actual instructions or decomposition used internally can vary by implementation.
Follow the accumulation in a 2×2 example
This example shows the math directly. These small integers are represented exactly in the calculation; the example is not a GPU measurement.
A = [[1, 2], [3, 4]]
B = [[5, 6], [7, 8]]
C = [[1, 0], [0, 1]]
A×B = [[19, 22], [43, 50]]
D = A×B+C = [[20, 22], [43, 51]]
For example, the top-left output is 1×5 + 2×7 + C[0,0], so it is 19+1=20. A new product with C=0 and accumulation into a previous result use the same basic operation, but start with different values in C.
Input, compute, and output precision are separate choices
Do not collapse “precision” into one setting when interpreting an MMA result. Check how A and B are stored, what format is used for products and partial sums, and how the final D is stored. If inputs were already rounded to a lower precision, a wider accumulator cannot restore information they lost. A wider accumulator can reduce rounding accumulated during a long sum, but storing the result in a narrower output format can round it again.
| Stage | What to check | Effect on the result |
|---|---|---|
| Inputs A and B | Storage format and any input conversion | Sets the spacing and range of representable values |
| Compute and accumulation | Precision used for products and intermediate sums | Affects rounding in partial sums and accumulated error |
| Output D | Format used to store the result | May convert and round the value when stored |
So an FP32 output alone does not prove that the inputs and computation were FP32. Check whether the library API has a separate compute type and what input conversions and intermediate arithmetic that option permits.
How should CUDA type examples be read?
CUDA WMMA documents input and accumulator combinations such as the following. These are examples of combinations that the documentation describes, not a promise that every GPU, library, or matrix size supports them.
| Inputs A and B | Example accumulator type | What to keep in mind |
|---|---|---|
| __half and __half | float, or another documented combination | FP16 inputs may use FP32 partial sums |
| __nv_bfloat16 and __nv_bfloat16 | float | BF16 keeps a range similar to FP32 but has lower precision |
| TF32 and TF32 | float | It targets an FP32-like range with lower precision; check WMMA conversion and support requirements |
| double and double | double | Check supported device generations and shape requirements |
Type names alone do not determine accuracy or speed. BF16 and FP16, for example, have different trade-offs in precision and representable range, so consider which losses matter for your input values. The CUDA Programming Guide restricts which fragment type combinations and matrix shapes are allowed. For real code, check the documentation for the toolkit and GPU in use.
Why can accumulation order and FMA change the result?
Finite-precision addition rounds after each operation. Therefore, ((a+b)+c) and (a+(b+c)) can differ in floating-point arithmetic even though they are the same real-number expression. If an MMA implementation groups partial sums in a different order or uses different input and accumulator formats from a reference calculation, the final result may not be bitwise identical.
FMA computes a×b+c with one rounding step. Its result can differ from multiplying, rounding that product, and then adding c; in cancellation cases FMA can produce a more accurate result. That does not mean FMA or MMA returns the exact mathematical answer for every input. Loss from lower-precision inputs, long accumulation, and output conversion still affects error.
How should you choose a compute mode for a workload?
First define the output error and input ranges your application can tolerate. Use a conservative mode as a reference, then evaluate modes that permit lower-precision inputs or Tensor Core computation. In cuBLAS 13.5, CUBLAS_COMPUTE_32F uses compute and intermediate-storage precision of at least 32 bits. CUBLAS_COMPUTE_32F_FAST_TF32 allows TF32 computation for FP32 input and output matrices. These options describe permitted compute paths; they do not guarantee the same algorithm or performance for every device and input.
| Requirement | Option to consider | Decision criterion |
|---|---|---|
| A strict limit on output error | A conservative API precision option and a wider-precision reference | Define the acceptable error and verification rule first |
| Explore a faster path with FP32 input and output | A documented option that permits TF32 | Compare error on representative inputs with time on the target device |
| Inputs can be stored in FP16 or BF16 | A library path supporting that input and accumulator combination | Check range, effective precision, conversion cost, and accumulated error |
Do not infer speed from a mode name. Check that the API call permits the intended compute format and confirm which algorithm the target library selects. If performance is the goal, review data layout and reuse separately. The GPU tiling guide covers that work organization. Hardware instructions and generation-specific features are a separate topic.
How can you validate results before using a mode?
Define the absolute and relative error your application accepts, and record why that limit is adequate.
Choose representative and boundary inputs. Include relevant ranges, differences in value magnitude, long accumulations, and likely cancellation.
Compare the candidate MMA mode with a reference on identical inputs. Where needed, also prepare a reference computed at wider precision.
Check not only maximum error, but where it occurs and how it affects downstream calculations. Do not assume bitwise equality with FP32.
Record the GPU, toolkit and library versions, input/compute/output formats, and elapsed time; then compare the application’s overall results and latency again.
MMA is a computation form that adds a matrix product to an existing output accumulator. Accuracy and performance are not determined by the operation’s name alone. Validate input representation, accumulation path, rounding order, output format, and the library’s actual choice together.
References
[NVIDIA CUDA Programming Guide — C/C++ Language Extensions, Warp Matrix Functions](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/cpp-language-extensions.html)
[NVIDIA CUDA Programming Guide — Floating-Point Computation](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html)
[NVIDIA CUDA C++ Best Practices Guide — Numerical Accuracy and Precision](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/)
[NVIDIA Floating Point and IEEE 754 — Fused Multiply-Add](https://docs.nvidia.com/cuda/floating-point/index.html)
[NVIDIA cuBLAS 13.5 Documentation — Compute Types](https://docs.nvidia.com/cuda/cublas/)
References
- NVIDIA CUDA Programming Guide — C/C++ Language Extensions, Warp Matrix Functions
- NVIDIA CUDA Programming Guide — Floating-Point Computation
- NVIDIA CUDA C++ Best Practices Guide — Numerical Accuracy and Precision
- NVIDIA Floating Point and IEEE 754 — Fused Multiply-Add
- NVIDIA cuBLAS 13.5 Documentation — Compute Types