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: 
Observer kevin_pang
Observer
416 Views
Registered: ‎05-26-2018

hls::stream is read while empty, simple axi4-stream problem, hls newbie, need help!

Jump to solution

Hi, everyone!

I am working on Vivado HLS.  and I want a simple function, 1080p axi4-stream input( raw input, one clk with two pixels), and i want a 720p axi4-stream output, just using simple cropping method.  But it keeps putting the warning like below: (the source file is in the attachment)

"WARNING: Hls::stream 'hls::stream<ap_axiu<24, 1, 1, 1> >.2' is read while empty, which may result in RTL simulation hanging."

 

I search the forum, and some suggest that :

while(!my_stream.empty()) { /*do something*/ }

but I still could solved it!    

 

Any help could be appreciated! 

 

 

 

the code is showed below:

#include <hls_video.h>
#include <hls_stream.h>
#include <ap_axi_sdata.h>

#include <iostream>
#include "hlsCrop.h"

using namespace std;

// input image 1920 x 1080
// output image 1280 x 720
// compliant to axi4-stream interface video protocol


void hlsCrop(axi_stream_t &RawIn, axi_stream_t &RawOut){
#pragma HLS INTERFACE s_axilite port=return
#pragma HLS INTERFACE axis port=RawIn
#pragma HLS INTERFACE axis port=RawOut


int rowIdx, colIdx;

 

For_RowScan: for(rowIdx = 0; rowIdx < IN_IMG_MAX_ROWS; rowIdx++) {

bool rowVld = ((rowIdx >=0) && (rowIdx <OUT_IMG_MAX_ROWS));

For_ColScan: for(colIdx = 0; colIdx < IN_IMG_MAX_COLS; colIdx++) {
#pragma HLS PIPELINE II=1
pix_t inPix;

while(!RawIn.empty()) {

inPix = RawIn.read();

if(1 == inPix.user) {
rowIdx = 0;
colIdx = 0;
}

bool colVld = ((colIdx >=0) && (colIdx <OUT_IMG_MAX_COLS));

if(rowVld && colVld) {
pix_t outPix;
outPix.data = inPix.data;
//outPix.keep = inPix.keep;
//outPix.dest = inPix.dest;
//outPix.id = inPix.id;
//outPix.strb = inPix.strb;
outPix.last = (colIdx == OUT_IMG_MAX_COLS);
outPix.user = ( (rowIdx == 0) && (colIdx == 0) );
RawOut.write(outPix);
}
}
}

}

return;

}

 

 

0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
338 Views
Registered: ‎09-05-2018

Re: hls::stream is read while empty, simple axi4-stream problem, hls newbie, need help!

Jump to solution

Hey @kevin_pang,

That's excellent! I'm glad you were able to find the issue!

Consider marking one of the posts in the thread as the solution so we know the thread is solved.

Nicholas Moellers

Xilinx Worldwide Technical Support
4 Replies
Xilinx Employee
Xilinx Employee
385 Views
Registered: ‎09-05-2018

Re: hls::stream is read while empty, simple axi4-stream problem, hls newbie, need help!

Jump to solution

Hey @kevin_pang,

What's your testbench look like? You're reading more values from your stream than you have written. What did you write to the stream in the testbench? I'd also be concerned about this line:

if(1 == inPix.user) {
rowIdx = 0;
colIdx = 0;
}

since that could cause your entire loop to restart. Does your testbench set the .user bit unexpectedly?

Consider running your simulation in debug mode with some breakpoints or just adding some print statements. Check how many reads and writes actually occur. Where does the simulation not match your expectations?

Nicholas Moellers

Xilinx Worldwide Technical Support
0 Kudos
Observer kevin_pang
Observer
366 Views
Registered: ‎05-26-2018

Re: hls::stream is read while empty, simple axi4-stream problem, hls newbie, need help!

Jump to solution

@nmoeller, Thank you very much for your answer. It is really helpful. 

I have worked it out according to your hints.  

I have made several mistakes, and one of it is "outPix.last = (colIdx == (OUT_IMG_MAX_COLS -1) );" , I generate the wrong outPix.last member. Now it works.

 

the testBench shows below:

#include <hls_video.h>
#include <hls_stream.h>
#include <ap_axi_sdata.h>
#include <iostream>
#include "hlsCrop.h"

using namespace std;

 

template<int ROWS, int COLS, int T>
void createColorBar(hls::Mat<ROWS, COLS, T> &imgColorbar)
{
hls::Scalar<HLS_MAT_CN(T), HLS_TNAME(T)> pixel;
int wBar;
int rows = imgColorbar.rows;
int cols = imgColorbar.cols;

for(int row=0;row<rows;row++)
{
#pragma HLS loop_flatten off

wBar = cols>>3;
for(int col=0;col<cols;col++)
{
#pragma HLS pipeline
int index = ((col)/wBar)&0x7;
switch(index)
{
case 0:
pixel.val[0] = 0x111;
pixel.val[1] = 0x111;
// pixel.val[2] = 0xff; //white
break;
case 1:
pixel.val[0] = 0x222;
pixel.val[1] = 0x222;
// pixel.val[2] = 0xff; //yellow
break;
case 2:
pixel.val[0] = 0x333;
pixel.val[1] = 0x000;
// pixel.val[2] = 0x00; //cyan
break;
case 3:
pixel.val[0] = 0x333;
pixel.val[1] = 0xfff;
// pixel.val[2] = 0x00; //green
break;
case 4:
pixel.val[0] = 0x444;
pixel.val[1] = 0x444;
// pixel.val[2] = 0xff; //magenta
break;
case 5:
pixel.val[0] = 0x555;
pixel.val[1] = 0x555;
// pixel.val[2] = 0xff; //red
break;
case 6:
pixel.val[0] = 0x666;
pixel.val[1] = 0x666;
// pixel.val[2] = 0x00; //blue
break;
default:
pixel.val[0] = 0x777;
pixel.val[1] = 0x777;
// pixel.val[2] = 0x00; //black
break;
}

imgColorbar << pixel;
}
}

}

