PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Need some help in linking Magma
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
Ragavan



Joined: 30 May 2012
Posts: 7

PostPosted: Wed May 30, 2012 5:47 pm    Post subject: Need some help in linking Magma Reply with quote

Dear All,

I am getting a generic error when I try to call the magma_dysgvd from a fortran code.

Here`s a snippet of my code:

! DSYGVD Example Program Text


! MAGMA INTERFACE

module magmafor
interface dsygvdmagma
subroutine dsygvdDev (ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK, &
LWORK,IWORK, LIWORK, INFO) bind (c, name = 'magma_dsygvd')
use iso_c_binding
integer(c_int), value :: ITYPE, N, LDA, LDB, LWORK, LIWORK, INFO
character(kind = c_char), value :: JOBZ, UPLO
double precision(c_double), device, allocatable :: A(:,:), B(:,:), W(:), WORK(:)
! double precision(c_double), device, dimension (:) :: W(N), WORK(LWORK)
integer(c_int), device, ALLOCATABLE :: IWORK(:)
end subroutine dsygvdDev
end interface
end module magmafor

program main

use magmafor

INTEGER NIN, NOUT
PARAMETER (NIN=5,NOUT=6)
INTEGER NB, NMAX
PARAMETER (NB=64,NMAX=10)
INTEGER LDA, LDB, LIWORK, LWORK, error
PARAMETER (LDA=NMAX,LDB=NMAX,LIWORK=3+5*NMAX,&
LWORK=1+(6+2*NMAX)*NMAX)

DOUBLE PRECISION, allocatable :: A(:,:), B(:,:), &
W(:), WORK(:)
double precision, device, allocatable :: dA(:,:), dB(:,:), &
dW(:), dWORK(:)
INTEGER IWORK(LIWORK)
integer, device, allocatable :: dIWORK(:)

WRITE (NOUT,*) 'DSYGVD Example Program Results'
WRITE (NOUT,*)

! Skip heading in data file
READ (NIN,*)
READ (NIN,*) N
IF (N.LE.NMAX) THEN
!
allocate (A(LDA,NMAX),B(LDA,NMAX), W(NMAX), WORK(LWORK), stat=error)
if(stat1.ne.0) then
print*,'error: couldn`t alloc memory'
end if

! Read the upper triangular parts of the matrices A and B

READ (NIN,*) ((A(I,J),J=I,N),I=1,N)
READ (NIN,*) ((B(I,J),J=I,N),I=1,N)

allocate (dA(LDA,NMAX), dB(LDA,NMAX), dW(NMAX), dWORK(LWORK))
allocate (dIWORK(LIWROK))

dA = A
dB = B
dW = W
dWORK = WORK

! Magma call

call dsygvdmagma(1,'V','U',N,dA,LDA,dB,dW,dWORK,LWORK,dIWORK,LIWORK,INFO)
!
! Solve the generalized symmetric eigenvalue problem
! A*B*x = lambda*x (ITYPE = 2)
!
! CALL DSYGVD(2,'Vectors','Upper',N,A,LDA,B,LDB,W,WORK,LWORK, &
! IWORK,LIWORK,INFO)
LWOPT = WORK(1)
LIWOPT = IWORK(1)
IF (INFO.EQ.0) THEN
!
W = dW
A = dA
! Print solution
!
WRITE (NOUT,*) 'Eigenvalues'
WRITE (NOUT,99999) (W(J),J=1,N)
WRITE (NOUT,*) 'Eigenvectors'
WRITE (NOUT,99999) ((A(I,J),J=1,N),I=1,N)

END IF



! Print workspace information
!
IF (LWORK.LT.LWOPT) THEN
WRITE (NOUT,*)
WRITE (NOUT,99995) 'Optimum workspace required = ', LWOPT, &
'Workspace provided = ', LWORK
END IF
IF (LIWORK.LT.LIWOPT) THEN
WRITE (NOUT,*)
WRITE (NOUT,99995) 'Integer workspace required = ', LIWOPT, &
'Integer workspace provided = ', LIWORK
END IF
ELSE
WRITE (NOUT,*) 'NMAX too small'
END IF

