PGI 10.6 cuda fortran support shared library or not?

when I was compiling fotran code with the paramneter
pgf95 -Minfo -Mfixed -Mcuda
there are some error:


Linking Fortran shared library …/…/lib/libBim31L.so
/usr/bin/ld: /opt/pgi/linux86-64/10.5/lib/libcudafor.a(dev_allo.o): relocation R_X86_64_32 against `a local symbol’ can not be used when making a shared object; recompile with -fPIC
/opt/pgi/linux86-64/10.5/lib/libcudafor.a: could not read symbols: Bad value

I was tring to create a shared library, but it didn’t work, so does PGI 10.6 cuda fortran support shared library or not?

Your error code is showing version 10.5. If you didn’t replace your 10.5 directories, make sure you change your path so that your pgf95 command looks in the 10.6 directory.

I don’t, however, know the direct answer to your question. Hopefully it’s answered indirectly.

Hi Huang Yongcheng,

Sorry, putting CUDA Fortran code into a shared library is not supported yet. It’s on our list but no ETA as of yet. Note that put CUDA Fortran code in static libraries is fine.

  • Mat

I was also trying to compile CUDA Fortran into a shared library, and I was having the same problems.

I had an R extension written in Fortran, which I had hoped to speed up using CUDA Fortran, but this is keeping me from doing this.

I’m curious, what is preventing you from simply recompiling the library (libcudafor.a) with -fPIC and linking with -shared? If this is possible, it would be helpful to have, even if it’s not very thoroughly tested.

Hi JPHNY,

If this is possible, it would be helpful to have, even if it’s not very thoroughly tested.

We’re working on building one (a .so and .a built with -fpic) for your colleague who sent in a request via PGI Customer Support. It should be ready in the next day or so. We’ll add them to the 10.8 release.

Thanks,
Mat

I an currently working on a C++/cuda fortran code and I am very interested to create
dynamic libraries.

Would it be possible to get the library cudafor ( .so and .a built with -fpic)
when it will be ready?

Thanks in advance for you help.

Hi cerfacs,

Send a note to PGI Customer Service (trs@pgroup.com) and we should be able to send you the beta version. It’s not been well tested, but you’re welcome to give it a try.

  • Mat

If I understand things correctly, this shared library (libcudafor.so) only enables support for using the PGI Accelerator model from within shared libraries. I’m still having problems getting the various nvidia directives to work from within a shared library.

For instance, if I declare a subroutine with:
attributes(global) subroutine_name()

and try to build a shared library, I get the linker error message:

relocation R_X86_64_PC32 against symbol `subroutine_name_’ can not be used when making a shared object; recompile with -fPIC

(I already am using -fPIC)

It seems like nvidia’s CUDA directives are not supported in shared libraries. Is this correct? And if so when would this support become available? I think nvcc supports it so it is possible for this to be done.
(I’m using version 10.9)

Thanks.

Hi JPHNY,

If I understand things correctly, this shared library (libcudafor.so) only enables support for using the PGI Accelerator model from within shared libraries. I’m still having problems getting the various nvidia directives to work from within a shared library.

libcudafor.so is for use with CUDA Fortran, not the PGI Accelerator Model. However, given your example below I assume that this is what you meant.

Note that you can link against the .so, but in the PGI libso directory there are FPIC versions of the static libraries that can be used when creating “whole archive” shared libraries.

It seems like nvidia’s CUDA directives are not supported in shared libraries. Is this correct?

I’ve created one before so it should work. What are the steps you’re doing to create the library?

  • Mat

I’ve tried to build the shared library in different ways. If I’m not using any CUDA extensions, I can create a shared library just with:

pgfortran -shared filename.f95 -o libfilename.so

And if I use CUDA extensions in a regular program (not a shared library) I can compile simply by adding -Mcuda=cuda3.0

So I’ve been trying:

pgfortran -shared -Mcuda=cuda3.0 filename.f95 -o libfilename.so

but this gives the error I described, when there is actual CUDA code present.

(If I try it with -fPIC explicitly put in, the same thing happens.)

Hi JPHNY,

Try making it a two step process. First compile the source file with -fpic and then link the resulting object file into the shared library.

  • Mat
pgfortran -c -Mcuda=cuda3.0 filename.f95 -fpic
pgfortran -shared -Mcuda=cuda3.0 filename.o -o libfilename.so

It gives the same error.

Any other thoughts on this?

It works fine for me here so I’m not sure why you’re having problems.

Can you send PGI Customer Support (trs@pgroup.com) your source and directions how you are building the library? Also, what OS are you using?

Thanks,
Mat