cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
9,838 Views
Registered: ‎03-30-2015

Dynamic memory for C++ in HLS

Jump to solution

Hello,

 

I'm writing a HLS program using C++. The target of this program is creating barrel distortion for input image.

The reason I'm using C++ because I want to use hls::stream class, and Vivado HLS only support it for C++ (UG902 - page.136)

In my program, I defined a constant array which its size is 540x480, it's quite large so I for C Simulation I tried to define by using new() command, but I got segment fault.

 

*********************************************************************************

Compiling ../../../barrel_test.cpp in debug mode
Generating csim.exe
@E Simulation failed: SIGSEGV.
@E [SIM-1] CSim failed with errors.
4
while executing
"source D:/FPGA-Zynq-7000/Projects/HLS/barrel_2/solution1/csim.tcl"
invoked from within
"hls::main D:/FPGA-Zynq-7000/Projects/HLS/barrel_2/solution1/csim.tcl"
("uplevel" body line 1)
invoked from within
"uplevel 1 hls::main {*}$args"
(procedure "hls_proc" line 5)
invoked from within
"hls_proc $argv"
@I [LIC-101] Checked in feature [VIVADO_HLS]

*********************************************************************************

 

I read from UG902, it mentioned that Dynamic memory command only support malloc(), alloc() command which means that using C language. Is there any way to using dynamic memory in C++?

 

Beside that, is it possible to have many input stream for one IP block (designed by HLS)? Example I have 2 input stream in my IP, one comes from camera, another comes from DRAM through VDMA.

 

Thank you,

Son.

 

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Teacher
Teacher
17,786 Views
Registered: ‎03-31-2012

Re: Dynamic memory for C++ in HLS

Jump to solution
You need to debug your C program first. Either step through your code in a debugger or add printfs to see where it's crashing and why. First step would be to compile your code with debug info and start it with a debugger. It should take you to the line which caused the crash
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.

View solution in original post

0 Kudos
7 Replies
Highlighted
Teacher
Teacher
9,803 Views
Registered: ‎03-31-2012

Re: Dynamic memory for C++ in HLS

Jump to solution

>> I read from UG902, it mentioned that Dynamic memory command only support malloc(), alloc() command 

 

I think you need to re-read ug902 which says nothing of the kind. It says: "Dynamic objects cannot be synthesized. The function calls malloc(), alloc(), pre-processor free() and C++ new and delete dynamically create or destroy memory resources which exist in the OS memory map. The only memory resources available in an FPGA are block RAMs and registers. Block RAMs are created when arrays are synthesized and the values in the array must be maintained over one or more clock cycles. Registers are created when the value stored by a variable must be maintained over one or more clock cycle. Arrays of a fixed size or variables must be used in place of any dynamic memory allocation."

It also says: "Memory allocation system calls must be removed from the design code before synthesis." 

 

So in short malloc is not supported. Your best option is to do your processing with several rows of the frame within the FPGA resources (block-rams etc) and keep the rest of the frame in external memory which you read with an M_AXI port or a stream port from a frame buffer.

 

Yes you can have multiple streams coming to your block. Just add another stream port.

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
Highlighted
Xilinx Employee
Xilinx Employee
9,791 Views
Registered: ‎08-17-2011

Re: Dynamic memory for C++ in HLS

Jump to solution

on top of the previous excellent response,

 

Compiling ../../../barrel_test.cpp in debug mode
Generating csim.exe
@E Simulation failed: SIGSEGV.
@E [SIM-1] CSim failed with errors.

 

this indicate that you have a seg falut at run time.

 

please compile with g++ and you will see that it seg fault, so that's a user coding issue that you need to fix.

g++ -I PATH_TO_VHLS_INCLUDE_DIR        YOUR_CPP_FILES

- Hervé

SIGNATURE:
* New Dedicated Vivado HLS forums* http://forums.xilinx.com/t5/High-Level-Synthesis-HLS/bd-p/hls
* Readme/Guidance* http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369

* Please mark the Answer as "Accept as solution" if information provided is helpful.
* Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Highlighted
Visitor
Visitor
9,766 Views
Registered: ‎03-30-2015

Re: Dynamic memory for C++ in HLS

Jump to solution

Hello @herver,

 

I fixed the code issue you mentioned (I forgot #endif) and compiling with g++ has done.

But I still got the Segfault issue when running C simulation.

 

Thank you,

Son

 

0 Kudos
Highlighted
Visitor
Visitor
9,759 Views
Registered: ‎03-30-2015

Re: Dynamic memory for C++ in HLS

Jump to solution
Hello @muzaffer,

Thank you for your reply.

Actually, I didn't go to Synthesis step. In synthesis step, the array will become an argument in the top function and it'll be a fifo. But I want to check the code by running C simulation first and got Seg fault.
I have no idea where Seg fault came from. Is there anyway to investigate this kind of issue in Vivado HLS?
0 Kudos
Highlighted
Teacher
Teacher
17,787 Views
Registered: ‎03-31-2012

Re: Dynamic memory for C++ in HLS

Jump to solution
You need to debug your C program first. Either step through your code in a debugger or add printfs to see where it's crashing and why. First step would be to compile your code with debug info and start it with a debugger. It should take you to the line which caused the crash
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.

View solution in original post

0 Kudos
Visitor
Visitor
9,752 Views
Registered: ‎03-30-2015

Re: Dynamic memory for C++ in HLS

Jump to solution
I found the issue, the image file I use is JPG but I used read/write BMP function, that gave me Seg fault error.
And I'm working on that.

Thank you.
Son
0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
9,686 Views
Registered: ‎08-17-2011

Re: Dynamic memory for C++ in HLS

Jump to solution

so i was right when i wrote <<please compile with g++ and you will see that it seg fault>> AT RUN TIME

good luck in your investigations!

- Hervé

SIGNATURE:
* New Dedicated Vivado HLS forums* http://forums.xilinx.com/t5/High-Level-Synthesis-HLS/bd-p/hls
* Readme/Guidance* http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369

* Please mark the Answer as "Accept as solution" if information provided is helpful.
* Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos