Problem with Building a Library with ATLAS package

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)
Post Reply
KONSTANTINOS_KOLOVOS
Posts: 6
Joined: Thu May 14, 2015 7:46 am

Problem with Building a Library with ATLAS package

Post by KONSTANTINOS_KOLOVOS » Tue May 26, 2015 3:13 am

I need some helpful informations about building a Library.

Any guidance you can give me will be valuable.

I want to complile examples with CHOLESKY and LU with NVCC (include MAGMA + CUBLAS)

The data of the machine and CUDA in my project are the following.

----------------------------------

Code: Select all

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.5 LTS"
----------------------------------

VGA compatible controller [0300]: NVIDIA Corporation GF108M [GeForce GT 635M]

NVIDIA CUDA 6.5

----------------------------------

My configuration is:

0) First of all i install these required packages:

sudo apt-get install libatlas-base-dev liblapack-dev libf2c2-dev gfortran

1) Modify the make.inc.atlas to make.inc

2) Change the paths but i have some questions about shared and static library.

----------
FIRST CASE
----------

First Case: If FPIC = FPIC i build a static library.

At this case i have problem when i try to compile an example

( fatal error: magma.h: No such file or directory ) but the magma.h there is at directory ~.bashrc EXPORT=/usr/local/magma/include:$EXPORT).

=================================================================================================================

Code: Select all

#//////////////////////////////////////////////////////////////////////////////
#   -- MAGMA (version 1.6.1) --
#      Univ. of Tennessee, Knoxville
#      Univ. of California, Berkeley
#      Univ. of Colorado, Denver
#      @date January 2015
#//////////////////////////////////////////////////////////////////////////////

# GPU_TARGET contains one or more of Tesla, Fermi, or Kepler,
# to specify for which GPUs you want to compile MAGMA:
#     Tesla  - NVIDIA compute capability 1.x cards (no longer supported in CUDA 6.5)
#     Fermi  - NVIDIA compute capability 2.x cards
#     Kepler - NVIDIA compute capability 3.x cards
# The default is "Fermi Kepler".
# See http://developer.nvidia.com/cuda-gpus
#
GPU_TARGET = Fermi Kepler

CC        = gcc
CXX       = g++
NVCC      = /usr/local/cuda-6.5/bin/nvcc
FORT      = gfortran -DCUBLAS_GFORTRAN
ARCH      = ar

ARCHFLAGS = cr
RANLIB    = ranlib

# Use -fPIC to make shared (.so) and static (.a) library;
# can be commented out if making only static library.
##
## Our ATLAS installation has only static libraries, and one can't
## build a shared library against a static library, so disable FPIC.
#FPIC      = -fPIC

CFLAGS    = -O3 $(FPIC) -DADD_ -Wall -fopenmp -DMAGMA_SETAFFINITY
FFLAGS    = -O3 $(FPIC) -DADD_ -Wall -Wno-unused-dummy-argument
F90FLAGS  = -O3 $(FPIC) -DADD_ -Wall -Wno-unused-dummy-argument -x f95-cpp-input
NVCCFLAGS = -O3         -DADD_       -Xcompiler "-fno-strict-aliasing $(FPIC)"
LDFLAGS   =     $(FPIC) -fopenmp

# Depending on how ATLAS and LAPACK were compiled, you may need one or more of:
# -lifcore -ldl -lf2c -lgfortran
LIB       = -llapack -lf77blas -lcblas -latlas -lcublas -lcudart -lstdc++ -lm -lgfortran 

# define library directories preferably in your environment, or here.
LAPACKDIR = /usr/lib/lapack
ATLASDIR  = /usr/lib/atlas-base
CUDADIR   = /usr/local/cuda-6.5
-include make.check-atlas
-include make.check-cuda

LIBDIR    = -L$(CUDADIR)/lib64 \
            -L$(LAPACKDIR) \
            -L$(ATLASDIR)/lib

INC       = -I$(CUDADIR)/include
=======================================================================

2.1) I make the Library with : sudo make lib

And these are the results:

Code: Select all

