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: 
Highlighted
Visitor kalopana
Visitor
216 Views
Registered: ‎11-23-2019

Array partition issue

Hello, I am trying to implement 2d (nxn) matrix multiplication (A*B=C) and when lets say synthesizing for n=8 or n=16 i get no WARNING (for array partitioning A and B cyclic factor=4 for dimension 1 and 2 respectively)  but when i do for 32 or above i get 

"Unable to schedule 'load' operation ('A_0_0_V_load_2', lab1/project1.cpp:38) on array 'A_0_0_V' due to limited memory ports" and i cannot pipeline II=1.

If I array_partition A and B complete on both dimensions I do not get this WARNING but i believe the cyclic one I chose is correct and it is not supposed to face this kind of WARNING.

I am trying to calculate in parallel 8 cells of C at a time (4 on top-left corner moving rightwards and 4 bottom right corner moving leftwards).

In addition to that, i got some dependence issue for writing on C that i believe it was faulty so I used 

"#pragma HLS dependence variable=C inter false" to overcome it ( an extra opinion would be handy for this move)

Any thoughts?

 

Thank you in advance.

******tool used: VIVADO HLS 2018.2******

---------------------------------------CODE USED-----------------------------------------------

#include "ap_int.h"
#define m 32//A nxm
#define p 32//B mxp
#define n 32//C nxp
void MATRIX_MUL(ap_uint<8> A[n][m],ap_uint<8> B[m][p],unsigned int C[n][p]){

unsigned int tmp,tmp1,tmp2,tmp3;
#pragma HLS ARRAY_PARTITION variable=A complete dim=2
#pragma HLS ARRAY_PARTITION variable=A cyclic factor=4 dim=1

#pragma HLS ARRAY_PARTITION variable=B complete dim=1
#pragma HLS ARRAY_PARTITION variable=B cyclic factor=4 dim=2

 

#pragma HLS ARRAY_PARTITION variable=C cyclic factor=2 dim=1
#pragma HLS ARRAY_PARTITION variable=C cyclic factor=2 dim=2

for (int i=0 ; i<n/2 ; i+=2)
{


for (int j=0;j<p;j++)
{
#pragma HLS unroll factor=2
#pragma HLS pipeline II=1
#pragma HLS dependence variable=C inter false
tmp1=0;
tmp=0;
tmp2=0;
tmp3=0;
for (int k=0;k<m;k++)
{
tmp+=A[i][k]*B[k][j];
tmp1+=A[i+1][k]*B[k][j];



tmp2+=A[n-1-i][k]*B[k][p-1-j];
tmp3+=A[n-2-i][k]*B[k][p-1-j];

 


}
C[i][j]=tmp;
C[i+1][j]=tmp1;


C[n-1-i][p-1-j]=tmp2;
C[n-2-i][p-1-j]=tmp3;

}
}


}

0 Kudos
2 Replies
Xilinx Employee
Xilinx Employee
111 Views
Registered: ‎09-04-2017

Re: Array partition issue

@kalopana This should be possible with cyclic. It looks like HLS is not able to handle the unroll in the second loop.

As a workaround, i have unrolled the second loop manually and we can achieve II=1 in this case

#include "ap_int.h"
#define m 64
#define p 64
#define n 64
void top(ap_int<8> A[n][m],ap_int<8> B[m][p],unsigned int C[n][p]){
unsigned int tmp,tmp1,tmp2,tmp3;
unsigned int tmp11,tmp12,tmp13,tmp14;
#pragma HLS ARRAY_PARTITION variable=A complete dim=2
#pragma HLS ARRAY_PARTITION variable=A cyclic factor=4 dim=1
#pragma HLS ARRAY_PARTITION variable=B complete dim=1
#pragma HLS ARRAY_PARTITION variable=B cyclic factor=4 dim=2

#pragma HLS ARRAY_PARTITION variable=C cyclic factor=2 dim=1
#pragma HLS ARRAY_PARTITION variable=C cyclic factor=2 dim=2


L1: for (int i=0 ; i<n/2 ; i+=2) {
L2: for (int j=0;j<p;j+=2) {
// #pragma HLS unroll factor=2
#pragma HLS pipeline II=1
#pragma HLS dependence variable=C inter false

tmp1=0;
tmp=0;
tmp2=0;
tmp3=0;

tmp11=0;
tmp12=0;
tmp13=0;
tmp14=0;
for (int k=0;k<m;k++) {
tmp+=A[i][k]*B[k][j];
tmp1+=A[i+1][k]*B[k][j];

tmp2+=A[n-1-i][k]*B[k][p-1-j];
tmp3+=A[n-2-i][k]*B[k][p-1-j];

tmp11+=A[i][k]*B[k][j+1];
tmp12+=A[i+1][k]*B[k][j+1];

tmp13+=A[n-1-i][k]*B[k][p-2-j];
tmp14+=A[n-2-i][k]*B[k][p-2-j];

}
C[i][j]=tmp;
C[i+1][j]=tmp1;

C[n-1-i][p-1-j]=tmp2;
C[n-2-i][p-1-j]=tmp3;

C[i][j+1]=tmp11;
C[i+1][j+1]=tmp12;

C[n-1-i][p-2-j]=tmp13;
C[n-2-i][p-2-j]=tmp14;

}
}
}

 

 

 

Visitor kalopana
Visitor
56 Views
Registered: ‎11-23-2019

Re: Array partition issue

Thank you for your response. I also came up with a similar solution. I just wanted to confirm that it was not a logic error and the tool gets confused in some cases.

0 Kudos