Dynamic library (.so) compilation on Linux

Open discussion for MAGMA

Dynamic library (.so) compilation on Linux

Postby Ced » Wed Mar 07, 2012 1:38 pm

Hi Magma team,

I'm trying to compile Magma to get the two library libmagma.so and libmagmablas.so under ubuntu 11.10.
I have write the make.inc as following :


CC = gcc
NVCC = /usr/local/cuda/bin/nvcc
FORT = gfortran

ARCH = gcc
ARCHFLAGS = -shared -o
RANLIB = strip

FOPTS = -DADD_ -O3 -fPIC -x f95-cpp-input
NVOPTS = -DADD_ --shared --compiler-options '-fPIC' -DUNIX -O3
LDOPTS = -fPIC -Xlinker -zmuldefs

LIB = -lcuda -lblas -lpthread -lcublas -lcudart -llapack -lm

CUDADIR = /usr/local/cuda

LIBDIR = -L/usr/local/cuda/lib64 -L/usr/lib64 -L/usr/lib/libblas/
INC = -I$(CUDADIR)/include

LIBMAGMA = $(MAGMA_DIR)/lib/libmagma.so
LIBMAGMABLAS = $(MAGMA_DIR)/lib/libmagmablas.so

But the compilation fails in src directory.

zheevdx_gpu.o: In function `Mylapackf77_zstedc':
zheevdx_gpu.cpp:(.text+0x0): multiple definition of `Mylapackf77_zstedc'
zheevd_gpu.o:zheevd_gpu.cpp:(.text+0x0): first defined here
zheevx_gpu.o: In function `Mylapackf77_zstein':
zheevx_gpu.cpp:(.text+0x0): multiple definition of `Mylapackf77_zstein'
zheevr_gpu.o:zheevr_gpu.cpp:(.text+0x10): first defined here

I remove in the makefile all files which make these errors and I can compile the src dir.
Next, the compilation stops in the testing directory for some "undefined reference to .." in testing_zgemm.cpp but I have my two libs.so

My problem here is that these two libs are empty so I removes the RANLIB = strip to get something in.

When I try to link these libs in my project i get errors as :
libmagmablas.so: undefined symbol: magma_stream
libmagma.so: undefined symbol: magmablas_zgetmatrix_transpose

nm libmagma.so | grep -i magmablas_zgetmatrix_transpose
U magmablas_zgetmatrix_transpose
U magmablas_zgetmatrix_transpose2

nm libmagmablas.so | grep magma_stream
U magma_stream

I have succeeded to compile in static library (.a) and run some testing so I think that i have made a mistake in the make.inc

Thanks for your help,

Posts: 4
Joined: Wed Mar 07, 2012 12:37 pm

Re: Dynamic library (.so) compilation on Linux

Postby mgates3 » Tue Mar 13, 2012 10:53 am

The multiple definitions of functions is a bug. Those functions are used only for profiling, so you can safely change the calls from Mylapackf77_* to lapackf77_*, and delete the definitions of Mylapackf77_*.

As for the linking errors, there is a cross-dependency between libmagma and libmagmablas. Usually this means you have to list magma twice, or tell the compiler they are a group:

g++ -o test test.o -lmagma -lmagmablas -lmagma ...

You might also try making a single library, e.g.,
LIBMAGMA = $(MAGMA_DIR)/lib/magma.so
LIBMAGMABLAS = $(MAGMA_DIR)/lib/magma.so
I haven't tried this, but it seems like it should work.

Posts: 401
Joined: Fri Jan 06, 2012 2:13 pm

Re: Dynamic library (.so) compilation on Linux

Postby Ced » Thu Mar 15, 2012 9:26 am

Hi Mark,

I have solved some multiple definitions by deleting the "My" before functions and some other by add "extern".
(e.g. : extern int event_num [MAX_THREADS] __attribute__ ((aligned (128))); in dgeqrf_mgpu-trace.cpp file)

For the problem :
libmagmablas.so: undefined symbol: magma_stream

In fact, this symbol should be in libmagma.so but libmagma.so is created in control directory and src directory.
When we create a static lib (.a), we can add symbols inside but not with a dynamic lib (.so).
In my case, libmagma.so créated in control directory was replaced by the same libmagma.so builded in src directory.

I have succeeded to set in the same dynamic library all symbols of control, src and magmablas directory.
But I can't load my lib because of undefined symbol: magmablas_dtrsm
This function is declared in include/magmablas_d.h, used in some #define cublasDtrsm magmablas_dtrsm but never defined.

These "#define cublas... magmablas... " are essential ?
Can I remove this and use the real cublas functions ?

Thanks for your reply.

Posts: 4
Joined: Wed Mar 07, 2012 12:37 pm

Re: Dynamic library (.so) compilation on Linux

Postby mgates3 » Wed May 02, 2012 3:53 pm

You can safely use the cublas functions. The magmablas functions are in some cases faster but otherwise provide the same functionality. The magmablas_dtrsm should be defined in magmablas/dtrsm_tesla.cu.
Posts: 401
Joined: Fri Jan 06, 2012 2:13 pm

Return to User discussion

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest