GPU Tiling: How Data Reuse Works and How to Choose Tile Sizes
GPU tiling splits a large computation into smaller regions so each region can reuse input data before fetching it again. Learn how output and reduction tiles map to GPU execution, why larger tiles also consume resources, and how to compare a safe candidate against a baseline.
GPU Tiling: How Data Reuse Works and How to Choose Tile Sizes
GPU tiling divides a large computation into smaller regions and assigns the work so that data for each region can be reused from nearby storage. In matrix multiplication, a block loads pieces of the input matrices, then reuses them while computing a region of the output. The goal is not simply to make tiles small: it is to balance reduced data movement against storage use, synchronization, and wasted work at the boundaries.
This article uses square, single-precision matrices stored in row-major order to explain C = A × B. The ideas also apply to other regular-grid computations, but the useful shape and storage location depend on the workload and GPU. No tile size is assumed to be fastest on every device.
What problem does GPU tiling solve?
Suppose the full input is in GPU global memory and each result needs some of the same input values repeatedly. Without tiling, separate output calculations may request the same values again. Caches can satisfy some repeated loads without every request reaching device memory, but explicitly organizing work around reusable regions makes the intended reuse and data flow easier to control.
A tile is a logical piece of work; shared memory is only one possible place to hold it. Depending on the kernel and programming model, data can be reused in registers, caches, shared memory, or another storage level. Tiling does not automatically pin data in a particular memory or guarantee a speedup. For the roles and scopes of GPU storage, see the GPU memory hierarchy overview.
Where do tiles fit in GPU computation?
For matrix multiplication C[M,N] = A[M,K] × B[K,N], a block can own a BM × BN region of the output and process the reduction dimension K in chunks of BK. A tile shape is therefore often described by three values: (BM, BN, BK). For each K chunk, the block reads an A region of BM × BK and a B region of BK × BN, then accumulates their products.
High-performance kernels can use several levels rather than one tile size. A block or threadblock can gather input regions from global memory; warp-level tiles divide the calculation among groups of threads; and each thread can accumulate a smaller set of values in registers. NVIDIA CUTLASS describes this hierarchy at threadblock, warp, and thread levels, with each level corresponding to both GPU execution parallelism and a level of the memory hierarchy. This is one documented design model, not a rule that every kernel must use identical layers.
| Work unit | Work it commonly divides | What to check |
|---|---|---|
| Block/threadblock | A large output region and repeated K chunks | Are there enough blocks to occupy the device, and do resource needs fit? |
| Warp or subgroup | A portion of the block tile to load and compute | Do thread cooperation and address layout match the data? |
| Thread/registers | Output values or fragments accumulated by one thread | Does each thread hold so much state that register pressure becomes a problem? |
This is a reader-friendly summary of the hierarchy in NVIDIA CUTLASS Efficient GEMM. GEMM means a general matrix-multiplication operation. The arithmetic behavior of multiply-accumulate or Tensor Core instructions themselves is outside this article's scope.
How does a tile reuse its inputs?
While calculating one output tile, each A value can be reused across several output columns that use the same A row. Each B value can be reused across several output rows that use the same B column. The flow below simplifies this work assignment; it does not represent a measured tile size or performance result.
Global memory: A region BM×BK ─┐ ┌─ B region BK×BN
└─ load input tiles ─┘
↓
Place in block-local storage
↓
Reuse for partial sums of a BM×BN output
↓ next K region
Repeat accumulation, write resultFor example, let one block calculate a 16×16 output region for one K chunk of 16 elements. That requires 16×16×16 = 4,096 multiply-accumulate operations. A simple implementation that calculates each of the 256 outputs independently requests 16 A values and 16 B values per output, or 8,192 input-element requests at the source-code level. A tiled implementation can load 256 A elements and 256 B elements once, then reuse them in the block: 512 input-element requests in total. In this simplified count, the number of input load requests is 16 times smaller.
This is an illustrative count of source-level requests. It ignores caches, compiler transformations, address alignment, synchronization cost, and boundary waste. It does not say that DRAM traffic or runtime improves by 16 times. NVIDIA's matrix-multiplication examples show how shared-memory tiles can avoid redundant transfers; the guide's measured numbers are specific to the named Tesla V100 example and should not be applied to this kernel or other hardware.
A 16×16 tiled matrix-multiplication example
The CUDA C++ kernel below is a teaching example: each block calculates a 16×16 output region and traverses K in chunks of 16. A, B, and C are non-overlapping row-major N×N arrays of float; N > 0; and the block dimensions are (16,16). The launch grid needs N / 16 + (N % 16 != 0) blocks on each axis and must fit the target device's grid limits.
#include <cuda_runtime.h>
#include <cstddef>
template <int TILE>
__global__ void matmulSquareTiled(
const float* A, const float* B, float* C, int N) {
static_assert(TILE > 0);
__shared__ float aTile[TILE][TILE];
__shared__ float bTile[TILE][TILE];
const int tx = threadIdx.x;
const int ty = threadIdx.y;
const std::size_t n = static_cast<std::size_t>(N);
const std::size_t row =
static_cast<std::size_t>(blockIdx.y) * TILE + ty;
const std::size_t col =
static_cast<std::size_t>(blockIdx.x) * TILE + tx;
const int tileCount = N / TILE + (N % TILE != 0);
float sum = 0.0f;
for (int t = 0; t < tileCount; ++t) {
const std::size_t aCol =
static_cast<std::size_t>(t) * TILE + tx;
const std::size_t bRow =
static_cast<std::size_t>(t) * TILE + ty;
aTile[ty][tx] = (row < n && aCol < n)
? A[row * n + aCol] : 0.0f;
bTile[ty][tx] = (bRow < n && col < n)
? B[bRow * n + col] : 0.0f;
__syncthreads();
for (int k = 0; k < TILE; ++k) {
sum += aTile[ty][k] * bTile[k][tx];
}
__syncthreads();
}
if (row < n && col < n) {
C[row * n + col] = sum;
}
}Out-of-bounds inputs are filled with zero, so a final tile can be computed when N is not a multiple of 16. Threads outside the matrix do not return early; every thread in the block still reaches both __syncthreads() calls on every loop iteration. The first barrier makes tile writes complete before reads begin. The second prevents a later iteration from overwriting shared storage while another thread may still be reading it. This code illustrates data flow; it has not been compiled, run, or benchmarked. A real application also needs error checking and decisions about data types, accuracy, and device limits.
How should you choose tile sizes?
Increasing a tile may let each input be reused for more output work, but it also increases the storage and state required by a block. A large output tile may not fit the shape of the problem; a small tile may increase the number of K chunks, loads, or synchronization points. CUTLASS notes that a larger threadblock tile can reduce global-memory fetches yet waste threads for small M or N dimensions or create too few blocks to use all multiprocessors.
| Dimension changed | Potential benefit | Costs that may also increase |
|---|---|---|
Output dimensions BM, BN | Reuse each input for more outputs; fewer blocks | More shared memory, accumulators, and registers; idle threads on small problems; too few parallel blocks |
K dimension BK | Fewer loop iterations and some synchronization points | Larger input storage, longer computation stages, and more masked work at the boundary |
| Outputs per thread | Keep more accumulators in registers and avoid memory round trips | Register pressure or spills, and fewer resident warps |
If a simple design stores both BM × BK and BK × BN input tiles as shared-memory float arrays, their theoretical element capacity is 4 × (BM×BK + BK×BN) bytes. This is only the array-capacity calculation; it is not the amount the compiler will allocate or the full resource use of the kernel. In CUDA, register use, shared memory, and launch configuration all influence active warps and occupancy. A higher occupancy value alone does not prove that a kernel is faster.
Start from the input shape and access pattern. Do not automatically choose square tiles: check whether a matrix is long and narrow, whether one dimension is very small, and how much work falls outside the last tile. Then compare resource use and end-to-end time. A tile tuned for one GPU generation or vendor is not automatically right for another.
When can tiling make a kernel slower, and what should you measure?
If data are reused very little, or repeated accesses already fit in cache, the loads and synchronization for staging a tile may cost more than they save. An oversized tile can leave many threads idle at the edge or create too few blocks for all SMs/CUs. Tiles that are too small may request the same input more often and add loop or barrier overhead.
| Observed symptom | Possible cause to check | Next action |
|---|---|---|
| Runtime barely changes after tiling | Cache already handles repeated loads, or arithmetic is the bottleneck | Check memory and compute pipeline evidence; identify the cost tiling was meant to reduce |
| A larger tile is slower | More registers or shared memory, spills, or fewer resident blocks | Check compiler resource reports and profiler data; reduce one dimension and compare |
| Only small inputs get slower | Launch and tile setup cost more than the work | Compare a simpler path against the actual input distribution |
| Results differ for aligned and unaligned sizes | Tail mask, final K chunk, early return, or accumulator initialization | Compare boundary sizes such as N=1, TILE-1, TILE, and TILE+1 against a reference |
| Expected memory improvement is absent | Misaligned addresses or uncoalesced thread accesses | Inspect lane addresses, global-memory transactions, and shared-memory bank accesses separately |
NVIDIA Nsight Compute provides Roofline analysis relating arithmetic intensity to measured compute and memory throughput, memory-workload analysis, and launch information such as register and shared-memory use. These metrics help identify what to investigate; they do not prove that changing one tile will make every workload faster. AMD HIP likewise uses matrix-multiplication tiles to illustrate reusing data from shared memory (LDS) and balancing memory access with resources. Confirm metric names and availability for the installed tool and GPU.
Should you write a custom kernel or use a library?
If the task is a standard matrix multiplication, first inspect the supported matrix-operation library API for the target platform. For example, NVIDIA cuBLAS provides GEMM APIs. A library path can serve as a correctness and performance baseline for a custom kernel, but do not assume a particular call is faster for every small shape or full application; measure representative inputs.
A custom tiled kernel is more worth considering when it can combine matrix multiplication with another operation to remove intermediate data movement, or when a special shape or data flow is central and the standard API cannot express it. Separate the effect of tiling from the effect of fusion or other changes when you compare results. Multiply-accumulate precision and Tensor Core instruction details are separate topics.
A practical sequence for checking a tiled kernel
Choose a reference implementation and accuracy requirement. Record the target GPU, compiler/toolkit, input dimensions, and data distribution.
Identify which values are reused by which outputs, then select a candidate `(BM, BN, BK)` and thread mapping.
Compare both regular and boundary inputs. Check masked values in the last tile, participation in every barrier, accumulator initialization, and that A, B, and C do not overlap.
Inspect compiler register data and shared-memory use; use the target profiler to collect runtime, memory traffic, compute throughput, and occupancy-related evidence.
Change one tile dimension or one mapping choice at a time. With the same inputs, compare kernel and application time plus output error against the reference.
Tiling is a way to express a data-movement optimization in the computation's structure. Its effect depends on reuse, tile shape, memory access, device resources, and available parallel work. Do not choose the final shape from the logical-load example alone; measure on the target workload, including boundary and resource costs.
References
[NVIDIA CUDA C++ Best Practices Guide — Matrix Multiplication and Shared Memory](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html)
[NVIDIA CUTLASS — Efficient GEMM in CUDA](https://docs.nvidia.com/cutlass/4.3.2/media/docs/cpp/efficient_gemm.html)
[NVIDIA CUDA Programming Guide — Writing SIMT Kernels](https://docs.nvidia.com/cuda/cuda-programming-guide/02-basics/writing-cuda-kernels.html)
[NVIDIA Nsight Compute — Profiling Guide](https://docs.nvidia.com/nsight-compute/ProfilingGuide/index.html)
[AMD HIP — Performance Guidelines](https://rocm.docs.amd.com/projects/HIP/en/latest/how-to/performance_guidelines.html)
[NVIDIA cuBLAS Documentation — GEMM APIs](https://docs.nvidia.com/cuda/cublas/)