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: 
Highlighted
Visitor mmiu.rimon
Visitor
246 Views
Registered: ‎11-15-2018

working with string

Dear altruists,

I am new to Vivado HLS. I am trying to work with string in vivado hls.

Just creating a string datatype in the top function like below,

void str (int cl) {
    std::string temp;

}

During synthesis, vivado hls is showing the following error message ,

function 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()' has no function body.

would you please let me the cause of this error?

 

Tags (1)
0 Kudos
7 Replies
Scholar u4223374
Scholar
209 Views
Registered: ‎04-26-2015

Re: working with string

C++ strings (as opposed to C-style null-terminated character arrays) rely on dynamic memory allocation. Your example demonstrates this; you've specified a string but not said how long it can be. HLS does not do dynamic memory allocation, and so it's not going to work with C++ strings.

 

Visitor mmiu.rimon
Visitor
175 Views
Registered: ‎11-15-2018

Re: working with string

Thank you very much for your reply. 

In that case, is it good to use "C-style null-terminated character arrays" for working with string related work? Actually, I need to sort string, I tried "qsort", but it is not compatible with vivado_hls? Do you have any recommendation for sorting string in vivado_hls? 

Tags (1)
0 Kudos
Scholar u4223374
Scholar
142 Views
Registered: ‎04-26-2015

Re: working with string

I would definitely use character arrays as strings in HLS, although depending on what you're doing just storing the length instead of a null terminator might make sense.

 

It's pretty easy to write a merge-sort in HLS, and achieving II=2 on that (ie one operation per two cycles, so total run-time is 2(n)log(n) cycles) is also both efficient and straightforward.

 

Alternatively, the new hls_db library appears to include a bitonic sort function. No idea how well that works, or for what data types.

0 Kudos
Explorer
Explorer
136 Views
Registered: ‎08-16-2018

Re: working with string

That the Linux kernel is written in "plain" C should be proof enough that C++ is an unnecessary complication of an outstanding programming language. 

Interesting to see how things have changed with generations. Just a couple of decades ago, if a software 'engineer' (improper term, imho, as they are just educated in so-called computer  sciences) needed a sorting algorithm, he or she would go to a text book like 'Numerical Recipes in C' that used to be my good companion for years. Now they seem to just whine and beg 'Can I have a function that does this?' 'Oh, there is no such function... so I need to move to another language'

Take it as venting, for me it's a reflection we all should give it a minute. 

Scholar u4223374
Scholar
127 Views
Registered: ‎04-26-2015

Re: working with string

@johnvivm I think that needs to be made more clear for people coming to HLS. It may be "C/C++" based, but the only libraries that will work are the ones that Xilinx provides. For everything else, it's time to either dig out a standard algorithm (honestly, I just used Wikipedia when I was implementing merge sort) or do some research on which state-of-the-art algorithms might be implementable efficiently.

 

People who are used to dealing with the little 8-bit microcontrollers should be pretty comfortable with HLS, as they're used to dealing with exactly this sort of limitation (few resources, few libraries, have to hand-code any significant functionality).

 

 

 

 

 

0 Kudos
Explorer
Explorer
120 Views
Registered: ‎08-16-2018

Re: working with string

One more time I write/ say "HLS just looks like C but you are still dealing with hardware"

Sorting strings is something a processor can do with, for example, the bubble algorithm. Strings are relatively complex types, first of all, not fixed length, yet processors deal efficiently (in the processor World) with them. Said that, if one comes to sort things on FPGA I'd assume it's for the sake of speed, then one of the first and foremost things to do is simplify data ("simplification is the ultimate form of sophistication"), simply by having fixed length char arrays, just choosing a practical maximum. 

Using strings when speed is needed is like having traffic lights in motorways

0 Kudos
Visitor mmiu.rimon
Visitor
70 Views
Registered: ‎11-15-2018

Re: working with string

Dear u4223374 & johnvivm,

Thank you very much for your suggestions and discussion.

Actually, I have to sort several strings lexicographically. As a newbie on HW, I am having trouble implementing strings sorting on HLS. 

0 Kudos