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

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

Collaboration diagram for WarpTransform Testbench:

Files

file  warp_transform_host_fwd_tb.cpp
 Testbench for WarpTransform userspace application for cF (x86, ppc64).
 
file  xf_ocv_ref.hpp
 The WarpTransform reference functions used in TB.
 
file  test_warp_transform.cpp
 : Testbench for WarpTransform.
 

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   3
 
#define ENABLE_DDR_EMULATE_DELAY_IN_TB
 
#define ENABLED   (ap_uint<1>)1
 
#define DISABLED   (ap_uint<1>)0
 
#define TRMAT_DIM2   3
 
#define TRMAT_DIM1   2
 
#define MEMORY_LINES_512   TOTMEMDW_512 /* 64 KiB */
 

Functions

int main (int argc, char *argv[])
 
void ocv_ref (cv::Mat image_input, cv::Mat &opencv_image, cv::Mat transformation_matrix)
 
stream< UdpWordsSHL_Uaf_Data ("sSHL_Uaf_Data")
 
stream< UdpWordsUAF_Shl_Data ("sUAF_Shl_Data")
 
stream< UdpWordimage_stream_from_warp_transform ("image_stream_from_warp_transform")
 
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+(32 *32 - 1)/(512/8))]
 
membus_t lcl_mem1 [(1+(32 *32 - 1)/(512/8))]
 
int simCnt
 

Detailed Description

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

Macro Definition Documentation

◆ DEBUG_LEVEL

#define DEBUG_LEVEL   (TRACE_ALL)

Definition at line 54 of file test_warp_transform.cpp.

◆ DEBUG_TRACE

#define DEBUG_TRACE   true

Definition at line 64 of file test_warp_transform.cpp.

◆ DISABLED

#define DISABLED   (ap_uint<1>)0

Definition at line 73 of file test_warp_transform.cpp.

◆ ENABLE_DDR_EMULATE_DELAY_IN_TB

#define ENABLE_DDR_EMULATE_DELAY_IN_TB

Definition at line 70 of file test_warp_transform.cpp.

◆ ENABLED

#define ENABLED   (ap_uint<1>)1

Definition at line 72 of file test_warp_transform.cpp.

◆ KO

#define KO   false

Definition at line 61 of file test_warp_transform.cpp.

◆ MEMORY_LINES_512

#define MEMORY_LINES_512   TOTMEMDW_512 /* 64 KiB */

Definition at line 121 of file test_warp_transform.cpp.

◆ OK

#define OK   true

Definition at line 60 of file test_warp_transform.cpp.

◆ TB_TRIALS

#define TB_TRIALS   3

Definition at line 67 of file test_warp_transform.cpp.

◆ THIS_NAME

#define THIS_NAME   "TB"

Definition at line 46 of file test_warp_transform.cpp.

◆ TRACE_ALL

#define TRACE_ALL   0xFFFF

Definition at line 52 of file test_warp_transform.cpp.

◆ TRACE_MMIO

#define TRACE_MMIO   1 << 3

Definition at line 51 of file test_warp_transform.cpp.

◆ TRACE_OFF

#define TRACE_OFF   0x0000

Definition at line 48 of file test_warp_transform.cpp.

◆ TRACE_UAF

#define TRACE_UAF   1 << 2

Definition at line 50 of file test_warp_transform.cpp.

◆ TRACE_URIF

#define TRACE_URIF   1 << 1

Definition at line 49 of file test_warp_transform.cpp.

◆ TRMAT_DIM1

#define TRMAT_DIM1   2

Definition at line 81 of file test_warp_transform.cpp.

◆ TRMAT_DIM2

#define TRMAT_DIM2   3

Definition at line 80 of file test_warp_transform.cpp.

◆ UNVALID

#define UNVALID   false

Definition at line 63 of file test_warp_transform.cpp.

◆ VALID

#define VALID   true

