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

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

Collaboration diagram for Harris Testbench:

Files

file  harris_host_fwd_tb.cpp
 Testbench for Harris userspace application for cF (x86, ppc64).
 
file  xf_ocv_ref.hpp
 The Harris reference functions used in TB.
 
file  test_harris.cpp
 : Testbench for Harris.
 

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
 

Typedefs

typedef float NMSTYPE
 

Functions

int main (int argc, char *argv[])
 
bool OCVFindMaximum2 (NMSTYPE *t1, NMSTYPE *t2, NMSTYPE *m1, NMSTYPE *b1, NMSTYPE *b2)
 
void OCVMaxSuppression2 (cv::Mat &src, cv::Mat &dst)
 
bool OCVFindMaximum1 (NMSTYPE t0, NMSTYPE t1, NMSTYPE t2, NMSTYPE m0, NMSTYPE m1, NMSTYPE m2, NMSTYPE b0, NMSTYPE b1, NMSTYPE b2)
 
void OCVMaxSuppression1 (cv::Mat &src, cv::Mat &dst)
 
void ocv_ref (cv::Mat img_gray, cv::Mat &ocv_out_img, float Th)
 
stream< UdpWordsSHL_Uaf_Data ("sSHL_Uaf_Data")
 
stream< UdpWordsUAF_Shl_Data ("sUAF_Shl_Data")
 
stream< UdpWordimage_stream_from_harris ("image_stream_from_harris")
 
stream< NetworkMetaStreamsiUdp_meta ("siUdp_meta")
 
stream< NetworkMetaStreamsoUdp_meta ("soUdp_meta")
 
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
 
int simCnt
 

Detailed Description

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

This is a subgroup of Harris 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_harris.cpp.

◆ DEBUG_TRACE

#define DEBUG_TRACE   true

Definition at line 63 of file test_harris.cpp.

◆ DISABLED

#define DISABLED   (ap_uint<1>)0

Definition at line 72 of file test_harris.cpp.

◆ ENABLE_DDR_EMULATE_DELAY_IN_TB

#define ENABLE_DDR_EMULATE_DELAY_IN_TB

Definition at line 69 of file test_harris.cpp.

◆ ENABLED

#define ENABLED   (ap_uint<1>)1

Definition at line 71 of file test_harris.cpp.

◆ KO

#define KO   false

Definition at line 60 of file test_harris.cpp.

◆ OK

#define OK   true

Definition at line 59 of file test_harris.cpp.

◆ TB_TRIALS

#define TB_TRIALS   2

Definition at line 66 of file test_harris.cpp.

◆ THIS_NAME

#define THIS_NAME   "TB"

Definition at line 45 of file test_harris.cpp.

◆ TRACE_ALL

#define TRACE_ALL   0xFFFF

Definition at line 51 of file test_harris.cpp.

◆ TRACE_MMIO

#define TRACE_MMIO   1 << 3

Definition at line 50 of file test_harris.cpp.

◆ TRACE_OFF

#define TRACE_OFF   0x0000

Definition at line 47 of file test_harris.cpp.

◆ TRACE_UAF

#define TRACE_UAF   1 << 2

Definition at line 49 of file test_harris.cpp.

◆ TRACE_URIF

#define TRACE_URIF   1 << 1

Definition at line 48 of file test_harris.cpp.

◆ UNVALID

#define UNVALID   false

Definition at line 62 of file test_harris.cpp.

◆ VALID

#define VALID   true

Definition at line 61 of file test_harris.cpp.

Typedef Documentation

◆ NMSTYPE

typedef float NMSTYPE

Definition at line 61 of file xf_ocv_ref.hpp.

Function Documentation

◆ image_stream_from_harris()

stream<UdpWord> image_stream_from_harris ( "image_stream_from_harris"  )