int main()
{

axi_stream_t RawIn;
axi_stream_t RawOut;

hls::Mat<IN_IMG_MAX_ROWS, IN_IMG_MAX_COLS, HLS_12UC2> imgColorbar(IN_IMG_MAX_ROWS, IN_IMG_MAX_COLS);
hls::Mat<OUT_IMG_MAX_ROWS, OUT_IMG_MAX_COLS, HLS_12UC2> outIMG(OUT_IMG_MAX_ROWS, OUT_IMG_MAX_COLS);

#pragma HLS dataflow
createColorBar(imgColorbar);
hls::Mat2AXIvideo(imgColorbar, RawIn);
hlsCrop(RawIn, RawOut);
hls::AXIvideo2Mat(RawOut, outIMG);

 

return 0;

 

}

 

and the modified design file is:

#include <hls_video.h>
#include <hls_stream.h>
#include <ap_axi_sdata.h>

#include <iostream>
#include "hlsCrop.h"

using namespace std;

// input image 1920 x 1080
// output image 1280 x 720
// compliant to axi4-stream interface video protocol

void hlsCrop(axi_stream_t &RawIn, axi_stream_t &RawOut){
#pragma HLS INTERFACE s_axilite port=return
#pragma HLS INTERFACE axis port=RawIn
#pragma HLS INTERFACE axis port=RawOut

int rowIdx, colIdx;

pix_t inPix;
pix_t outPix;
int testOutImgPixCnt = 0;

For_RowScan: for(rowIdx = 0; rowIdx < IN_IMG_MAX_ROWS; rowIdx++) {

#pragma HLS loop_flatten off

bool rowVld = ((rowIdx >=0) && (rowIdx <OUT_IMG_MAX_ROWS));

For_ColScan: for(colIdx = 0; colIdx < IN_IMG_MAX_COLS; colIdx++) {
#pragma HLS PIPELINE II=1
// pix_t inPix;

// while(RawIn.empty()) {
// };

if( ((IN_IMG_MAX_COLS -1) == colIdx) && ((IN_IMG_MAX_ROWS -1) == rowIdx) ) {
cout<<"the last pixel"<<endl;
}

{
inPix = RawIn.read();

if(1 == inPix.user) {
rowIdx = 0;
colIdx = 0;
}

if(1 == inPix.last) {
colIdx = (IN_IMG_MAX_COLS -1);
}

bool colVld = ((colIdx >=0) && (colIdx <OUT_IMG_MAX_COLS));

if(rowVld && colVld) {
// pix_t outPix;
outPix.data = inPix.data;
outPix.keep = inPix.keep;
outPix.dest = inPix.dest;
outPix.id = inPix.id;
outPix.strb = inPix.strb;
outPix.last = (colIdx == (OUT_IMG_MAX_COLS -1) );
outPix.user = ( (rowIdx == 0) && (colIdx == 0) );
RawOut.write(outPix);

testOutImgPixCnt ++;
if(testOutImgPixCnt >= (OUT_IMG_MAX_COLS * OUT_IMG_MAX_ROWS)) {
cout<<"test outImgPIxCnt"<<testOutImgPixCnt<<endl;
}

}
}
}

}

return;

}

 

and still two warning(but not keep printing),

WARNING: Hls::stream 'hls::stream<ap_uint<12> >.4' contains leftover data, which may result in RTL simulation hanging.
WARNING: Hls::stream 'hls::stream<ap_uint<12> >.3' contains leftover data, which may result in RTL simulation hanging.

 

I want to know, does it  mean that there are some warning about  the member  "ap_uint<U> user; ap_uint<1> last;"   ?    what should I do with the warning ?

template<int D,int U,int TI,int TD>
struct ap_axiu{
ap_uint<D> data;
ap_uint<(D+7)/8> keep;
ap_uint<(D+7)/8> strb;
ap_uint<U> user;
ap_uint<1> last;
ap_uint<TI> id;
ap_uint<TD> dest;
};

 

 

 

0 Kudos
Observer kevin_pang
Observer
365 Views
Registered: ‎05-26-2018

Re: hls::stream is read while empty, simple axi4-stream problem, hls newbie, need help!

Jump to solution

I use the code below to recover the stream when some errors occur, since it is a video stream.

if(1 == inPix.user) {
rowIdx = 0;
colIdx = 0;
}

if(1 == inPix.last) {
colIdx = (IN_IMG_MAX_COLS -1);
}

 

 

0 Kudos
Xilinx Employee
Xilinx Employee
339 Views
Registered: ‎09-05-2018

Re: hls::stream is read while empty, simple axi4-stream problem, hls newbie, need help!

Jump to solution

Hey @kevin_pang,

That's excellent! I'm glad you were able to find the issue!

Consider marking one of the posts in the thread as the solution so we know the thread is solved.

Nicholas Moellers

Xilinx Worldwide Technical Support