Main testbench of Hrris.
163 unsigned int tb_trials = 0;
165 printf(
"#####################################################\n");
166 printf(
"## MAIN TESTBENCH STARTS HERE ##\n");
167 printf(
"#####################################################\n");
173 cv::Mat in_img, img_gray;
174 cv::Mat hls_out_img, ocv_out_img;
177 printf(
"Usage : %s <input image> \n", argv[0]);
180 in_img = cv::imread(argv[1], 0);
183 printf(
"ERROR: Failed to load the image ... %s\n!", argv[1]);
187 printf(
"INFO: Succesfully loaded image ... %s\n", argv[1]);
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);
200 DmCmd dmCmd_MemCmdP0;
201 DmSts dmSts_MemWrStsP0;
202 DmSts dmSts_MemRdStsP0;
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;
219 hls_out_img.create(in_img.rows, in_img.cols, CV_8U);
220 ocv_out_img.create(in_img.rows, in_img.cols, CV_8U);
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);
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);
242 printf (
"##################################################### \n" );
243 printf (
"## TESTBENCH #%u STARTS HERE ##\n", tb_trials );
244 printf (
"##################################################### \n" );
258 imgInput = xf::cv::imread<TYPE, HEIGHT, WIDTH, XF_NPPC8> ( argv[1], 0 );
277 printf (
"### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n" );
323 printf (
"DEBUG tb: Read a memory write command from SHELL/Mem/Mp0 \n" );
327 assert ( dmCmd_MemCmdP0.
type == 1 && dmCmd_MemCmdP0.
dsa == 0 && dmCmd_MemCmdP0.
eof == 1 && dmCmd_MemCmdP0.
drr == 1 && dmCmd_MemCmdP0.
tag == 0x0 );
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);
334 ddr_write_req_iter = 0;
336 printf (
"DEBUG tb: ddr_write_req_iter=%u\n", ddr_write_req_iter);
338 #ifdef ENABLE_DDR_EMULATE_DELAY_IN_TB
344 if (ddr_write_req_iter == 1) {
347 else if (ddr_write_req_iter == 2) {
354 printf(
"WARNING: Emptying sSHL_Rol_Mem_WrStsP0 fifo.\n");
358 wait_cycles_to_ack_ddr_status = 0;
360 count_cycles_to_ack_ddr_status = 0;
361 ddr_write_sts_req =
false;
366 printf (
"DEBUG tb: Write a memory line from SHELL/Mem/Mp0 \n" );
368 assert ( memP0.
tkeep == 0xffffffffffffffff );
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;
378 ddr_write_sts_req =
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" );
390 ddr_write_sts_req =
false;
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);
412 printf(
"WARNING: Emptying sSHL_Rol_Mem_WrStsP0 fifo.\n");
416 printf (
"## End of simulation at cycle=%3d. \n",
simCnt );
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 );
443 printf (
"Error No metadata received...\n" );
451 printf (
"### ERROR : Failed to set input array from file \"ofsUAF_Shl_Data.dat\". \n" );
454 xf::cv::Array2xfMat<OUTPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX> ( imgOutputArray, imgOutput );
460 int rc1 = system (
"diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
461 ../../../../test/verify_UAF_Shl_Data.dat" );
463 printf (
"## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n" );
465 printf (
"Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n" );
470 printf (
"#####################################################\n" );
472 printf (
"## ERROR - TESTBENCH #%u FAILED (RC=%d) !!! ##\n", tb_trials, nrErr );
474 printf (
"## SUCCESSFULL END OF TESTBENCH #%u (RC=0) ##\n", tb_trials );
476 printf (
"#####################################################\n" );
496 xf::cv::Array2xfMat<OUTPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX>(imgOutputArrayTb, imgOutputTb);
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);
515 unsigned short int row, col;
518 out_img = in_img.clone();
520 std::vector<cv::Point> hls_points;
521 std::vector<cv::Point> ocv_points;
522 std::vector<cv::Point> common_pts;
524 xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX>* select_imgOutput;
529 select_imgOutput = &imgOutput;
532 free(imgOutputArrayTb);
533 free(imgOutputArray);
ap_uint< 64 > currentMemPattern
void ocv_ref(cv::Mat img_gray, cv::Mat &ocv_out_img, float Th)
#define EXTRA_DDR_LATENCY_DUE_II
#define TYPICAL_DDR_LATENCY
bool setInputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string inpFileName)
Initialize an input data stream from a file.
bool getOutputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string outFileName)
Fill an output file with data from an output stream.
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".