◆ 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_harris.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 HARRIS
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  uint16_t Thresh; // Threshold for HLS
214  float Th;
215  if (FILTER_WIDTH == 3) {
216  Th = 30532960.00;
217  Thresh = 442;
218  } else if (FILTER_WIDTH == 5) {
219  Th = 902753878016.0;
220  Thresh = 3109;
221  } else if (FILTER_WIDTH == 7) {
222  Th = 41151168289701888.000000;
223  Thresh = 566;
224  }
225 
226 
227  //------------------------------------------------------
228  //-- STEP-1.1 : CREATE MEMORY FOR OUTPUT IMAGES
229  //------------------------------------------------------
230  // cvtColor(in_img, img_gray, CV_BGR2GRAY);
231  // Convert rgb into grayscale
232  hls_out_img.create(in_img.rows, in_img.cols, CV_8U); // create memory for hls output image
233  ocv_out_img.create(in_img.rows, in_img.cols, CV_8U); // create memory for opencv output image
234 
235  #if NO
236  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC1> imgInput(in_img.rows, in_img.cols);
237  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC1> imgOutput(in_img.rows, in_img.cols);
238  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC1> imgOutputTb(in_img.rows, in_img.cols);
239  imgInput.copyTo(in_img.data);
240  // imgInput = xf::cv::imread<IN_TYPE, HEIGHT, WIDTH, XF_NPPC1>(argv[1], 0);
241  ap_uint<INPUT_PTR_WIDTH> *imgInputArray = (ap_uint<INPUT_PTR_WIDTH>*) malloc(in_img.rows * in_img.cols * sizeof(ap_uint<INPUT_PTR_WIDTH>));
242  ap_uint<OUTPUT_PTR_WIDTH> *imgOutputArrayTb = (ap_uint<OUTPUT_PTR_WIDTH>*) malloc(in_img.rows * in_img.cols * sizeof(ap_uint<OUTPUT_PTR_WIDTH>));
243  ap_uint<OUTPUT_PTR_WIDTH> *imgOutputArray = (ap_uint<OUTPUT_PTR_WIDTH>*) malloc(in_img.rows * in_img.cols * sizeof(ap_uint<OUTPUT_PTR_WIDTH>));
244  xf::cv::xfMat2Array<INPUT_PTR_WIDTH, IN_TYPE, HEIGHT, WIDTH, NPIX>(imgInput, imgInputArray);
245  #endif
246 
247  #if RO
248  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC8> imgInput(in_img.rows, in_img.cols);
249  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC8> imgOutput(in_img.rows, in_img.cols);
250  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC1> imgOutputTb(in_img.rows, in_img.cols);
251  #endif
252 
253  while (tb_trials++ < TB_TRIALS) {
254 
255 
256  printf ( "##################################################### \n" );
257  printf ( "## TESTBENCH #%u STARTS HERE ##\n", tb_trials );
258  printf ( "##################################################### \n" );
259 
260 
261  simCnt = 0;
262  nrErr = 0;
263 
264 #if NO
265  if ( !dumpImgToFile ( imgInput, "ifsSHL_Uaf_Data.dat", simCnt ) ) {
266  nrErr++;
267  }
268 #endif
269 
270 #if RO
271  // imgInput.copyTo(img_gray.data);
272  imgInput = xf::cv::imread<IN_TYPE, HEIGHT, WIDTH, XF_NPPC8> ( argv[1], 0 );
273 #endif
274 
275 
276 
277  //------------------------------------------------------
278  //-- STEP-1.2 : RUN HARRIS DETECTOR FROM OpenCV LIBRARY
279  //------------------------------------------------------
280  ocv_ref ( in_img, ocv_out_img, Th );
281 
282 
283 
284  //------------------------------------------------------
285  //-- STEP-2.1 : CREATE TRAFFIC AS INPUT STREAMS
286  //------------------------------------------------------
287  if ( nrErr == 0 ) {
288  if ( !setInputDataStream ( sSHL_Uaf_Data, "sSHL_Uaf_Data", "ifsSHL_Uaf_Data.dat", simCnt ) ) {
289  printf ( "### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n" );
290  nrErr++;
291  }
292 
293  //there are TOT_TRANSFERS streams from the the App to the Role
295  for ( int i=0; i<TOT_TRANSFERS; i++ ) {
296  siUdp_meta.write ( NetworkMetaStream ( tmp_meta ) );
297  }
298  //set correct node_rank and cluster_size
299  node_rank = 1;
300  cluster_size = 2;
301  }
302 
303  //------------------------------------------------------
304  //-- STEP-2.2 : SET THE PASS-THROUGH MODE
305  //------------------------------------------------------
306  //piSHL_This_MmioEchoCtrl.write(ECHO_PATH_THRU);
307  //[TODO] piSHL_This_MmioPostPktEn.write(DISABLED);
308  //[TODO] piSHL_This_MmioCaptPktEn.write(DISABLED);
309 
310  //------------------------------------------------------
311  //-- STEP-3 : MAIN TRAFFIC LOOP
312  //------------------------------------------------------
313  while ( !nrErr ) {
314 
315  // Keep enough simulation time for sequntially executing the FSMs of the main 3 functions
316  // (Rx-Proc-Tx)
318 #ifdef ENABLE_DDR
321 #endif
322 #endif
323  ) {
324  stepDut();
325 
326  if ( simCnt > 2 ) {
327  assert ( s_udp_rx_ports == PORTS_OPENED );
328  }
329 
330 if (simCnt < 0)
331  exit(0);
332 #ifdef ENABLE_DDR
333 
334  if ( !sROL_Shl_Mem_WrCmdP0.empty() ) {
335  printf ( "DEBUG tb: Read a memory write command from SHELL/Mem/Mp0 \n" );
336  //-- Read a memory write command from SHELL/Mem/Mp0
337  sROL_Shl_Mem_WrCmdP0.read ( dmCmd_MemCmdP0 );
338  //assert ( dmCmd_MemCmdP0.bbt == CHECK_CHUNK_SIZE );
339  assert ( dmCmd_MemCmdP0.type == 1 && dmCmd_MemCmdP0.dsa == 0 && dmCmd_MemCmdP0.eof == 1 && dmCmd_MemCmdP0.drr == 1 && dmCmd_MemCmdP0.tag == 0x0 );
340  ddr_addr_in = (unsigned int)dmCmd_MemCmdP0.saddr / BPERMDW_512; // Convert the byte-aligned address to local mem of stack tb.
341  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);
342  assert (ddr_addr_in <= MEMORY_LINES_512-1);
343  //ddr_write_req_iter++;
344  //printf ( "DEBUG tb: (ddr_write_req_iter)%(MEMORY_LINES_512-1)=%u\n", (ddr_write_req_iter)%(MEMORY_LINES_512-1));
345  if ((++ddr_write_req_iter)%(MEMORY_LINES_512) == 0) {
346  ddr_write_req_iter = 0;
347  }
348  printf ( "DEBUG tb: ddr_write_req_iter=%u\n", ddr_write_req_iter);
349 
350 #ifdef ENABLE_DDR_EMULATE_DELAY_IN_TB
351  /*
352  * 16 -> emulate a response in 16 cycles
353  * 1 -> emulate immediate response
354  * CYCLES_UNTIL_TIMEOUT -> on purpose timeout
355  */
356  if (ddr_write_req_iter == 1) {
357  wait_cycles_to_ack_ddr_status = TYPICAL_DDR_LATENCY;
358  }
359  else if (ddr_write_req_iter == 2) {
360  wait_cycles_to_ack_ddr_status = TYPICAL_DDR_LATENCY;
361  }
362  else {
363  wait_cycles_to_ack_ddr_status = TYPICAL_DDR_LATENCY;
364  }
365  if (!sSHL_Rol_Mem_WrStsP0.empty()) {
366  printf("WARNING: Emptying sSHL_Rol_Mem_WrStsP0 fifo.\n");
367  dmSts_MemWrStsP0 = sSHL_Rol_Mem_WrStsP0.read();
368  }
369 #else
370  wait_cycles_to_ack_ddr_status = 0;
371 #endif
372  count_cycles_to_ack_ddr_status = 0;
373  ddr_write_sts_req = false;
374  }
375 
376  if ( !sROL_Shl_Mem_WriteP0.empty() ) {
377  sROL_Shl_Mem_WriteP0.read ( memP0 );
378  printf ( "DEBUG tb: Write a memory line from SHELL/Mem/Mp0 \n" );
379 
380  assert ( memP0.tkeep == 0xffffffffffffffff );
381 
382  /* Read from AXI stream DDR interface and write to the memory mapped interface of
383  * DDR channel P0. In the real HW, this is enabled by the AXI interconnect and AXI
384  * Datamover, being instantiated in VHDL.
385  * */
386  printf ( "DEBUG tb: Writting to address 0x%x : %u an amount of %u bytes\n", ddr_addr_in, memP0.tdata.to_long(), BPERMDW_512);
387  //lcl_mem0[ddr_addr_in++] = memP0.tdata;
388  memcpy(&lcl_mem0[ddr_addr_in++], &memP0.tdata, BPERMDW_512);
389  ddr_write_sts_req = true;
390  }
391  // When we have emulated the writting to lcl_mem0, we acknowledge with a P0 status
392  if ((ddr_write_sts_req == true) && !sSHL_Rol_Mem_WrStsP0.full() && (memP0.tlast == true)) {
393  if (count_cycles_to_ack_ddr_status++ == wait_cycles_to_ack_ddr_status) {
394  dmSts_MemWrStsP0.tag = 7;
395  dmSts_MemWrStsP0.okay = 1;
396  dmSts_MemWrStsP0.interr = 0;
397  dmSts_MemWrStsP0.slverr = 0;
398  dmSts_MemWrStsP0.decerr = 0;
399  printf ( "DEBUG tb: Write a memory status command to SHELL/Mem/Mp0 \n" );
400  sSHL_Rol_Mem_WrStsP0.write ( dmSts_MemWrStsP0 );
401  ddr_write_sts_req = false;
402  }
403  else{
404  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);
405  }
406  }
407 
408 
409 
410 #endif // ENABLE_DDR
411 
412 
413  //if( !soUdp_meta.empty())
414  //{
415  // NetworkMetaStream tmp_meta = soUdp_meta.read();
416  // printf("NRC received NRCmeta stream from node_rank %d.\n", (int) tmp_meta.tdata.src_rank);
417  //}
418 
419 
420  } else {
421 #ifdef ENABLE_DDR
422  if (!sSHL_Rol_Mem_WrStsP0.empty()) {
423  printf("WARNING: Emptying sSHL_Rol_Mem_WrStsP0 fifo.\n");
424  dmSts_MemWrStsP0 = sSHL_Rol_Mem_WrStsP0.read();
425  }
426 #endif
427  printf ( "## End of simulation at cycle=%3d. \n", simCnt );
428  break;
429  }
430 
431  } // End: while()
432 
433  //-------------------------------------------------------
434  //-- STEP-4 : DRAIN AND WRITE OUTPUT FILE STREAMS
435  //-------------------------------------------------------
436  //---- UAF-->SHELL Data ----
437  if ( !getOutputDataStream ( sUAF_Shl_Data, "sUAF_Shl_Data", "ofsUAF_Shl_Data.dat", simCnt ) ) {
438  nrErr++;
439  }
440  //---- UAF-->SHELL META ----
441  if ( !soUdp_meta.empty() ) {
442  int i = 0;
443  while ( !soUdp_meta.empty() ) {
444  i++;
445  NetworkMetaStream tmp_meta = soUdp_meta.read();
446  printf ( "NRC received NRCmeta stream from rank %d to rank %d.\n", ( int ) tmp_meta.tdata.src_rank, ( int ) tmp_meta.tdata.dst_rank );
447  assert ( tmp_meta.tdata.src_rank == node_rank );
448  //ensure forwarding behavior
449  assert ( tmp_meta.tdata.dst_rank == ( ( tmp_meta.tdata.src_rank + 1 ) % cluster_size ) );
450  }
451  //printf("DEBUG: i=%u\tTOT_TRANSFERS=%u\n", i, TOT_TRANSFERS);
452  assert ( i == TOT_TRANSFERS );
453  } else {
454  printf ( "Error No metadata received...\n" );
455  nrErr++;
456  }
457 
458  //-------------------------------------------------------
459  //-- STEP-5 : FROM THE OUTPUT FILE CREATE AN ARRAY
460  //-------------------------------------------------------
461  if ( !setInputFileToArray ( "ofsUAF_Shl_Data.dat", imgOutputArray, simCnt ) ) {
462  printf ( "### ERROR : Failed to set input array from file \"ofsUAF_Shl_Data.dat\". \n" );
463  nrErr++;
464  }
465  xf::cv::Array2xfMat<OUTPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPIX> ( imgOutputArray, imgOutput );
466 
467 
468  //------------------------------------------------------
469  //-- STEP-6 : COMPARE INPUT AND OUTPUT FILE STREAMS
470  //------------------------------------------------------
471  int rc1 = system ( "diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
472  ../../../../test/verify_UAF_Shl_Data.dat" );
473  if ( rc1 ) {
474  printf ( "## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n" );
475  } else {
476  printf ( "Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n" );
477  }
478 
479  nrErr += rc1;
480 
481  printf ( "#####################################################\n" );
482  if ( nrErr ) {
483  printf ( "## ERROR - TESTBENCH #%u FAILED (RC=%d) !!! ##\n", tb_trials, nrErr );
484  } else {
485  printf ( "## SUCCESSFULL END OF TESTBENCH #%u (RC=0) ##\n", tb_trials );
486  }
487  printf ( "#####################################################\n" );
488 
489 
490 
491 
492 
493  } // End tb trials while loop
494 
495 
496 
497 
498 
499 
500 
501 
502  float K = 0.04;
503  uint16_t k = K * (1 << 16); // Convert to Q0.16 format
504 
505  #if NO
506 
507  // L2 Vitis Harris
508  cornerHarrisAccelArray(imgInputArray, imgOutputArrayTb, in_img.rows, in_img.cols, Thresh, k);
509  xf::cv::Array2xfMat<OUTPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPIX>(imgOutputArrayTb, imgOutputTb);
510 
511  // L1 Vitis Harris
512  //harris_accel(imgInput, imgOutput, Thresh, k);
513 
514  #endif
515 
516  #if RO
517 
518  harris_accel(imgInput, imgOutputTb, Thresh, k);
519 
520  #endif
521 
523  xf::cv::imwrite("hls_out_tb.jpg", imgOutputTb);
524  xf::cv::imwrite("hls_out.jpg", imgOutput);
525 
526  unsigned int val;
527  unsigned short int row, col;
528 
529  cv::Mat out_img;
530  out_img = in_img.clone();
531 
532  std::vector<cv::Point> hls_points;
533  std::vector<cv::Point> ocv_points;
534  std::vector<cv::Point> common_pts;
535 
536  xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPIX>* select_imgOutput;
537 
538  // Select which output you want to process for image outputs and corners comparisons:
539  // &imgOutput : The processed image by Harris IP inside the ROLE (i.e. I/O traffic is passing through SHELL)
540  // &imgOutputTb : The processed image by Harris IP in this testbench (i.e. I/O traffic is done in testbench)
541  select_imgOutput = &imgOutput;
542 
543  // Mark HLS points on the image
544  markPointsOnImage(*select_imgOutput, in_img, out_img, hls_points);
545 
546  // Write HLS and Opencv corners into a file
547  //nrErr +=
548  writeCornersIntoFile(in_img, ocv_out_img, out_img, hls_points, ocv_points, common_pts);
549 
550  // Clear memory
551  free(imgOutputArrayTb);
552  free(imgOutputArray);
553  free(imgInputArray);
554 
555 
556  return(nrErr);
557 }
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
#define FILTER_WIDTH
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
void markPointsOnImage(Mat &imgOutput, Mat &in_img, Mat &out_img, vector< Point > &hw_points)
Mark the points found by Gammacorrection into the image.
#define FRAME_WIDTH
Definition: config.h:46
#define BPERMDW_512
Definition: harris.hpp:120
#define PORTS_OPENED
Definition: harris.hpp:102
#define TB_TRIALS
Definition: test_harris.cpp:66
stream< NetworkMetaStream > siUdp_meta("siUdp_meta")
stream< NetworkMetaStream > soUdp_meta("soUdp_meta")
int simCnt
stream< UdpWord > sUAF_Shl_Data("sUAF_Shl_Data")
void stepDut()
Run a single iteration of the DUT model.
stream< UdpWord > sSHL_Uaf_Data("sSHL_Uaf_Data")
#define ENABLE_DDR_EMULATE_DELAY_IN_TB
Definition: test_harris.cpp:69
ap_uint< 32 > cluster_size
Definition: test_harris.cpp:93
ap_uint< 32 > s_udp_rx_ports
Definition: test_harris.cpp:89
ap_uint< 32 > node_rank
Definition: test_harris.cpp:92
void harris_accel(xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &_src, xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &_dst, unsigned short Thresh, unsigned short k)
Top-level accelerated function of the Harris Application with xf::cv I/F.
void cornerHarrisAccelArray(ap_uint< 8 > *img_inp, ap_uint< 64 > *img_out, int rows, int cols, int threshold, int k)
Top-level accelerated function of the Harris Application with array I/F.
#define MIN_TX_LOOPS
#define MIN_RX_LOOPS
#define TOT_TRANSFERS
Definition: config.h:70
stream< Axis< 512 > > sROL_Shl_Mem_WriteP0("sROL_Shl_Mem_WriteP0")
stream< DmCmd > sROL_Shl_Mem_WrCmdP0("sROL_Shl_Mem_WrCmdP0")
stream< DmSts > sSHL_Rol_Mem_WrStsP0("sSHL_Rol_Mem_WrStsP0")
#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
membus_t lcl_mem0[16384]
membus_t lcl_mem1[16384]
#define MEMORY_LINES_512
#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
unsigned int writeCornersIntoFile(cv::Mat &in_img, cv::Mat &ocv_out_img, cv::Mat &out_img, std::vector< cv::Point > &hls_points, std::vector< cv::Point > &ocv_points, std::vector< cv::Point > &common_pts)
Write the corners found by Harris into a file.
Definition: common.cpp:437
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 Harris on host. Server

