Block FIR — a stateful accelerator, in fixed point, built two ways

This example builds on interleaver. That one added a real compute stage to a data mover; every firing of it was still independent — a gather reads its inputs, writes its outputs, and remembers nothing. fir_block is the first design in the tree where that stops being true.

A block FIR filters a signal y[i] = Σₖ h[k]·x[i−k] one block at a time. Two things therefore have to survive from one firing to the next:

  1. the coefficients h, loaded once by a LOAD_TAPS command and read by every FILTER after it;
  2. the tail of the previous block — the last T−1 samples — because y[0] of a block needs samples that arrived in the previous one.

Neither is a buffer passed between components, and neither is memory on the far side of a bus. Both are storage the module owns, declared with add_state. That is the headline of this example, and it is why the design is a filter rather than something smaller: it needs two flavours of state with different lifetimes in one module, so no single-flavour toy can stand in for it.

Two other things come with the territory. A filter is arithmetic, so this is the example where the fixed-point story is told end to end — one format for samples, coefficients and output, and an accumulator that is derived rather than hand-sized. And a filter is a loop, so it is the natural place to show that the same specification can be realized more than one way: fir_block ships two hand-written kernels computing bit-identical results, selected by one parameter, and measures what each costs.

On the word “firing”

This example needs two words that are easy to conflate, so they are used strictly throughout:

  • A firing is one execution of a task body — one job, one command. State persists across firings.
  • An iteration is one trip of a loop inside a body. The two kernels here differ in what happens per iteration of the filter loop.

They are independent axes: unroll_lane changes the iteration structure and does not change what a firing is, while add_state changes what survives a firing and does not change any loop. Every other page in the guide uses the words this way — see free-running codegen, where a task body is defined as one firing rather than a loop.

Learning Objectives

What this adds to Composite kernel interleaver, in the order the pages teach it:

  1. Give a module memory between firings with add_state: state loaded once and held (the taps), state carried from one firing to the next (the tail), and a declared reset path.
  2. Compute a filter in fixed point with one declared format, and derive the full-precision accumulator from the format algebra instead of sizing it by hand.
  3. Write two kernel bodies for one specification – one output per iteration, or a whole lane per iteration – and select between them with a compile-time parameter.
  4. Verify stateful hardware against a deliberately stateless golden, and write falsification tests that break each kind of state in turn.
  5. Keep every stage’s token count uniform across opcodes, so a command with no output still issues a (zero-length) transfer and lands its completion, and the pipeline cannot wedge.
  6. Sweep the bitwidth parameters and build a resource model from the results: a DSP prior from the DSP48’s geometry with nothing fitted, a fit only for the counters no closed form reaches, and a whole-design estimate that reports its confidence.

In this example

The pages build the design up from Python, parallel to interleaver:

  • Module overview — the filter, the four stages, one leaf dispatching two opcodes, and why the tap load deliberately does not overlap the compute.
  • Cross-firing state — the two flavours, add_state, where the static lands in a free-running task, the declared reset path, and the evidence that it survives in real RTL.
  • Fixed point — one format for everything, the derived accumulator, why the window reduction is fixed_sum and never a loop of add, and the width ceiling that lives in Python.
  • Python — building the design: the command/descriptor split, samples versus words, and the composite.
  • Testbench (Python) — the stateless golden, and the falsification tests that prove the gate can fail.
  • The two kernels — the serial and unrolled task bodies, the shared delay line, and the seeding rule that has bitten this kernel twice.
  • DUT codegen — the composite top, how unroll_lane selects a body, and the storage declarations generated straight from add_state.
  • RTL simulation — the generated BFM harness, the run, and bit-exactness for both realizations against one golden.
  • Resource models — what the design asserts about its own area: a zero-parameter DSP prior from the DSP48E1’s geometry, a BRAM prior that asserts zero, a LUT/FF fit over structural features, and the one method per class that installs them.
  • The sweep and its results — what 24 syntheses in 20 minutes actually showed, and a composed whole-design estimate checked against totals that trained none of it.

Table of contents

  • Module Overview - What the module computes, and why a block FIR is the next step after the interleaver: not the arithmetic, but that a firing is no longer self-contained. The first output of a block needs samples that arrived in the previous one, and nothing in the current firing's input contains them.
  • Cross-firing state - Using HwState for real: two storages with different lifetimes in one module, interacting — the coefficients, loaded once and held, and the carry tail, rewritten every firing. That pairing is the thing a single-storage example cannot show, and it is why this design exists.
  • Fixed point - The three decisions a real filter makes on top of the fixed-point guide: what format to declare, what to derive, and how the derived answer reaches the C++. Samples, coefficients and output share one format — Q2.14 by default — and the accumulator width is derived from it rather than chosen.
  • Python - Building the design in code: the two commands, the two custom leaves, and the composite that wires them to the framework mem-streams. The build is a BuildDag behind the standard CLI, so every stage is a --through target, and the first checkpoint runs the golden with no toolchain in seconds.
  • Testbench (Python) - The harder half: writing a check that can actually catch a state bug. Computing the expected output the same way the DUT does — block by block, carrying the tail — is nearly worthless, because a bug in how the carry is stored reproduces itself in the check. The gate on this page found a bug C-synthesis was perfectly happy with.
  • The two kernels - Two hand-written task bodies that compute bit-identical results and differ only in how much work an iteration does: one output per iteration, or a whole transport word at once. One boolean parameter picks between them, so the pair is a quality-of-results probe rather than two designs.
  • DUT codegen - Lowering the four-component graph to a free-running hls::task top. The mechanism is the one mem_copy and interleaver already cover; what is specific here is what feeds the hand-written bodies — the storage and the types — and how one parameter picks between two of them.
  • RTL simulation - The rung that answers what nothing earlier can: does the state actually survive between firings? C-synthesis can say the emitted static compiles and infers a memory, but a static swept by ap_rst would synthesize identically and quietly zero itself every job. A free-running composite also has no scheduler, so a token-count bug hangs or drops a job rather than producing a wrong answer.
  • Resource models - What this design declares about its own area, and how five modules compose into one estimate. FirCompute states its structure — how many multipliers of what width, that nothing goes in block RAM, and the terms LUT and FF may grow in — and a stock VitisResourceModel prices it. FirBlock declares only the interface term. Three modules declare nothing at all and keep the inherited lookup, which is the ratio to expect: the authoring effort concentrates where area actually moves.
  • The sweep and its results - What 24 syntheses in 20 minutes actually showed. The DSP prior lands exactly at every point with zero fitted parameters; the LUT/FF fit is 9.8%/7.1% mean under leave-one-out; the composed whole-design estimate is validated against totals that trained none of it, with the warning that the 3.3% design-level figure flatters the model because most of the design is known rather than predicted. Includes the two results that only appear because the design has coupled step functions in it -- the DSP packing win at 8 bits, and the unrolled plateau that is two effects cancelling -- and a design finding: the right realization inverts with sample width.