Custom code running into infinite loop

Hi All,

I am working on a video processing project using the PYNQ Z2 board (v2.6). I am a beginner in HLS and creating a custom IP involving some computer vision algorithms. I have given below my code, where I am applying the sobel filter algorithm. I wanted to custom implement the sobel filter algorithm but the problem is that when I use my custom function within my ip, the ip never switches into the DONE state within my PYNQ board. If I am using the vision sobel function instead of my custom function it works properly.

Now as the simulation was working as required and from the error from pynq which stated mismatch in the data type I believe the issue was due to the datatype of the pixels I had provided. Therefore just to verify this theory I tried to make all the pixels either black or white by hardcoding them into 0 or 255 in my custom function. If this works then the problem should be in my logic I suspected.

void edge_algo(xf::cv::Mat<XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1>& blur_mat, xf::cv::Mat<XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1>& out_mat, unsigned int rows, unsigned int cols){

	ap_uint<8> value;

	xf::cv::Mat<XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> copy_mat(rows,cols);
	xf::cv::insertBorder<XF_8UC1>(blur_mat, copy_mat, 0);

	for(int idx=0; idx<(rows*cols) ; idx++){	// here the rows and cols are for the original image
	#pragma HLS pipeline
		value = ap_uint<8>(255);
		out_mat.write(idx, value);
	}

}


void find_SI(ap_uint<24>* inp_stream, ap_uint<8>* output_stream, unsigned int rows, unsigned int cols){

	#pragma HLS INTERFACE m_axi port=inp_stream offset=slave bundle=gem1
	#pragma HLS INTERFACE m_axi port=output_stream offset=slave bundle=gem2
	#pragma HLS INTERFACE s_axilite port=rows offset=0x10
	#pragma HLS INTERFACE s_axilite port=cols offset=0x18
	#pragma HLS INTERFACE s_axilite port=return

	float sigma = 0.5f;

	//defining all the required Mat
	xf::cv::Mat<XF_8UC3, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> in_mat(rows,cols);
	xf::cv::Mat<XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> gray_mat(rows,cols);
	xf::cv::Mat<XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> blur_mat(rows,cols);
	xf::cv::Mat<XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> out_mat(rows,cols);

	#pragma HLS DATAFLOW

	xf::cv::Array2xfMat<24, XF_8UC3, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1>(inp_stream, in_mat);
	xf::cv::rgb2gray<XF_8UC3, XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1>(in_mat, gray_mat);
	xf::cv::GaussianBlur<3, XF_BORDER_CONSTANT, XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1>(gray_mat, blur_mat, sigma);
	edge_algo(blur_mat, out_mat, rows, cols);
	xf::cv::xfMat2Array<8, XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1>(out_mat, output_stream);
}

But even in this scenario my custom ip is going into an infinite loop kind of state. The simulation works as expected for my logic.

Can someone please help me understand what am I doing wrong while writing processed pixel values into the output Mat?

Hoping for reply soon ! Thank you in advance.

Regards,
Srijith

1 Like