Scatter: Task-Level Pipelining
The histogram showed how a kernel reaches memory: it sends a command to a data mover, the mover streams the words, and a completion says when a write is in memory. It ran one job at a time. Each job had a load phase (read the samples), a compute phase (bin them) and a store phase (write the counts), and only one of them was busy at any moment. This demo is about putting those idle resources to work. It is the running example of unit 10.
The kernel is a scatter. Given n indices and n samples in memory, it computes
y[ind[i]] = x[i] for i = 0 .. n-1
and writes y back to memory. Its sibling, the gather, is y[i] = x[ind[i]]. A gather
reads at random; a scatter writes at random. Both are everywhere in hardware: channel
interleavers and de-interleavers, the FFT’s bit reversal, matrix transposes, packet reordering,
sparse matrices.
The arithmetic is nothing, one write per element. The memory is everything. Because y is
written in an unpredictable order, it has to be held on chip until the last element lands:
any y[j] might be the one written last. So every job really does have three phases. Load
ind and x, scatter into an on-chip block, then store y. The store is as large as the
load, which makes it the example the histogram could not be: its store was only 32 words.
The designs
Both designs take the same ScatterCmd, send the same ScatterResp on the same four ports,
run the same nine test jobs and are checked against the same NumPy golden.
| Design | Unit 10 | What it shows |
|---|---|---|
scatter_seq |
section 1 | One kernel task between Waveflow’s plain data movers, as in hist_simple. Each job runs load, scatter, store, wait, respond, one phase at a time. The timing shows how idle each resource is. |
scatter_pipe |
sections 2–4 | Load, compute and store as separate tasks, joined by ping-pong blocks, with one descriptor per job carried in front of its data. Consecutive jobs overlap: a job every 1,123 cycles instead of every 2,240. |
| scatter-add | section 6 | y[ind[i]] += x[i]: pipelining a read-modify-write. To come. |
The numbers, for jobs of n = 512 under XSI at 100 MHz:
scatter_seq |
scatter_pipe |
|
|---|---|---|
| One job alone, command to response | 2,240 cycles | 2,267 cycles |
| A new job every, back to back | 2,240 | 1,123 (1.99×) |
| All nine test jobs, back to back | 17,239 | 11,162 |
| Read port busy, per job | 1,101 | 1,104 |
Pipelining does not make a job faster; it makes jobs overlap. The period it reaches is set
by the busiest resource, here the read port, which carries both ind and x.
Learning objectives
With scatter_seq (unit 10, section 1), you will:
- Split a job into load, compute and store, and see why a scatter needs an on-chip block
- Measure how busy each resource is, from the RTL waveform
- Predict what overlapping jobs could gain: the period is the busiest resource’s time
- See why speeding up the compute alone gains little
With scatter_pipe (sections 2–4), you will:
- Give load, compute and store their own
hls::tasks, joined by ping-pong blocks (hls::stream_of_blocks) - Carry one descriptor per job through every task, in front of its data, through Waveflow’s framed data movers
- Tell latency (one job, start to finish) from period (one job every …), and find the bottleneck
- Avoid a C-simulation trap in Vitis’s model of
stream_of_blocks
The pages
- scatter_seq: the sequential kernel, how it is checked, its phases and how busy each resource is.
- scatter_pipe: the pipelined top, its timing, and the two designs side by side.
- scatter_pipe’s tasks: the descriptor, the ping-pong blocks and the five task bodies.
The code
Everything is in hwdesign/demos/scatter. The Python is shared; each design has a directory
and a build script:
| Path | What it is |
|---|---|
scatter_schema.py |
ScatterCmd, ScatterResp and scatter_pipe’s ScatterDesc, as Waveflow data schemas |
scatter_golden.py |
the nine test jobs, the memory image and the NumPy golden |
scatter_timing.py |
each job’s phases and each resource’s busy time, measured from the RTL waveform, and the figures |
scatter_build.py |
the build steps, shared by both designs |
scatter_seq.py, scatter_pipe.py |
the build script for each design |
run.tcl |
the Vitis HLS script: C simulation or synthesis of one design |
seq/ |
scatter_seq.cpp (the top and the kernel task), scatter_seq.h, and the testbenches |
pipe/ |
scatter_pipe.cpp (the top), its five task bodies, and the testbenches |
To run it, in hwdesign-venv with Vitis and Vivado installed:
(env) cd demos/scatter
(env) python scatter_seq.py --through verify_csim # C simulation only: about 30 s
(env) python scatter_seq.py # + synthesis, RTL and timing: about 2 min
(env) python scatter_pipe.py # about 2 min; run scatter_seq.py first
scatter_pipe.py draws the two designs side by side, so it reads scatter_seq’s results.
Each script lists its steps with --list-steps, and skips any step whose inputs have not
changed.