Static and Dynamic Libraries for MAGMA and MKL

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)

Static and Dynamic Libraries for MAGMA and MKL

Postby mentat » Mon Jul 16, 2018 4:26 pm

Hello,

I am a newbie to scientific computing and C programming. I made some code using MAGMA FUNCTIONS, but after running the tests I realized that my GPU (1050 ti) is beaten in many routines by the CPU function. I want two create multiple versions of the code that use the CPU or HYBRID_MAGMA routines depending of the needs (no GPU, double type, float type, slow double GPU, fast double GPU). For example, I would like to have a program that uses, a LAPACK/CPU for dgemm, MAGMA dsgeqrsv and CUBLAS lvl 2 routines function. I have been experiencing troubles combining functions from LAPACK/CPU and MAGMA/CUBLAS. I am currently programming in C/Linux, compiling with gcc:

Code: Select all
% MAGMA 2.4.0  compiled for CUDA capability >= 3.0, 64-bit magma_int_t, 64-bit pointer.
% CUDA runtime 9010, driver 9010. OpenMP threads 8. MKL 2018.0.3, MKL threads 4.
% device 0: GeForce GTX 1050, 1493.0 MHz clock, 4042.4 MiB memory, capability 6.1


I am having trouble calling the CPU routines from the tests, so I decided to call the mkl_lapack libraries directly, but after doing that I am having trouble calling MAGMA functions. Multiple error messages appear at compiling, mostly conflict types appear (a little snippet):

Code: Select all
 make
gcc  main.c -o hit_run   -Wall -lm -no-pie -DADD_ -I/usr/local/magma/include -I/usr/local/magma/sparse/include -I/usr/lib/cuda/include -L/usr/local/magma/lib -lmagma_sparse -lmagma -L/usr/lib/cuda/lib64 -lcublas -lcudart -lcusparse -L/usr/lib/x86_64-linux-gnu/openblas/lib -lopenblas ./lpsolve/liblpsolve55.a -ldl -I/opt/intel/mkl/include  -L /opt/intel/mkl/lib/64 -L /opt/intel/mkl/lib/64 -lmkl_intel_lp64 -lmkl_sequential -lmkl_core
In file included from main.c:3:0:
matrix/matrix_read.c: In function ‘count’:
matrix/matrix_read.c:70:8: warning: implicit declaration of function ‘count_lines’ [-Wimplicit-function-declaration]
   ME = count_lines(b_eq);
        ^~~~~~~~~~~
matrix/matrix_read.c:79:13: warning: implicit declaration of function ‘count_vars’; did you mean ‘count’? [-Wimplicit-function-declaration]
   N       = count_vars(a_eq);
             ^~~~~~~~~~
             count
In file included from /usr/local/magma/include/magma_lapack.h:14:0,
                 from matrix/matrix_operations_magma.c:13,
                 from main.c:7:
/usr/local/magma/include/magma_zlapack.h: At top level:
/usr/local/magma/include/magma_zlapack.h:46:42: error: conflicting types for ‘zrot_’
 #define blasf77_zrot       FORTRAN_NAME( zrot,   ZROT   )
                                          ^
/usr/local/magma/include/magma_mangling.h:26:47: note: in definition of macro ‘FORTRAN_NAME’
         #define FORTRAN_NAME(lcname, UCNAME)  lcname##_
                                               ^~~~~~
/usr/local/magma/include/magma_zlapack.h:298:6: note: in expansion of macro ‘blasf77_zrot’
 void blasf77_zrot(   const magma_int_t *n,
      ^~~~~~~~~~~~
In file included from /opt/intel/mkl/include/mkl.h:33:0,
                 from matrix/matrix_read.c:10,
                 from main.c:3:
/opt/intel/mkl/include/mkl_lapack.h:30372:6: note: previous declaration of ‘zrot_’ was here
 void zrot_( const MKL_INT* n, MKL_Complex16* cx, const MKL_INT* incx,
      ^~~~~
In file included from /usr/local/magma/include/magma_lapack.h:14:0,
                 from matrix/matrix_operations_magma.c:13,
                 from main.c:7:
/usr/local/magma/include/magma_zlapack.h:62:42: error: conflicting types for ‘zbdsqr_’
 #define lapackf77_zbdsqr   FORTRAN_NAME( zbdsqr, ZBDSQR )
                                          ^
/usr/local/magma/include/magma_mangling.h:26:47: note: in definition of macro ‘FORTRAN_NAME’
         #define FORTRAN_NAME(lcname, UCNAME)  lcname##_



Here are the headers used in the .c file that uses the mkl routines:
Code: Select all
/*--------- Algebra libraries--------- */
#include "mkl.h"
#include "mkl_service.h"
#include "i_malloc.h"
/*-------------------------------------- */


MAGMA headers and the function used in the .c file that uses MAGMA/CUBLAS:
Code: Select all
/*--------- Algebra libraries--------- */
#include <cuda_runtime.h>
#include <cuda.h>
#include "cublas_v2.h"
#include "magma_v2.h"
#include "magma_lapack.h"

  cblas_dgemm(CblasColMajor, CblasTrans, CblasNoTrans,
              m, n, k, alpha, E, k ,E, k, beta, AAT, n);
/*-------------------------------------- */


After some research I read it could be resolved by using static libraries, or by calling the lapack/cblas functions from MAGMA. I have read some documentation but I am unable to call the dgemm (LAPACK/BLAS no GPU) function that it is used in the test code (to name one function). I would really appreciate if some one could give me some insight of what should I do. At best I would like to learn both methods and test them to pick the best one. The dgemm function is one of many examples. I had some troubles with CUBLAS and MAGMA libraries, but resolved it by redefining the REALS (hope this does not cause more problems).

Thanks for reading, I would really appreciate some help!
mentat
 
Posts: 2
Joined: Mon May 14, 2018 4:24 pm

Re: Static and Dynamic Libraries for MAGMA and MKL

Postby mgates3 » Tue Jul 17, 2018 11:51 am

If you are including MKL headers to define LAPACK & BLAS functions, do not include magma_lapack.h. MKL and magma_lapack.h may have differing prototypes, usually in minor things like whether an argument is const or not.

Note that "blasf77_dgemm" is just MAGMA's macro alias for the Fortran dgemm function. The actual Fortran name is either dgemm_, dgemm, or DGEMM, depending on your Fortran compiler / BLAS library name mangling scheme. If you don't include magma_lapack.h, then you will have to use the Fortran name (dgemm_, dgemm, or DGEMM).

Similarly, all the "blasf77_xyz" and "lapackf77_xyz" are just macro aliases for some Fortran function, xyz.

-mark
mgates3
 
Posts: 827
Joined: Fri Jan 06, 2012 2:13 pm

Re: Static and Dynamic Libraries for MAGMA and MKL

Postby mentat » Tue Jul 17, 2018 12:14 pm

Thanks for replying so fast mgates3 . The problem seem solved, I really appreciate it.

M
mentat
 
Posts: 2
Joined: Mon May 14, 2018 4:24 pm


Return to User discussion

Who is online

Users browsing this forum: Google [Bot], rayhanseo2018 and 4 guests