UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor augustvh
Visitor
1,085 Views
Registered: ‎05-15-2018

hls::stream in SDSoC?

Jump to solution

Hi all!

 

I have found a Vivado HLS library which contains plenty of useful templated C/C++ functions which I would like to include in my SDSoC project. However, it is heavily based on the hls::stream data type which according to the SDSoC user guide:

"The hls::stream data type is not supported as the function argument to any harward function" ug1027 page 96

 

Have anyone made a port between Vivado HLS hls::stream data type to a data type in SDSoC which behaves exactly in the same manner (once synthesised)? What is the specific reason why this data type is not compatible between the two tools?

 

best regards,

Avh

0 Kudos
1 Solution

Accepted Solutions
Highlighted
1,317 Views
Registered: ‎10-17-2017

Re: hls::stream in SDSoC?

Jump to solution

Hey @augustvh - 

What you can do is write a wrapper function that handles the hls stream - 

 

Consider this example where I have an IntegralImage function that takes hls streams as arguments 

 

void IntegralImageHLS(hls::stream < ap_uint<8> >& _in,hls::stream < ap_uint<32> >& _out )
{

.
.
.

}

 

I would write a wrapper function something like this: 

 

 

#pragma SDS data mem_attribute("_src_mat.data":NON_CACHEABLE|PHYSICAL_CONTIGUOUS)
#pragma SDS data mem_attribute("_dst_mat.data":NON_CACHEABLE|PHYSICAL_CONTIGUOUS)
#pragma SDS data access_pattern("_src_mat.data":SEQUENTIAL, "_dst_mat.data":SEQUENTIAL)
//#pragma SDS data data_mover("_src_mat.data":AXIDMA_SIMPLE)
//#pragma SDS data data_mover("_dst_mat.data":AXIDMA_SIMPLE)
#pragma SDS data copy("_src_mat.data"[0:"_src_mat.size"], "_dst_mat.data"[0:"_dst_mat.size"])
void integral_image(xf::Mat<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1> & _src_mat,
						xf::Mat<XF_32UC1, HEIGHT, WIDTH, XF_NPPC1> & _dst_mat)

{
#pragma HLS INLINE OFF
#pragma HLS DATAFLOW


	hls::stream< ap_uint<8> > in_stream;
	hls::stream< ap_uint<32> > out_stream;


	for(int i=0; i<_src_mat.rows;i++)
	{		
		for(int j=0; j<_src_mat.cols;j++)
		{
			#pragma HLS LOOP_FLATTEN off
			#pragma HLS PIPELINE

			in_stream.write( *(_src_mat.data + i*(_src_mat.cols) +j) );
		}
	}


// call HLS function 
	IntegralImageHLS(in_stream,out_stream);



	for(int i=0; i<_dst_mat.rows;i++)
	{
		for(int j=0; j<_dst_mat.cols;j++)
		{
			#pragma HLS PIPELINE
			#pragma HLS LOOP_FLATTEN off

			*(_dst_mat.data + i*(_dst_mat.cols) +j) = out_stream.read();
		}
	}
}

 

 

 The function integral_image() takes xf::Mat as input and can now be used in SDSoC. 

 

You can simply call it from main() : 

 

 

int main()
{

xf::Mat<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1> imgInput(1080, 1920); xf::Mat<XF_32UC1, HEIGHT, WIDTH, XF_NPPC1> integralImage(1080, 1920); Response integral_image(imgInput, integralImage );

return 0;

}

 

You would be selecting the wrapper function integral_image() for hardware acceleration instead of the one using hls::streams. 

 

You can write similar wrapper function with arrays instead of xf::Mat. It will also be supported by SDSoC. Simply copy the array elements to the hls::stream and call the functions that take hls::stream as argumets. 

 

 

 

3 Replies
Highlighted
1,318 Views
Registered: ‎10-17-2017

Re: hls::stream in SDSoC?

Jump to solution

Hey @augustvh - 

What you can do is write a wrapper function that handles the hls stream - 

 

Consider this example where I have an IntegralImage function that takes hls streams as arguments 

 

void IntegralImageHLS(hls::stream < ap_uint<8> >& _in,hls::stream < ap_uint<32> >& _out )
{

.
.
.

}

 

I would write a wrapper function something like this: 

 

 

#pragma SDS data mem_attribute("_src_mat.data":NON_CACHEABLE|PHYSICAL_CONTIGUOUS)
#pragma SDS data mem_attribute("_dst_mat.data":NON_CACHEABLE|PHYSICAL_CONTIGUOUS)
#pragma SDS data access_pattern("_src_mat.data":SEQUENTIAL, "_dst_mat.data":SEQUENTIAL)
//#pragma SDS data data_mover("_src_mat.data":AXIDMA_SIMPLE)
//#pragma SDS data data_mover("_dst_mat.data":AXIDMA_SIMPLE)
#pragma SDS data copy("_src_mat.data"[0:"_src_mat.size"], "_dst_mat.data"[0:"_dst_mat.size"])
void integral_image(xf::Mat<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1> & _src_mat,
						xf::Mat<XF_32UC1, HEIGHT, WIDTH, XF_NPPC1> & _dst_mat)

{
#pragma HLS INLINE OFF
#pragma HLS DATAFLOW


	hls::stream< ap_uint<8> > in_stream;
	hls::stream< ap_uint<32> > out_stream;


	for(int i=0; i<_src_mat.rows;i++)
	{		
		for(int j=0; j<_src_mat.cols;j++)
		{
			#pragma HLS LOOP_FLATTEN off
			#pragma HLS PIPELINE

			in_stream.write( *(_src_mat.data + i*(_src_mat.cols) +j) );
		}
	}


// call HLS function 
	IntegralImageHLS(in_stream,out_stream);



	for(int i=0; i<_dst_mat.rows;i++)
	{
		for(int j=0; j<_dst_mat.cols;j++)
		{
			#pragma HLS PIPELINE
			#pragma HLS LOOP_FLATTEN off

			*(_dst_mat.data + i*(_dst_mat.cols) +j) = out_stream.read();
		}
	}
}

 

 

 The function integral_image() takes xf::Mat as input and can now be used in SDSoC. 

 

You can simply call it from main() : 

 

 

int main()
{

xf::Mat<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1> imgInput(1080, 1920); xf::Mat<XF_32UC1, HEIGHT, WIDTH, XF_NPPC1> integralImage(1080, 1920); Response integral_image(imgInput, integralImage );

return 0;

}

 

You would be selecting the wrapper function integral_image() for hardware acceleration instead of the one using hls::streams. 

 

You can write similar wrapper function with arrays instead of xf::Mat. It will also be supported by SDSoC. Simply copy the array elements to the hls::stream and call the functions that take hls::stream as argumets. 

 

 

 

Visitor augustvh
Visitor
1,022 Views
Registered: ‎05-15-2018

Re: hls::stream in SDSoC?

Jump to solution

Hey @khareashish_trimble

 

Thank you for a great explanation to continue using the data type. It does indeed solve the issue of being unable to toggle a function having hls::stream as function argument for hardware acceleration.

 

The way I interpreted the "is not supported as the function argument to ANY hardware function" was NOT that only the TOP function cannot have hls::stream in its function argument. Additionally, since the documentation (UG1027 SDSoC user guide 2018.1) in SDSoC about hls::stream ends after that (should I continue read about it in Vivado HLS guide UG902 Vivado high level synthesis 2018.1??)

 

Shortly, I interpreted it as hls::stream is not a compatible data type in SDSoC which lead me to believe that its behaviour was undefined in the SDSoC environment. But I guess that it behaves exactly as described in the Vivado HLS guide?

 

Thanks,

Avh

 

 

0 Kudos
1,000 Views
Registered: ‎10-17-2017

Re: hls::stream in SDSoC?

Jump to solution

@augustvh - Yes it would behave exactly as described in the HLS guide. Its only that hls::stream is not supported as an argument to the top function. 

0 Kudos