cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
699 Views
Registered: ‎03-04-2019

Shared BRAM between different TOP functions

Can I have a shared BRAM variable between 2 TOP functions? 

For example, I have 2 TOP functions 

int gloabl_mem[1000];  

void vadd (int a*, int b*)

{

        int local_vadd[1000];          // BRAM

}

void vmul (int a*, int b*)

{

       int local_vmul[1000];         //BRAM

}

The 2 var local_vadd and local_vmul are local to their TOP function and are implemented in the BRAM but the gloabl_mem var is in the DRAM. Is there any way to have shared BRAM between 2 TOP functions for Eg: 

int shared_mem[100];

void vadd (int a*, int b*)

{

        int local_vadd[1000];          // BRAM

        int x = shared_mem[0];

}

void vmul (int a*, int b*)

{

       int local_vmul[1000];         //BRAM

       int b = shared_mem[0];

}

0 Kudos
4 Replies
Highlighted
Observer
Observer
569 Views
Registered: ‎03-04-2019

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
491 Views
Registered: ‎09-04-2017

@kaustubhmhatre 

Based on the size, HLS will automatically infer a BlockRAM. You can force it if needed using directives.

Below, is a simple example which uses ROM as the shared memory. I have forced it to use BlockRAM

int shared_mem[128] = {
  1,2,3,4,5,6,7,8,
  8,7,6,5,4,3,2,1,
  1,2,3,4,5,6,7,8,
  8,7,6,5,4,3,2,1,
  1,2,3,4,5,6,7,8,
  8,7,6,5,4,3,2,1,
  1,2,3,4,5,6,7,8,
  8,7,6,5,4,3,2,1,
  1,2,3,4,5,6,7,8,
  8,7,6,5,4,3,2,1,
  1,2,3,4,5,6,7,8,
  8,7,6,5,4,3,2,1,
  1,2,3,4,5,6,7,8,
  8,7,6,5,4,3,2,1,
  1,2,3,4,5,6,7,8,
  8,7,6,5,4,3,2,1
                      };
void vadd (int *a, int *b, int addr)
{
  int local_vadd[1000];
  int x = shared_mem[addr];
  for(int i=0;i<1000;i++)
  {
    local_vadd[i] = a[i];
  }
  for(int i=0;i<1000;i++)
  {
    b[i] = x + local_vadd[i];
  }
}

void vmul (int *a, int *b,int addr)
{
  int local_vmul[1000];      
  int x = shared_mem[addr];
  for(int i=0;i<1000;i++)
  {
    local_vmul[i] = a[i];
  }
  for(int i=0;i<1000;i++)
  {
    b[i] = x * local_vmul[i];
  }
}

void top(int *a, int *b,int addr)
{
#pragma HLS RESOURCE variable=shared_mem core=RAM_2P_BRAM
#pragma HLS INTERFACE m_axi depth=1024 port=a
#pragma HLS INTERFACE m_axi depth=1024 port=b
int temp[1000];
vadd(a,temp,addr);
vmul(temp,b,addr);
}
0 Kudos
Highlighted
Advisor
Advisor
484 Views
Registered: ‎04-26-2015

@kaustubhmhatre Unless something has changed very recently, the answer is simply "you can't have two top functions". HLS builds a module corresponding to the top function selected, not a group of top functions.

 

If you need multiple functions with shared RAM, the solution is to either merge them into a single top function with a switch that tells it which operation to perform (no shared RAM needed), or two entirely separate HLS blocks both communicating with an external BRAM.

Highlighted
Xilinx Employee
Xilinx Employee
482 Views
Registered: ‎09-04-2017

@u4223374    Yes, having two top functions is not possible. I went with the assumption that he want's to use a shared array across two different functions within the top function

Thanks,

Nithin