0Pricing
CUDA Academy · Lektion

Stencil und gleitende Fenster

Kacheln Sie Nachbarschaften mit Halo-Zellen.

Stencil und gleitende Fenster ist eine kostenlose CUDA Academy-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des CUDA Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der CUDA Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

What a Stencil Is

A stencil computes each output from a fixed neighborhood of inputs, like averaging a pixel with the cells around it.

The Sliding Window

As you move along the array, the input window slides by one. Consecutive outputs share most of their inputs, so reuse is huge.

Perfect for Tiling

Because neighbors overlap, a tile loaded once feeds many outputs. Stencils are a textbook case where tiling shines.

Meet the Halo

To compute the edges of a tile you also need a few elements just outside it. Those extra border cells are called the halo.

Why the Halo Exists

The first thread in a tile needs its left neighbor, which belongs to the previous tile. Without halo cells that read goes wrong.

Sizing the Halo

For a radius-r stencil you load r extra cells on each side. A 3-point blur has radius 1, so one halo cell per side suffices.

A Padded Tile

Declare shared memory as blockDim plus 2 * radius so it holds the interior plus both halos in one tidy buffer.

__shared__ float tile[BLOCK + 2 * RADIUS];

Loading the Interior

Each thread first loads its own element into the tile at an offset of radius, leaving room for the left halo in front.

tile[threadIdx.x + RADIUS] = in[gid];

Loading the Halos

The first few threads do double duty, also fetching the left and right halo cells before the block synchronizes.

Then Sync and Stencil

After __syncthreads, each thread reads its neighbors entirely from the tile, never touching global memory again for that step.

Reuse Multiplier

Every interior value now serves 2r + 1 outputs from one shared-memory load. That is exactly the redundant traffic tiling removes.

Quick Check

Why does a tiled stencil need halo cells?

Recap

Stencils slide overlapping windows, so a halo of r extra cells per side lets a tile serve every output with one load each. ✅

Häufig gestellte Fragen

Ist die Lektion „Stencil und gleitende Fenster“ kostenlos?

Ja — der vollständige Text von „Stencil und gleitende Fenster“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des CUDA Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der CUDA Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Stencil und gleitende Fenster“?

Kacheln Sie Nachbarschaften mit Halo-Zellen. Du übst CUDA Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um CUDA Academy zu starten?

Keine Vorkenntnisse erforderlich. CUDA Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.

Wie lange dauert die Lektion „Stencil und gleitende Fenster“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser CUDA Academy-Lektion Code schreiben und ausführen?

Ja. Jede CUDA Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Das Problem der Datenwiederverwendung
  2. Das Load-Sync-Compute-Muster
  3. Stencil und gleitende Fenster
  4. Randkacheln verarbeiten
← Zurück zu CUDA Academy