UCLA-VAST / tapa

TAPA is a dataflow HLS framework that features fast compilation, expressive programming model and generates high-frequency FPGA accelerators.
https://tapa.rtfd.io
MIT License
144 stars 27 forks source link

In tapa, is it possible to add specific delays (in clock cycles) in the testbench for C/RTL cycle-accurate simulation? #144

Closed liaoyunkun closed 7 months ago

liaoyunkun commented 7 months ago

I am doing networking hardware design. Currently, I cannot add the delays to control the packet timing in Vitis HLS. I have tried ap_wait_n() and couter-based for loop.

Blaok commented 7 months ago

I think ap_wait_n has been removed from Vitis HLS's manual for years, and it is unclear what it does exactly. Adding a simple loop is unlikely going to work either because the compiler may optimize it away. ap_shift_reg is your best chance; try something like this (disclaimer: not tested in any way)

ap_shift_reg<Pkt, kDelay> shift_reg;
for (int i = 0; i < n + kDelay;) {
#pragma HLS pipeline II = 1
  if (!pkt_in.empty()) {
    Pkt pkt_in;
    if (i < n) {
      pkt_in_q.try_read(pkt);
    }
    Pkt pkt_out = shift_reg.shift(pkt_in);
    if (i >= kDelay) {
      pkt_out_q.write(pkt_out);
    }
    ++i;
  }
}
liaoyunkun commented 7 months ago

Thanks for your suggestion and contribution to Tapa!!! I will try. I think the flexible timing control of stimulus is vital for networking-oriented test. Plus, why not add some tips for including Xilinx HLS headers in the HelloWord demo. My environment is Ubuntu 20.04 and I install tapa with the command "curl -L https://git.io/JnERa | bash". As you konw, there are gfw problems for users in mainland China. After I setup the network and finish installing tapa, I execute "g++ -o vadd -O2 vadd.cpp vadd-host.cpp -ltapa -lfrt -lglog -lgflags -lOpenCL" for the HelloWrold example. But the OpenCL library is missing, so I setup OpenCL by "sudo apt-get install opencl-headers" and "sudo apt install opencl-dev". It seems that the OpenCL dependency is not mentioned in the Doc? When I migrate my own projects from Vitis HLS to Tapa, the "ap_uint" library are missed. Although I solve the problem by including "-I /tools/Xilinx/Vitis_HLS/2022.1/include/" option to g++, I suggest that we can add this tip directly to the document.