Undefined symbol errors while calling magma routine from a matlab mex file

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)
Post Reply
srinidhi_ganeshan
Posts: 1
Joined: Sat Apr 06, 2019 7:18 pm

Undefined symbol errors while calling magma routine from a matlab mex file

Post by srinidhi_ganeshan » Sat Apr 06, 2019 8:23 pm

i have problem running a magma routine in the Matlab MEX function.
the software version i am using are: intel/2018.3, cuda/10.0.130,
magma/2.4.0, matlab/2018b

Below, I have added my mex-magma file 'my_magma.c'

Code: Select all

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "mex.h"
#include <cuda.h>  // for CUDA_VERSION

// includes, project
#include "flops.h"
#include "magma.h"
//#include "magma_lapack.h"
#include "testings.h"


/*#if defined(_OPENMP)
#include <omp.h>
#include "../control/magma_threadsetting.h"  // internal header
#endif*/



void mexFunction(int nlhs, mxArray *plhs[], int nrhs,const mxArray *prhs[])

    {

    // Get input variables from Matlab (host variables).

    double *A;
    // Get dimensions of input variables from Matlab.
    int m, n,k;
    const mwSize *Adims;
    Adims = mxGetDimensions(prhs[0]);
    m = Adims[0];
    n = Adims[1];
    //k = Adims[2];
    A = mxGetPr(prhs[0]);
    k = (int)*mxGetPr(prhs[1]);
        magma_init() ;
    magma_print_environment();

    real_Double_t    gflops, magma_perf, magma_time, cublas_perf=0,
cublas_time=0, cpu_perf, cpu_time;
    double           magma_error, cublas_error, magma_error2,
cublas_error2;

    double *h_A, *h_R, *h_Amagma, *tau, *h_work, tmp[1], unused[1];
    double *d_A, *dtau_magma, *dtau_cublas;

    double **dA_array = NULL;
    double **dtau_array = NULL;
   // magma_queue_t queue = NULL ;
    magma_int_t dev =0;
   // magma_queue_create (dev ,& queue );
    magma_int_t   *dinfo_magma, *dinfo_cublas;

    magma_int_t M, N, lda, ldda, lwork, n2, info, min_mn;
    magma_int_t ione     = 1;
    magma_int_t ISEED[4] = {0,0,0,1};
    int status = 0;

    magma_int_t batchCount;
    magma_int_t column;

    //magma_opts opts( MagmaOptsBatched );
    //opts.parse_opts( argc, argv );
    batchCount = k;
        printf("%% BatchCount   M     N   MAGMA Gflop/s (ms)   CUBLAS Gflop/s (ms)
   CPU Gflop/s (ms)   |R - Q^H*A|_mag   |I - Q^H*Q|_mag   |R - Q^H*A|_cub  
|I - Q^H*Q|_cub\n");

printf("%%============================================================================================================================================================\n");

            M     = 2000;
            N     = 103;
            min_mn = N;
            lda    = M;
            n2     = lda*N * batchCount;
            ldda = M;
            //ldda   =          //  magma_roundup( M, opts.align );  //
multiple of 32 by default

            gflops = (FLOPS_DGEQRF( M, N ) + FLOPS_DGEQRT( M, N )) / 1e9 *
batchCount;

            /* Allocate memory for the matrix */
                        /*magma_dmalloc_pinned( &h_R,   n2     );
                        // magma_time = magma_sync_wtime( queue );
             magma_dmalloc_cpu( &tau,   min_mn * batchCount );
             magma_dmalloc_cpu( &h_A,   n2     );
             magma_dmalloc_cpu( &h_Amagma,   n2     );


             magma_dmalloc( &d_A,   ldda*N * batchCount );

             magma_dmalloc( &dtau_magma,  min_mn * batchCount );
             magma_dmalloc( &dtau_cublas, min_mn * batchCount );

             magma_imalloc( &dinfo_magma,  batchCount );
             magma_imalloc( &dinfo_cublas, batchCount );

             magma_malloc( (void**) &dA_array,   batchCount *
sizeof(double*) );
             magma_malloc( (void**) &dtau_array, batchCount *
sizeof(double*) );

            column = N * batchCount;


            /*
====================================================================
               Performs operation using MAGMA

=================================================================== */
           /* magma_dsetmatrix( M, column, A, lda,  d_A, ldda );
            magma_dset_pointer( dA_array, d_A, 1, 0, 0, ldda*N,
batchCount);
            magma_dset_pointer( dtau_array, dtau_magma, 1, 0, 0, min_mn,
batchCount);



            info = magma_dgeqrf_batched(M, N, dA_array, ldda, dtau_array,
dinfo_magma, batchCount);

            magma_time = magma_sync_wtime( queue ) - magma_time;
            magma_perf = gflops / magma_time;

            magma_dgetmatrix( M, column, d_A, ldda, h_Amagma, lda);

            if (info != 0) {
                printf("magma_dgeqrf_batched returned error %lld: %s.\n",
                       (long long) info, magma_strerror( info ));
            }
                        printf("%10lld %5lld %5lld    %7.2f (%7.2f)     ",
                       (long long) batchCount, (long long) M, (long long)
N,
                       magma_perf,  1000.*magma_time );



}


When I compile it,
>>mex my_magma.c -DADD_ -lmagma_sparse -lmagma -lcublas -lcudart
Building with 'gcc'.
MEX completed successfully.

After compiling, I am calling from matlab (example.m), that has the lines below,

Code: Select all

A=rand(10,10);
A=my_magma(A);

When I do this, I get the following error
>> example
Invalid MEX-file '/home/my_magma.mexa64':
/cvmfs/soft.computecanada.ca/easybuild/software/2017/Core/ifort/2018.3.222/compilers_and_libraries_2018.3.222/linux/compiler/lib/intel64/libirng.so: undefined symbol:
__intel_skx_avx512_memcpy.



To solve this error, I used

export LD_PRELOAD=//cvmfs/soft.computecanada.ca/easybuild/software/2017/Core/ifort/2018.3.222/compilers_and_libraries_2018.3.222/linux/compiler/lib/intel64/libirc.so


After solving this error,i ran again and again I got " undefined symbol" error, which is stated below

>>example
Invalid MEX-file '/home/naveen/Matlab/Mexcuda2019-03-16/mex_magma_qr.mexa64':
/cvmfs/soft.computecanada.ca/easybuild/software/2017/avx2/CUDA/intel2018.3/cuda10.0/magma/2.4.0/lib/libmagma.so: undefined symbol: __svml_copysignf4.

Can anyone provide me with a solution to this issue? Thank you

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

Re: Undefined symbol errors while calling magma routine from a matlab mex file

Post by mgates3 » Tue Apr 23, 2019 3:50 pm

You may need to link with the MKL library that ships with Matlab, instead of an external one. Search for mkl in your Matlab installation. The specifics depend on your platform. For instance, on MacOS, Matlab's MKL library is here:

Code: Select all

>> pfind mkl /Applications/Mine/MATLAB_R2017a.app/
/Applications/Mine/MATLAB_R2017a.app/bin/maci64/mkl.dylib
/Applications/Mine/MATLAB_R2017a.app/bin/maci64/mklcompat.dylib
[Sorry for the delay in posting. A misconfiguration left messages in the moderation queue.]

Post Reply