Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Intel's Math Kernel Library with M2 #3372

Open
mahrud opened this issue Jul 21, 2024 · 0 comments
Open

Using Intel's Math Kernel Library with M2 #3372

mahrud opened this issue Jul 21, 2024 · 0 comments

Comments

@mahrud
Copy link
Member

mahrud commented Jul 21, 2024

Here are the problems I ran into:

  1. First, you need to set the compiler variables, e.g for MKL 2024.1:
. /opt/local/oneapi/2024.1/setvars.sh --force
 
:: initializing oneAPI environment ...
   -bash: BASH_VERSION = 5.2.15(1)-release
   args: Using "$@" for setvars.sh arguments: --force
:: advisor -- latest
:: compiler -- latest
:: debugger -- latest
:: dev-utilities -- latest
:: dpcpp-ct -- latest
:: dpl -- latest
:: ipp -- latest
:: ippcp -- latest
:: mkl -- latest
:: mpi -- latest
:: tbb -- latest
:: oneAPI environment initialized ::

Though finding this file was a bit tricky. Then ninja build-givaro build-fflas-ffpack detected MKL fine as well, and this was reported by cmake:

## Library information
     Linear Algebra    = /opt/local/oneapi/2024.1/mkl/2024.1/lib/libmkl_intel_lp64.so;/opt/local/oneapi/2024.1/mkl/2024.1/lib/libmkl_intel_thread.so;/opt/local/oneapi/2024.1/mkl/2024.1/lib/libmkl_core.so;/opt/local/oneapi/2024.1/compiler/2024.1/lib/libiomp5.so;-lm;-ldl;-lm;-ldl
  1. Conflicting declaration of C functions from lapack.hpp, e.g.:
/usr/people/sayrafi/M2/M2/Macaulay2/e/lapack.hpp:18:5: error: conflicting declaration of C function ‘int dgesv_(int*, int*, double*, int*, int*, double*, int*, int*)’
   18 | int dgesv_(int *n,      // number of rows in A
      |     ^~~~~~
compilation terminated due to -Wfatal-errors.

I got around this by adding #ifndef _MKL_LAPACK_H_ around the extern "C" section of our lapack.hpp. It seems to me like we should be including this section from somewhere, why is it here?

  1. Incompatible complex types:
/usr/people/sayrafi/M2/M2/Macaulay2/e/dmat-lu-inplace.hpp: In member function ‘void DMatLUinPlace<RT>::computeLU() [with RT = M2::ARingCC]’:
/usr/people/sayrafi/M2/M2/Macaulay2/e/dmat-lu-inplace.hpp:372:25: error: cannot convert ‘double*’ to ‘MKL_Complex16*’
  372 |   zgetrf_(&rows, &cols, copyA, &rows, perm, &info);
      |                         ^~~~~
      |                         |
      |                         double*
compilation terminated due to -Wfatal-errors.

For reference, this is the declaration of zgetrf_ in lapack.hpp vs mkl_lapack.hpp:

int zgetrf_(int *rows,   // rows
            int *cols,   // columns
            double *M,   // input matrix, on exit L & U from A=PLU.
            int *ld,     // rows
            int *ipiv,   // becomes permutation indices of P
            int *info);  // error info

void zgetrf_( const MKL_INT* m, const MKL_INT* n, MKL_Complex16* a,
              const MKL_INT* lda, MKL_INT* ipiv, MKL_INT* info ) NOTHROW;

and this is the type MKL_Complex16 in mkl_types.hpp:

#ifndef MKL_Complex16 
typedef 
struct _MKL_Complex16 { 
    double real; 
    double imag; 
} MKL_Complex16; 
#endif

This feels very sketchy, but I got around this by pre-declaring the type in engine-includes.hpp:

#define MKL_Complex16 double

Putting this in lapack.hpp didn't work, and I'm not sure where makes more sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant