Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

lapack_int for x86 vs x64

JohnZhang
New Contributor I
1,630 Views

I am having trouble calling a MKL library function in a 32bit-compiled C# application in Visual Studio. The MKL library function is exposed through a native DLL for C# to reference.  I wonder what I need to do in terms of the function signature part: lapack_int. I saw in 

LAPACK: LAPACKE/include/lapack.h Source File (netlib.org)

that there is a switch between int32 and int64. Do I need c#  "long" for int64_t and "int" for int32_t"?

 

#ifndef lapack_int
if defined(LAPACK_ILP64)
define lapack_int int64_t
else
define lapack_int int32_t
endif
endif
0 Kudos
9 Replies
mecej4
Honored Contributor III
1,591 Views

The distinction between LP64 and ILP64 apply only to 64 bit MKL libraries and DLLs. They do not apply to 32-bit applications and DLLs, which pass only 32-bit integer arguments to MKL routines. The distinctions have no relevance for MKL routine arguments of types other than integer.

0 Kudos
JohnZhang
New Contributor I
1,582 Views

Many thanks for the rely.

My 32bits C# application had this error message when calling the native dll, which  links to the MKL library and has the MKL function exposed.

Managed Debugging Assistant 'PInvokeStackImbalance' : 'A call to PInvoke function 'Intel.MKL.Native.UnsafeNativeMethods::LAPACKE_dsytrf' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.'

 

The same call has no problem when compiling in x64 mode.

 

This is the function signature defined in the native dll:

[DllImport(LibName)]
internal static extern int LAPACKE_dsytrf(int layout, char uplo, int n, double* a, int lda, int* ipiv);

0 Kudos
mecej4
Honored Contributor III
1,570 Views

Did you build the Lapack_E library yourself? Were they built from sources at Netlib or the ones in the Zip file provided with the MKL examples?

0 Kudos
JohnZhang
New Contributor I
1,567 Views

MKL library (both 32/64bit version) was installed in Visual Studio via Nuget.

0 Kudos
AryanK_Intel
Employee
1,443 Views

Hi,

 

Thanks for posting in Intel Communities.

 

Could you please assist us by providing the following details so that we can reproduce the issue from our end:

 

  1. MKL version, software, and hardware details along with a sample reproducer.
  2. Detail Steps that you have followed for installing Visual Studio via Nuget.
  3. Steps for linking your 32-bit C# application with Visual Studio.
  4. Complete error log.

 

We request you to use 64bit only, since Intel® oneMKL 32-bit binaries will be deprecated in the upcoming release. Please refer to this link:

https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Deprecation-Notices/td-p/1505877

 

Thanks & Regards,

Aryan

 

0 Kudos
JohnZhang
New Contributor I
1,437 Views

1) MKL version, software, and hardware details along with a sample reproducer.

MKL static lib installed from NuGet (https://www.nuget.org/packages/intelmkl.static.win-x64). 

Version Number: 2023.1.0.46356

2) Detail Steps that you have followed for installing Visual Studio via Nuget.

Solution Menu/Manager NuGet Packages for Solution.../Browse, type in IntelMKL.static in the search box and install.

3) Steps for linking your 32-bit C# application with Visual Studio.

Create a DLL project in the solution and enable mkl api by setting up appropriate header/lib files.

Expose the MKL function in the exports.def file

Create a C# project in the same solution and import the function by 

[DllImport(LibName)]
internal static extern int LAPACKE_dsytrf(MklLayoutEnum layout, char uplo, int n, double* a, int lda, int* ipiv);

4) Complete error log.

Managed Debugging Assistant 'PInvokeStackImbalance'

  Message=Managed Debugging Assistant 'PInvokeStackImbalance' : 'A call to PInvoke function 'Intel.MKL.Native.UnsafeNativeMethods::LAPACKE_dsytrf' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.'

0 Kudos
AryanK_Intel
Employee
1,310 Views

Hi,

 

Thank you for providing the steps.

 

We have successfully installed the MKL static library from NuGet. Could you please elaborate on step 3 for better understanding?

 

Alternatively, it would be more convenient for us to reproduce the issue if you could share your project file zipped and provide the necessary steps for replication (if applicable). If the file size is too large, you can try to isolate the issue and send us a sample working reproducer. This will greatly assist us in addressing the issue and providing you with the appropriate assistance.

 

Thanks and Regards,

Aryan

 

0 Kudos
AryanK_Intel
Employee
1,233 Views

Hi,


Gentle reminder:


We haven't heard back from you. Could you please provide an update on the above information?


Thanks and Regards,

Aryan


0 Kudos
AryanK_Intel
Employee
1,151 Views

Hi,


Gentle reminder:


We haven't heard back from you. Could you please provide an update on the above information?


Thanks and Regards,

Aryan


0 Kudos
Reply