How a warp cooperates on a matrix tile
Follow a CUDA warp-level matrix operation and distinguish its input fragments from its accumulator.
Before you run
A warp can perform a matrix multiply-accumulate collectively. This example gives one warp two row-major 16 × 16 FP16 tiles and a 16 × 16 FP32 accumulator. A and B contain 1.0 throughout. Each output receives a 16-term dot product plus its starting accumulator.
Definitions
- Accumulator
- A running sum that keeps earlier contributions when another product is added.
- WMMA
- CUDA’s warp-level matrix multiply-accumulate interface.
- Fragment
- The portion of a matrix tile stored in a thread’s registers for a warp-wide operation.
Read the starter excerpts
Read-only CUDA C++ · tile · kernel body excerpt
w::fill_fragment(sum, startingValue);
w::load_matrix_sync(left, a, 16);
w::load_matrix_sync(right, b, 16);
w::mma_sync(sum, left, right, sum);
w::store_matrix_sync(c, sum, 16, w::mem_row_major);Inside tile, left and right are FP16 matrix fragments and sum is an FP32 accumulator fragment. fill_fragment sets the initial accumulator; the loads use a row stride of 16 elements. All 32 threads call the same warp-wide operations with matching pointers and parameters.
CUDA C++ · launch inside main()
tile<<<1, 32>>>(deviceInput, deviceInput, output);The settings inside <<< >>> give the block count and threads per block. Parentheses pass the arguments to the kernel. These read-only excerpts show the starter. The CUDA source editor contains the storage and launch settings.
Edit and run CUDA
The CUDA source editor opens with the complete starter or your saved draft. To run the starter again, use Editor tools → Restore starter. Choose Undo restore there to recover the previous draft.
Click Compile and run with the starter. Find C[0,0] in Console. The starter accumulates into a tile filled with 0.0.
Change the source
In the CUDA source editor, inside tile, change startingValue from 0.0f to 4.0f. Predict C[0,0], then run again and check C[0,0] in Console. Does the matrix operation replace the starting value or add to it? Optionally open Inspect generated PTX to locate the matrix instructions.
Read the starter’s execution diagram
- A and B fragmentsEach operand holds part of an FP16 tile.
- Warp multipliesThe warp executes a collective matrix operation; all 32 lanes participate.
- Accumulator fragmentAdd the dot products to the FP32 values already here.
The warp can use the updated accumulator again with a new pair of input tiles.
Hardware context
Tensor cores are matrix execution units inside an SM. A warp collectively supplies register fragments for matrix instructions. WMMA’s fragment layout is device-dependent; a source tile is not a diagram of individual tensor-core units.
Read the hardware key
- Resident warp
- A warp has 32 lane positions; a small block can leave some unused. A resident warp has its state and required resources allocated on an SM. Its next instruction may still be waiting for data.
- Instruction
- One operation run by GPU hardware, such as a load, multiply or store.
- Warp scheduler
- Selects ready warp instructions for available execution hardware.
- Registers
- Hold working values associated with individual threads.
- Execution units
- Perform arithmetic and other instructions for threads; they are shared hardware.
- Load/store units
- Execute memory instructions, forming requests from active lanes’ addresses.
- L1 / L2 cache
- Keep recently used data on the GPU chip. L1 is local to an SM; L2 is shared across SMs in this simplified view.
- Shared memory
- SM-local storage allocated to blocks for explicit data exchange. It may share physical storage with L1, depending on the GPU.
- Bank
- A subdivision of shared memory that serves a group of word addresses.
- Tensor cores
- Matrix execution units used by supported warp-wide matrix instructions.
CPU side · CUDA host
Host ↔ device · copies move data; launches request execution
GPU device
GPU compute chip
SM · streaming multiprocessor
Logical groups using this SM’s resources
Issue to the appropriate units
Registers ↔ execution units · operands and results
Have their own execution hardware and registers.
Blocks may be assigned to different SMs.
Global-memory requests ↔ on-chip interconnect
Chip ↔ device memory · data transfers
Simplified NVIDIA-style architecture. Boundaries show containment; arrows name relationships. Unit counts, block placement and timing vary by GPU. A thread or warp is not a dedicated physical processor.
Explore the model: warp-wide matrix calls
Predict and run
Try it
Set Starting accumulator value to 0.0 and predict C[0,0], then click Run model. Inspect the Collective call table. Change the accumulator to 4.0, predict again and rerun: which call preserves and adds to the starting sum?
These controls change only this model and its displayed excerpt; they do not edit the CUDA program above. Enter a prediction to compare with the model result.
CUDA C++ excerpt
// Device body; #include <mma.h>. One complete warp.
// A and B: aligned FP16 16 × 16 arrays. C: aligned FP32.
namespace w = nvcuda::wmma;
w::fragment<w::matrix_a, 16, 16, 16,
__half, w::row_major> a;
w::fragment<w::matrix_b, 16, 16, 16,
__half, w::row_major> b;
w::fragment<w::accumulator, 16, 16, 16, float> c;
w::fill_fragment(c, 0.0f);
w::load_matrix_sync(a, A, 16);
w::load_matrix_sync(b, B, 16);
w::mma_sync(c, a, b, c);
w::store_matrix_sync(C, c, 16, w::mem_row_major);All 32 threads call the same operations with the same tile pointers. The 16 passed to each load or store is the row stride in elements. The arithmetic model shows a single output coordinate and the collective dataflow. Fragment-to-lane placement depends on the device.
Apply what you saw
If the warp uses a second tile pair with a dot product of 8.0, what should it pass as the fourth argument to keep the existing 16.0?
Compare your explanation
Pass c, the existing accumulator fragment. The next operation adds 8.0 to 16.0, producing 24.0 in that coordinate.
Follow a warp-level matrix operation through an SM 1 min 46 sec · Video walkthrough, captions and transcript
Use fullscreen to inspect the code and diagram labels.
Read the transcript
A matrix tile is a collective operation
The starter’s two sixteen-by-sixteen input matrices contain ones. One warp cooperates on the matrix operation. Follow the data through that cooperation instead of assigning an output element to a particular lane.
Fragments are distributed working state
A fragment is the matrix API’s container for part of the collective operation’s working state. The fragment layout across lanes is implementation-dependent. The diagram therefore groups fragments by role, not by an invented lane-to-element mapping.
The SM supplies matrix arithmetic hardware
The warp-level matrix call uses the SM’s matrix execution capability with the input fragments and accumulator. It is a collective call. The API operation is not a promise about one particular machine instruction or a fixed execution duration.
The initial accumulator contributes to the result
For C at row zero and column zero, sixteen products of one contribute sixteen point zero. The initial accumulator is zero. The final store writes the collective result back to GPU memory.
Start the accumulator at five
Now consider startingValue equal to five point zero, with the same input matrices and warp. Pause and predict C at row zero, column zero. Does changing that starting value require a different set of cooperating threads?
The same warp adds into a different starting value
The selected output becomes twenty-one point zero: five plus the sixteen products. The same warp still participates collectively. Fragments supply operands and working state; the SM supplies shared matrix hardware; GPU memory receives the stored result.
References warp matrix functions · SIMT architecture
The browser exercises need no installed CUDA documentation version. For local execution, use the documentation matching your toolkit. External references need internet access.
- CUDA · warp matrix functions (new tab)
Warp matrix calls require matching warp participation. Fragments do not specify a portable per-lane coordinate layout.
May half a warp skip mma_sync because those lanes have no output coordinate assigned by your source?
Compare your answer
No. The warp-wide operation requires the documented matching participation. Fragment elements do not define a portable per-lane matrix-coordinate layout.
- CUDA · SIMT architecture (new tab)
A warp instruction uses its participating lanes. Different branch paths can execute with different active lane sets.
When lanes follow different paths, does each lane acquire its own physical processor for its path?
Compare your answer
No. Threads remain logical executions using shared SM resources. Different paths use participating lane sets; details of instruction issue and reconvergence depend on the architecture.
Further GPU investigation Run this CUDA example on an NVIDIA GPU
In the CUDA source editor, open Editor tools and choose Export .cu to save the complete program. Use an NVIDIA GPU and a matching CUDA toolkit to run it outside the browser.
Browser simulation checks program behaviour; physical GPU timing requires a hardware measurement.
Enable JavaScript to save completion.