cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
MedianBlur Testbench

This is a subgroup of MedianBlur accelerated function with only testbench-related functions/classes. More...

Collaboration diagram for MedianBlur Testbench:

Files

file  median_blur_host_fwd_tb.cpp
 Testbench for MedianBlur userspace application for cF (x86, ppc64).
 
file  xf_ocv_ref.hpp
 The MedianBlur reference functions used in TB.
 
file  test_median_blur.cpp
 : Testbench for MedianBlur.
 

Macros

#define THIS_NAME   "TB"
 
#define TRACE_OFF   0x0000
 
#define TRACE_URIF   1 << 1
 
#define TRACE_UAF   1 << 2
 
#define TRACE_MMIO   1 << 3
 
#define TRACE_ALL   0xFFFF
 
#define DEBUG_LEVEL   (TRACE_ALL)
 
#define OK   true
 
#define KO   false
 
#define VALID   true
 
#define UNVALID   false
 
#define DEBUG_TRACE   true
 
#define TB_TRIALS   2
 
#define ENABLE_DDR_EMULATE_DELAY_IN_TB
 
#define ENABLED   (ap_uint<1>)1
 
#define DISABLED   (ap_uint<1>)0
 
#define MEMORY_LINES_512   TOTMEMDW_512 /* 64 KiB */
 

Functions

int main (int argc, char *argv[])
 
void ocv_ref (cv::Mat img_gray, cv::Mat &ocv_out_img, int ksize)
 
stream< UdpWordsSHL_Uaf_Data ("sSHL_Uaf_Data")
 
stream< UdpWordsUAF_Shl_Data ("sUAF_Shl_Data")
 
stream< UdpWordimage_stream_from_median_blur ("image_stream_from_median_blur")
 
stream< NetworkMetaStreamsiUdp_meta ("siUdp_meta")
 
stream< NetworkMetaStreamsoUdp_meta ("soUdp_meta")
 
stream< DmCmdsROL_Shl_Mem_RdCmdP0 ("sROL_Shl_Mem_RdCmdP0")
 
stream< DmStssSHL_Rol_Mem_RdStsP0 ("sSHL_Rol_Mem_RdStsP0")
 
stream< Axis< 512 > > sSHL_Rol_Mem_ReadP0 ("sSHL_Rol_Mem_ReadP0")
 
stream< DmCmdsROL_Shl_Mem_WrCmdP0 ("sROL_Shl_Mem_WrCmdP0")
 
stream< DmStssSHL_Rol_Mem_WrStsP0 ("sSHL_Rol_Mem_WrStsP0")
 
stream< Axis< 512 > > sROL_Shl_Mem_WriteP0 ("sROL_Shl_Mem_WriteP0")
 
void stepDut ()
 Run a single iteration of the DUT model. More...
 
int main (int argc, char **argv)
 Main testbench of Hrris. More...
 

Variables

ap_uint< 1 > piSHL_This_MmioPostPktEn
 
ap_uint< 1 > piSHL_This_MmioCaptPktEn
 
ap_uint< 32 > s_udp_rx_ports = 0x0
 
ap_uint< 32 > node_rank
 
ap_uint< 32 > cluster_size
 
membus_t lcl_mem0 [(1+(IMGSIZE - 1)/(512/8))]
 
membus_t lcl_mem1 [(1+(IMGSIZE - 1)/(512/8))]
 
int simCnt
 

Detailed Description

This is a subgroup of MedianBlur accelerated function with only testbench-related functions/classes.

Macro Definition Documentation

◆ DEBUG_LEVEL

#define DEBUG_LEVEL   (TRACE_ALL)

Definition at line 53 of file test_median_blur.cpp.

◆ DEBUG_TRACE

#define DEBUG_TRACE   true

Definition at line 63 of file test_median_blur.cpp.

◆ DISABLED

#define DISABLED   (ap_uint<1>)0

Definition at line 72 of file test_median_blur.cpp.

◆ ENABLE_DDR_EMULATE_DELAY_IN_TB

#define ENABLE_DDR_EMULATE_DELAY_IN_TB

Definition at line 69 of file test_median_blur.cpp.

◆ ENABLED

#define ENABLED   (ap_uint<1>)1

Definition at line 71 of file test_median_blur.cpp.

◆ KO

#define KO   false

Definition at line 60 of file test_median_blur.cpp.

◆ MEMORY_LINES_512

#define MEMORY_LINES_512   TOTMEMDW_512 /* 64 KiB */

Definition at line 112 of file test_median_blur.cpp.

◆ OK

#define OK   true

Definition at line 59 of file test_median_blur.cpp.

◆ TB_TRIALS

#define TB_TRIALS   2

Definition at line 66 of file test_median_blur.cpp.

◆ THIS_NAME

#define THIS_NAME   "TB"

Definition at line 45 of file test_median_blur.cpp.

◆ TRACE_ALL

#define TRACE_ALL   0xFFFF

Definition at line 51 of file test_median_blur.cpp.

◆ TRACE_MMIO

#define TRACE_MMIO   1 << 3

Definition at line 50 of file test_median_blur.cpp.

◆ TRACE_OFF

#define TRACE_OFF   0x0000

Definition at line 47 of file test_median_blur.cpp.

◆ TRACE_UAF

#define TRACE_UAF   1 << 2