Returns
O on success, 1 on fail

Definition at line 45 of file harris_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 harris HLS TB
131  imwrite("../../../../../../ROLE/vision/hls/harris/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/harris/harris_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/harris/harris_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/harris/harris_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/harris/harris_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 = "make clean && ";
158  }
159  string str_command = "cd ../../../../../../ROLE/vision/hls/harris/ && " + clean_cmd + synth_cmd + "\
160  INPUT_IMAGE=./test/input_from_udp_to_fpga.png " + exec_cmd + " && \
161  cd ../../../../HOST/vision/harris/languages/cplusplus/build/ ";
162  const char *command = str_command.c_str();
163  cout << "Calling TB with command:" << command << endl;
164  system(command);
165 
166  free(longbuf);
167 
168  clock_t next_cycle_rx = clock();
169  double duration_rx = (next_cycle_rx - last_cycle_rx) / (double) CLOCKS_PER_SEC;
170  cout << "INFO: Effective FPS RX:" << (1 / duration_rx) << " \tkbps:" << (PACK_SIZE *
171  total_pack / duration_rx / 1024 * 8) << endl;
172  last_cycle_rx = next_cycle_rx;
173 
174 
175  // TX step
176  frame = cv::imread(ouf_file, cv::IMREAD_GRAYSCALE); // reading in the image in grey scale
177  if (!frame.data) {
178  cerr << "ERROR: Failed to load the image " << ouf_file << endl;
179  return -1;
180  }
181  else {
182  cout << "INFO: Succesfully loaded image " << ouf_file << endl;
183  }
184 
185  assert(frame.total() == FRAME_WIDTH * FRAME_HEIGHT);
186 
187  imshow("tb_send", frame);
188 
189  // Ensure that the send Mat is in continuous memory space. Typically, imread or resize
190  // will return such a continuous Mat, but we should check it.
191  assert(frame.isContinuous());
192 
193  // TX Loop
194  unsigned int sending_now = PACK_SIZE;
195  clock_t last_cycle_tx = clock();
196  for (int i = 0; i < total_pack; i++) {
197  if ( i == total_pack - 1 ) {
198  sending_now = bytes_in_last_pack;
199  }
200  #if NET_TYPE == udp
201  sock.sendTo( & frame.data[i * PACK_SIZE], sending_now, sourceAddress, servPort);
202  #else
203  //sock.send( & frame.data[i * PACK_SIZE], sending_now);
204  servsock->send( & frame.data[i * PACK_SIZE], sending_now);
205  #endif
206  }
207 
208  clock_t next_cycle_tx = clock();
209  double duration_tx = (next_cycle_tx - last_cycle_tx) / (double) CLOCKS_PER_SEC;
210  cout << "INFO: Effective FPS TX:" << (1 / duration_tx) << " \tkbps:" << (PACK_SIZE *
211  total_pack / duration_tx / 1024 * 8) << endl;
212  last_cycle_tx = next_cycle_tx;
213  cout << "\\___________________________________________________________________/" << endl;
214  break;} // while loop
215  #if NET_TYPE == tcp
216  delete servsock;
217  #endif
218  } catch (SocketException & e) {
219  cerr << e.what() << endl;
220  exit(1);
221  }
222  return 0;
223 }
#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  img_gray,
cv::Mat &  ocv_out_img,
float  Th 
)

