Ein zweidimensionales Gitter mit nummerierten Zellen. Eine Schablone (Stencil) ist über eine mittlere Zelle gelegt und markiert die vier direkten Nachbarn (oben, unten, links, rechts) sowie die Zelle selbst. Ein Pfeil zeigt, wie aus diesen fünf Werten ein einziger neuer Wert für die mittlere Zelle im rechts daneben gezeigten neuen Gitter berechnet wird.

Stencil Computation

A stencil computation is a computational pattern in which the new value of a data point is always calculated from its direct neighbors – the same pattern, everywhere and repeated over and over. It forms the basis of many simulations in science and engineering, from weather models to chip design.

Imagine a sheet of graph paper, with each square containing a number. In a stencil computation, the value of every square is replaced by a new value — calculated from the square itself and its immediate neighbors. The crucial point: the same computation rule applies to every square across the entire grid. This process repeats many times, step by step. This way, a temporal evolution emerges from an initial state, for example how heat spreads through a metal rod.

Stencil computations as the backbone of simulations

This pattern sounds simple, but it underlies some of the most computationally intensive tasks there are. Weather forecasts divide the atmosphere into a three-dimensional grid and calculate, for every point, how temperature, pressure, and humidity evolve from the neighboring points. The same principle applies to flow simulations in aviation or to physical models in chip design.

Why does this matter as its own concept? Because the regularity of the pattern makes it possible to make the computation extremely efficient. If you know that the same structure always applies, you can tailor hardware and software specifically to it. Many supercomputers and graphics processors — chips originally built for game graphics but now used for scientific computations — are optimized exactly for such regular, parallel patterns.

How a stencil step works

The term “stencil” comes from the English word for a template. The stencil defines which neighbors enter the calculation and with what weight. A simple one-dimensional stencil might read: “New value = 0.25 × left neighbor + 0.5 × current value + 0.25 × right neighbor.” This stencil is placed over every point on the grid, and its new value is calculated. Then the stencil moves one position further.

It is important that the old values always serve as the basis for this calculation. They are not overwritten directly; instead, the new values are written into a separate grid. Only once all points have been fully calculated does the new grid become the current one. This procedure is called double buffering: you always work with two copies of the data to avoid errors caused by overwritten neighbor values.

The size of the stencil varies depending on the problem. A simple heat stencil in two dimensions considers four direct neighbors. More complex stencils draw on neighbors two or three fields further away and become correspondingly more computationally intensive.

Where stencil computations appear in practice

In image processing, the principle has been standard for decades. Blur filters and edge-detection filters in image editing programs like Photoshop are nothing other than stencil computations on a two-dimensional pixel grid. Every pixel gets a new color value calculated from its neighboring pixels.

In AI research, the pattern appears in so-called convolution operations, which form the heart of image recognition systems. A convolutional layer in a neural network — a system roughly modeled on the structure of the human brain — slides a small template over an image and calculates a new value at every position. This is structurally identical to a stencil computation. Many hardware accelerators built today for AI training therefore benefit directly from decades of research into stencil methods.

In the news, the term usually appears in connection with high-performance computers. When a new supercomputer is introduced, stencil benchmarks — standardized tests that measure how quickly a system executes stencil steps — are regularly part of the performance measurement. They are considered representative of how well a computer handles real-world scientific simulations.

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.