building GPU as a shared library

hey everyone! I could build lammps as a library to be used through
python, and everything worked as a charm. however, when i came back to
work, willing to do that again, i found myself in a situation: i don't
have the GPU package at home, and when I tried to install this with
GPU, i got:

/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld:
../../lib/gpu/libgpu.a(lal_device.o): relocation R_X86_64_32 against
`global_device' can not be used when making a shared object; recompile
with -fPIC

I tried recompiling lib/gpu several times, trying to put -fPIC
wherever it looked correct with trial and error (a.k.a.
metropolis-montecarlo programming), but I must admit when I hit my
head against the wall and I don't know what to do. this is the case,
so anyone knows what can I do to overcome this?

thanks,
pablo

hey everyone! I could build lammps as a library to be used through
python, and everything worked as a charm. however, when i came back to
work, willing to do that again, i found myself in a situation: i don't
have the GPU package at home, and when I tried to install this with
GPU, i got:

/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld:
../../lib/gpu/libgpu.a(lal_device.o): relocation R_X86_64_32 against
`global_device' can not be used when making a shared object; recompile
with -fPIC

I tried recompiling lib/gpu several times, trying to put -fPIC
wherever it looked correct with trial and error (a.k.a.
metropolis-montecarlo programming), but I must admit when I hit my
head against the wall and I don't know what to do. this is the case,
so anyone knows what can I do to overcome this?

two options.

a) compile with OpenCL instead of CUDA (not much of a performance
difference in my tests), which uses only the host compiler.

b) use -Xcompiler -fPIC with the CUDA_OPTS variable, so you have nvcc
pass the -fPIC to the underlying gcc compiler.

as an aside, it is not only possible to compile a shared liblammps.so
object, but you can also compile libgpu as a shared library this way
and build one with CUDA and another with OpenCL, place the two into
two different directories, and then switch between the two via
LD_LIBRARY_PATH. fun. ;-()

ciao,
    axel.