FIFOs and Streaming Interfaces Questions

Question 1. Sizing FIFOs

A FIFO buffer stores commands with three elements, here ap_int represents an arbitrary bit-width integer type with n bits.

struct Command {
    ap_int<16> command_id;
    ap_int<32> operand1;
    ap_int<32> operand2;
};
  1. What is the element width in bytes?
  2. If the FIFO has a depth of 32 elements, what is the total size of the FIFO in bytes?

Question 2. FIFO Timing

A producer writes data elements A, B, and C into a FIFO buffer at clock cycles 0, 1, and 6, respectively. Data can be read from the FIFO on the clock cycle immediately after it is written (for example, data element A can be read starting at clock cycle 1). Once a consumer reads an element, it takes 2 clock cycles to process it before the consumer can read the next element from the FIFO. Assuming the consumer attempts to read from the FIFO as soon as possible and starts at clock cycle 1, at which clock cycles will the consumer read:

  1. Data element A
  2. Data element B
  3. Data element C

Question 3. FIFO Write Stall

A producer generates data elements A, B, C, and D. The earliest clock cycles at which each element becomes available for writing into a FIFO are:

The FIFO has a capacity of 2 elements. A write can occur only if the FIFO is not full. If the FIFO is full when an element becomes available, the producer must stall and retry the write on each subsequent cycle until it succeeds.

A consumer reads one element at a time from the FIFO. If data is written on cycle N, it is available to be read and removed from the FIFO on cycle N+1, and will process the element until cycle N+3. Thus, the next read is possible at cycle N+4.

For each element, determine the clock cycle at which the write actually succeeds ( i.e., when the element is stored in the FIFO) and when the processing is complete.

  1. Element A
  2. Element B
  3. Element C
  4. Element D

Question 4. CV Accelerator Throughput and FIFO

A computer vision accelerator processes a stream of video frames. Each frame requires 5 ms of base processing time. On 10% of the frames, an object of interest is detected. For these frames, the accelerator requires an additional 100 ms of processing time (for a total of 105 ms on those frames). The accelerator processes frames one at a time.

Assume frames arrive continuously and the accelerator must keep up with the input stream without the input FIFO growing without bound.

  1. What is the maximum frame rate (in frames per second) that the accelerator can sustain without falling behind?
  2. Now suppose the accelerator is preceded by an input FIFO that buffers frames before they are processed. The probability that a frame requires the extra 100 ms of processing is still 10%, but the pattern of when these expensive frames occur can differ. Rank the following three patterns in terms of how large the input FIFO must be to avoid overflow (from smallest required FIFO size to largest):
    1. Objects of interest arrive uniformly, e.g., on frames 0, 10, 20, 30, ...
    2. Objects of interest arrive in bursts, e.g., on frames 0, 1, 2, then 30, 31, 32, ...
    3. Objects of interest arrive randomly, e.g., frames 15, 21, 27, ... (but 1/10 on average).

Question 5. AXI Stream Timing

An AXI4-Stream master has data elements A, B, C, and D. The earliest they can be transferred are:

The slave has no FIFO size limit and therefore always asserts TREADY = 1. However, the slave can only consume one element every 2 cycles with a 1 cycle delay after it is written:

Fill in the following table for cycles 0–8. In the Write action column, indicate whether the master transfers an element or is idle. For example, transfer A or idle. Similarly, in the slave action column, indicate whether the slave reads, processes, or is idle. For example, read A, process A, or idle.

Cycle Write Action (transfer or idle) TVALID FIFO State after read/write Slave Action (read, process, or idle)

Assume the FIFO starts empty. Note that you do not need to show TREADY for each cycle since it is always asserted. If you are writing the solution in the solution box, any format is acceptable. For example, for the first row you can write:

Cycle 0: Write A, TVALID=1, FIFO=[A], Slave=Idle

or even, since the columns are known, you can just write the values:

0: Write A, 1, [A], Idle

