Jump to content

directives in vivado hls


Recommended Posts

I have a " prodmatrice " function implemented in c I want to transform it into vhdl

void prodmatrice (double mat1 [2 ] [2] , double mat2 [2 ] [2] , double C [2 ] [2] )
int I, J , K, ii, jj ;
for ( ii = 0; ii < 2; ii ++)
    {For ( dd = 0; jj < 2; dd ++)
         C [ ii ] [dd ] = 0;

for ( I = 0 ; I < 2; I ++ )
for ( J = 0; J < 2; J ++)
       C [J] = 0;
for ( k = 0 ; K < 2; K ++)
       C [J ] + = mat1 [K ] * mat2 [K] [J] ;

I searched the Internet how to choose the directives for variables mat1 , mat2 , C, prodmatrice and for loops , but it does not work
Is that you have an idea about that?
Thank you

Link to comment
Share on other sites

Wow ... you picked a complex project.  Do you have any experience with FPGA's?  You might wish to start with *much* simpler projects before taking on the project listed above.

Okay, some challenges you will have:

  1. First, you will need to think in parallel.  Everything in an FPGA happens at once.  If you want things to happen sequentially, you will need to build a state machine and work through all the pieces one piece at a time.  If you are familiar with software, you will know that your code above translates into a series of instructions that the computer does one at a time.  This isn't true with an FPGA.  On an FPGA, everything happens on the clock.  If you want to multiply all 16 values together on one clock, and FPGA will let you do so--only it will probably take you more than one clock to multiply two double precision floating point numbers.  If you have no experience with this, I suggest learning it before tackling your problem above. 
  2. Second, floating point multiplies don't come for free.  On a Xilinx part, you can get some number of 18 bit by 18 bit integer multiplies for free, but not floating point multiplies.  (Look at the number of DSP48's on the FPGA part that you will be using for this number.)  Further, double precision floating point multiplies, i.e. with 52 bit mantissa's, will need to be broken into components that can use the 18x18 bit multiplies.  Hence, just to do one of your multiplies will take nine 18x18 multiplies, plus some work adding and subtracting exponents.  (These might also use DSP48 blocks.)
  3. Third, floating point additions are also a pain.  Depending upon your clock speed and the chip you choose, you may be able to add two 52 bit numbers ... but what about that mantissa?  You'll need to shift the individuals mantissa's around first so that their exponents match before you can add them together.  Then, you'll need to adjust the mantissa's again (possibly) after the addition, depending upon the size of your result.
  4. Fourth, where are your values coming from?  This is also something to think about.  Are you going to be presented with all eight values (two 2x2 matrices) at once?  (This is what your code suggests above.)  Or will they be in memory somewhere?  (This would be the case with most CPU's.)  If from memory, then be aware that reading memory takes cycles which need to be accounted for as well.  Of course, as you've presented it above, all 8 values are presented at once and all four values will need to be produced at once ... some number of clocks later.  Is this what you want?  It's not wrong.  It's quite doable, but on cheaper hardware it's often easier to produce one answer at a time.

If you haven't done any of this kind of work before, you might wish to check out fpga4fun.com.  They have some wonderful overview and introductory materials.

If you think I've misjudged you and your ability completely, then you might wish to check out opencores.org instead.  There you will find examples of how to do double precision floating point computations, and you might even manage to find some that you can use directly into your project.  One example to consider would be their "Floating Point Unit" project, found under coprocessor projects here, although as I recall that's only a single precision floating point example.

Hope this helps,


Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...