=============================================
compile for CUDA arch 2.x (Fermi)
compile for CUDA arch 3.0 (Kepler)
compile for CUDA arch 3.5 (Kepler)
======================================== magmablas
( cd magmablas      && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/magmablas'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/magmablas'
======================================== src
( cd src            && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/src'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/src'
======================================== control
( cd control        && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/control'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/control'
======================================== interface
( cd interface_cuda && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/interface_cuda'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/interface_cuda'
=========================================================================================================
2.2) I test the Library with sudo make test

Code: Select all

=========================================================================================================
compile for CUDA arch 2.x (Fermi)
compile for CUDA arch 3.0 (Kepler)
compile for CUDA arch 3.5 (Kepler)
======================================== magmablas
( cd magmablas      && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/magmablas'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/magmablas'
======================================== src
( cd src            && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/src'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/src'
======================================== control
( cd control        && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/control'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/control'
======================================== interface
( cd interface_cuda && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/interface_cuda'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/interface_cuda'
======================================== testing
( cd testing        && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/testing'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/testing'
=========================================================================================================

2.3) I install the Library with: sudo make install prefix=/usr/local/magma

Code: Select all

=========================================================================================================
compile for CUDA arch 2.x (Fermi)
compile for CUDA arch 3.0 (Kepler)
compile for CUDA arch 3.5 (Kepler)
======================================== magmablas
( cd magmablas      && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/magmablas'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/magmablas'
======================================== src
( cd src            && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/src'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/src'
======================================== control
( cd control        && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/control'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/control'
======================================== interface
( cd interface_cuda && make )
make[1]: Entering directory `/home/kostas/Desktop/magma-1.6.2/interface_cuda'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2/interface_cuda'

mkdir -p /usr/local/magma
mkdir -p /usr/local/magma/include
mkdir -p /usr/local/magma/lib
mkdir -p /usr/local/magma/lib/pkgconfig
# MAGMA
cp ./include/*.h  /usr/local/magma/include
cp ./lib/libmagma.a               /usr/local/magma/lib
cp ./lib/libmagma.so           /usr/local/magma/lib
cp: cannot stat `./lib/libmagma.so': No such file or directory
make: [install] Error 1 (ignored)
cp               /usr/local/magma/lib
cp: missing destination file operand after `/usr/local/magma/lib'
Try `cp --help' for more information.
make: [install] Error 1 (ignored)
# QUARK
# cp /include/quark.h             /usr/local/magma/include
# cp /include/quark_unpack_args.h /usr/local/magma/include
# cp /include/icl_hash.h          /usr/local/magma/include
# cp /include/icl_list.h          /usr/local/magma/include
# cp /lib/libquark.a              /usr/local/magma/lib
# pkgconfig
cat ./lib/pkgconfig/magma.pc.in         | \
	    sed -e s:@INSTALL_PREFIX@:"/usr/local/magma":         | \
	    sed -e s:@CFLAGS@:"-DADD_ -fopenmp -DHAVE_CUBLAS -I/usr/local/cuda-6.5/include":    | \
	    sed -e s:@LIBS@:"-fopenmp -L/usr/local/cuda-6.5/lib64 -L/usr/lib/lapack -L/usr/lib/atlas-base/lib -llapack -lf77blas -lcblas -latlas -lcublas -lcudart -lstdc++ -lm -lgfortran ": | \
	    sed -e s:@MAGMA_REQUIRED@::                      \
	    > /usr/local/magma/lib/pkgconfig/magma.pc
=========================================================================================================
-----------
SECOND CASE
-----------

Second Case: If FPIC = -fPIC then build a shared library. At this case i have errors from the begin.

Code: Select all

==========================================================================================================
#//////////////////////////////////////////////////////////////////////////////
#   -- MAGMA (version 1.6.1) --
#      Univ. of Tennessee, Knoxville
#      Univ. of California, Berkeley
#      Univ. of Colorado, Denver
#      @date January 2015
#//////////////////////////////////////////////////////////////////////////////

# GPU_TARGET contains one or more of Tesla, Fermi, or Kepler,
# to specify for which GPUs you want to compile MAGMA:
#     Tesla  - NVIDIA compute capability 1.x cards (no longer supported in CUDA 6.5)
#     Fermi  - NVIDIA compute capability 2.x cards
#     Kepler - NVIDIA compute capability 3.x cards
# The default is "Fermi Kepler".
# See http://developer.nvidia.com/cuda-gpus
#
GPU_TARGET = Fermi Kepler

CC        = gcc
CXX       = g++
NVCC      = /usr/local/cuda-6.5/bin/nvcc
FORT      = gfortran -DCUBLAS_GFORTRAN

ARCH      = ar
ARCHFLAGS = cr
RANLIB    = ranlib

# Use -fPIC to make shared (.so) and static (.a) library;
# can be commented out if making only static library.
##
## Our ATLAS installation has only static libraries, and one can't
## build a shared library against a static library, so disable FPIC.
FPIC      = -fPIC

CFLAGS    = -O3 $(FPIC) -DADD_ -Wall -fopenmp -DMAGMA_SETAFFINITY
FFLAGS    = -O3 $(FPIC) -DADD_ -Wall -Wno-unused-dummy-argument
F90FLAGS  = -O3 $(FPIC) -DADD_ -Wall -Wno-unused-dummy-argument -x f95-cpp-input
NVCCFLAGS = -O3         -DADD_       -Xcompiler "-fno-strict-aliasing $(FPIC)"
LDFLAGS   =     $(FPIC) -fopenmp

# Depending on how ATLAS and LAPACK were compiled, you may need one or more of:
# -lifcore -ldl -lf2c -lgfortran
LIB       = -llapack -lf77blas -lcblas -latlas -lcublas -lcudart -lstdc++ -lm -lgfortran 

# define library directories preferably in your environment, or here.
LAPACKDIR = /usr/lib/lapack
ATLASDIR  = /usr/lib/atlas-base
CUDADIR   = /usr/local/cuda-6.5
-include make.check-atlas
-include make.check-cuda

LIBDIR    = -L$(CUDADIR)/lib64 \
            -L$(LAPACKDIR) \
            -L$(ATLASDIR)/lib

INC       = -I$(CUDADIR)/include
=======================================================================
2.4) I make the Library with sudo make lib

And these are the results:

Code: Select all

=============================================
.o magmablas/zsymv.o magmablas/zsymv_upper.o magmablas/ztranspose_inplace.o magmablas/ztranspose.o magmablas/ztrsm_batched.o magmablas/ztrsm.o magmablas/ztrtri_diag_batched.o magmablas/ztrtri_diag.o magmablas/ztrtri_lower.o magmablas/ztrtri_upper.o \
	-L/usr/local/cuda-6.5/lib64 -L/usr/lib/lapack -L/usr/lib/atlas-base/lib \
	-llapack -lf77blas -lcblas -latlas -lcublas -lcudart -lstdc++ -lm -lgfortran 
/usr/bin/ld: src/cbulge_applyQ.o: relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
src/cbulge_applyQ.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [lib/libmagma.so] Error 1
make[1]: Leaving directory `/home/kostas/Desktop/magma-1.6.2'
make: *** [shared] Error 2
==========================================================================================================
3) What is wrong at these cases?

I would greatly appreciate it if you provide me with any information on the above.
Last edited by mgates3 on Tue May 26, 2015 12:39 pm, edited 1 time in total.
Reason: remove extraneous newlines and put code into [code] ... [/code] blocks

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Problem with Building a Library with ATLAS package

Post by mgates3 » Tue May 26, 2015 1:21 pm

There is no need to use sudo for compiling MAGMA, or really 99.9% of all codes. The only time you need sudo is to install it with make install, if the destination (/usr/local) is not writable. Using sudo unnecessarily is a bad habit to get into.

2) You mentioned a "fatal error: magma.h: No such file or directory" but didn't show the context of what you were compiling. I'm assuming you resolved that issue.

2.1 and 2.2) You apparently already compiled MAGMA, as it says there is nothing to be done here. I'm assuming that everything worked the first time around.

2.4) You need to "make clean" before re-compiling as a shared library. Otherwise it tries to use existing .o files compiled without -fPIC. That's what the error message means: "can not be used when making a shared object; recompile with -fPIC".

-mark

KONSTANTINOS_KOLOVOS
Posts: 6
Joined: Thu May 14, 2015 7:46 am

Re: Problem with Building a Library with ATLAS package

Post by KONSTANTINOS_KOLOVOS » Wed May 27, 2015 4:34 am

I try to compile this code:

============================================
#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <cublas.h>
#include <magma.h>
#include <magma_lapack.h>




int main ( int argc , char ** argv )
{
magma_init();
std::cout<<" TEST "<<std::endl;
magma_finalize();
return 0;
}
============================================

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Problem with Building a Library with ATLAS package

Post by mgates3 » Wed May 27, 2015 1:34 pm

Please show how you tried to compile, i.e., the compiler command. You need to point the include (-I) and library (-L) paths to the MAGMA directory, as shown below and in magma/example/Makefile.

Also, to use the magma_lapack.h header, you will need to define one of -DADD_, -DNOCHANGE, or -DUPCASE (usually -DADD_). But if you don't call blasf77_* or lapackf77_* functions from MAGMA, then you don't need magma_lapack.h.

Code: Select all

gcc -I/usr/local/magma/include -DADD_ -c -o test.o test.c
gcc -L/usr/local/magma/lib -lmagma -o test test.o
-mark

KONSTANTINOS_KOLOVOS
Posts: 6
Joined: Thu May 14, 2015 7:46 am

Re: Problem with Building a Library with ATLAS package

Post by KONSTANTINOS_KOLOVOS » Wed May 27, 2015 4:35 pm

thank you very much

Post Reply