Search code examples
cublas

cublas AA' using GEMM


I am trying to Find calculate AA' multiplication where A is MxN I am trying this :

    double al =1.0f; // al =1
    double bet =0.0f; // bet =1
stat=cublasDgemm(handle,CUBLAS_OP_N,CUBLAS_OP_T,M,M,N,&al,d_A,M,d_Acopy,M,&bet,d_temp,M);

But it gives segmentation error I found this question but I couldn't follow

could you help me doing the AA', knowing that I manually initialized the Matrices using a double pointer

double ** m = (double**)malloc(rows * sizeof(double*));

also I saved the values as following

int i,j;
//initalize A
for (i=0;i<cols;i++)
    {
     for (j=0;j<rows;j++)
       {
        a[i][j]=A_example[i*rows+j];
        //a[i][j]=my_round(a[i][j]*10000.0)/10000.0;
        }
    }

Solution

  • I just redefined my matrices the way they define it in their examples. I think the issue is the data layout they use. I couldn't adapt my C matrices to cuBlas format.

    Anyways: they define it as follows:

    double *m=( double *) malloc (rows*cols* sizeof ( double ));
    

    for data initilizaing: int i; int j;

    for (i=0;i<k;i ++){
        for (j=0;j<n;j ++){
            printf (" %5.0f",a[ IDX2C(i,j,k )]);
            }
    

    where IDX2C is a macro defined as:

    # define IDX2C(i,j,ld) (((j)*( ld ))+( i ))
    

    and finally I was able to find AA' as follows:

    double al =1.0f; // al =1
    double bet =0.0f; // bet =1
    stat=cublasDgemm(handle,CUBLAS_OP_N,CUBLAS_OP_T,M,M,N,&al,d_A,N,d_A,M,&bet,d_temp,M);
    

    where A is MxN Matrix.