Definition at line 49 of file test_median_blur.cpp.

◆ TRACE_URIF

#define TRACE_URIF   1 << 1

Definition at line 48 of file test_median_blur.cpp.

◆ UNVALID

#define UNVALID   false

Definition at line 62 of file test_median_blur.cpp.

◆ VALID

#define VALID   true

Definition at line 61 of file test_median_blur.cpp.

Function Documentation

◆ image_stream_from_median_blur()

stream<UdpWord> image_stream_from_median_blur ( "image_stream_from_median_blur"  )

◆ main() [1/2]

int main ( int  argc,
char **  argv 
)

Main testbench of Hrris.

Returns
0 upon success, nrErr else.

hls_out_img.data = (unsigned char *)imgOutput.copyFrom();

Definition at line 157 of file test_median_blur.cpp.

157  {
158 
159  //------------------------------------------------------
160  //-- TESTBENCH LOCAL VARIABLES
161  //------------------------------------------------------
162  int nrErr;
163  unsigned int tb_trials = 0;
164 
165  printf("#####################################################\n");
166  printf("## MAIN TESTBENCH STARTS HERE ##\n");
167  printf("#####################################################\n");
168 
169 
170  //------------------------------------------------------
171  //-- TESTBENCH LOCAL VARIABLES FOR MEDIANBLUR
172  //------------------------------------------------------
173  cv::Mat in_img, img_gray;
174  cv::Mat hls_out_img, ocv_out_img;
175 
176  if (argc != 2) {
177  printf("Usage : %s <input image> \n", argv[0]);
178  return -1;
179  }
180  in_img = cv::imread(argv[1], 0); // reading in the color image
181 
182  if (!in_img.data) {
183  printf("ERROR: Failed to load the image ... %s\n!", argv[1]);
184  return -1;
185  }
186  else {
187  printf("INFO: Succesfully loaded image ... %s\n", argv[1]);
188  if (in_img.total() != FRAME_WIDTH * FRAME_HEIGHT) {
189  printf("WARNING: Resizing input image %s from [%u x %u] to [%u x %u] !\n", argv[1], in_img.rows, in_img.cols, FRAME_WIDTH, FRAME_HEIGHT);
190  cv::resize(in_img, in_img, cv::Size(FRAME_WIDTH, FRAME_HEIGHT), 0, 0, cv::INTER_LINEAR);
191  }
192  // Ensure that the selection of MTU is a multiple of 8 (Bytes per transaction)
193  assert(PACK_SIZE % 8 == 0);
194  }
195 
196  #ifdef ENABLE_DDR
197  memset(lcl_mem0, 0x0, sizeof(lcl_mem0));
198  memset(lcl_mem1, 0x0, sizeof(lcl_mem1));
199 
200  DmCmd dmCmd_MemCmdP0;
201  DmSts dmSts_MemWrStsP0;
202  DmSts dmSts_MemRdStsP0;
203  Axis<MEMDW_512> memP0;
204  ap_uint<64> currentMemPattern = 0;
205 
206  unsigned int ddr_addr_in = 0x0;
207  unsigned int ddr_write_req_iter = 0;
208  unsigned int wait_cycles_to_ack_ddr_status = 0;
209  unsigned int count_cycles_to_ack_ddr_status = 0;
210  bool ddr_write_sts_req = false;
211  #endif
212 
213 
214  //------------------------------------------------------
215  //-- STEP-1.1 : CREATE MEMORY FOR OUTPUT IMAGES
216  //------------------------------------------------------
217  // cvtColor(in_img, img_gray, CV_BGR2GRAY);
218  // Convert rgb into grayscale
219  hls_out_img.create(in_img.rows, in_img.cols, CV_8U); // create memory for hls output image
220  ocv_out_img.create(in_img.rows, in_img.cols, CV_8U); // create memory for opencv output image
221 
222  #if NO
223  static xf::cv::Mat<TYPE, HEIGHT, WIDTH, XF_NPPC1> imgInput(in_img.rows, in_img.cols);
224  static xf::cv::Mat<TYPE, HEIGHT, WIDTH, XF_NPPC1> imgOutput(in_img.rows, in_img.cols);
225  static xf::cv::Mat<TYPE, HEIGHT, WIDTH, XF_NPPC1> imgOutputTb(in_img.rows, in_img.cols);
226  imgInput.copyTo(in_img.data);
227  ap_uint<INPUT_PTR_WIDTH> *imgInputArray = (ap_uint<INPUT_PTR_WIDTH>*) malloc(in_img.rows * in_img.cols * sizeof(ap_uint<INPUT_PTR_WIDTH>));
228  ap_uint<OUTPUT_PTR_WIDTH> *imgOutputArrayTb = (ap_uint<OUTPUT_PTR_WIDTH>*) malloc(in_img.rows * in_img.cols * sizeof(ap_uint<OUTPUT_PTR_WIDTH>));
229  ap_uint<OUTPUT_PTR_WIDTH> *imgOutputArray = (ap_uint<OUTPUT_PTR_WIDTH>*) malloc(in_img.rows * in_img.cols * sizeof(ap_uint<OUTPUT_PTR_WIDTH>));
230  xf::cv::xfMat2Array<INPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX>(imgInput, imgInputArray);
231  #endif
232 
233  #if RO
234  static xf::cv::Mat<TYPE, HEIGHT, WIDTH, XF_NPPC8> imgInput(in_img.rows, in_img.cols);
235  static xf::cv::Mat<TYPE, HEIGHT, WIDTH, XF_NPPC8> imgOutput(in_img.rows, in_img.cols);
236  static xf::cv::Mat<TYPE, HEIGHT, WIDTH, XF_NPPC1> imgOutputTb(in_img.rows, in_img.cols);
237  #endif
238 
239  while (tb_trials++ < TB_TRIALS) {
240 
241 
242  printf ( "##################################################### \n" );
243  printf ( "## TESTBENCH #%u STARTS HERE ##\n", tb_trials );
244  printf ( "##################################################### \n" );
245 
246 
247  simCnt = 0;
248  nrErr = 0;
249 
250 #if NO
251  if ( !dumpImgToFile ( imgInput, "ifsSHL_Uaf_Data.dat", simCnt ) ) {
252  nrErr++;
253  }
254 #endif
255 
256 #if RO
257  // imgInput.copyTo(img_gray.data);
258  imgInput = xf::cv::imread<TYPE, HEIGHT, WIDTH, XF_NPPC8> ( argv[1], 0 );
259 #endif
260 
261 
262 
263  //------------------------------------------------------
264  //-- STEP-1.2 : RUN MEDIANBLUR DETECTOR FROM OpenCV LIBRARY
265  //------------------------------------------------------
266  // ksize: aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...
267  int ksize = WINDOW_SIZE ;
268  ocv_ref ( in_img, ocv_out_img, ksize);
269 
270 
271 
272  //------------------------------------------------------
273  //-- STEP-2.1 : CREATE TRAFFIC AS INPUT STREAMS
274  //------------------------------------------------------
275  if ( nrErr == 0 ) {
276  if ( !setInputDataStream ( sSHL_Uaf_Data, "sSHL_Uaf_Data", "ifsSHL_Uaf_Data.dat", simCnt ) ) {
277  printf ( "### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n" );
278  nrErr++;
279  }
280 
281  //there are TOT_TRANSFERS streams from the the App to the Role
283  for ( int i=0; i<TOT_TRANSFERS; i++ ) {
284  siUdp_meta.write ( NetworkMetaStream ( tmp_meta ) );
285  }
286  //set correct node_rank and cluster_size
287  node_rank = 1;
288  cluster_size = 2;
289  }
290 
291  //------------------------------------------------------
292  //-- STEP-2.2 : SET THE PASS-THROUGH MODE
293  //------------------------------------------------------
294  //piSHL_This_MmioEchoCtrl.write(ECHO_PATH_THRU);
295  //[TODO] piSHL_This_MmioPostPktEn.write(DISABLED);
296  //[TODO] piSHL_This_MmioCaptPktEn.write(DISABLED);
297 
298  //------------------------------------------------------
299  //-- STEP-3 : MAIN TRAFFIC LOOP
300  //------------------------------------------------------
301  while ( !nrErr ) {
302 
303  // Keep enough simulation time for sequntially executing the FSMs of the main 3 functions
304  // (Rx-Proc-Tx)
306 #ifdef ENABLE_DDR
309 #endif
310 #endif
311  ) {
312  stepDut();
313 
314  if ( simCnt > 2 ) {
315  assert ( s_udp_rx_ports == PORTS_OPENED );
316  }
317 
318 if (simCnt < 0)
319  exit(0);
320 #ifdef ENABLE_DDR
321 
322  if ( !sROL_Shl_Mem_WrCmdP0.empty() ) {
323  printf ( "DEBUG tb: Read a memory write command from SHELL/Mem/Mp0 \n" );
324  //-- Read a memory write command from SHELL/Mem/Mp0
325  sROL_Shl_Mem_WrCmdP0.read ( dmCmd_MemCmdP0 );
326  //assert ( dmCmd_MemCmdP0.bbt == CHECK_CHUNK_SIZE );
327  assert ( dmCmd_MemCmdP0.type == 1 && dmCmd_MemCmdP0.dsa == 0 && dmCmd_MemCmdP0.eof == 1 && dmCmd_MemCmdP0.drr == 1 && dmCmd_MemCmdP0.tag == 0x0 );
328  ddr_addr_in = (unsigned int)dmCmd_MemCmdP0.saddr / BPERMDW_512; // Convert the byte-aligned address to local mem of stack tb.
329  printf ( "DEBUG tb: Requesting writting to address %u (max depth = %u) an amount of %u bytes (%u memory lines), ddr_write_req_iter=%u\n", ddr_addr_in, MEMORY_LINES_512-1, (unsigned int)dmCmd_MemCmdP0.bbt, (unsigned int)(1 + (dmCmd_MemCmdP0.bbt - 1) / BPERMDW_512), ddr_write_req_iter);
330  assert (ddr_addr_in <= MEMORY_LINES_512-1);
331  //ddr_write_req_iter++;
332  //printf ( "DEBUG tb: (ddr_write_req_iter)%(MEMORY_LINES_512-1)=%u\n", (ddr_write_req_iter)%(MEMORY_LINES_512-1));
333  if ((++ddr_write_req_iter)%(MEMORY_LINES_512) == 0) {
334  ddr_write_req_iter = 0;
335  }
336  printf ( "DEBUG tb: ddr_write_req_iter=%u\n", ddr_write_req_iter);
337 
338 #ifdef ENABLE_DDR_EMULATE_DELAY_IN_TB
339  /*
340  * 16 -> emulate a response in 16 cycles
341  * 1 -> emulate immediate response
342  * CYCLES_UNTIL_TIMEOUT -> on purpose timeout
343  */
344  if (ddr_write_req_iter == 1) {
345  wait_cycles_to_ack_ddr_status = TYPICAL_DDR_LATENCY;
346  }
347  else if (ddr_write_req_iter == 2) {
348  wait_cycles_to_ack_ddr_status = TYPICAL_DDR_LATENCY;
349  }
350  else {
351  wait_cycles_to_ack_ddr_status = TYPICAL_DDR_LATENCY;
352  }
353  if (!sSHL_Rol_Mem_WrStsP0.empty()) {
354  printf("WARNING: Emptying sSHL_Rol_Mem_WrStsP0 fifo.\n");
355  dmSts_MemWrStsP0 = sSHL_Rol_Mem_WrStsP0.read();
356  }
357 #else
358  wait_cycles_to_ack_ddr_status = 0;
359 #endif
360  count_cycles_to_ack_ddr_status = 0;
361  ddr_write_sts_req = false;
362  }
363 
364  if ( !sROL_Shl_Mem_WriteP0.empty() ) {
365  sROL_Shl_Mem_WriteP0.read ( memP0 );
366  printf ( "DEBUG tb: Write a memory line from SHELL/Mem/Mp0 \n" );
367 
368  assert ( memP0.tkeep == 0xffffffffffffffff );
369 
370  /* Read from AXI stream DDR interface and write to the memory mapped interface of
371  * DDR channel P0. In the real HW, this is enabled by the AXI interconnect and AXI
372  * Datamover, being instantiated in VHDL.
373  * */
374  // printf ( "DEBUG tb: Writting to address 0x%x : %u an amount of %u bytes\n", ddr_addr_in, memP0.tdata.to_long(), BPERMDW_512);
375  std::cout << "DEBUG tb: Writting to address 0x" << std::hex << ddr_addr_in << " : " << memP0.tdata << " an amount of " << std::dec << BPERMDW_512 << " bytes" << std::endl;
376  //lcl_mem0[ddr_addr_in++] = memP0.tdata;
377  memcpy(&lcl_mem0[ddr_addr_in++], &memP0.tdata, BPERMDW_512);
378  ddr_write_sts_req = true;
379  }
380  // When we have emulated the writting to lcl_mem0, we acknowledge with a P0 status
381  if ((ddr_write_sts_req == true) && !sSHL_Rol_Mem_WrStsP0.full() && (memP0.tlast == true)) {
382  if (count_cycles_to_ack_ddr_status++ == wait_cycles_to_ack_ddr_status) {
383  dmSts_MemWrStsP0.tag = 0;
384  dmSts_MemWrStsP0.okay = 1;
385  dmSts_MemWrStsP0.interr = 0;
386  dmSts_MemWrStsP0.slverr = 0;
387  dmSts_MemWrStsP0.decerr = 0;
388  printf ( "DEBUG tb: Write a memory status command to SHELL/Mem/Mp0 \n" );
389  sSHL_Rol_Mem_WrStsP0.write ( dmSts_MemWrStsP0 );
390  ddr_write_sts_req = false;
391  }
392  else{
393  printf ( "DEBUG tb: Waiting to write a memory status command to SHELL/Mem/Mp0 [%u out of %u] cycles\n", count_cycles_to_ack_ddr_status, wait_cycles_to_ack_ddr_status);
394  }
395  }
396 
397 
398 
399 #endif // ENABLE_DDR
400 
401 
402  //if( !soUdp_meta.empty())
403  //{
404  // NetworkMetaStream tmp_meta = soUdp_meta.read();
405  // printf("NRC received NRCmeta stream from node_rank %d.\n", (int) tmp_meta.tdata.src_rank);
406  //}
407 
408 
409  } else {
410 #ifdef ENABLE_DDR
411  if (!sSHL_Rol_Mem_WrStsP0.empty()) {
412  printf("WARNING: Emptying sSHL_Rol_Mem_WrStsP0 fifo.\n");
413  dmSts_MemWrStsP0 = sSHL_Rol_Mem_WrStsP0.read();
414  }
415 #endif
416  printf ( "## End of simulation at cycle=%3d. \n", simCnt );
417  break;
418  }
419 
420  } // End: while()
421 
422  //-------------------------------------------------------
423  //-- STEP-4 : DRAIN AND WRITE OUTPUT FILE STREAMS
424  //-------------------------------------------------------
425  //---- UAF-->SHELL Data ----
426  if ( !getOutputDataStream ( sUAF_Shl_Data, "sUAF_Shl_Data", "ofsUAF_Shl_Data.dat", simCnt ) ) {
427  nrErr++;
428  }
429  //---- UAF-->SHELL META ----
430  if ( !soUdp_meta.empty() ) {
431  int i = 0;
432  while ( !soUdp_meta.empty() ) {
433  i++;
434  NetworkMetaStream tmp_meta = soUdp_meta.read();
435  printf ( "NRC received NRCmeta stream from rank %d to rank %d.\n", ( int ) tmp_meta.tdata.src_rank, ( int ) tmp_meta.tdata.dst_rank );
436  assert ( tmp_meta.tdata.src_rank == node_rank );
437  //ensure forwarding behavior
438  assert ( tmp_meta.tdata.dst_rank == ( ( tmp_meta.tdata.src_rank + 1 ) % cluster_size ) );
439  }
440  //printf("DEBUG: i=%u\tTOT_TRANSFERS=%u\n", i, TOT_TRANSFERS);
441  assert ( i == TOT_TRANSFERS );
442  } else {
443  printf ( "Error No metadata received...\n" );
444  nrErr++;
445  }
446 
447  //-------------------------------------------------------
448  //-- STEP-5 : FROM THE OUTPUT FILE CREATE AN ARRAY
449  //-------------------------------------------------------
450  if ( !setInputFileToArray ( "ofsUAF_Shl_Data.dat", imgOutputArray, simCnt ) ) {
451  printf ( "### ERROR : Failed to set input array from file \"ofsUAF_Shl_Data.dat\". \n" );
452  nrErr++;
453  }
454  xf::cv::Array2xfMat<OUTPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX> ( imgOutputArray, imgOutput );
455 
456 
457  //------------------------------------------------------
458  //-- STEP-6 : COMPARE INPUT AND OUTPUT FILE STREAMS
459  //------------------------------------------------------
460  int rc1 = system ( "diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
461  ../../../../test/verify_UAF_Shl_Data.dat" );
462  if ( rc1 ) {
463  printf ( "## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n" );
464  } else {
465  printf ( "Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n" );
466  }
467 
468  nrErr += rc1;
469 
470  printf ( "#####################################################\n" );
471  if ( nrErr ) {
472  printf ( "## ERROR - TESTBENCH #%u FAILED (RC=%d) !!! ##\n", tb_trials, nrErr );
473  } else {
474  printf ( "## SUCCESSFULL END OF TESTBENCH #%u (RC=0) ##\n", tb_trials );
475  }
476  printf ( "#####################################################\n" );
477 
478 
479 
480 
481 
482  } // End tb trials while loop
483 
484 
485 
486 
487 
488 
489 
490 
492  #if NO
493 
494  // L2 Vitis MedianBlur
495  medianBlurAccelArray(imgInputArray, imgOutputArrayTb, in_img.rows, in_img.cols);
496  xf::cv::Array2xfMat<OUTPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX>(imgOutputArrayTb, imgOutputTb);
497 
498  // L1 Vitis MedianBlur
499  //median_blur_accel(imgInput, imgOutput, Thresh, k);
500 
501  #endif
502 
503  #if RO
504 
505  median_blur_accel(imgInput, imgOutputTb);
506 
507  #endif
508 
510  xf::cv::imwrite("hls_out_tb.jpg", imgOutputTb);
511  xf::cv::imwrite("hls_out.jpg", imgOutput);
512  cv::imwrite("ocv_ref_out.jpg", ocv_out_img);
513 
514  unsigned int val;
515  unsigned short int row, col;
516 
517  cv::Mat out_img;
518  out_img = in_img.clone();
519 
520  std::vector<cv::Point> hls_points;
521  std::vector<cv::Point> ocv_points;
522  std::vector<cv::Point> common_pts;
523 
524  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX>* select_imgOutput;
525 
526  // Select which output you want to process for image outputs and corners comparisons:
527  // &imgOutput : The processed image by MedianBlur IP inside the ROLE (i.e. I/O traffic is passing through SHELL)
528  // &imgOutputTb : The processed image by MedianBlur IP in this testbench (i.e. I/O traffic is done in testbench)
529  select_imgOutput = &imgOutput;
530 
531  // Clear memory
532  free(imgOutputArrayTb);
533  free(imgOutputArray);
534  free(imgInputArray);
535 
536 
537  return(nrErr);
538 }
ap_uint< 64 > currentMemPattern
ap_uint< 40 > saddr
ap_uint< 1 > drr
ap_uint< 1 > eof
ap_uint< 23 > bbt
ap_uint< 4 > tag
ap_uint< 6 > dsa
ap_uint< 1 > type
ap_uint< 1 > okay
ap_uint< 1 > decerr
ap_uint< 1 > slverr
ap_uint< 4 > tag
ap_uint< 1 > interr
void ocv_ref(cv::Mat img_gray, cv::Mat &ocv_out_img, float Th)
Definition: xf_ocv_ref.hpp:552
#define FRAME_HEIGHT
Definition: config.h:43
#define FRAME_WIDTH
Definition: config.h:46
#define BPERMDW_512
Definition: harris.hpp:120
#define PORTS_OPENED
Definition: harris.hpp:102
#define MIN_TX_LOOPS
#define MIN_RX_LOOPS
#define TOT_TRANSFERS
Definition: config.h:70
#define WINDOW_SIZE
#define TB_TRIALS
stream< NetworkMetaStream > siUdp_meta("siUdp_meta")
stream< NetworkMetaStream > soUdp_meta("soUdp_meta")
int simCnt
stream< Axis< 512 > > sROL_Shl_Mem_WriteP0("sROL_Shl_Mem_WriteP0")
stream< DmCmd > sROL_Shl_Mem_WrCmdP0("sROL_Shl_Mem_WrCmdP0")
stream< UdpWord > sUAF_Shl_Data("sUAF_Shl_Data")
membus_t lcl_mem0[(1+(IMGSIZE - 1)/(512/8))]
void stepDut()
Run a single iteration of the DUT model.
#define MEMORY_LINES_512
membus_t lcl_mem1[(1+(IMGSIZE - 1)/(512/8))]
stream< UdpWord > sSHL_Uaf_Data("sSHL_Uaf_Data")
stream< DmSts > sSHL_Rol_Mem_WrStsP0("sSHL_Rol_Mem_WrStsP0")
#define ENABLE_DDR_EMULATE_DELAY_IN_TB
ap_uint< 32 > cluster_size
ap_uint< 32 > s_udp_rx_ports
ap_uint< 32 > node_rank
void medianBlurAccelArray(ap_uint< 8 > *img_inp, ap_uint< 64 > *img_out, int rows, int cols)
Top-level accelerated function of the MedianBlur Application with array I/F.
void median_blur_accel(xf::cv::Mat< XF_8UC1, 1024, 1024, XF_NPPC1 > &_src, xf::cv::Mat< XF_8UC1, 1024, 1024, XF_NPPC1 > &_dst)
Top-level accelerated function of the MedianBlur Application with xf::cv I/F.
#define EXTRA_DDR_LATENCY_DUE_II
Definition: memtest.hpp:99
#define DDR_LATENCY
Definition: memtest.hpp:98
#define ENABLE_DDR
Definition: memtest.hpp:42
#define TYPICAL_DDR_LATENCY
Definition: memtest.hpp:97
#define PACK_SIZE
Definition: config.h:51
bool setInputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string inpFileName)
Initialize an input data stream from a file.
Definition: tb_nal.cpp:214
#define DEFAULT_RX_PORT
Definition: nal.hpp:139
bool getOutputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string outFileName)
Fill an output file with data from an output stream.
Definition: tb_nal.cpp:526
bool dumpImgToFile(xf::cv::Mat< OUT_TYPE, HEIGHT, WIDTH, NPIX > &_img, const std::string outFileName, int simCnt)
Fill an output file with data from an image.
bool setInputFileToArray(const std::string inpFileName, ap_uint< OUTPUT_PTR_WIDTH > *imgArray, int simCnt)
Initialize an input array from a file with format "tdata tkeep tlast".
ap_uint<(D+7)/8 > tkeep
Definition: axi_utils.hpp:49
ap_uint< 1 > tlast
Definition: axi_utils.hpp:50
ap_uint< D > tdata
Definition: axi_utils.hpp:48
NetworkMeta tdata
Definition: network.hpp:109
NodeId dst_rank
Definition: network.hpp:95
NodeId src_rank
Definition: network.hpp:97
Here is the call graph for this function:

◆ main() [2/2]

int main ( int  argc,
char *  argv[] 
)

Main testbench for the user-application for MedianBlur on host. Server

Returns
O on success, 1 on fail

Definition at line 46 of file median_blur_host_fwd_tb.cpp.

46  {
47 
48  if ((argc < 2) || (argc > 3)) { // Test for correct number of parameters
49  cerr << "Usage: " << argv[0] << " <Server Port> <optional simulation mode>" << endl;
50  exit(1);
51  }
52 
53  if (!isNumeric(argv[1])) {
54  cerr << "ERROR: Unidentified provided port : " << argv[1] << " . Aborting..." << endl;
55  exit(1);
56  }
57 
58  unsigned short servPort = atoi(argv[1]); // First arg: local port
59  unsigned int num_frame = 0;
60  string clean_cmd;
61 
62 #ifdef SHOW_WINDOWS
63  namedWindow("tb_recv", WINDOW_AUTOSIZE);
64 #endif // SHOW_WINDOWS
65 
66  try {
67  #if NET_TYPE == udp
68  UDPSocket sock(servPort);
69  #else
70  TCPServerSocket servSock(servPort); // Server Socket object
71  TCPSocket *servsock = servSock.accept(); // Wait for a client to connect
72  #endif
73  char buffer[BUF_LEN]; // Buffer for echo string
74  int recvMsgSize; // Size of received message
75  string sourceAddress; // Address of datagram source
76 
77  #if NET_TYPE == tcp
78  // TCP client handling
79  cout << "Handling client ";
80  try {
81  cout << servsock->getForeignAddress() << ":";
82  } catch (SocketException e) {
83  cerr << "Unable to get foreign address" << endl;
84  }
85  try {
86  cout << servsock->getForeignPort();
87  } catch (SocketException e) {
88  cerr << "Unable to get foreign port" << endl;
89  }
90  cout << endl;
91  #endif
92 
93 
94  // RX Step
95  clock_t last_cycle_rx = clock();
96  while (1) {
97  // Block until receive message from a client
98 
99  int total_pack = 1 + (FRAME_TOTAL - 1) / PACK_SIZE;
100  int bytes_in_last_pack = (FRAME_TOTAL) - (total_pack - 1) * PACK_SIZE;
101  int receiving_now = PACK_SIZE;
102  cout << " ___________________________________________________________________ " << endl;
103  cout << "/ \\" << endl;
104  cout << "INFO: Proxy tb Frame # " << ++num_frame << endl;
105  cout << "INFO: Expecting length of packs:" << total_pack << endl;
106  char * longbuf = new char[PACK_SIZE * total_pack];
107 
108  // RX Loop
109  for (int i = 0; i < total_pack; i++) {
110  if ( i == total_pack - 1 ) {
111  receiving_now = bytes_in_last_pack;
112  }
113  #if NET_TYPE == udp
114  recvMsgSize = sock.recvFrom(buffer, BUF_LEN, sourceAddress, servPort);
115  #else
116  recvMsgSize = servsock->recv(buffer, receiving_now);
117  #endif
118  if (recvMsgSize != receiving_now) {
119  cerr << "ERROR: Received unexpected size pack:" << recvMsgSize << endl;
120  continue;
121  }
122  memcpy( & longbuf[i * PACK_SIZE], buffer, receiving_now);
123  }
124 
125  cout << "INFO: Received packet from " << sourceAddress << ":" << servPort << endl;
126 
127  cv::Mat frame = cv::Mat(FRAME_HEIGHT, FRAME_WIDTH, INPUT_TYPE_HOST, longbuf); // OR vec.data() instead of ptr
128  if (frame.size().width == 0) {
129  cerr << "ERROR: receive failure!" << endl;
130  continue;
131  }
132 #ifdef SHOW_WINDOWS
133  imshow("tb_recv", frame);
134 #endif // SHOW_WINDOWS
135 
136  // We save the image received from network in order to process it with the median_blur HLS TB
137  imwrite("../../../../../../ROLE/vision/hls/median_blur/test/input_from_udp_to_fpga.png", frame);
138 
139  // Select simulation mode, default fcsim
140  string synth_cmd = " ";
141  string exec_cmd = "make fcsim -j 4";
142  string ouf_file = "../../../../../../ROLE/vision/hls/median_blur/median_blur_prj/solution1/fcsim/build/hls_out.jpg";
143  if (argc == 3) {
144  if (atoi(argv[2]) == 2) {
145  exec_cmd = "make csim";
146  ouf_file = "../../../../../../ROLE/vision/hls/median_blur/median_blur_prj/solution1/csim/build/hls_out.jpg";
147  }
148  else if (atoi(argv[2]) == 3) {
149  synth_cmd = "make csynth && ";
150  exec_cmd = "make cosim";
151  ouf_file = "../../../../../../ROLE/vision/hls/median_blur/median_blur_prj/solution1/sim/wrapc_pc/hls_out.jpg";
152  }
153  else if (atoi(argv[2]) == 4) {
154  exec_cmd = "make kcachegrind";
155  ouf_file = "../../../../../../ROLE/vision/hls/median_blur/median_blur_prj/solution1/fcsim/build/hls_out.jpg";
156  }
157  }
158  // Calling the actual TB over its typical makefile procedure, but passing the save file
159  // Skip the rebuilding phase on the 2nd run. However ensure that it's a clean recompile
160  // the first time.
161  clean_cmd = " ";
162  if (num_frame == 1) {
163  clean_cmd = "make clean && ";
164  }
165  string str_command = "cd ../../../../../../ROLE/vision/hls/median_blur/ && " + clean_cmd + synth_cmd + "\
166  INPUT_IMAGE=./test/input_from_udp_to_fpga.png " + exec_cmd + " && \
167  cd ../../../../HOST/vision/median_blur/languages/cplusplus/build/ ";
168  const char *command = str_command.c_str();
169  cout << "Calling TB with command:" << command << endl;
170  system(command);
171 
172  free(longbuf);
173 
174  clock_t next_cycle_rx = clock();
175  double duration_rx = (next_cycle_rx - last_cycle_rx) / (double) CLOCKS_PER_SEC;
176  cout << "INFO: Effective FPS RX:" << (1 / duration_rx) << " \tkbps:" << (PACK_SIZE *
177  total_pack / duration_rx / 1024 * 8) << endl;
178  last_cycle_rx = next_cycle_rx;
179 
180 
181  // TX step
182  frame = cv::imread(ouf_file, cv::IMREAD_GRAYSCALE); // reading in the image in grey scale
183  if (!frame.data) {
184  cerr << "ERROR: Failed to load the image " << ouf_file << endl;
185  return -1;
186  }
187  else {
188  cout << "INFO: Succesfully loaded image " << ouf_file << endl;
189  }
190 
191  assert(frame.total() == FRAME_WIDTH * FRAME_HEIGHT);
192 
193  imshow("tb_send", frame);
194 
195  // Ensure that the send Mat is in continuous memory space. Typically, imread or resize
196  // will return such a continuous Mat, but we should check it.
197  assert(frame.isContinuous());
198 
199  // TX Loop
200  unsigned int sending_now = PACK_SIZE;
201  clock_t last_cycle_tx = clock();
202  for (int i = 0; i < total_pack; i++) {
203  if ( i == total_pack - 1 ) {
204  sending_now = bytes_in_last_pack;
205  }
206  #if NET_TYPE == udp
207  sock.sendTo( & frame.data[i * PACK_SIZE], sending_now, sourceAddress, servPort);
208  #else
209  //sock.send( & frame.data[i * PACK_SIZE], sending_now);
210  servsock->send( & frame.data[i * PACK_SIZE], sending_now);
211  #endif
212  }
213 
214  clock_t next_cycle_tx = clock();
215  double duration_tx = (next_cycle_tx - last_cycle_tx) / (double) CLOCKS_PER_SEC;
216  cout << "INFO: Effective FPS TX:" << (1 / duration_tx) << " \tkbps:" << (PACK_SIZE *
217  total_pack / duration_tx / 1024 * 8) << endl;
218  last_cycle_tx = next_cycle_tx;
219  cout << "\\___________________________________________________________________/" << endl;
220  break;} // while loop
221  #if NET_TYPE == tcp
222  delete servsock;
223  #endif
224  } catch (SocketException & e) {
225  cerr << e.what() << endl;
226  exit(1);
227  }
228  return 0;
229 }
#define FRAME_TOTAL
Definition: config.h:74
#define INPUT_TYPE_HOST
Definition: config.h:68
#define BUF_LEN
Definition: config.h:54
def clock()
Definition: common.py:174
bool isNumeric(const std::string str)
Definition: util.cpp:58
Here is the call graph for this function:

◆ ocv_ref()

void ocv_ref ( cv::Mat  img_gray,
cv::Mat &  ocv_out_img,
int  ksize 
)

Definition at line 62 of file xf_ocv_ref.hpp.

62  {
63 
64  cv::medianBlur (img_gray, ocv_out_img, ksize);
65 
66 }

◆ siUdp_meta()

stream<NetworkMetaStream> siUdp_meta ( "siUdp_meta"  )
Here is the caller graph for this function:

◆ soUdp_meta()

stream<NetworkMetaStream> soUdp_meta ( "soUdp_meta"  )
Here is the caller graph for this function:

◆ sROL_Shl_Mem_RdCmdP0()

stream<DmCmd> sROL_Shl_Mem_RdCmdP0 ( "sROL_Shl_Mem_RdCmdP0"  )
Here is the caller graph for this function:

◆ sROL_Shl_Mem_WrCmdP0()

stream<DmCmd> sROL_Shl_Mem_WrCmdP0 ( "sROL_Shl_Mem_WrCmdP0"  )
Here is the caller graph for this function:

◆ sROL_Shl_Mem_WriteP0()

stream<Axis< 512 > > sROL_Shl_Mem_WriteP0 ( "sROL_Shl_Mem_WriteP0"  )
Here is the caller graph for this function:

◆ sSHL_Rol_Mem_RdStsP0()

stream<DmSts> sSHL_Rol_Mem_RdStsP0 ( "sSHL_Rol_Mem_RdStsP0"  )
Here is the caller graph for this function:

◆ sSHL_Rol_Mem_ReadP0()

stream<Axis< 512 > > sSHL_Rol_Mem_ReadP0 ( "sSHL_Rol_Mem_ReadP0"  )
Here is the caller graph for this function:

◆ sSHL_Rol_Mem_WrStsP0()

stream<DmSts> sSHL_Rol_Mem_WrStsP0 ( "sSHL_Rol_Mem_WrStsP0"  )
Here is the caller graph for this function:

◆ sSHL_Uaf_Data()

stream<UdpWord> sSHL_Uaf_Data ( "sSHL_Uaf_Data"  )
Here is the caller graph for this function:

◆ stepDut()

void stepDut ( )

Run a single iteration of the DUT model.

Returns
Nothing.

Definition at line 127 of file test_median_blur.cpp.

127  {
128  median_blur(
133  #ifdef ENABLE_DDR
134  ,
135  // sROL_Shl_Mem_RdCmdP0,
136  // sSHL_Rol_Mem_RdStsP0,
137  // sSHL_Rol_Mem_ReadP0,
141  lcl_mem0,
142  lcl_mem1
143  #endif
144  );
145  simCnt++;
146  printf("[%4.4d] STEP DUT \n", simCnt);
147 }
void median_blur(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NetworkWord > &siSHL_This_Data, stream< NetworkWord > &soTHIS_Shl_Data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &soNrc_meta, ap_uint< 32 > *po_rx_ports, stream< DmCmd > &soMemWrCmdP0, stream< DmSts > &siMemWrStsP0, stream< Axis< 512 > > &soMemWriteP0, membus_t *lcl_mem0, membus_t *lcl_mem1)
Main process of the MedianBlur Application directives.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sUAF_Shl_Data()

