cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
vantades
Newbie
Newbie
367 Views
Registered: ‎01-06-2021

I am new to HLS and i am having issues using C++ functions in HLS

Jump to solution

So i have this code 

#include <algorithm>
#include <iostream>
#include <vector>

void rotate(std::string &a) {
int len = a.length();
char t = 'c';
for ( int i = len - 1; i > 0; i--) {
a[i] = a[i - 1];
}
a[0] = t;
}

 

and i am getting these errors 

ERROR: [HLS 214-194] in function 'rotate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)': Undefined function std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::length (tester.cpp:6:14)
ERROR: [HLS 214-194] in function 'rotate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)': Undefined function std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[] (tester.cpp:9:16)
ERROR: [HLS 214-194] in function 'rotate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)': Undefined function std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[] (tester.cpp:9:9)
ERROR: [HLS 214-194] in function 'rotate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)': Undefined function std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[] (tester.cpp:11:5)
ERROR: [HLS 214-135] Syn check fail!

 

are there any documentations i can read to solve these problems..

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
joancab
Mentor
Mentor
355 Views
Registered: ‎05-11-2015

There is the HLS user guide (HLS User Guide UG902) and a number of tutorials, fir example Vivado Design Suite Tutorial: High-Level Synthesis (UG871)

Keep in mind:

1 - An FPGA is not a processor so it isn't "programmed" with software, they are with Hardware Description Languages, like Verilog or VHDL.

2 - HLS uses C and C++ syntax but is not software, you are again describing hardware with a borrowed syntax.

The problem in your code is that std::string is not defined. My suggestion for a smooth start without much swearing is to forget about fancy types (yes, string is a fancy type for an FPGA) and use uint8 arrays (that at the end of the day are the same thing, but are well defined). 

View solution in original post

3 Replies
joancab
Mentor
Mentor
356 Views
Registered: ‎05-11-2015

There is the HLS user guide (HLS User Guide UG902) and a number of tutorials, fir example Vivado Design Suite Tutorial: High-Level Synthesis (UG871)

Keep in mind:

1 - An FPGA is not a processor so it isn't "programmed" with software, they are with Hardware Description Languages, like Verilog or VHDL.

2 - HLS uses C and C++ syntax but is not software, you are again describing hardware with a borrowed syntax.

The problem in your code is that std::string is not defined. My suggestion for a smooth start without much swearing is to forget about fancy types (yes, string is a fancy type for an FPGA) and use uint8 arrays (that at the end of the day are the same thing, but are well defined). 

View solution in original post

joancab
Mentor
Mentor
349 Views
Registered: ‎05-11-2015

a.length is nonsense in an FPGA. It does make sense in software, but you can't use it here.

In software, when you assign a string to a variable, the variable points to a memory address with a number of characters and 0x0 as termination, so the function length can start at the beginning and count characters until the termination character.

In an FPGA, an array has a fixed length at compile time. No other way. Or, if a pointer, the range of addresses it spans is also fixed. Data in an FPGA is not memory contents you can grow and shrink, but more like wires, fixed connections between elements.

0 Kudos
joancab
Mentor
Mentor
344 Views
Registered: ‎05-11-2015

HLS has a bless and a curse.

The bless is it borrows the C and C++ syntax so the learning curve looks easier.

The curse is it borrows the C and C++ syntax so a hoard of software folks fall into a deep dark trap.

0 Kudos