Definition at line 577 of file xf_ocv_ref.hpp.

577  {
578  cv::Mat gradx, grady;
579  cv::Mat gradx2, grady2, gradxy;
580  cv::Mat gradx2g, grady2g, gradxyg;
581  cv::Mat x2y2, xy, mtrace;
582  cv::Mat dst, ocvthresh_img;
583 
584 
585  // Step one: Apply gradient
586  cv::Sobel(img_gray, gradx, CV_32FC1, 1, 0, FILTER_WIDTH, 1, 0, cv::BORDER_CONSTANT);
587  cv::Sobel(img_gray, grady, CV_32FC1, 0, 1, FILTER_WIDTH, 1, 0, cv::BORDER_CONSTANT);
588  // Step Two: Calculate gx^2, gy^2, gx*gy
589  pow(gradx, 2.0, gradx2);
590  pow(grady, 2.0, grady2);
591  multiply(gradx, grady, gradxy);
592  // Step Three: Apply boxfilter
593  cv::boxFilter(gradx2, gradx2g, -1, cv::Size(BLOCK_WIDTH, BLOCK_WIDTH));
594  cv::boxFilter(grady2, grady2g, -1, cv::Size(BLOCK_WIDTH, BLOCK_WIDTH));
595  cv::boxFilter(gradxy, gradxyg, -1, cv::Size(BLOCK_WIDTH, BLOCK_WIDTH));
596 
597  multiply(gradx2g, grady2g, x2y2);
598  multiply(gradxyg, gradxyg, xy);
599  pow((gradx2g + grady2g), 2.0, mtrace);
600 
601  // Step Four: Compute score
602  dst.create(img_gray.rows, img_gray.cols, CV_32FC1);
603  ocvthresh_img.create(img_gray.rows, img_gray.cols, dst.depth());
604 
605  float sum = 0;
606  for (int j = 0; j < img_gray.rows; j++) {
607  for (int i = 0; i < img_gray.cols; i++) {
608  float v1 = x2y2.at<float>(j, i);
609  float v2 = xy.at<float>(j, i);
610  float v3 = mtrace.at<float>(j, i);
611  float temp1 = (v1 - v2) - (0.04 * v3);
612  dst.at<float>(j, i) = temp1;
613 
614  if (temp1 > 0.0) sum += temp1;
615  }
616  }
617  //float meanval = sum / (img_gray.rows * img_gray.cols);
618 
619  // Step five: Apply Threshold
620  for (int i = 0; i < img_gray.rows; i++) {
621  for (int j = 0; j < img_gray.cols; j++) {
622  float pix = dst.at<NMSTYPE>(i, j);
623  if (pix > Th) {
624  ocvthresh_img.at<NMSTYPE>(i, j) = pix;
625  } else {
626  ocvthresh_img.at<NMSTYPE>(i, j) = 0;
627  }
628  }
629  }
630 
631  // Step six: Find Non maxima supppression
632  if (NMS_RADIUS == 1) {
633  OCVMaxSuppression1(ocvthresh_img, ocv_out_img);
634  } else if (NMS_RADIUS == 2) {
635  OCVMaxSuppression2(ocvthresh_img, ocv_out_img);
636  }
637 
638  gradx.~Mat();
639  grady.~Mat();
640  gradx2.~Mat();
641  grady2.~Mat();
642  gradxy.~Mat();
643  gradx2g.~Mat();
644  grady2g.~Mat();
645  gradxyg.~Mat();
646  x2y2.~Mat();
647  xy.~Mat();
648  mtrace.~Mat();
649  dst.~Mat();
650  ocvthresh_img.~Mat();
651 
652 }
#define NMS_RADIUS
#define BLOCK_WIDTH
void OCVMaxSuppression2(cv::Mat &src, cv::Mat &dst)
Definition: xf_ocv_ref.hpp:48
float NMSTYPE
Definition: xf_ocv_ref.hpp:36
void OCVMaxSuppression1(cv::Mat &src, cv::Mat &dst)
Definition: xf_ocv_ref.hpp:454
Here is the call graph for this function:

◆ OCVFindMaximum1()

bool OCVFindMaximum1 ( NMSTYPE  t0,
NMSTYPE  t1,
NMSTYPE  t2,
NMSTYPE  m0,
NMSTYPE  m1,
NMSTYPE  m2,
NMSTYPE  b0,
NMSTYPE  b1,
NMSTYPE  b2 
)

Definition at line 471 of file xf_ocv_ref.hpp.

472  {
473  bool Max = false;
474  if (m1 > t1 && m1 > m0 && m1 > m2 && m1 > b1) Max = true;
475  return Max;
476 }

◆ OCVFindMaximum2()

bool OCVFindMaximum2 ( NMSTYPE t1,
NMSTYPE t2,
NMSTYPE m1,
NMSTYPE b1,
NMSTYPE b2 
)

Definition at line 63 of file xf_ocv_ref.hpp.

63  {
64  bool Max = false;
65  NMSTYPE maxval = m1[2];
66  if ((maxval > t1[2]) && (maxval > t2[1]) && (maxval > t2[2]) && (maxval > t2[3]) && (maxval > m1[0]) &&
67  (maxval > m1[1]) && (maxval > m1[3]) && (maxval > m1[4]) && (maxval > b1[1]) && (maxval > b1[2]) &&
68  (maxval > b1[3]) && (maxval > b2[2]))
69  Max = true;
70  return Max;
71 }