stream<UdpWord> sUAF_Shl_Data ( "sUAF_Shl_Data"  )
Here is the caller graph for this function:

Variable Documentation

◆ cluster_size

ap_uint<32> cluster_size

Definition at line 93 of file test_median_blur.cpp.

◆ lcl_mem0

membus_t lcl_mem0[(1+(IMGSIZE - 1)/(512/8))]

Definition at line 113 of file test_median_blur.cpp.

◆ lcl_mem1

membus_t lcl_mem1[(1+(IMGSIZE - 1)/(512/8))]

Definition at line 114 of file test_median_blur.cpp.

◆ node_rank

ap_uint<32> node_rank

Definition at line 92 of file test_median_blur.cpp.

◆ piSHL_This_MmioCaptPktEn

ap_uint<1> piSHL_This_MmioCaptPktEn

Definition at line 82 of file test_median_blur.cpp.

◆ piSHL_This_MmioPostPktEn

ap_uint<1> piSHL_This_MmioPostPktEn

Definition at line 81 of file test_median_blur.cpp.

◆ s_udp_rx_ports

ap_uint<32> s_udp_rx_ports = 0x0

Definition at line 89 of file test_median_blur.cpp.

◆ simCnt

int simCnt

Definition at line 120 of file test_median_blur.cpp.