linking CUDA fortran and gfortran

hi there,

I am adding some GPU function (consider “selva.f”) to the existing fortran (compiled using gfortran) consider it as (X) which in turn is called by some subroutine. I need to add CUDA fortran functionality to the existing system.
ie)
I called my subroutine “selva” from X
I compiled “selva.f” and obtained the object file using following command
pgfortran -Mcuda -Mfree -c -fpic selva.f
I got my object file generated. I did not get any error.
while linking my object file (A.o) to (X.o) I am getting the following error
selva.o: In function ksaxpy_': /home/ssk87/gamess/source/./selva.f:7: undefined reference to cudaSetupArgument’
/home/ssk87/gamess/source/./selva.f:7: undefined reference to cudaSetupArgument' /home/ssk87/gamess/source/./selva.f:7: undefined reference to cudaSetupArgument’
/home/ssk87/gamess/source/./selva.f:7: undefined reference to cudaSetupArgument' /home/ssk87/gamess/source/./selva.f:7: undefined reference to cudaLaunch’
selva.o: In function ..cuda_fortran_constructor_1': /home/ssk87/gamess/source/./selva.f:18: undefined reference to __cudaRegisterFatBinary’
/home/ssk87/gamess/source/./selva.f:18: undefined reference to __cudaRegisterFunction' /home/ssk87/gamess/source/./selva.f:18: undefined reference to _cudaUnregisterFatBinary’
selva.o: In function solve_': /home/ssk87/gamess/source/./selva.f:18: undefined reference to pgf90_dev_configure_call’
selva.o: In function .STATICS2': selva.f:(.data+0x1d48): undefined reference to cudafor

selva.f:(.data+0x1d50): undefined reference to iso_c_binding_' selva.f:(.data+0x1d58): undefined reference to pgf90_compiled’
collect2: ld returned 1 exit status


linking command:

gfortan -o selva.o X.o DFT.o

can anyone explain me why the error is ?
Am i need to change the linker options to link that object file(A) to object file(X)
How can i link the existing fortran code(compiled using gfortran) and cuda fortran code (compiled using pgfortran)

help deeply appreciated!!!

Selva,

Sorry you are having problems.

gfortan -o selva.o X.o DFT.o

will link X.o and DFT.o with gfortran libs, and put the executable into
selva.o

You may have meant

gfortran -o foo selva.o X.o DFT.o
which tries to link selva.o, X.o, and DFT.o and create foo.


This will also fail, since none of the PGI runtime libraries and CUDA
libraries are in the link line.

If the gfortran program has any F90 datatypes or uses I/O,
it may conflict with the PGI equivalent, but not identical
support routines.

You best bet is compile everything with pgfortran, or
make sure the gfortran routines have no I/O and use
F77 data types only (the kind that do not need interface
descriptors to pass between routines), and link with pgfortran.
Any missing link symbols from the gfortran compiled routine
then can be added to the pgfortran link line.

If you link with
-v -Wl,-t
you can see what libs and objects are linked, and which
objects from libs are extracted or resolved.

dave

hey,
I compiled everything with pgfortran and try to link the same also using pgfortran
But still i am getting this error.
selva.o: In function ksaxpy_': /home/ssk87/gamess/source/./selva.cuf:6: undefined reference to cudaSetupArgument’
/home/ssk87/gamess/source/./selva.cuf:6: undefined reference to cudaSetupArgument' /home/ssk87/gamess/source/./selva.cuf:6: undefined reference to cudaSetupArgument’
/home/ssk87/gamess/source/./selva.cuf:6: undefined reference to cudaSetupArgument' /home/ssk87/gamess/source/./selva.cuf:6: undefined reference to cudaLaunch’
selva.o: In function ..cuda_fortran_constructor_1': /home/ssk87/gamess/source/./selva.cuf:17: undefined reference to __cudaRegisterFatBinary’
/home/ssk87/gamess/source/./selva.cuf:17: undefined reference to __cudaRegisterFunction' /home/ssk87/gamess/source/./selva.cuf:17: undefined reference to cudaUnregisterFatBinary’
selva.o: In function solve_': /home/ssk87/gamess/source/./selva.cuf:17: undefined reference to pgf90_dev_configure_call’
selva.o: In function .STATICS2': selva.cuf:(.data+0x1d48): undefined reference to cudafor

zmatrx.o: In function gtbond_': /home/ssk87/gamess/./zmatrx.f:1120: relocation truncated to fit: R_X86_64_32S against symbol frginf
’ defined in COMMON section in gamess.o

How can i fix this ? Is there a another way to link gfortran and pgfortran?
Thanks

Hi Selva,

I’m guessing that you forgot to add “-Mcuda” to your link flags. Without this flag, the pgfortran driver doesn’t know to include the CUDA Fortran runtime libraries.

  • Mat