◆ OCVMaxSuppression1()

void OCVMaxSuppression1 ( cv::Mat &  src,
cv::Mat &  dst 
)

Definition at line 479 of file xf_ocv_ref.hpp.

479  {
480  int i, j;
481  NMSTYPE t0, t1, t2;
482  NMSTYPE m0, m1, m2;
483  NMSTYPE b0, b1, b2;
484  bool result;
485 
486  /* First row */
487  i = 0;
488  for (j = 0; j < src.cols; j++) {
489  if (j == 0) {
490  t0 = 0;
491  t1 = 0;
492  t2 = 0;
493  m0 = 0;
494  m1 = src.at<NMSTYPE>(i, j);
495  m2 = src.at<NMSTYPE>(i, j + 1);
496  b0 = 0;
497  b1 = src.at<NMSTYPE>(i + 1, j);
498  b2 = src.at<NMSTYPE>(i + 1, j + 1);
499  } else if ((j > 0) && (j < src.cols - 1)) {
500  t0 = 0;
501  t1 = 0;
502  t2 = 0;
503  m0 = src.at<NMSTYPE>(i, j - 1);
504  m1 = src.at<NMSTYPE>(i, j);
505  m2 = src.at<NMSTYPE>(i, j + 1);
506  b0 = src.at<NMSTYPE>(i + 1, j - 1);
507  b1 = src.at<NMSTYPE>(i + 1, j);
508  b2 = src.at<NMSTYPE>(i + 1, j + 1);
509  } else if (j == src.cols - 1) {
510  t0 = 0;
511  t1 = 0;
512  t2 = 0;
513  m0 = src.at<NMSTYPE>(i, j - 1);
514  m1 = src.at<NMSTYPE>(i, j);
515  m2 = 0;
516  b0 = src.at<NMSTYPE>(i + 1, j - 1);
517  b1 = src.at<NMSTYPE>(i + 1, j);
518  b2 = 0;
519  }
520  result = OCVFindMaximum1(t0, t1, t2, m0, m1, m2, b0, b1, b2);
521  dst.at<uchar>(i, j) = result ? 255 : 0;
522  }
523  for (i = 1; i < src.rows - 1; i++) {
524  for (j = 0; j < src.cols; j++) {
525  if (j == 0) {
526  t0 = 0;
527  t1 = src.at<NMSTYPE>(i - 1, j);
528  t2 = src.at<NMSTYPE>(i - 1, j + 1);
529  m0 = 0;
530  m1 = src.at<NMSTYPE>(i, j);
531  m2 = src.at<NMSTYPE>(i, j + 1);
532  b0 = 0;
533  b1 = src.at<NMSTYPE>(i + 1, j);
534  b2 = src.at<NMSTYPE>(i + 1, j + 1);
535  } else if ((j > 0) && (j < src.cols - 1)) {
536  t0 = src.at<NMSTYPE>(i - 1, j - 1);
537  t1 = src.at<NMSTYPE>(i - 1, j);
538  t2 = src.at<NMSTYPE>(i - 1, j + 1);
539  m0 = src.at<NMSTYPE>(i, j - 1);
540  m1 = src.at<NMSTYPE>(i, j);
541  m2 = src.at<NMSTYPE>(i, j + 1);
542  b0 = src.at<NMSTYPE>(i + 1, j - 1);
543  b1 = src.at<NMSTYPE>(i + 1, j);
544  b2 = src.at<NMSTYPE>(i + 1, j + 1);
545  } else if (j == src.cols - 1) {
546  t0 = src.at<NMSTYPE>(i - 1, j - 1);
547  t1 = src.at<NMSTYPE>(i - 1, j);
548  t2 = 0;
549  m0 = src.at<NMSTYPE>(i, j - 1);
550  m1 = src.at<NMSTYPE>(i, j);
551  m2 = 0;
552  b0 = src.at<NMSTYPE>(i + 1, j - 1);
553  b1 = src.at<NMSTYPE>(i + 1, j);
554  b2 = 0;
555  }
556  result = OCVFindMaximum1(t0, t1, t2, m0, m1, m2, b0, b1, b2);
557  dst.at<uchar>(i, j) = result ? 255 : 0;
558  }
559  }
560  /* Last row */
561  i = src.rows - 1;
562  for (j = 1; j < src.cols - 1; j++) {
563  t0 = src.at<NMSTYPE>(i - 1, j - 1);
564  t1 = src.at<NMSTYPE>(i - 1, j);
565  t2 = src.at<NMSTYPE>(i - 1, j + 1);
566  m0 = src.at<NMSTYPE>(i, j - 1);
567  m1 = src.at<NMSTYPE>(i, j);
568  m2 = src.at<NMSTYPE>(i, j + 1);
569  b0 = 0;
570  b1 = 0;
571  b2 = 0;
572  result = OCVFindMaximum1(t0, t1, t2, m0, m1, m2, b0, b1, b2);
573  dst.at<uchar>(i, j) = result ? 255 : 0;
574  }
575 }
bool OCVFindMaximum1(NMSTYPE t0, NMSTYPE t1, NMSTYPE t2, NMSTYPE m0, NMSTYPE m1, NMSTYPE m2, NMSTYPE b0, NMSTYPE b1, NMSTYPE b2)
Definition: xf_ocv_ref.hpp:446
Here is the call graph for this function:

◆ OCVMaxSuppression2()

void OCVMaxSuppression2 ( cv::Mat &  src,
cv::Mat &  dst 
)

Definition at line 73 of file xf_ocv_ref.hpp.