!
99999 FORMAT (3X,(6F11.4))
99998 FORMAT (4X,1P,6E11.1)
99997 FORMAT (1X,A,I4,A)
99996 FORMAT (1X,A,I4)
99995 FORMAT (1X,A,I5,/1X,A,I5)
deallocate(A)
deallocate(B)
deallocate(W,WORK)
deallocate(dA)
deallocate(dB)
deallocate(dW)
deallocate(dWORK)
deallocate(dIWORK)

end program

I compiled with:

dsygvdmagma: dsygvdmagma.f90
pgf90 -Mcuda -c $<
pgf90 -Mcuda -o $@ $@.o -L/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib -R/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib -lmagma -lmagmablas -lmagma -lcublas -llapack -lblas -lm

I am following the methodology given in this article:
http://www.pgroup.com/lit/articles/insider/v3n1a5.htm
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6120
Location: The Portland Group Inc.

PostPosted: Thu May 31, 2012 8:45 am    Post subject: Reply with quote

Hi Ragavan,

When I compile your code I get the following syntax error:
Quote:
GF90-S-0155-Could not resolve generic procedure dsygvdmagma (magma.F90: 67)

This is because you forgot the "LDB" argument in your call so the compiler can't match which generic function to use.

Is this the same error that you're seeing?

- Mat
Back to top
View user's profile
Ragavan



Joined: 30 May 2012
Posts: 7

PostPosted: Thu May 31, 2012 9:00 am    Post subject: Thanks Reply with quote

Hi Mkcolg,

Thank you so much for pointing it out.

I recompiled and got a bunch of errors :

pgf90 -Mcuda -c dsygvdmagma.f90
pgf90 -Mcuda -o dsygvdmagma dsygvdmagma.o -L/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib -R/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib -lmagma -lmagmablas -lmagma -lcublas -lm

