Segfault with magma_zsetmatrix

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)
Post Reply
achilles0613
Posts: 2
Joined: Tue Jun 30, 2015 2:05 pm

Segfault with magma_zsetmatrix

Post by achilles0613 » Tue Jul 28, 2015 5:14 pm

Hi,

I'm trying to use Magma blas routines (specifically ZGEMM) in Fortran. Since blas routines on Fortran are not supported yet, I have a C wrapper for the MAGMA code that my Fortran program calls. I'm trying to use the c code with a huge, old Fortran 77 program but I keep running into a segfault with the values given in the Fortran program below. Using the small Fortran test code, I was able to isolate the call but I don't know what is going wrong exactly. Any help would be appreciated!

Code: Select all

/*
compilation code:
gcc -c d_magma_mpyacc.c -I/usr/local/magma-1.6.2/include -I/usr/local/cuda-7.0/include
*/

#include <stdio.h>
#include <stdlib.h>

#include "cublas_v2.h"     // if you need CUBLAS, include before magma.h
#include "magma.h"
void d_magma_mpyacc_(magmaDoubleComplex *zmata, magmaDoubleComplex *zmatb, magmaDoubleComplex *zmatc, magma_int_t *nrowa, magma_int_t *ncolb, magma_int_t *ncarb, magma_int_t *ldima, magma_int_t *ldimb, magma_int_t *ldimc, magma_int_t *isum, magma_int_t *isym)
{
        printf("hi from acc, nrowa=%d\n", *nrowa);
        printf("hi, ncolb=%d\n", *ncolb);
        printf("hi, ncarb=%d\n", *ncarb);
        printf("hi, ldima=%d\n", *ldima);
        printf("hi, ldimb=%d\n", *ldimb);
        printf("hi from acc, ldimc=%d\n", *ldimc);
        fflush(stdout);
        magmaDoubleComplex zalpha, zbeta;
        magmaDoubleComplex_ptr dzmata, dzmatb, dzmatc;
        magma_zmalloc(&dzmata, (*ldima)*(*ncarb));
        printf("hi got here\n");
        fflush(stdout);
        magma_zmalloc(&dzmatb, (*ldimb)*(*ncolb));
        printf("got here as well\n");
        fflush(stdout);
        magma_zmalloc(&dzmatc, (*ldimc)*(*ncolb));
        printf("made it here\n");
        fflush(stdout);
        magma_zsetmatrix(*ldima, *ncarb, zmata, *ldima, dzmata, *ldima);
        printf("almost there\n");
        fflush(stdout);
        magma_zsetmatrix(*ldimb, *ncolb, zmatb, *ldimb, dzmatb, *ldimb);
        printf("I think we're done\n");
        fflush(stdout);
        //magma_zprint_gpu(*ldima, *ncarb, dzmata, *ldima);
        //magma_zprint_gpu(*ldimb,*ncolb, dzmatb, *ldimb);
        if( isum < 0 )
        {
                zalpha = MAGMA_Z_MAKE(-1.,0.);
                zbeta = MAGMA_Z_MAKE(1.,0.);
                magma_zgemm(MagmaNoTrans,MagmaNoTrans,*nrowa,*ncolb,*ncarb,zalpha,dzmata,*ldima,dzmatb,*ldimb,zbeta,dzmatc,*ldimc);
        }
        else if( isum==0 )
        {
                zalpha = MAGMA_Z_MAKE(1.,0.);
                zbeta = MAGMA_Z_MAKE(0.,0.);
                magma_zgemm(MagmaNoTrans,MagmaNoTrans,*nrowa,*ncolb,*ncarb,zalpha,dzmata,*ldima,dzmatb,*ldimb,zbeta,dzmatc,*ldimc);
        }
        else
        {
                zalpha = MAGMA_Z_MAKE(1.,0.);
                zbeta = MAGMA_Z_MAKE(1.,0.);
                magma_zgemm(MagmaNoTrans,MagmaNoTrans,*nrowa,*ncolb,*ncarb,zalpha,dzmata,*ldima,dzmatb,*ldimb,zbeta,dzmatc,*ldimc);
        }
        //magma_zprint_gpu(*ldimc, *ncolb, dzmatc, *ldimc);
        printf("surprise, one more check\n");
        fflush(stdout);
        magma_zgetmatrix(*ldimc, *ncolb, dzmatc, *ldimc, zmatc, *ldimc);
        printf("home free\n");
        fflush(stdout);
        magma_free(dzmata);
        magma_free(dzmatb);
        magma_free(dzmatc);
}

Code: Select all

! gfortran -O3 MagmaProblem.f90 d_magma_mpyacc.o -o MagmaProblem.x -I/usr/local/magma-1.6.2/include -I/usr/local/cuda-7.0/include -L/usr/local/magma-1.6.2/lib -lmagma -L/usr/local/cuda-7.0/lib64 -lcublas -lcudart

program MagmaProblem
        use magma

        implicit none
        integer, parameter :: isum=0
        complex*16 :: L(50,1200),U(1200,2500),X(2501,2500), alpha, beta
        
        X = 0
        !print*, "X =", X
        L = 5
        !print*, "L=", L
        U = 5
        !print*, "U=", U
        alpha=cmplx(1.0,0.0)
        beta=cmplx(0.0,0.0)
        
        call d_magma_mpyacc(L,U,X,50,2500,1200,2501,2501,2501,isum)
        !print*, "X now equals:", X
        !X = matmul(L,U)
        !print*, "X should equal:", X
end program

Post Reply