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: 
Adventurer
Adventurer
7,902 Views
Registered: ‎03-15-2012

coding style: MAC

Jump to solution

hi,

 

i'm struggling with describing an multiply accumulate. The line is similar to

 

...

accu[i] += a*b[i];

...

 

the code is work, even in VHDL, but the resources are used suboptimal. I'm using a V6 but the DSP48E1 are only used for the multiplication not for the accumulation too. The accumulation is done by seperate logic.

 

The next: it would be nice, if i can cascade the DSP48E1 to use the ACOUT/ACIN (or BCOUT/BCIN) as shift-register. Actually, this will be also implement as seperate logic.

 

Does anyone know, how to code it correctly?

 

thanks

0 Kudos
1 Solution

Accepted Solutions
Adventurer
Adventurer
12,174 Views
Registered: ‎03-15-2012

Re: coding style: MAC

Jump to solution

The solution seems to be found.

 

Althought declared as static, the accu wasn't registered and therefore not pulled into the DSP48E1.

 

The following code worked as expected:

 

template<class T>
T Reg(T in)
{
#pragma HLS PIPELINE
#pragma HLS INLINE off
#pragma HLS INTERFACE port=return register
return in;
}

int mac(short a_in, short b_in)
{
static int c = 0;

c = Reg(c + a_in * b_in);
return c;

}

 

thanks @all 



0 Kudos
7 Replies
Moderator
Moderator
7,894 Views
Registered: ‎04-17-2011

Re: coding style: MAC

Jump to solution
Are you writing this code in C?
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- 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
Adventurer
Adventurer
7,893 Views
Registered: ‎03-15-2012

Re: coding style: MAC

Jump to solution

at the moment i'm using the c++ compiler without classes

0 Kudos
Xilinx Employee
Xilinx Employee
7,887 Views
Registered: ‎08-01-2008

Re: coding style: MAC

Jump to solution
you can use dsp48 macro core for your application

Here is AR which tell you How to connect up the PCIN when it is not connected to the PCOUT of an adjacent DSP48 slice?

http://www.xilinx.com/support/answers/44205.html
Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
0 Kudos
Xilinx Employee
Xilinx Employee
7,884 Views
Registered: ‎08-01-2008

Re: coding style: MAC

Jump to solution

#include "array_arith.h"

void array_arith (dio_t d[5]) {
  static int acc = 0;
  int i;
 
    for (i=0;i<4;i++) {
    acc += d[i+1];
    d[i] = acc;
  }
}

Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
0 Kudos
Xilinx Employee
Xilinx Employee
7,881 Views
Registered: ‎03-24-2010

Re: coding style: MAC

Jump to solution

It's possible to be put into DSP and post-adder if width(accu[i])<=48, width(a,b[i])<=(18,25) and width(a+b[i])<=width(accu[i]).

Regards,
brucey
----------------------------------------------------------------------------------------------
Kindly note- 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
Adventurer
Adventurer
7,878 Views
Registered: ‎03-15-2012

Re: coding style: MAC

Jump to solution
this conditions are met
a, b = 8 bit ns
accu = 30 bit ns

Maybe due to the fact, that multiplications are done in a separate component, the XST does not interfere a MAC. Even if hierarchy is turned off.
0 Kudos
Adventurer
Adventurer
12,175 Views
Registered: ‎03-15-2012

Re: coding style: MAC

Jump to solution

The solution seems to be found.

 

Althought declared as static, the accu wasn't registered and therefore not pulled into the DSP48E1.

 

The following code worked as expected:

 

template<class T>
T Reg(T in)
{
#pragma HLS PIPELINE
#pragma HLS INLINE off
#pragma HLS INTERFACE port=return register
return in;
}

int mac(short a_in, short b_in)
{
static int c = 0;

c = Reg(c + a_in * b_in);
return c;

}

 

thanks @all 



0 Kudos