Definition at line 62 of file test_warp_transform.cpp.

Function Documentation

◆ image_stream_from_warp_transform()

stream<UdpWord> image_stream_from_warp_transform ( "image_stream_from_warp_transform"  )

◆ 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 163 of file test_warp_transform.cpp.

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

Returns
O on success, 1 on fail

Definition at line 45 of file warp_transform_host_fwd_tb.cpp.

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

◆ ocv_ref()

void ocv_ref ( cv::Mat  image_input,
cv::Mat &  opencv_image,
cv::Mat  transformation_matrix 
)

Definition at line 62 of file xf_ocv_ref.hpp.

62  {
63 
64  for (int I1 = 0; I1 < opencv_image.rows; I1++) {
65  for (int J1 = 0; J1 < opencv_image.cols; J1++) {
66 #if GRAY
67  opencv_image.at<unsigned char>(I1, J1) = 0;
68 #else
69  opencv_image.at<cv::Vec3b>(I1, J1) = 0;
70 #endif
71  }
72  }
73 
74 #if TRANSFORM_TYPE == 1
75 #if INTERPOLATION == 1
76  cv::warpPerspective(image_input, opencv_image, transformation_matrix,
77  cv::Size(image_input.cols, image_input.rows), cv::INTER_LINEAR + cv::WARP_INVERSE_MAP,
78  cv::BORDER_TRANSPARENT, 80);
79 #else
80  cv::warpPerspective(image_input, opencv_image, transformation_matrix,
81  cv::Size(image_input.cols, image_input.rows), cv::INTER_NEAREST + cv::WARP_INVERSE_MAP,
82  cv::BORDER_TRANSPARENT, 80);
83 #endif
84 #else
85 #if INTERPOLATION == 1
86  cv::warpAffine(image_input, opencv_image, transformation_matrix, cv::Size(image_input.cols, image_input.rows),
87  cv::INTER_LINEAR + cv::WARP_INVERSE_MAP, cv::BORDER_TRANSPARENT, 80);
88 #else
89  cv::warpAffine(image_input, opencv_image, transformation_matrix, cv::Size(image_input.cols, image_input.rows),
90  cv::INTER_NEAREST + cv::WARP_INVERSE_MAP, cv::BORDER_TRANSPARENT, 80);
91 #endif
92 #endif
93 
94  cv::imwrite("opencv_output.png", opencv_image);
95 }

◆ 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"  )

◆ 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"  )

◆ sSHL_Rol_Mem_ReadP0()

stream<Axis< 512 > > sSHL_Rol_Mem_ReadP0 ( "sSHL_Rol_Mem_ReadP0"  )

◆ 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 136 of file test_warp_transform.cpp.

136  {
142  #ifdef ENABLE_DDR
143  ,
147  lcl_mem0,
148  lcl_mem1
149  #endif
150  );
151  simCnt++;
152  printf("[%4.4d] STEP DUT \n", simCnt);
153 }
void warp_transform(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)
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 102 of file test_warp_transform.cpp.

◆ lcl_mem0

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

Definition at line 122 of file test_warp_transform.cpp.

◆ lcl_mem1

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

Definition at line 123 of file test_warp_transform.cpp.

◆ node_rank

ap_uint<32> node_rank

Definition at line 101 of file test_warp_transform.cpp.

◆ piSHL_This_MmioCaptPktEn

ap_uint<1> piSHL_This_MmioCaptPktEn

Definition at line 91 of file test_warp_transform.cpp.

◆ piSHL_This_MmioPostPktEn

ap_uint<1> piSHL_This_MmioPostPktEn

Definition at line 90 of file test_warp_transform.cpp.

◆ s_udp_rx_ports

ap_uint<32> s_udp_rx_ports = 0x0

Definition at line 98 of file test_warp_transform.cpp.

◆ simCnt

int simCnt

Definition at line 129 of file test_warp_transform.cpp.