/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a
(dsygvd.o): In function `magma_dsygvd':
dsygvd.cpp:(.text+0x8a): undefined reference to `lsame_'
dsygvd.cpp:(.text+0x9d): undefined reference to `lsame_'
dsygvd.cpp:(.text+0x2b9): undefined reference to `lsame_'
dsygvd.cpp:(.text+0x31f): undefined reference to `lsame_'
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a(dpotrf_gpu.o): In function `magma_dpotrf_gpu':
dpotrf_gpu.cpp:(.text+0x58): undefined reference to `lsame_'
dpotrf_gpu.cpp:(.text+0x1a8): undefined reference to `dpotrf_'
dpotrf_gpu.cpp:(.text+0x399): undefined reference to `lsame_'
dpotrf_gpu.cpp:(.text+0x3ea): undefined reference to `dpotrf_'
dpotrf_gpu.cpp:(.text+0x508): undefined reference to `dpotrf_'
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a(dsygst_gpu.o): In function `magma_dsygst_gpu':
dsygst_gpu.cpp:(.text+0x5c): undefined reference to `lsame_'
dsygst_gpu.cpp:(.text+0x60f): undefined reference to `dsygs2_'
dsygst_gpu.cpp:(.text+0x74e): undefined reference to `lsame_'
dsygst_gpu.cpp:(.text+0xc73): undefined reference to `dsygs2_'
dsygst_gpu.cpp:(.text+0xf19): undefined reference to `dsygs2_'
dsygst_gpu.cpp:(.text+0x16a6): undefined reference to `dsygs2_'
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a(xerbla.o): In function `magma_xerbla':
xerbla.cpp:(.text+0x1c): undefined reference to `xerbla_'
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a(dsyevd_gpu.o): In function `magma_dsyevd_gpu':
dsyevd_gpu.cpp:(.text+0x86): undefined reference to `lsame_'
dsyevd_gpu.cpp:(.text+0x99): undefined reference to `lsame_'
dsyevd_gpu.cpp:(.text+0x264): undefined reference to `dlamch_'
dsyevd_gpu.cpp:(.text+0x276): undefined reference to `dlamch_'
dsyevd_gpu.cpp:(.text+0x40f): undefined reference to `dsterf_'
dsyevd_gpu.cpp:(.text+0x4c9): undefined reference to `lsame_'
dsyevd_gpu.cpp:(.text+0x4f0): undefined reference to `lsame_'
dsyevd_gpu.cpp:(.text+0x5de): undefined reference to `dstedc_'
dsyevd_gpu.cpp:(.text+0x75c): undefined reference to `dscal_'
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a(dsytrd_gpu.o): In function `magma_dsytrd_gpu':
dsytrd_gpu.cpp:(.text+0x62): undefined reference to `lsame_'
dsytrd_gpu.cpp:(.text+0x435): undefined reference to `dsytrd_'
dsytrd_gpu.cpp:(.text+0x524): undefined reference to `lsame_'
dsytrd_gpu.cpp:(.text+0x921): undefined reference to `dsytrd_'
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a(dlatrd.o): In function `magma_dlatrd':
dlatrd.cpp:(.text+0xaa): undefined reference to `lsame_'
dlatrd.cpp:(.text+0x160): undefined reference to `dlarfg_'
dlatrd.cpp:(.text+0x344): undefined reference to `dscal_'
dlatrd.cpp:(.text+0x39d): undefined reference to `ddot_'
dlatrd.cpp:(.text+0x3f4): undefined reference to `daxpy_'
dlatrd.cpp:(.text+0x4c9): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0x556): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0x67a): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0x6ed): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0x76e): undefined reference to `dlarfg_'
dlatrd.cpp:(.text+0x9c1): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0xa35): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0xab5): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0xb41): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0xb78): undefined reference to `dscal_'
dlatrd.cpp:(.text+0xbdf): undefined reference to `ddot_'
dlatrd.cpp:(.text+0xc41): undefined reference to `daxpy_'
dlatrd.cpp:(.text+0xcca): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0xd5a): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0xddc): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0xe76): undefined reference to `dgemv_'
dlatrd.cpp:(.text+0xeb3): undefined reference to `daxpy_'
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a(dormtr_gpu.o): In function `magma_dormtr_gpu':
dormtr_gpu.cpp:(.text+0x87): undefined reference to `lsame_'
dormtr_gpu.cpp:(.text+0x97): undefined reference to `lsame_'
dormtr_gpu.cpp:(.text+0xc7): undefined reference to `lsame_'
dormtr_gpu.cpp:(.text+0x133): undefined reference to `lsame_'
dormtr_gpu.cpp:(.text+0x1a9): undefined reference to `lsame_'
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a(dormtr_gpu.o):dormtr_gpu.cpp:(.text+0x1cc): more undefined references to `lsame_' follow
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a(dormqr2_gpu.o): In function `magma_dormqr2_gpu':
dormqr2_gpu.cpp:(.text+0x547): undefined reference to `dlarft_'
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagma.a(dormql2_gpu.o): In function `magma_dormql2_gpu':
dormql2_gpu.cpp:(.text+0x103): undefined reference to `lsame_'
dormql2_gpu.cpp:(.text+0x118): undefined reference to `lsame_'
dormql2_gpu.cpp:(.text+0x1f9): undefined reference to `lsame_'
dormql2_gpu.cpp:(.text+0x221): undefined reference to `lsame_'
dormql2_gpu.cpp:(.text+0x52b): undefined reference to `dlarft_'
/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/libmagmablas.a(dauxiliary.cu_o): In function `cpu_gpu_ddiff':
tmpxft_0000388c_00000000-1_dauxiliary.cudafe1.cpp:(.text+0x6ad): undefined reference to `daxpy_'
tmpxft_0000388c_00000000-1_dauxiliary.cudafe1.cpp:(.text+0x6d5): undefined reference to `dlange_'
make: *** [dsygvdmagma] Error 2
Back to top
View user's profile
Ragavan



Joined: 30 May 2012
Posts: 7

PostPosted: Thu May 31, 2012 12:26 pm    Post subject: CPU interface call Reply with quote

Hi,

The errors were due to the passing of GPU memory as input parameters to the function. In the magma_dsygvd.cpp, I found that they have internal cudaMalloc and Cuda2DMemcpy and hence only a host pointer is reqd.

Though I got rid of all the linking errors, I still get the generic error. This time I have added LDB as per your suggestion.

Here`s my new code:
! MAGMA INTERFACE

