scatter_pipe: Overlapping Jobs

scatter_seq keeps each resource busy in only one phase of a job: the read port during the load, the compute during the scatter, the write port during the store. scatter_pipe gives each phase its own task, so that while one job is scattered, the next is loaded and the previous one stored. It has the same ports, takes the same commands and passes the same checks. Four jobs of n = 512 in a row now finish one every 1,123 cycles instead of every 2,240.

s_cmd -> control -[MemRCmd|desc|MemRCmd]-> mem_r_stream_framed -[desc|ind|x]-> load
                                               (m_rd)                           |
                        ind_blk, x_blk (ping-pong)  +---------------------------+
                                                    v
                                                 compute --desc--> store
                        y_blk (ping-pong)  ---------------------->   | [MemWCmd|desc|y]
s_done <- response <---desc--- mem_w_stream_framed_done <------------+
                                       (m_wr)

Three things change from scatter_seq, and the tasks page covers each:

  • One task per phase. scatter_compute’s job is split into five task bodies: control, load, compute, store and response. The two data movers stay.
  • Ping-pong blocks between the phases. The buffers become hls::stream_of_blocks, each a pair of blocks: the task before fills one while the task after reads the other.
  • A descriptor travels with the data. Once the tasks work on different jobs, a task cannot ask “which job is this?”. The control task builds one ScatterDesc per job, and it rides in front of the job’s data through every task and both movers.

The structure is that of Waveflow’s interleaver (interleaver_inband). The interleaver is a gather, Y[i] = X[P[i]], so its random access is a read of the x block; here it is a write into the y block.

The top

void scatter_pipe(hls::stream<word_t>& s_cmd, const word_t* m_rd, word_t* m_wr,
                  hls::stream<word_t>& s_done) {
#pragma HLS INTERFACE axis port=s_cmd
#pragma HLS INTERFACE m_axi port=m_rd offset=off bundle=gmem0 depth=65536
#pragma HLS stable variable=m_rd
#pragma HLS INTERFACE m_axi port=m_wr offset=off bundle=gmem1 depth=65536
#pragma HLS stable variable=m_wr
#pragma HLS INTERFACE axis port=s_done
#pragma HLS INTERFACE ap_ctrl_none port=return
    static const int DESC = ScatterDesc::nwords<MEM_DW>();
    static const int RD_HDR = 2 * MemRCmd::nwords<MEM_DW>() + DESC;
    static const int WR_HDR = MemWCmd::nwords<MEM_DW>() + DESC;
    hls_thread_local hls::stream<frame_t, 2 * RD_HDR> rd_cmd;
    hls_thread_local hls::stream<frame_t, 2 * WR_HDR> rd_data, wr_data;
    hls_thread_local hls::stream<frame_t, 2 * DESC> desc_lc, desc_cs;
    hls_thread_local hls::stream<word_t> wr_done;
    hls_thread_local hls::stream_of_blocks<block_t> ind_blk, x_blk, y_blk;

    hls_thread_local hls::task t_ctrl(scatter_control, s_cmd, rd_cmd);
    hls_thread_local hls::task t_rd(mem_r_stream_framed_task<MEM_DW>, rd_cmd, m_rd, rd_data);
    hls_thread_local hls::task t_load(scatter_load, rd_data, desc_lc, ind_blk, x_blk);
    hls_thread_local hls::task t_comp(scatter_compute, desc_lc, desc_cs, ind_blk, x_blk, y_blk);
    hls_thread_local hls::task t_store(scatter_store, desc_cs, y_blk, wr_data);
    hls_thread_local hls::task t_wr(mem_w_stream_framed_done_task<MEM_DW, ScatterDesc::nwords<MEM_DW>()>,
                                    wr_data, m_wr, wr_done);
    hls_thread_local hls::task t_resp(scatter_response, wr_done, s_done);
}
  • Seven tasks. Five bodies of our own and Waveflow’s two framed movers: they carry frame_t words, a data word plus a last bit, so a header the mover does not read can ride ahead of the data.
  • stream_of_blocks for ind, x and y: three ping-pong pairs, six blocks of 1,024 words. That is where the extra BRAM goes (14 against 8).
  • FIFO depths sized to a header. Each framed stream holds two jobs’ headers, so a task can pass the next job’s header on while the task after it is still busy with this one. rd_cmd matters most: the control task queues job k+1’s two reads while the mover is still on job k, and the read port never waits for the control task.

Vitis schedules every loop at II=1 and estimates 111 MHz (FF 4157, LUT 5544, BRAM 14), against 137 MHz for scatter_seq: the framed movers have the slowest paths, as in the histogram’s pipelined design.

How it is checked

Exactly as scatter_seq: the nine jobs, C simulation, then the RTL under XSI back to back and with each job alone, the whole memory and every response compared with the golden. All three runs pass. The refused job and the bad-index job flow through every task too (see the tasks), so the pipeline stays in step around them.

Latency and period

Each job alone, in cycles after its command’s last word:

n first AR last word loaded scatter starts scatter ends first AW last B response
256 17 581 586 845 883 1170 1179
512 17 1125 1130 1645 1683 2258 2267
1024 17 2213 2218 3245 3283 4434 4443

A job alone is 27 cycles slower than in scatter_seq (2,267 against 2,240 at n = 512): the control task frames the reads (the first request goes out at 17, not 11), and the descriptor passes from task to task between the phases. Pipelining does not shorten a job. It is the period that changes.

Four jobs of n = 512 back to back: a response every 1,123 cycles, against 2,240.

Resource, per job busy
read port (ind and x) 1,104
load task 1,103
compute task 516
store task 557
write port 576

The read port is busy 1,104 cycles of every 1,123. It is the bottleneck, as scatter_seq’s measurements predicted (1,101). The compute is idle more than half of every period, so a faster scatter would not help at all; a second read port, so ind and x arrive at once, would.

All nine jobs back to back take 11,162 cycles from the first command to the last response, against 17,239 for scatter_seq and 17,477 for the same jobs run alone, one after another.

The two designs side by side

The same three jobs through scatter_seq and scatter_pipe, one row per resource

Jobs 7 to 9 (n = 512 each, each after a job of its own size), from the first read beat to the last response. In scatter_seq (top) the read port works on one job, then waits while that job is scattered and stored. In scatter_pipe (bottom) it never waits: job 8 is read while job 7 is scattered and stored. Compute, store and the write port follow one period behind, each busy less than half the time. The run’s first job is left out: its read waits behind the larger jobs ahead of it, which is the pipeline filling, not its steady state.

What the testbench’s memory hides

As for scatter_seq: the memory model answers a read on the next cycle, and serves one request at a time. On a DRAM behind an interconnect each read takes longer, so the read port, already the bottleneck, gets slower. The overlap still hides the compute and the store under it. XSI’s memory also has no contention between the two ports: on a board where both reach one DRAM controller, the reads and writes of overlapping jobs would compete for it.


This site uses Just the Docs, a documentation theme for Jekyll.