9.7.16. Warp Level Matrix Multiply-Accumulate Instructions
The matrix multiply and accumulate operation has the following form:
D = A * B + Cwhere D and C are called accumulators and may refer to the same matrix.
PTX provides two ways to perform matrix multiply-and-accumulate computation:
- Using
wmmainstructions: - This warp-level computation is performed collectively by all threads in the warp as follows:
- Load matrices A, B and C from memory into registers using the
wmma.loadoperation. When the operation completes, the destination registers in each thread hold a fragment of the loaded matrix. - Perform the matrix multiply and accumulate operation using the
wmma.mmaoperation on the loaded matrices. When the operation completes, the destination registers in each thread hold a fragment of the result matrix returned by thewmma.mmaoperation. - Store result Matrix D back to memory using the
wmma.storeoperation. Alternately, result matrix D can also be used as argument C for a subsequentwmma.mmaoperation. - The
wmma.loadandwmma.storeinstructions implicitly handle the organization of matrix elements when loading the input matrices from memory for thewmma.mmaoperation and when storing the result back to memory. - Using
mmainstruction: - Similar to
wmma,mmaalso requires computation to be performed collectively by all threads in the warp however distribution of matrix elements across different threads in warp needs to be done explicitly before invoking themmaoperation. Themmainstruction supports both dense as well as sparse matrix A. The sparse variant can be used when A is a structured sparse matrix as described in Sparse matrix storage.
Pages
- 9.7.16.1. Matrix Shape — the MxNxK shapes supported by
wmmaandmmafor each multiplicand data-type, with the PTX ISA version that introduced each. - 9.7.16.2. Matrix Data-types — the multiplicand and accumulator data-type combinations allowed in a matrix multiply-accumulate.
- 9.7.16.3. Block Scaling for mma.sync — block-scaled
mmawith.kind::mxf8f6f4,.kind::mxf4and.kind::mxf4nvf4: scale matrix shapes, valid type combinations and the selector components. - 9.7.16.4. Matrix multiply-accumulate operation using wmma instructions — the
wmma.load,wmma.mmaandwmma.storeinstructions and the organization of their matrix fragments and storage. - 9.7.16.5. Matrix multiply-accumulate operation using mma instruction — the
mmainstruction, its per-shape register fragments, and theldmatrix,stmatrixandmovmatrixhelpers. - 9.7.16.6. Matrix multiply-accumulate operation using mma.sp instruction — the sparse
mma.spinstruction, sparse matrix storage and its per-shape fragments.