73  {
74  int i, j, k;
75  int ii, jj;
76  NMSTYPE t1[5], t2[5];
77  NMSTYPE m1[5];
78  NMSTYPE b1[5], b2[5];
79  bool result;
80 
81  /* Process zeroth row */
82  i = 0;
83  for (j = 0; j < src.cols; j++) {
84  if (j < 2) {
85  for (k = 0; k < 5; k++) {
86  t1[k] = 0;
87  }
88  for (k = 0; k < 5; k++) {
89  t2[k] = 0;
90  }
91  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
92  if (jj >= 0)
93  m1[k] = src.at<NMSTYPE>(ii, jj);
94  else
95  m1[k] = 0;
96  }
97  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
98  if (jj >= 0)
99  b1[k] = src.at<NMSTYPE>(ii, jj);
100  else
101  b1[k] = 0;
102  }
103  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
104  if (jj >= 0)
105  b2[k] = src.at<NMSTYPE>(ii, jj);
106  else
107  b2[k] = 0;
108  }
109  } else if ((j >= 2) && (j < src.cols - 2)) {
110  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
111  t1[k] = 0;
112  }
113  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
114  t2[k] = 0;
115  }
116  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
117  m1[k] = src.at<NMSTYPE>(ii, jj);
118  }
119  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
120  b1[k] = src.at<NMSTYPE>(ii, jj);
121  }
122  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
123  b2[k] = src.at<NMSTYPE>(ii, jj);
124  }
125  } else if (j >= src.cols - 2) {
126  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
127  t1[k] = 0;
128  }
129  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
130  t2[k] = 0;
131  }
132  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
133  if (jj < src.cols)
134  m1[k] = src.at<NMSTYPE>(ii, jj);
135  else
136  m1[k] = 0;
137  }
138  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
139  if (jj < src.cols)
140  b1[k] = src.at<NMSTYPE>(ii, jj);
141  else
142  b1[k] = 0;
143  }
144  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
145  if (jj < src.cols)
146  b2[k] = src.at<NMSTYPE>(ii, jj);
147  else
148  b2[k] = 0;
149  }
150  }
151  result = OCVFindMaximum2(t1, t2, m1, b1, b2);
152  dst.at<uchar>(i, j) = result ? 255 : 0;
153  }
154  /* Process second row */
155  i = 1;
156  for (j = 0; j < src.cols; j++) {
157  if (j < 2) {
158  for (k = 0; k < 5; k++) {
159  t1[k] = 0;
160  }
161  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
162  if (jj >= 0)
163  t2[k] = src.at<NMSTYPE>(ii, jj);
164  else
165  t2[k] = 0;
166  }
167  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
168  if (jj >= 0)
169  m1[k] = src.at<NMSTYPE>(ii, jj);
170  else
171  m1[k] = 0;
172  }
173  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
174  if (jj >= 0)
175  b1[k] = src.at<NMSTYPE>(ii, jj);
176  else
177  b1[k] = 0;
178  }
179  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
180  if (jj >= 0)
181  b2[k] = src.at<NMSTYPE>(ii, jj);
182  else
183  b2[k] = 0;
184  }
185  } else if ((j >= 2) && (j < src.cols - 2)) {
186  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
187  t1[k] = 0;
188  }
189  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
190  t2[k] = src.at<NMSTYPE>(ii, jj);
191  }
192  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
193  m1[k] = src.at<NMSTYPE>(ii, jj);
194  }
195  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
196  b1[k] = src.at<NMSTYPE>(ii, jj);
197  }
198  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
199  b2[k] = src.at<NMSTYPE>(ii, jj);
200  }
201  } else if (j >= src.cols - 2) {
202  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
203  t1[k] = 0;
204  }
205  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
206  t2[k] = 0;
207  }
208  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
209  if (jj < src.cols)
210  m1[k] = src.at<NMSTYPE>(ii, jj);
211  else
212  m1[k] = 0;
213  }
214  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
215  if (jj < src.cols)
216  b1[k] = src.at<NMSTYPE>(ii, jj);
217  else
218  b1[k] = 0;
219  }
220  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
221  if (jj < src.cols)
222  b2[k] = src.at<NMSTYPE>(ii, jj);
223  else
224  b2[k] = 0;
225  }
226  }
227  result = OCVFindMaximum2(t1, t2, m1, b1, b2);
228  dst.at<uchar>(i, j) = result ? 255 : 0;
229  }
230 
231  for (i = 2; i < src.rows - 2; i++) {
232  for (j = 0; j < src.cols; j++) {
233  if (j < 2) {
234  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
235  if (jj >= 0)
236  t1[k] = src.at<NMSTYPE>(ii, jj);
237  else
238  t1[k] = 0;
239  }
240  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
241  if (jj >= 0)
242  t2[k] = src.at<NMSTYPE>(ii, jj);
243  else
244  t2[k] = 0;
245  }
246  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
247  if (jj >= 0)
248  m1[k] = src.at<NMSTYPE>(ii, jj);
249  else
250  m1[k] = 0;
251  }
252  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
253  if (jj >= 0)
254  b1[k] = src.at<NMSTYPE>(ii, jj);
255  else
256  b1[k] = 0;
257  }
258  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
259  if (jj >= 0)
260  b2[k] = src.at<NMSTYPE>(ii, jj);
261  else
262  b2[k] = 0;
263  }
264  } else if ((j >= 2) && (j < src.cols - 2)) {
265  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
266  t1[k] = src.at<NMSTYPE>(ii, jj);
267  }
268  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
269  t2[k] = src.at<NMSTYPE>(ii, jj);
270  }
271  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
272  m1[k] = src.at<NMSTYPE>(ii, jj);
273  }
274  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
275  b1[k] = src.at<NMSTYPE>(ii, jj);
276  }
277  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
278  b2[k] = src.at<NMSTYPE>(ii, jj);
279  }
280  } else if (j >= src.cols - 2) {
281  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
282  if (jj < src.cols)
283  t1[k] = src.at<NMSTYPE>(ii, jj);
284  else
285  t1[k] = 0;
286  }
287  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
288  if (jj < src.cols)
289  t2[k] = src.at<NMSTYPE>(ii, jj);
290  else
291  t2[k] = 0;
292  }
293  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
294  if (jj < src.cols)
295  m1[k] = src.at<NMSTYPE>(ii, jj);
296  else
297  m1[k] = 0;
298  }
299  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
300  if (jj < src.cols)
301  b1[k] = src.at<NMSTYPE>(ii, jj);
302  else
303  b1[k] = 0;
304  }
305  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
306  if (jj < src.cols)
307  b2[k] = src.at<NMSTYPE>(ii, jj);
308  else
309  b2[k] = 0;
310  }
311  }
312 
313  result = OCVFindMaximum2(t1, t2, m1, b1, b2);
314  dst.at<uchar>(i, j) = result ? 255 : 0;
315  }
316  }
317  /* Process zeroth row */
318  i = src.rows - 2;
319  for (j = 0; j < src.cols; j++) {
320  if (j < 2) {
321  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
322  if (jj >= 0)
323  t1[k] = src.at<NMSTYPE>(ii, jj);
324  else
325  t1[k] = 0;
326  }
327  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
328  if (jj >= 0)
329  t2[k] = src.at<NMSTYPE>(ii, jj);
330  else
331  t2[k] = 0;
332  }
333  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
334  if (jj >= 0)
335  m1[k] = src.at<NMSTYPE>(ii, jj);
336  else
337  m1[k] = 0;
338  }
339  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
340  if (jj >= 0)
341  b1[k] = src.at<NMSTYPE>(ii, jj);
342  else
343  b1[k] = 0;
344  }
345  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
346  b2[k] = 0;
347  }
348  } else if ((j >= 2) && (j < src.cols - 2)) {
349  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
350  t1[k] = src.at<NMSTYPE>(ii, jj);
351  }
352  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
353  t2[k] = src.at<NMSTYPE>(ii, jj);
354  }
355  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
356  m1[k] = src.at<NMSTYPE>(ii, jj);
357  }
358  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
359  b1[k] = src.at<NMSTYPE>(ii, jj);
360  }
361  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
362  b2[k] = 0;
363  }
364  } else if (j >= src.cols - 2) {
365  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
366  if (jj < src.cols)
367  t1[k] = src.at<NMSTYPE>(ii, jj);
368  else
369  t1[k] = 0;
370  }
371  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
372  if (jj < src.cols)
373  t2[k] = src.at<NMSTYPE>(ii, jj);
374  else
375  t2[k] = 0;
376  }
377  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
378  if (jj < src.cols)
379  m1[k] = src.at<NMSTYPE>(ii, jj);
380  else
381  m1[k] = 0;
382  }
383  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
384  if (jj < src.cols)
385  b1[k] = src.at<NMSTYPE>(ii, jj);
386  else
387  b1[k] = 0;
388  }
389  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
390  b2[k] = 0;
391  }
392  }
393  result = OCVFindMaximum2(t1, t2, m1, b1, b2);
394  dst.at<uchar>(i, j) = result ? 255 : 0;
395  }
396  /* Process second row */
397  i = src.rows - 1;
398  for (j = 0; j < src.cols; j++) {
399  if (j < 2) {
400  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
401  if (jj >= 0)
402  t1[k] = src.at<NMSTYPE>(ii, jj);
403  else
404  t1[k] = 0;
405  }
406  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
407  if (jj >= 0)
408  t2[k] = src.at<NMSTYPE>(ii, jj);
409  else
410  t2[k] = 0;
411  }
412  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
413  if (jj >= 0)
414  m1[k] = src.at<NMSTYPE>(ii, jj);
415  else
416  m1[k] = 0;
417  }
418  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
419  b1[k] = 0;
420  }
421  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
422  b2[k] = 0;
423  }
424  } else if ((j >= 2) && (j < src.cols - 2)) {
425  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
426  t1[k] = src.at<NMSTYPE>(ii, jj);
427  }
428  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
429  t2[k] = src.at<NMSTYPE>(ii, jj);
430  }
431  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
432  m1[k] = src.at<NMSTYPE>(ii, jj);
433  }
434  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
435  b1[k] = 0;
436  }
437  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
438  b2[k] = 0;
439  }
440  } else if (j >= src.cols - 2) {
441  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
442  if (jj < src.cols)
443  t1[k] = src.at<NMSTYPE>(ii, jj);
444  else
445  t1[k] = 0;
446  }
447  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
448  if (jj < src.cols)
449  t2[k] = src.at<NMSTYPE>(ii, jj);
450  else
451  t2[k] = 0;
452  }
453  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
454  if (jj < src.cols)
455  m1[k] = src.at<NMSTYPE>(ii, jj);
456  else
457  m1[k] = 0;
458  }
459  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
460  b1[k] = 0;
461  }
462  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
463  b2[k] = 0;
464  }
465  }
466  result = OCVFindMaximum2(t1, t2, m1, b1, b2);
467  dst.at<uchar>(i, j) = result ? 255 : 0;
468  }
469 }
bool OCVFindMaximum2(NMSTYPE *t1, NMSTYPE *t2, NMSTYPE *m1, NMSTYPE *b1, NMSTYPE *b2)
Definition: xf_ocv_ref.hpp:38
Here is the call graph for this function:

◆ 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:

◆ 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_harris.cpp.

127  {
128  harris(
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 harris(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)
Main process of the Harris Application directives.
Definition: harris.cpp:918
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_harris.cpp.

◆ node_rank

ap_uint<32> node_rank

Definition at line 92 of file test_harris.cpp.

◆ piSHL_This_MmioCaptPktEn

ap_uint<1> piSHL_This_MmioCaptPktEn

Definition at line 82 of file test_harris.cpp.

◆ piSHL_This_MmioPostPktEn

ap_uint<1> piSHL_This_MmioPostPktEn

Definition at line 81 of file test_harris.cpp.

◆ s_udp_rx_ports

ap_uint<32> s_udp_rx_ports = 0x0

Definition at line 89 of file test_harris.cpp.

◆ simCnt

int simCnt

Definition at line 120 of file test_harris.cpp.