Main testbench of Hrris.
169 unsigned int tb_trials = 0;
171 printf(
"#####################################################\n");
172 printf(
"## MAIN TESTBENCH STARTS HERE ##\n");
173 printf(
"#####################################################\n");
189 float transformation_matrix_float [9] = {1.5,0,0,0,1.8,0,0,0,0};
191 cv::Mat hls_out_img, ocv_out_img;
194 printf(
"Usage : %s <input image> \n", argv[0]);
197 in_img = cv::imread(argv[1], 0);
200 printf(
"ERROR: Failed to load the image ... %s\n!", argv[1]);
204 printf(
"INFO: Succesfully loaded image ... %s\n", argv[1]);
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);
217 DmCmd dmCmd_MemCmdP0;
218 DmSts dmSts_MemWrStsP0;
219 DmSts dmSts_MemRdStsP0;
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;
236 hls_out_img.create(in_img.rows, in_img.cols, CV_8U);
237 ocv_out_img.create(in_img.rows, in_img.cols, CV_8U);
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);
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);
258 xf::cv::Array2xfMat<OUTPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX>(imgOutputArrayTb, imgOutputTb);
266 printf (
"##################################################### \n" );
267 printf (
"## TESTBENCH #%u STARTS HERE ##\n", tb_trials );
268 printf (
"##################################################### \n" );
282 imgInput = xf::cv::imread<TYPE, HEIGHT, WIDTH, XF_NPPC8> ( argv[1], 0 );
292 ocv_ref ( in_img, ocv_out_img, transformation_matrix);
301 printf (
"### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n" );
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++ ) {
348 printf (
"DEBUG tb: Read a memory write command from SHELL/Mem/Mp0 \n" );
352 assert ( dmCmd_MemCmdP0.
type == 1 && dmCmd_MemCmdP0.
dsa == 0 && dmCmd_MemCmdP0.
eof == 1 && dmCmd_MemCmdP0.
drr == 1 && dmCmd_MemCmdP0.
tag == 0x0 );
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);
359 ddr_write_req_iter = 0;
361 printf (
"DEBUG tb: ddr_write_req_iter=%u\n", ddr_write_req_iter);
363 #ifdef ENABLE_DDR_EMULATE_DELAY_IN_TB
369 if (ddr_write_req_iter == 1) {
372 else if (ddr_write_req_iter == 2) {
379 printf(
"WARNING: Emptying sSHL_Rol_Mem_WrStsP0 fifo.\n");
383 wait_cycles_to_ack_ddr_status = 0;
385 count_cycles_to_ack_ddr_status = 0;
386 ddr_write_sts_req =
false;
391 printf (
"DEBUG tb: Write a memory line from SHELL/Mem/Mp0 \n" );
393 assert ( memP0.
tkeep == 0xffffffffffffffff );
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;
403 ddr_write_sts_req =
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" );
415 ddr_write_sts_req =
false;
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);
437 printf(
"WARNING: Emptying sSHL_Rol_Mem_WrStsP0 fifo.\n");
441 printf (
"## End of simulation at cycle=%3d. \n",
simCnt );
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 );
466 assert ( i == TOT_TRANSFERS_RX );
468 printf (
"Error No metadata received...\n" );
476 printf (
"### ERROR : Failed to set input array from file \"ofsUAF_Shl_Data.dat\". \n" );
479 xf::cv::Array2xfMat<OUTPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX> ( imgOutputArray, imgOutput );
485 int rc1 = system (
"diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
486 ../../../../test/verify_UAF_Shl_Data.dat" );
488 printf (
"## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n" );
490 printf (
"Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n" );
492 const string outfilename =
"hls_out-"+std::to_string(tb_trials)+
".jpg";
493 xf::cv::imwrite(outfilename.c_str(), imgOutput);
497 printf (
"#####################################################\n" );
499 printf (
"## ERROR - TESTBENCH #%u FAILED (RC=%d) !!! ##\n", tb_trials, nrErr );
501 printf (
"## SUCCESSFULL END OF TESTBENCH #%u (RC=0) ##\n", tb_trials );
503 printf (
"#####################################################\n" );
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);
542 unsigned short int row, col;
545 out_img = in_img.clone();
547 std::vector<cv::Point> hls_points;
548 std::vector<cv::Point> ocv_points;
549 std::vector<cv::Point> common_pts;
551 xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX>* select_imgOutput;
556 select_imgOutput = &imgOutput;
559 free(imgOutputArrayTb);
560 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 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.
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".