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
Observer nikhilghanathe
Observer
14,067 Views
Registered: ‎12-28-2014

Separate Array for each function invocation

Jump to solution

 Hello,

I am trying to synthesie a piece of code as shown below:

 

void test_top(ap_uint<3> a[5],ap_uint<3> b[5],ap_uint<3> index[5],ap_uint<3> c[5])

#include <ap_int.h>

class test{
public: ap_uint<3> bx[9];
};

 

void test_func(ap_uint<3> a,ap_uint<3> b,ap_uint<3> index,ap_uint<3> *c,ap_uint<3> bx[9])
{

bx[index]=int(bx[index])+1;
*c=a+b+bx[index];
}


void multiple_inst(ap_uint<3> a[5],ap_uint<3> b[5],ap_uint<3> index[5],ap_uint<3> c[5],ap_uint<1> en)
{

ap_uint<3> res;
test inst[5];

#pragma HLS UNROLL
multiple_inst_label1:for(int i=0;i<5;i++)
{
test_func(a[i],b[i],index[i],&c[i],inst[i].bx);
}

}

 

 

 

 

My aim here is when I unroll the loop "multiple_inst_label1", each instance of the function should run parallely and each instance of the function should have its own copy of "bx" array which is defined in the the class. Also each "bx" array should be persistent, in other words it should hold its previus value whenever it reenters the function.

 

The code uses different objects for each invocation of the function test_func but somehow the HLS compiler is optimizing and removing the "bx" array and always replacing it by '0'.

 

This is just a sample test case I was working on.

 

Any help or suggestions are really appreciated.

0 Kudos
1 Solution

Accepted Solutions
Observer nikhilghanathe
Observer
26,523 Views
Registered: ‎12-28-2014

Re: Separate Array for each function invocation

Jump to solution

Hi I solved the problem by defining the array of instances as a static array.

   static test inst[5];

Without "static", the HLS compiler does not retain the contents of the array because the object is destroyed once the function is exited. And everytime that function is called a new array of objects is created.

With "static", the object is destroyed only when the program is terminated and hence it results in persistence of the member variables ( "bx" array in this case)  in the generated RTL.

0 Kudos
6 Replies
Xilinx Employee
Xilinx Employee
14,038 Views
Registered: ‎08-17-2011

Re: Separate Array for each function invocation

Jump to solution

Hello @nikhilghanathe

 

Do you have a C TB and when you run C sim do you see the N different instances of the same class/object.

have you tested your arrays are persistent ? i'm not sure this is achieved in the code there..

 

Is this a working C code that matches your specs ? - please let alone VHLS for a moment...

 

- 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
Observer nikhilghanathe
Observer
14,025 Views
Registered: ‎12-28-2014

Re: Separate Array for each function invocation

Jump to solution

Hello @herver,
I have checked the arrays to be persistent in C simulation.

Also 5 different objects are being created and each has its own "bx" array which was verified in C simulation.

0 Kudos
Xilinx Employee
Xilinx Employee
13,949 Views
Registered: ‎08-17-2011

Re: Separate Array for each function invocation

Jump to solution

hi @nikhilghanathe

 

Okay so in this situation, please include a testcase here so that someone can further investigate and file a bug report.

I don't think that what you have provided so far is enough to reproduce the issue so this testcase and its C TB is really needed to reproduce and see the issue, and then address it.

 

- 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
Observer nikhilghanathe
Observer
13,941 Views
Registered: ‎12-28-2014

Re: Separate Array for each function invocation

Jump to solution

Hello @herver.

Please find the test case attached.

 

Problem:

In the top function "multiple_inst" in the file test_cls.cpp, I am creating 5 objects of class "test". I am then calling this function 5 times in a for loop and unrolling the for loop so that the 5 instances of the function run in parallel. 
 
When I observe the generated RTL code, I do have 5 separate instances of the function "test_func", and 5 separate bx arrays.
I included the array_partition for the array in the constructor so that all arrays of the objects are partitioned.
 
But the problem is all elements of the array 'bx' is hard-coded to '0' even though the "test_func" reads and writes new values every time.
In other words, the "bx" array is not persistent i.e. it is not retaining its values. It is just hard-coded to 0.
But in C simulation, it does work fine and all arrays are persistent.
The problem lies with the RTL that is generated.
 
 
 
0 Kudos
Observer nikhilghanathe
Observer
26,524 Views
Registered: ‎12-28-2014

Re: Separate Array for each function invocation

Jump to solution

Hi I solved the problem by defining the array of instances as a static array.

   static test inst[5];

Without "static", the HLS compiler does not retain the contents of the array because the object is destroyed once the function is exited. And everytime that function is called a new array of objects is created.

With "static", the object is destroyed only when the program is terminated and hence it results in persistence of the member variables ( "bx" array in this case)  in the generated RTL.

0 Kudos
Xilinx Employee
Xilinx Employee
13,680 Views
Registered: ‎08-17-2011

Re: Separate Array for each function invocation

Jump to solution

well done!

it looks like your C TB wasn't robust enough to catch this issue.

persistence needed across multiple calls <=> static keyword needed somewhere. that's C so VHLS will follow that.

- 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