Call magma from Fortran, problem of wrapper

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)
liuxingrui4p
Posts: 5
Joined: Wed Apr 01, 2015 9:22 am

Call magma from Fortran, problem of wrapper

Post by liuxingrui4p » Tue May 19, 2015 10:22 am

Environment : CUDA v7.0 + intel fortran + magma1.6.1
I try to call Magma from Fortran and I used the wrapper control/magma_*fortran.F90 and magma.F90 offered by Magma.
I add them in my projet and compile them, there are lots of bugs with "magma_devptr_t" which is a pointer for GPU memory . Does anyone know how to fix it?
Thanks in advance

Code: Select all

error #5082: Syntax error, found '::' when expecting one of: ( % [ : . = =>	G:\PROJECTS\magma-1.6.1\control\magma_zfortran.F90	131	
And the wrapper is as below :

Code: Select all

subroutine magmaf_dlarfb_gpu_gemm( side, trans, direct, storev, m, n, k, dV, lddv, dT,  &
        lddt, dC, lddc, dwork, ldwork, dworkvt, ldworkvt )
    character        :: side
    character        :: trans
    character        :: direct
    character        :: storev
    integer          :: m
    integer          :: n
    integer          :: k
    magma_devptr_t   :: dV
    integer          :: lddv
    magma_devptr_t   :: dT
    integer          :: lddt
    magma_devptr_t   :: dC
    integer          :: lddc
    magma_devptr_t   :: dwork
    integer          :: ldwork
    magma_devptr_t   :: dworkvt
    integer          :: ldworkvt
end subroutine magmaf_dlarfb_gpu_gemm
For the function which has no variable of magma_devptr_t, it works well.

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Call magma from Fortran, problem of wrapper

Post by mgates3 » Wed May 20, 2015 10:48 am

When you say, you "add them in my project", what build environment are you using? It sounds like you are not using Makefiles.

In Makefile.internal, there is:

PTREXEC = $(MAGMA_DIR)/control/sizeptr
PTRSIZE = $(shell $(PTREXEC))
PTROPT = -Dmagma_devptr_t="integer(kind=$(PTRSIZE))"
F90FLAGS += $(PTROPT)

which passes -Dmagma_devptr_t="integer(kind=8)" as a compiler flag to define magma_devptr_t as integer(kind=8), assuming 64-bit (8-byte) pointers.

-mark

liuxingrui4p
Posts: 5
Joined: Wed Apr 01, 2015 9:22 am

Re: Call magma from Fortran, problem of wrapper

Post by liuxingrui4p » Wed May 27, 2015 8:01 am

Thanks Mark. I used vs2013. If possible, I want to ask anthother question. When we use the interface for Magma Blas, do we need to allocate GPU memory or it will be done automatically? I have not found interface for magma_malloc. Thanks a lot

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Call magma from Fortran, problem of wrapper

Post by mgates3 » Wed May 27, 2015 1:42 pm

You need to allocate the memory already. There is a cublas_alloc provided by CUDA in cuda/src/fortran.c. See fortran.o in the magma/testing/Makefile. There is an example in magma/testing/testing_zgetrf_gpu_f.F90.

-mark

liuxingrui4p
Posts: 5
Joined: Wed Apr 01, 2015 9:22 am

Re: Call magma from Fortran, problem of wrapper

Post by liuxingrui4p » Tue Jun 23, 2015 7:47 am

Thanks a lot, Mark. I have successfully compiled the example.

When I am trying to use Magma BLAS functions, for example "dtrsm", I have just found the wrapper "magmaf_dtrsm_m", it is a hybrid CPU/multiple-GPU routine.
If I want to use a hybrid CPU/GPU routine, do I need to create a new wrapper? And for magma BLAS, there are two types of prefix: magma_ prefix and magmablas_ prefix. I want to know the fortran wrapper indicates which prefix.

Thank you in advance,
Liu

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Call magma from Fortran, problem of wrapper

Post by mgates3 » Tue Jun 23, 2015 1:08 pm

We haven't yet made Fortran wrappers for the MAGMA BLAS functions. For the time being, you can call cublas directly, e.g.,

call cublas_dtrsm

magma_dtrsm is simply a wrapper around cublas_dtrsm, used for portability between cuBLAS, clBLAS, and Xeon Phi MKL BLAS.

magmablas_dtrsm is our own implementation of trsm, which is faster in some circumstances. There is not currently a means to call this from Fortran.

-mark

liuxingrui4p
Posts: 5
Joined: Wed Apr 01, 2015 9:22 am

Re: Call magma from Fortran, problem of wrapper

Post by liuxingrui4p » Wed Jun 24, 2015 4:08 am

Thanks Mark, And what is the difference between magmaf_init() & cublas_init() and magmaf_finalize() & cublas_shutdown()? If I want to use Magma Lapack and Cublas Blas in my program at the same time, do I need to call all these four functions or just call cublas_init & cublas_shuydown? I wonder that perhaps magmaf_init is a wrapper around cublas_init.

Thank you in advance
Liu

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Call magma from Fortran, problem of wrapper

Post by mgates3 » Wed Jun 24, 2015 11:35 am

magmaf_init is actually required to initialize MAGMA. It query the GPUs and cache some information about them, like what architecture they are. magmaf_finalize frees up some memory, so it's good to have.

cublas_init and cublas_finalize are for the CUBLAS library. Oddly, in my experience, everything works without them. This may be due to internal changes when cublas v2 came out some years ago. It looks like the Fortran cublas interface was never updated for cublas v2, so it still has cublas_init & finalize (from v1) instead of cublas_create & destroy (from v2).

-mark

liuxingrui4p
Posts: 5
Joined: Wed Apr 01, 2015 9:22 am

Re: Call magma from Fortran, problem of wrapper

Post by liuxingrui4p » Fri Aug 14, 2015 8:37 am

mgates3 wrote:We haven't yet made Fortran wrappers for the MAGMA BLAS functions. For the time being, you can call cublas directly, e.g.,

call cublas_dtrsm

magma_dtrsm is simply a wrapper around cublas_dtrsm, used for portability between cuBLAS, clBLAS, and Xeon Phi MKL BLAS.

magmablas_dtrsm is our own implementation of trsm, which is faster in some circumstances. There is not currently a means to call this from Fortran.

-mark
Hello, mark

I want to ask if magmablas_dtrsm uses hybrid (CPU + GPU) architecture for implementation?

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Call magma from Fortran, problem of wrapper

Post by mgates3 » Fri Aug 14, 2015 9:00 am

No, it is GPU-only, similar to cublasDtrsm.

On a side note, magmablas_dtrsm works by inverting diagonal blocks, which is fine if the triangular matrix is nicely conditioned as in Cholesky, but is less stable than a usual trsm that divides by individual diagonal elements.

-mark

Post Reply