cancel
Showing results for
Show  only  | Search instead for
Did you mean:  Contributor
11,726 Views
Registered: ‎05-27-2015

## Matrix multiplication without using DSP

Hello everybody,

I am trying to simulate a c program of matrix multiplication of float numbers. I don't want to use DSPs for doing this. I tried multiple directives (allocate, resource, ...) but i was unable to eliminate DSPs from my design.

Here is my code :

```void matrix_multiply_hw(float mat_in1[DIM][DIM], float mat_in2[DIM][DIM], float mat_out[DIM][DIM])
{
#pragma HLS INLINE off

// matrix multiplication of a A*B matrix
L1: for (int y = 0; y < DIM; y++)
L2: for (int x = 0; x < DIM; x++)
{
float sum = 0;
L3: for (int i = 0; i < DIM; i++)
sum = sum + mat_in1[y][i] * mat_in2[i][x];
mat_out[y][x] = sum;
}
return;
}```

My directive file contains the following directive to pipeline a loop:

`set_directive_pipeline "matrix_multiply_hw/L2"`

If I apply the following directive to limit number of DSPs to 1 :

`#pragma HLS ALLOCATION instances=mul limit=1 operation`

I get 10 instances of matrix_multiply_hw function in my top function. I applied the directive to have only 1 instance of this function by using the following directive :

`#pragma HLS ALLOCATION instances=matrix_multiply_hw limit=1 function`

The problem is at line :

`sum = sum + mat_in1[y][i] * mat_in2[i][x];`

As this line does the multiplication and addition, it uses DSPs.

How can i tell Vivado HLS to not use DSPs at all for this design. Any suggestion would be appreciated.

Kind regards,

Abdul

Tags (4)
1 Solution

Accepted Solutions  Moderator
20,284 Views
Registered: ‎04-17-2011

In this particular case for DIM = 10, making some minor changes removed all the DSP's with RESOURCE directive.

As this is a floating point operation, the operations which inferred the DSP were fmul & fAddSub.

Try this below:

void matrix_multiply_hw(float mat_in1, float mat_in2, float mat_out)
{

#pragma HLS INLINE off

float sum = 0;
float temp;
#pragma HLS RESOURCE variable=temp core=FMul_nodsp

// matrix multiplication of a A*B matrix
L1: for (int y = 0; y < 10; y++)
L2: for (int x = 0; x < 10; x++)
{
L3: for (int i = 0; i < 10; i++)
temp = mat_in1[y][i] * mat_in2[i][x];
sum = sum + temp ;
mat_out[y][x] = sum;
}
return;
}

With this, no DSP were inferred as the Floating Point operations would be inferring No DSP. Regards,
Debraj
----------------------------------------------------------------------------------------------

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
3 Replies  Contributor
11,713 Views
Registered: ‎05-27-2015

I have seen multiple times the same question in the forum and the proposed suggestions to resolve it but I was unable to get it done with the suggestions. So, that's why I asked another question about it.

I tried to synthesize in Vivado without using DSPs (by changing max_dsp flag in synthesis settings) but even there it was unable to do it.

Regards,

Abdul  Moderator
20,285 Views
Registered: ‎04-17-2011

In this particular case for DIM = 10, making some minor changes removed all the DSP's with RESOURCE directive.

As this is a floating point operation, the operations which inferred the DSP were fmul & fAddSub.

Try this below:

void matrix_multiply_hw(float mat_in1, float mat_in2, float mat_out)
{

#pragma HLS INLINE off

float sum = 0;
float temp;
#pragma HLS RESOURCE variable=temp core=FMul_nodsp

// matrix multiplication of a A*B matrix
L1: for (int y = 0; y < 10; y++)
L2: for (int x = 0; x < 10; x++)
{
L3: for (int i = 0; i < 10; i++)
temp = mat_in1[y][i] * mat_in2[i][x];
sum = sum + temp ;
mat_out[y][x] = sum;
}
return;
}

With this, no DSP were inferred as the Floating Point operations would be inferring No DSP. Regards,
Debraj
----------------------------------------------------------------------------------------------

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------  Contributor
11,541 Views
Registered: ‎05-27-2015
Debrajr,

Thank you very much. I am going to try and if it works, I will accept it as solution.

Regards,
Abdul