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!

Reply

How to access a struct within hls:stream class?

Accepted Solution Solved
Highlighted
Visitor
Posts: 5
Registered: ‎01-12-2018
Accepted Solution

How to access a struct within hls:stream class?

Hello. I am trying to figure out how to access a struct within an hls::stream and I cannot seem to figure it out.

If I have a struct like so:

typedef struct{
    char A[16]
} data_strm;

And my stream is:

hls::stream<data_strm> strm_name;

How can I access member A within the stream class?

strm_name.????.A[0] = '1';

Accepted Solutions
Scholar
Posts: 1,869
Registered: ‎03-22-2016

Re: How to access a struct within hls:stream class?

[ Edited ]

@mledwon Same thing, you are supposed to call write() on the stream with a struct. 

Look at page 264 on UG902,

https://www.xilinx.com/support/documentation/sw_manuals/xilinx2014_2/ug902-vivado-high-level-synthesis.pdf

In particular, "Blocking write methods" on page 266

In summary, you create a struct of data_strm type, fill it and then call stream.write( my_struct )

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.

View solution in original post


All Replies
Scholar
Posts: 1,869
Registered: ‎03-22-2016

Re: How to access a struct within hls:stream class?

@mledwon  You are supposed to call read() on the stream to get the next value.

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
Visitor
Posts: 5
Registered: ‎01-12-2018

Re: How to access a struct within hls:stream class?

[ Edited ]

In this example I am trying to write to the stream, not read from it.

EDIT: When I try using strm_name.write();  It gives me the error message:

Invalid arguments '
Candidates are:
void write(const {struct_test_tb.cpp:25} &)'

 

It looks like it's expecting a constant. I need to figure out how to tell it I want to write to struct member A, not the stream class itself.

Scholar
Posts: 1,869
Registered: ‎03-22-2016

Re: How to access a struct within hls:stream class?

[ Edited ]

@mledwon Same thing, you are supposed to call write() on the stream with a struct. 

Look at page 264 on UG902,

https://www.xilinx.com/support/documentation/sw_manuals/xilinx2014_2/ug902-vivado-high-level-synthesis.pdf

In particular, "Blocking write methods" on page 266

In summary, you create a struct of data_strm type, fill it and then call stream.write( my_struct )

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
Scholar
Posts: 1,869
Registered: ‎03-22-2016

Re: How to access a struct within hls:stream class?

@mledwon Try this

 

data_strm obj;
for ( int j=0; j<16; ++j ) obj.A[j] = j;
stream.write( obj );

The "const" in the call means that the write() call will not modify the object passed.

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
Visitor
Posts: 5
Registered: ‎01-12-2018

Re: How to access a struct within hls:stream class?

Ah yes. I've figured it out now. The error message it was giving me was confusing me. I was trying to write the individual members of the array within the struct within the stream. I followed your advice and wrote to a struct outside the stream and then wrote that to the stream as follows:

hls::stream<data_strm> strm_name;
data_strm temp;
for(int i=0; i<16; i++){
    temp.A[i] = i;
}
strm_name.write(temp);

This works now. Thanks for the help!

Scholar
Posts: 1,869
Registered: ‎03-22-2016

Re: How to access a struct within hls:stream class?

@mledwon  Remember you have to pass the actual stream as a reference through the top function. You should not create it in the stack as you did. 

vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.
Visitor
Posts: 5
Registered: ‎01-12-2018

Re: How to access a struct within hls:stream class?

Yes, that is correct. I just wrote this quick test code to figure out this problem. I've worked with hls::stream before, just never using structs.