Question 6. AXI Stream Burst Timing

A master on an AXI4-Stream interface writes 10 data elements (1st, 2nd, ..., 10th) beginning on clock cycle 0. The slave has a large FIFO, so it always asserts TREADY = 1, and therefore the master successfully transfers one element per cycle for 10 cycles.

The slave behavior is non-pipelined:

Assume the slave starts idle and attempts to read and process elements as soon as possible.

  1. On what clock cycle is the final (10th) element transferred into the FIFO?
  2. At the end of which clock cycle is the first element completed processing?
  3. At the end of which clock cycle is the final (10th) element completed processing?

Question 7. AXI Stream Timing with Stalls

An AXI4-Stream master has data elements A, B, C, and D that are all available for transfer at cycle 0. The slave has an input FIFO of depth 2. The slave asserts TREADY = 1 whenever the FIFO is not full. If the FIFO becomes full in cycle n, then TREADY = 0 in cycle n+1.

The slave consumes data as follows:

Fill in the following table for cycles 0–8. In the Write Action column, indicate whether the master transfers an element or stalls. For example, transfer A, Write A stall or idle. In the Slave Action column, indicate whether the slave reads, processes, or is idle. For example, read A, process A, or idle.

The FIFO starts empty.

Cycle Write Action (transfer, stall or idle) TVALID TREADY Slave Action FIFO State after read/write TREADY_next

Question 8. AXI4-Stream Burst Timing

You are given the following AXI4‑Stream timing table. A transfer occurs on any cycle where TVALID = 1 and TREADY = 1.

Cycle TREADY TVALID TLAST
0000
1110
2010
3110
4011
5111
  1. What is the first cycle of the burst (the first cycle where TVALID = 1)?
  2. On which cycle does the last transfer occur?
  3. How many elements were transferred in the burst?

Question 9. Serializing Command Header

You are given a command header with the following data structure. Here ap_uint represents an unsigned integer with n bits, and ap_fixed represents a signed fixed-point value with W total bits and I integer bits (including the sign bit).

class CmdHdr {
    ap_uint<16> trans_id;   // Transaction ID

    // Rotation angles in Q12.10 format, where 1.0 corresponds to π radians
    ap_fixed<12,1> yaw, pitch, roll;

    ap_uint<16> nsamp;      // Number of samples to rotate
};
  1. How many 32-bit words are required to store one instance of this header? Assume that no field may be split across word boundaries.
  2. Complete the function below to serialize an instance of this header into an array of 32-bit words. There are multiple valid layouts; choose one that uses the minimum number of 32-bit words.
void serialize(const CmdHdr &cmd_hdr, ap_uint<32> words[/* fill in */]) {
    ...
}

Question 10. Deserializing Command Header

You are given the same command header structure as in the serialization problem. Here ap_uint represents an unsigned integer with n bits, and ap_fixed represents a signed fixed‑point value with W total bits and I integer bits (including the sign bit).

class CmdHdr {
    ap_uint<16> trans_id;   // Transaction ID

    // Rotation angles in Q12.10 format, where 1.0 corresponds to π radians
    ap_fixed<12,1> yaw, pitch, roll;

    ap_uint<16> nsamp;      // Number of samples to rotate
};

The header has been serialized into three 32‑bit words using the packing shown in the table below. No field crosses a 32‑bit boundary.

Word Bits Field Width
Word 0 15:0 trans_id 16 bits
27:16 yaw 12 bits
Word 1 11:0 pitch 12 bits
23:12 roll 12 bits
Word 2 15:0 nsamp 16 bits
  1. Using the packing table, write code to extract each field from the 32‑bit words and reconstruct a CmdHdr object.
  2. Complete the function below. Your implementation must correctly sign‑extend the fixed‑point fields and assign all fields of cmd_hdr.
void deserialize(CmdHdr &cmd_hdr, ap_uint<32> words[3]) {
    // Fill in your solution here
}