Loop tiling is a loop transformation that partitions a loop's iteration space into smaller blocks or tiles to improve data locality and reuse within cache hierarchies. By restructuring nested loops to operate on sub-blocks of data, this technique reduces expensive accesses to slower main memory, which is a critical bottleneck for matrix multiplication and convolution kernels in deep learning. It is a core strategy in hardware-aware model optimization for NPUs.
Glossary
Loop Tiling

What is Loop Tiling?
Loop tiling is a fundamental compiler optimization for enhancing memory performance in compute-intensive workloads, particularly for neural network execution on NPUs.
The compiler determines optimal tile sizes based on hardware constraints like cache capacity and memory bandwidth. This transformation increases arithmetic intensity—the ratio of computation to memory operations—maximizing the utilization of parallel compute units. It is closely related to loop fusion and kernel auto-tuning, and is essential for generating efficient code in graph compilation strategies for neural processing units.
Key Characteristics of Loop Tiling
Loop tiling is a fundamental compiler transformation that restructures nested loops to partition the iteration space into smaller blocks, optimizing for data locality and memory hierarchy efficiency.
Core Mechanism: Partitioning Iteration Space
Loop tiling, also known as loop blocking, transforms a loop's iteration space by introducing new, outer loops that step through the space in fixed-size blocks (tiles). The original inner loops then iterate within each tile. This restructuring is defined by a tile size parameter. For a 2D loop nest, it changes access from a row-major traversal to a block-major traversal, fundamentally altering the memory access pattern to exploit temporal and spatial locality.
Primary Goal: Improving Cache Utilization
The principal objective of tiling is to maximize data reuse within the CPU's cache hierarchy. By working on a small tile of data, the computation can keep that tile resident in fast L1/L2 cache for the duration of its processing. This drastically reduces expensive accesses to slower main memory (DRAM). The effectiveness hinges on selecting a tile size that matches the capacity of the target cache level, ensuring the working set of a tile fits entirely within it.
Impact on Memory Access Patterns
Tiling transforms strided, often non-unit stride, memory accesses into localized, sequential accesses within a tile. For example, in matrix multiplication, accessing a column of a large matrix in the inner loop causes poor cache use due to cache line underutilization and capacity misses. Tiling ensures that both the row of matrix A and the column of matrix B are accessed in small, contiguous chunks, leading to efficient cache line fills and prefetching behavior.
Tile Size Selection and Trade-offs
Choosing the optimal tile size is a critical and non-trivial optimization problem. Key trade-offs include:
- Cache Capacity: Tile data must fit within the target cache (L1, L2, or TLB).
- Register Pressure: Smaller tiles may increase overhead; larger tiles may spill registers.
- Parallelism Granularity: Tile size affects load balancing in parallel execution.
- Hardware-Specific Factors: Cache line size, associativity, and prefetcher behavior. Kernel auto-tuning is often used to empirically search for the best tile size for a given hardware target.
Relation to Other Loop Optimizations
Loop tiling is frequently combined with other transformations to form a powerful optimization pipeline:
- Loop Fusion: Often performed after tiling to merge operations on the same tiled data.
- Loop Unrolling: Applied to the innermost loop within a tile to reduce branch overhead and enable instruction-level parallelism (ILP).
- Loop Vectorization: The contiguous, predictable accesses within a tile are ideal for SIMD vectorization.
- Loop Interchange: Can be used in conjunction with tiling to place the loop with the most reuse potential as the innermost loop within the tile.
Application in NPU/GPU Graph Compilation
In neural network compilation for NPUs and GPUs, tiling is essential for managing specialized memory hierarchies (e.g., global memory, shared memory, registers). Compilers like TVM or MLIR apply tiling to map convolutional and matrix multiplication loops onto hardware resources. The tile sizes are chosen to maximize data reuse in fast scratchpad memory (SRAM) and minimize transfers to/from slow High-Bandwidth Memory (HBM). This is a cornerstone of hardware-aware model optimization.
Loop Tiling vs. Related Loop Optimizations
A feature comparison of loop tiling against other key compiler transformations used to optimize loop nests for memory hierarchy and parallelism.
| Optimization Feature | Loop Tiling | Loop Fusion | Loop Vectorization |
|---|---|---|---|
Primary Objective | Improve data locality & cache reuse | Reduce loop overhead & improve locality | Exploit data-level parallelism (SIMD) |
Transformation Type | Iteration space partitioning | Loop merging | Instruction-level parallelization |
Key Mechanism | Blocks (tiles) inner & outer loops | Fuses adjacent loops with same bounds | Uses vector/SIMD instructions on arrays |
Memory Hierarchy Target | Cache (L1/L2/L3) | Register & cache | Vector registers |
Impact on Parallelism | Enables coarse-grained (thread-level) parallelism | May limit parallelism by fusing loops | Enables fine-grained (instruction-level) parallelism |
Compiler Pass Integration | Often combined with fusion & vectorization | Precursor or follow-on to tiling | Often applied after tiling within a tile |
Typical Use Case | Dense linear algebra (matmul, convolutions) | Element-wise operations on same data | Inner loops with independent iterations |
Hardware Benefit | Reduces DRAM bandwidth pressure | Reduces loop control instructions | Increases computational throughput per cycle |
Implementation in Frameworks & Compilers
Loop tiling is a foundational optimization implemented within ML compilers and frameworks to restructure computation for efficient execution on NPUs and other accelerators. This section details its specific implementations and related compiler passes.
MLIR Dialects and Transformations
Within the MLIR compiler infrastructure, loop tiling is expressed as a transformation on the affine or scf (Structured Control Flow) dialects. A typical lowering pipeline involves:
- Applying the
tiletransformation with specific tile size parameters. - Generating tiled loops with explicit bounds for the outer (tile) and inner (intra-tile) loops.
- Subsequent passes like promotion move tiled data into fast memory (e.g., NPU scratchpad).
- The tiled representation is then lowered through
vectorandgpuor vendor-specific dialects for final code generation.
XLA's Operation Fusion & Tiling
Google's XLA compiler integrates tiling with its fusion optimizer. The process is:
- Loop analysis identifies multi-dimensional loops in HLO (High-Level Optimizer) operations like convolutions and matmuls.
- Tile size selection is often heuristic-driven or based on hardware parameters (e.g., tensor core dimensions for NVIDIA GPUs, systolic array dimensions for NPUs).
- Fusion decisions are made post-tiling; smaller, tiled loops are more amenable to being fused with adjacent operations, reducing global memory traffic. This creates compound operations optimized for a single hardware kernel launch.
Polyhedral Model Compilers (e.g., Pluto, PPCG)
Advanced polyhedral model compilers use affine transformation frameworks to derive optimal tiling hyper-planes mathematically. For NPU compilation:
- The iteration space of nested loops is modeled as a polyhedron.
- Transformations for locality (tiling) and parallelism are computed simultaneously.
- Dependence analysis ensures tiling is legal (does not violate data flow).
- This approach can find complex, non-rectangular tiles that maximize data reuse in multi-level memory hierarchies, which is essential for NPU efficiency.
Vendor SDK Intrinsics & Manual Tiling
Vendor NPU SDKs (e.g., NVIDIA TensorRT, Intel OpenVINO, ARM Compute Library) often expose low-level intrinsics or APIs that assume or require tiled data layouts.
- Kernels are pre-optimized for specific tile sizes (e.g., 4x4, 8x8, 16x16).
- The compiler's job is to transform the model's data layout to match this expected tiled format, often through layout transformation passes.
- Manual tiling hints can be provided via SDK APIs to override compiler heuristics for performance-critical sections.
Interaction with Related Optimizations
Loop tiling is rarely applied in isolation; it enables and interacts with other critical graph compilation strategies:
- Loop Fusion: Tiling creates smaller, uniform loops that are more easily fused with neighboring operations.
- Vectorization: The inner, intra-tile loop is a prime candidate for SIMD vectorization as it often operates on contiguous, aligned data.
- Memory Planning: Tiling directly informs scratchpad memory allocation and double buffering schemes to overlap computation and data movement.
- Parallelism: The outer tile loops often become targets for parallelization across NPU cores.
Frequently Asked Questions
Loop tiling is a fundamental compiler optimization for high-performance computing and neural network acceleration. These questions address its core mechanics, benefits, and implementation for NPU hardware.
Loop tiling is a loop transformation that partitions a loop's iteration space into smaller blocks or tiles to improve data reuse within cache hierarchies and enhance memory access performance. It works by restructuring nested loops. For example, a matrix multiplication loop over dimensions i, j, k is split into outer loops that step through the matrix in tile-sized blocks and inner loops that perform the computation within a single tile. This confines the working data set of the inner loops to a size that fits within the processor's cache, dramatically reducing expensive accesses to slower main memory (DRAM). The tile size is a critical parameter, often tuned for the specific memory hierarchy (L1, L2 cache sizes) of the target hardware, such as a Neural Processing Unit (NPU).
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Loop tiling is a foundational transformation within a broader ecosystem of compiler optimizations. These related techniques work in concert to restructure computation for optimal performance on modern hardware accelerators.
Loop Fusion
A compiler transformation that merges two or more adjacent loops with the same iteration space into a single loop. This optimization improves data locality by keeping intermediate results in faster cache levels and reduces loop overhead from separate kernel launches or loop control instructions. It is often applied before or in conjunction with loop tiling to maximize the benefit of each tile.
- Example: Fusing a convolution operation with its subsequent ReLU activation into a single loop.
- Key Benefit: Reduces the number of memory loads/stores for data shared between the fused operations.
Loop Vectorization
A compiler optimization that transforms scalar operations within a loop to use Single Instruction, Multiple Data (SIMD) instructions. This enables parallel execution on multiple data elements within a single CPU or NPU core. While tiling optimizes for cache hierarchy, vectorization exploits data-level parallelism within a core's execution units.
- Relationship to Tiling: The inner loops created by tiling are prime candidates for vectorization.
- Hardware Target: Essential for utilizing the wide vector units in modern NPUs and CPUs.
Memory Planning
A compiler optimization pass that allocates memory buffers for tensors in a computational graph, aiming to minimize peak memory usage. It works closely with transformations like tiling by determining the lifetime of data buffers. Effective memory planning enables in-place operations and buffer reuse across tiles and operators.
- Critical for Tiling: Determines if tile-sized buffers can fit in target cache or shared memory.
- Goal: Reduce expensive transfers to and from global DRAM, which is a primary objective of tiling.
Kernel Auto-Tuning
An automated process that searches a space of possible kernel implementation parameters to find the configuration that delivers optimal performance for a specific hardware target. For tiled loops, this involves empirically testing different tile sizes, unroll factors, and scheduling strategies to find the best combination.
- Direct Application: Used to find the optimal tile dimensions (Tx, Ty) for a given loop nest on specific hardware.
- Methodology: Often employs search algorithms like grid search, random search, or machine learning-based predictors.
Operator Clustering
A compiler technique that groups sets of operators within a computational graph into clusters, typically to be executed together on a specific hardware unit. This high-level grouping creates boundaries for lower-level optimizations. Loop tiling is then applied within these clusters to optimize the execution of the fused operation sequence.
- Compilation Flow: Clustering → Fusion → Tiling & Vectorization.
- Purpose: Isolates sections of the graph for targeted optimization and potential offloading to an NPU.
Data Layout Transformation
A compiler optimization that changes the in-memory data layout of tensors to align with the access patterns preferred by specific hardware or computational kernels. This transformation is highly synergistic with tiling. Choosing the correct memory layout (e.g., NHWC vs NCHW) can make the access patterns within a tile unit-stride, maximizing cache line utilization and prefetcher effectiveness.
- Performance Impact: A poor layout can negate the benefits of tiling by causing cache thrashing.
- Hardware-Specific: NPUs often have a strongly preferred layout for their matrix multiplication units.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us