advanced24 min studyLesson 474 in Engineering

Tensor Core operands: a matrix instruction still needs a layout contract

Separate matrix shape, memory layout, fragment mapping, operand precision, and accumulation precision in an architecture-scoped Tensor Core path.

On this page

What you’ll understand

  • Explain leading dimensions and row/column layout for a supported matrix operation.
  • Distinguish input quantization from accumulation and output conversion.
  • Identify collective participation and architecture constraints before using a matrix API.

Tensor Core instructions accelerate particular matrix operations, not arbitrary arrays whose pointers happen to be nearby. A valid path must agree on shapes, layout, alignment, data types, and collective execution. Higher accumulation precision can reduce one source of numerical error without restoring information already lost while converting inputs. Treat those contracts as part of correctness before inspecting throughput.

Memory layout is distinct from a fragment's lane mapping

In a row-major matrix, the leading dimension gives the element distance between successive rows; in a column-major matrix it gives the distance between successive columns. Padding can make that distance larger than the visible row or column length. Declaring the wrong layout can compute a different product even when every access remains inside an allocation. CUDA 12.8's WMMA interface specifies supported shape/type combinations, pointer alignment, leading-dimension constraints, and uniform arguments. These requirements describe that interface rather than every matrix instruction on every accelerator.

A WMMA fragment distributes a matrix tile across a cooperating NVIDIA warp, and the documented element-to-lane mapping is not a portable row-major array layout. Do not infer that one fragment index always names a particular global matrix coordinate across architectures or compilation targets. The collective calls require appropriate participation by all warp threads and uniform control flow under the documented contract. Later architectures also expose different asynchronous or warp-group mechanisms. A working warp-level example is not proof that the same synchronization and fragment assumptions apply to all those paths.

arow(i,j)=b+e(i ld+j),acol(i,j)=b+e(i+j ld)a_{\rm row}(i,j)=b+e(i\,ld+j),\qquad a_{\rm col}(i,j)=b+e(i+j\,ld)
b is the matrix origin byte address, e is bytes per element, and ld is the leading dimension in elements. Both formulas require valid indices, enough backing storage, and the chosen API's alignment and stride constraints. They describe memory layout, not an unspecified fragment-to-lane mapping.↔ Scroll wide equations horizontally.

Input, accumulator, and output formats are separate choices

Consider a supported NVIDIA mixed-precision path with FP16 multiplicands and FP32 accumulation. Conversion to FP16 changes the values entering multiplication; FP32 accumulation then operates on those represented inputs under its instruction semantics. Converting the final result back to FP16 adds another rounding stage. FP16 and BF16 both use sixteen storage bits but allocate exponent and significand bits differently, so they are not interchangeable error models. TF32 and other modes have their own contracts. Record the actual library or compiler settings instead of assuming a float32 tensor necessarily implies full-precision scalar multiplication.

A useful reference comparison first separates error relative to the original real-valued problem from error relative to the quantized-input problem. A wider accumulator can improve the latter without fixing the former. Overflow, underflow, cancellation, reduction order, and output conversion remain relevant. Specialized matrix instructions can also have documented accumulation details that differ from a sequential scalar reference. Validate the intended accuracy against representative and difficult inputs, and do not require bitwise equality unless the operation and execution contract actually promises it.

∣(a+δa)⊤(b+δb)−a⊤b∣≤∑i(∣δai∣∣bi∣+∣ai∣∣δbi∣+∣δaiδbi∣)\left|(\mathbf a+\delta\mathbf a)^\top(\mathbf b+\delta\mathbf b)-\mathbf a^\top\mathbf b\right|\leq\sum_i\left(|\delta a_i||b_i|+|a_i||\delta b_i|+|\delta a_i\delta b_i|\right)
This real-arithmetic triangle-inequality bound isolates input perturbations for equal-length finite vectors. Values are dimensionless here. It excludes accumulation and output-rounding errors, which must be added to a complete numerical analysis.↔ Scroll wide equations horizontally.

Use a supported path and test the exact contract

