This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 573

Summary: MKL matrix-matrix multiplication issue
Product: Eigen Reporter: dvijcse
Component: InteroperabilityAssignee: Nobody <eigen.nobody>
Status: RESOLVED WORKSFORME    
Severity: Unknown CC: ctejeda, gael.guennebaud, hauke.heibel, jacob.benoit.1, marcho
Priority: Normal    
Version: 3.2   
Hardware: x86 - 64-bit   
OS: Windows   
Whiteboard:
Bug Depends on:    
Bug Blocks: 387    

Description dvijcse 2013-03-23 01:15:54 UTC
This issue arises when using eigen with MKL on a 64-bit windows system (with both the intel and the microsoft compiler).

When I create mapped matrix objects and multiple them, MKL reports an error: Parameter 8 invalid on entry to DGEMM.

I realized that this was happening because the parameters lda,ldb,ldc are set to lhsStride,rhsStride and resStride, which have garbage values when mapped matrices are used. I was able to fix it by changing lines 87-89 in GeneralMatrixMatrix_MKL.h to the following:

  lda = (transa=='N')? ((m>1)?m:1) : ((k>1)?k:1) /*(MKL_INT)lhsStride*/; \
  ldb = (transb=='N')? ((k>1)?k:1) : ((n>1)?n:1)/*(MKL_INT)rhsStride*/; \
  ldc = (m>1)?m:1/*(MKL_INT)resStride*/; \

The comments have the original statements. Of course, this assumes a default unit stride, so it is not an appropriate fix. 

Also, in the file Assign_MKL.h, line 213 should be #ifndef, not #ifdef, otherwise, eigen fails to compile.
Comment 1 Gael Guennebaud 2013-04-16 14:22:45 UTC
*** Bug 589 has been marked as a duplicate of this bug. ***
Comment 2 Gael Guennebaud 2013-04-16 14:30:23 UTC
For the typo see:

https://bitbucket.org/eigen/eigen/commits/62ed8708b7e6711a52e9735fa7177dc91773dc2d

and the backport:

https://bitbucket.org/eigen/eigen/commits/62df767dbf37/
Changeset:   62df767dbf37
Branch:      3.1
User:        ggael
Date:        2012-08-27 13:17:45
Summary:     fix a typo in commit 4b483eaddf74 (regarding MKL on windows)
(transplanted from 62ed8708b7e6711a52e9735fa7177dc91773dc2d)
Comment 3 Gael Guennebaud 2013-04-16 14:32:50 UTC
Now regarding the problem with strides, I don't see why the provided lhsStride values would be wrong? If that happens, then this must be fixed earlier in the code. Does it work fine without MKL?
Comment 4 dvijcse 2013-04-22 03:07:32 UTC
(In reply to comment #3)
> Now regarding the problem with strides, I don't see why the provided lhsStride
> values would be wrong? If that happens, then this must be fixed earlier in the
> code. Does it work fine without MKL?

Yes, without MKL its fine.
Comment 5 Gael Guennebaud 2013-07-12 00:13:02 UTC
Work for me with:

#include <Eigen/Eigen>
using namespace Eigen;
int main() {
  int rows, cols, depth;
  rows = cols = depth = 50;
  double *data = new double[rows*cols+rows*depth+depth*cols];
  MatrixXd::Map(data, rows, cols) += MatrixXd::Map(data+rows*cols, depth,depth).transpose() * MatrixXd::Map(data+rows*(cols+depth), depth, cols);
  return 0;
}

compiled with:

icpc  -mkl=sequential -DEIGEN_USE_MKL_ALL bug_573.cpp -o bug_573 -O3
Comment 6 Cesar Tejeda 2013-08-09 10:49:42 UTC
For me it didn't work in linux with gcc 4.6.3 either. I had to deactivate it completely. I am using MKL 10.3 update 7. Eigen 3.1.3.
Comment 7 Gael Guennebaud 2013-08-20 13:37:35 UTC
works for me with the previous example, g++ 6.3 and MKL 10.3.9. Compiled with:

g++ -DEIGEN_USE_MKL_ALL bug_573.cpp -o bug_573 -O3 -I eigen-hg  -Wl,--start-group  $MKLROOT/lib/intel64/libmkl_intel_lp64.a $MKLROOT/lib/intel64/libmkl_gnu_thread.a $MKLROOT/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm -fopenmp -m64 -I$MKLROOT/include
Comment 8 Nobody 2019-12-04 12:11:59 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/573.