Free-running polynomial

A polynomial evaluator, $y = c_0 + c_1 x + c_2 x^2 + c_3 x^3$ on float32 samples, as a free-running kernel: no ap_start, no register map – it fires once per command, and runs until an error stops it. It is the first kernel example (after the data-only Basic vector arithmetic) because its shape is the one most accelerators take: a command comes in on a stream, the work happens on its data, and the answer goes out on streams, including the answer that something went wrong. The arithmetic is deliberately trivial, so every page is about the flow.

The kernel is one Python class, PolyKernel. Around it, everything is generated or comes from the framework: its testbench (a harness built from its ports), its RTL top, its calibration, and – in The polynomial on a bus – its memory-mapped device.

Learning Objectives

What this adds to Basic vector arithmetic (schemas, vectorized goldens, bit-exactness against Vitis), in the order the pages teach it:

  1. Define a command-response protocol for a simple kernel: a command and its data in, the results out headed by which command they answer and how many.
  2. Add a status stream for error reporting, and halt the kernel on an error.
  3. Write DataSchema classes for every message to and from the kernel: the command, the results header, the status.
  4. Write the golden as pure Python functions, and compute the expected outputs from intent: from what each scenario means, not from an implementation.
  5. Write the kernel as a FreeRunMod with framed stream ports, one firing per command: read the command, head the results, run the samples through a pipelined phase, write the status, and stop after an error.
  6. Write its HLS twin with the generated lane routines (loop optimization), and generate its top.
  7. Make the kernel the DUT of its own harness, and run the system flow: csynth, the RTL run under XSI, and the comparison of RTL against pysim.
  8. Declare the kernel’s timing as timed phases and calibrate them in its harness.

Putting the same kernel on a bus – behind AXI-MM, with a software host, its timing composed from the calibrated parts – is its own example, The polynomial on a bus.

The pages

  • The protocol – three streams, one command at a time, a status plane, errors fatal.
  • The golden – the schemas, the reference arithmetic, stimulus and expected outputs.
  • The kernel – PolyKernel.run_iter, its HLS body, and the generated top.
  • The system flow – the kernel’s harness, csynth, the RTL run, the comparison.
  • Timing – two timed phases, calibrated in the harness and filed under the kernel’s identity.

For the general practice behind the last two – harnesses, stand-ins, calibrating a unit alone and composing a parent – see Developing module by module.

Running it

python -m examples.stream_kernel.stream_kernel_build --through pysim          # pysim only
python -m examples.stream_kernel.stream_kernel_build                          # through compare (Vitis, Vivado)
python -m examples.stream_kernel.stream_kernel_build --through calib_phases   # calibrate the timing

The gate is tests/examples/test_stream_kernel.py. Cycle counts on these pages were measured with Vitis HLS and Vivado 2025.1 at 100 MHz.

This kernel is the free-running form of Streaming polynomial, which teaches the same arithmetic as a host-activated kernel with a status register.


Table of contents