Check device capability, selected kernel implementation, supported element combinations, dimensions, alignment, and tail handling. A compiler or library can choose a fallback when a specialized path is unavailable, so dtype and source-level intent do not prove instruction selection. Inspect the generated path or relevant profiler evidence. Benchmark against a library configured for the same precision policy, including any input conversion and layout transformation that production needs. A fast inner multiply can lose end-to-end if its preparation or output handling dominates.

The matrix lab illustrates conditioning without simulating matrix hardware. Reset, set a=1 and shear b=0, predict singular values one and one and condition number one, then Play or Step. Separately Reset, set a=0.25 and b=0, predict singular values one and 0.25 and condition number four, then Play or Step. The readouts always describe the selected final triangular matrix, while playback interpolates geometry. It does not quantize operands or represent WMMA fragments. Use the changing sensitivity as a reason to test precision choices on more than one convenient input family.

A wider accumulator cannot reconstruct a rounded input

Use round-to-nearest, ties-to-even conversion to IEEE binary16 for the four inputs 1, 1+2⁻¹¹, 1, 1, then take their dot product with four ones using a sufficiently precise accumulator.

  1. Near one, binary16 spacing is 2⁻¹⁰. The value 1+2⁻¹¹ is halfway between one and the next representable value, so the stated tie rule rounds it to one.

  2. The converted-input dot product is therefore 1+1+1+1=4. These tiny exact values can be accumulated without needing to recover the discarded half-spacing.

  3. The original real-valued dot product is 4+2⁻¹¹=4.00048828125. Its difference from four arose in input conversion; changing only accumulator precision cannot restore it.

The result

Input quantization and accumulation error require separate baselines. This hand calculation is not a measurement of any particular Tensor Core instruction.

Explore the model

Interactive lab

Interactive lab · matrix

Sensitivity can change while storage width stays fixed

Reset, set a=1 and b=0, predict κ₂=1, then Play or Step. Separately Reset, set a=0.25 and b=0, predict singular values 1 and 0.25 and κ₂=4, then Play or Step. Readouts describe the selected final matrix; the geometry interpolates. This lab has no operand formats, Tensor Cores, or fragment layout.

Sensitivity can change while storage width stays fixedThe selected matrix is A = [[a,b],[0,1]]. Playback interpolates geometry between the identity and A; readouts always describe A. Its determinant is a and its singular values come from AᵀA. Positive a makes every supported matrix invertible. This two-dimensional family is not a general eigensolver or a learned network. Current readings: Area scale · det A: 1.4; Singular values · σmax, σmin: 1.597, 0.876; Condition number · κ₂(A): 1.823. All parameters are adjustable with the labeled controls below.Matrix A with first row 1.4, 0.6 and second row zero, one; display interpolates between identity and A while final determinant remains 1.4.−4−2024−2−1012x · equal geometric scaleyA = [ 1.4 0.6 ; 0 1 ]Display blend: 0% · final values below
Interpolated geometryOriginal unit squareSelected final transform
Area scale · det A
1.4
Singular values · σmax, σmin
1.597, 0.876
Condition number · κ₂(A)
1.823
t = 0 s

The selected matrix is A = [[a,b],[0,1]]. Playback interpolates geometry between the identity and A; readouts always describe A. Its determinant is a and its singular values come from AᵀA. Positive a makes every supported matrix invertible. This two-dimensional family is not a general eigensolver or a learned network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forPrecision validation depends on the numerical problem as well as the chosen accumulator.

Check your understanding

What can FP32 accumulation guarantee about information lost when original inputs were converted to FP16?

Try it yourself

A row-major four-byte matrix has leading dimension 8 and base address 4,096. Find element (2,3)'s address. Explain why this alone does not prove a WMMA load is valid.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Compute the element offset, then separate ordinary addressing from the collective API contract.

Compare with the solution

The element offset is 2×8+3=19, giving address 4,096+4×19=4,172. A valid matrix load still needs enough storage, correct shape/type/layout, required alignment and leading-dimension constraints, and proper collective participation. A correct scalar address is only one part of that contract.

Take it with you

  • Matrix memory layout and fragment lane mapping are separate contracts.
  • Input conversion, accumulation, and output conversion introduce different errors.
  • Specialized hardware paths require architecture-scoped validity and measured instruction selection.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.