How tusharkatole/ml-accelerator works
Project type and purpose
• This is a hardware accelerator (FPGA/ASIC) implementation and verification of a Non-Maximum Suppression (NMS) algorithm for object detection.
• It’s written in Verilog (nms_top, calculate_iou modules, variants with/without pipelining) and exercised by a Verilog testbench. A Python “Pre-Treatment Unit” extracts YOLO detections and a Python NMS script illustrate the algorithmic reference.
Main components
a. Host/Pre-Treatment (Python)
• Exports a .coe file to initialize on-chip Block RAM
b. Block RAM (blk_mem_gen_0)
• Synchronous read with 2-cycle output delay tracked by delayed_addr_1/2
c. nms_top (top-level Verilog)
• Addr Generator & BRAM interface
• Control FSM: LOAD_BOXES → SORT_INIT → SORT_BOXES/SORT_SWAP → INIT_NMS → COMPARE_BOXES → CALCULATE_IOU → UPDATE_VALID → FINISH
• Bubble-sort unit for ordering by score
• Valid/suppressed bitmaps
d. calculate_iou (submodule)
• Q8.8 fixed-point IoU computation
• Variants: combinational, 4-stage pipeline, 7-stage pipeline, approximate (A-IoU2 eliminates mult/div)
• Inputs: x1,y1,w1,h1, x2,y2,w2,h2 + start/reset/clk; Outputs: iou, done/valid
e. Testbench (Verilog)
• Drives clk/reset, waits for FSM = FINISH, monitors suppressed vector
Component interactions and data flows
• IoU result returns → FSM compares with IOU_THRESHOLD → sets suppressed_reg[compare_box] and clears valid[compare_box].
• At FINISH, suppressed_reg holds final NMS mask output.
Key architectural patterns
• Central monolithic FSM orchestrating memory-load, sorting, comparison, suppression.
• Streaming hardware pipeline for IoU to maintain throughput (configurable pipeline depth).
• Dual-port Block RAM (read-only here) pre-initialized via .coe.
• Parameterized design: NUM_BOXES, IOU_THRESHOLD, DATA_WIDTH, ADDR_WIDTH, pipe stages.