36 #include "../include/harris.hpp"
37 #include "../../common/src/common.cpp"
45 #define THIS_NAME "TB"
47 #define TRACE_OFF 0x0000
48 #define TRACE_URIF 1 << 1
49 #define TRACE_UAF 1 << 2
50 #define TRACE_MMIO 1 << 3
51 #define TRACE_ALL 0xFFFF
53 #define DEBUG_LEVEL (TRACE_ALL)
63 #define DEBUG_TRACE true
69 #define ENABLE_DDR_EMULATE_DELAY_IN_TB
71 #define ENABLED (ap_uint<1>)1
72 #define DISABLED (ap_uint<1>)0
112 #define MEMORY_LINES_512 TOTMEMDW_512
146 printf(
"[%4.4d] STEP DUT \n",
simCnt);
157 int main(
int argc,
char** argv) {
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;
222 Th = 41151168289701888.000000;
232 hls_out_img.create(in_img.rows, in_img.cols, CV_8U);
233 ocv_out_img.create(in_img.rows, in_img.cols, CV_8U);
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);
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);
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);
256 printf (
"##################################################### \n" );
257 printf (
"## TESTBENCH #%u STARTS HERE ##\n", tb_trials );
258 printf (
"##################################################### \n" );
272 imgInput = xf::cv::imread<IN_TYPE, HEIGHT, WIDTH, XF_NPPC8> ( argv[1], 0 );
280 ocv_ref ( in_img, ocv_out_img, Th );
289 printf (
"### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n" );
335 printf (
"DEBUG tb: Read a memory write command from SHELL/Mem/Mp0 \n" );
339 assert ( dmCmd_MemCmdP0.
type == 1 && dmCmd_MemCmdP0.
dsa == 0 && dmCmd_MemCmdP0.
eof == 1 && dmCmd_MemCmdP0.
drr == 1 && dmCmd_MemCmdP0.
tag == 0x0 );
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);
346 ddr_write_req_iter = 0;
348 printf (
"DEBUG tb: ddr_write_req_iter=%u\n", ddr_write_req_iter);
350 #ifdef ENABLE_DDR_EMULATE_DELAY_IN_TB
356 if (ddr_write_req_iter == 1) {
359 else if (ddr_write_req_iter == 2) {
366 printf(
"WARNING: Emptying sSHL_Rol_Mem_WrStsP0 fifo.\n");
370 wait_cycles_to_ack_ddr_status = 0;
372 count_cycles_to_ack_ddr_status = 0;
373 ddr_write_sts_req =
false;
378 printf (
"DEBUG tb: Write a memory line from SHELL/Mem/Mp0 \n" );
380 assert ( memP0.
tkeep == 0xffffffffffffffff );
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);
389 ddr_write_sts_req =
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" );
401 ddr_write_sts_req =
false;
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);
423 printf(
"WARNING: Emptying sSHL_Rol_Mem_WrStsP0 fifo.\n");
427 printf (
"## End of simulation at cycle=%3d. \n",
simCnt );
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 );
454 printf (
"Error No metadata received...\n" );
462 printf (
"### ERROR : Failed to set input array from file \"ofsUAF_Shl_Data.dat\". \n" );
465 xf::cv::Array2xfMat<OUTPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPIX> ( imgOutputArray, imgOutput );
471 int rc1 = system (
"diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
472 ../../../../test/verify_UAF_Shl_Data.dat" );
474 printf (
"## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n" );
476 printf (
"Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n" );
481 printf (
"#####################################################\n" );
483 printf (
"## ERROR - TESTBENCH #%u FAILED (RC=%d) !!! ##\n", tb_trials, nrErr );
485 printf (
"## SUCCESSFULL END OF TESTBENCH #%u (RC=0) ##\n", tb_trials );
487 printf (
"#####################################################\n" );
503 uint16_t k = K * (1 << 16);
509 xf::cv::Array2xfMat<OUTPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPIX>(imgOutputArrayTb, imgOutputTb);
523 xf::cv::imwrite(
"hls_out_tb.jpg", imgOutputTb);
524 xf::cv::imwrite(
"hls_out.jpg", imgOutput);
527 unsigned short int row, col;
530 out_img = in_img.clone();
532 std::vector<cv::Point> hls_points;
533 std::vector<cv::Point> ocv_points;
534 std::vector<cv::Point> common_pts;
536 xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPIX>* select_imgOutput;
541 select_imgOutput = &imgOutput;
551 free(imgOutputArrayTb);
552 free(imgOutputArray);
ap_uint< 64 > currentMemPattern
void ocv_ref(cv::Mat img_gray, cv::Mat &ocv_out_img, float Th)
void markPointsOnImage(Mat &imgOutput, Mat &in_img, Mat &out_img, vector< Point > &hw_points)
Mark the points found by Gammacorrection into the image.
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.
stream< NetworkMetaStream > siUdp_meta("siUdp_meta")
int main(int argc, char **argv)
Main testbench of Hrris.
stream< NetworkMetaStream > soUdp_meta("soUdp_meta")
ap_uint< 1 > piSHL_This_MmioCaptPktEn
ap_uint< 1 > piSHL_This_MmioPostPktEn
stream< UdpWord > sUAF_Shl_Data("sUAF_Shl_Data")
stream< UdpWord > image_stream_from_harris("image_stream_from_harris")
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
ap_uint< 32 > cluster_size
ap_uint< 32 > s_udp_rx_ports
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 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.
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.
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".