module magmafor
interface dsygvd
subroutine dsygvdDev (ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK, &
LWORK,IWORK, LIWORK, INFO) bind (c, name = 'magma_dsygvd')
use iso_c_binding
integer(c_int), value :: ITYPE, N, LDA, LDB, LWORK, LIWORK, INFO
character(kind = c_char), value :: JOBZ, UPLO
double precision(c_double), device, allocatable :: A(:,:), B(:,:), W(:), WORK(:)
! double precision(c_double), device, dimension (:) :: W(N), WORK(LWORK)
integer(c_int), device, ALLOCATABLE :: IWORK(:)
end subroutine dsygvdDev
end interface
end module magmafor


program main

use magmafor
integer :: ITYPE,NIN,NOUT,N,NMAX,NB,LDA,LDB,LWORK, LIWORK,INFO,stat
double precision, device, allocatable :: dA(:,:), dB(:,:), dW(:), dWORK(:)
double precision, allocatable :: A(:,:),B(:,:),W(:),WORK(:)
integer, device, allocatable :: dIWORK(:)
integer, allocatable :: IWORK(:)

ITYPE=0;
NIN=5
NOUT=6
NMAX=10
NB=64
LDA=NMAX
LDB=NMAX
LWORK=1+(6+NB+2*NMAX)*NMAX
LIWORK=3+5*NMAX

WRITE (NOUT,*) 'DSYGVD Example Program Results'
WRITE (NOUT,*)
! Skip heading in data file
READ (NIN,*)
READ (NIN,*) N

IF (N.LE.NMAX) THEN
allocate (A(LDA,NMAX), B(LDA,NMAX), W(NMAX), WORK(LWORK))
! allocate (dA(LDA,NMAX), dB(LDA,NMAX), dWORK(LWORK), dW(NMAX))
allocate (IWORK(LIWORK))
READ (NIN,*) ((A(I,J),J=I,N),I=1,N)
READ (NIN,*) ((B(I,J),J=I,N),I=1,N)

subroutine dsygvdDev (ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK, &
LWORK,IWORK, LIWORK, INFO) bind (c, name = 'magma_dsygvd')

call dsygvd(2,'V','U',N,A,LDA,B,LDB,W,WORK,LWORK,IWORK,LIWORK,INFO)

if (INFO.EQ.0) then
write (NOUT,*) 'Eigenvalues'
write (NOUT,9999) (W(J),J=1,N)
write (NOUT,*) 'EIGENVECTORS'
write (NOUT,9999) ((A(I,J),J=1,N),I=1,N)

end if
!double precision, device, allocate (dW(N),dWORK(N))
!real*8, dimension(LDA,N) :: A,B

!double precision, device, deallocate(dW,dWORK)
9999 FORMAT (3X,(6F11.4))
!deallocate (dA, dB, dWORK, dW, dIWORK)
deallocate (A, B, WORK, W, IWORK)
END IF
end program

Makefile:

magmatest2: magmatest2.f90
pgf90 -Mcuda -c $<
pgf90 -Mcuda -o $@ $@.o -L/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib -R/sw/keeneland/magma/1.1/centos5.5_gnu4.4/magma_1.1.0/lib/ -lmagma -lmagmablas -lcublas -lcuda -lm

And I end up with this error again:

pgf90 -Mcuda -c magmatest2.f90
PGF90-S-0155-Could not resolve generic procedure dsygvd (magmatest2.f90: 50)
0 inform, 0 warnings, 1 severes, 0 fatal for main
make: *** [magmatest2] Error 2
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6120
Location: The Portland Group Inc.

PostPosted: Thu May 31, 2012 2:02 pm    Post subject: Reply with quote

When you changed your arguments to pass in the host variables, you forgot to change your interface. You need to remove the "device" attribute from the interface.

- Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group