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

Matrix multiplication without using DSP

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Moderator
Moderator
19,728 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[10][10], float mat_in2[10][10], float mat_out[10][10])
{

#pragma HLS INLINE off

float sum = 0;
float temp;
#pragma HLS RESOURCE variable=temp core=FMul_nodsp
#pragma HLS RESOURCE variable=sum core=FAddSub_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.

 

HLS_DSP.JPG

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.
----------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
3 Replies
Highlighted
Contributor
Contributor
11,157 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

0 Kudos
Highlighted
Moderator
Moderator
19,729 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[10][10], float mat_in2[10][10], float mat_out[10][10])
{

#pragma HLS INLINE off

float sum = 0;
float temp;
#pragma HLS RESOURCE variable=temp core=FMul_nodsp
#pragma HLS RESOURCE variable=sum core=FAddSub_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.

 

HLS_DSP.JPG

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.
----------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
Highlighted
Contributor
Contributor
10,985 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
0 Kudos