Browse Source

MKL: add capability query support

provider
Christoph Ruegg 13 years ago
parent
commit
09f504a762
  1. 2
      MathNet.Numerics.NativeProviders.sln
  2. 10
      src/NativeProviders/Common/resource.rc
  3. 61
      src/NativeProviders/MKL/capabilities.cpp
  4. 1
      src/NativeProviders/Windows/MKL/MKLWrapper.vcxproj
  5. 3
      src/NativeProviders/Windows/MKL/MKLWrapper.vcxproj.filters
  6. 43
      src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
  7. 3
      src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs

2
MathNet.Numerics.NativeProviders.sln

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013 # Visual Studio 2013
VisualStudioVersion = 12.0.21005.1 VisualStudioVersion = 12.0.30110.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5A0892FF-82CE-40FC-BCE1-73810C615F52}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5A0892FF-82CE-40FC-BCE1-73810C615F52}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject

10
src/NativeProviders/Common/resource.rc

@ -51,8 +51,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,3,0,0 FILEVERSION 1,4,0,0
PRODUCTVERSION 1,3,0,0 PRODUCTVERSION 1,4,0,0
FILEFLAGSMASK 0x17L FILEFLAGSMASK 0x17L
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -70,12 +70,12 @@ BEGIN
VALUE "Comments", "http://numerics.mathdotnet.com/" VALUE "Comments", "http://numerics.mathdotnet.com/"
VALUE "CompanyName", "Math.NET" VALUE "CompanyName", "Math.NET"
VALUE "FileDescription", "MathNET Numerics Native Provider" VALUE "FileDescription", "MathNET Numerics Native Provider"
VALUE "FileVersion", "1.3.0.0" VALUE "FileVersion", "1.4.0.0"
VALUE "InternalName", "Math.NET" VALUE "InternalName", "Math.NET"
VALUE "LegalCopyright", "Copyright (C) Math.NET 2009-2013" VALUE "LegalCopyright", "Copyright (C) Math.NET 2009-2014"
VALUE "OriginalFilename", "MathNet.Numerics" VALUE "OriginalFilename", "MathNet.Numerics"
VALUE "ProductName", "Math.NET Numerics" VALUE "ProductName", "Math.NET Numerics"
VALUE "ProductVersion", "1.3.0.0" VALUE "ProductVersion", "1.4.0.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

61
src/NativeProviders/MKL/capabilities.cpp

@ -0,0 +1,61 @@
#include "wrapper_common.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
Capability is supported if >0
Actual number can be increased over time to indicate
extensions/revisions (that do not break compatibility)
*/
DLLEXPORT int query_capability(const int capability)
{
switch (capability)
{
// SANITY CHECKS
case 0: return 0;
case 1: return -1;
// PLATFORM
case 8:
#ifdef _M_IX86
return 1;
#else
return 0;
#endif
case 9:
#ifdef _M_X64
return 1;
#else
return 0;
#endif
case 10:
#ifdef _M_IA64
return 1;
#else
return 0;
#endif
// COMMON/SHARED
case 64: return 4; // revision
// LINEAR ALGEBRA
case 128: return 1; // basic dense linear algebra
// OPTIMIZATION
case 256: return 0; // basic optimization
// FFT
case 384: return 0; // basic FFT
default: return 0; // unknown or not supported
}
}
#ifdef __cplusplus
}
#endif /* __cplusplus */

1
src/NativeProviders/Windows/MKL/MKLWrapper.vcxproj

@ -290,6 +290,7 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\Common\WindowsDLL.cpp" /> <ClCompile Include="..\..\Common\WindowsDLL.cpp" />
<ClCompile Include="..\..\MKL\capabilities.cpp" />
<ClCompile Include="..\..\MKL\blas.c" /> <ClCompile Include="..\..\MKL\blas.c" />
<ClCompile Include="..\..\MKL\lapack.cpp" /> <ClCompile Include="..\..\MKL\lapack.cpp" />
<ClCompile Include="..\..\MKL\vector_functions.c" /> <ClCompile Include="..\..\MKL\vector_functions.c" />

3
src/NativeProviders/Windows/MKL/MKLWrapper.vcxproj.filters

@ -27,6 +27,9 @@
<ClCompile Include="..\..\Common\WindowsDLL.cpp"> <ClCompile Include="..\..\Common\WindowsDLL.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\MKL\capabilities.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="..\..\Common\resource.rc"> <ResourceCompile Include="..\..\Common\resource.rc">

43
src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs

@ -28,6 +28,8 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
#if NATIVEMKL #if NATIVEMKL
namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
@ -37,6 +39,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary> /// </summary>
public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider
{ {
int _nativeRevision = 0;
bool _nativeIX86 = false;
bool _nativeX64 = false;
bool _nativeIA64 = false;
/// <param name="bitConsistent">If true improves MKL Consistency to get bit consistent results on repeated identical calculations</param> /// <param name="bitConsistent">If true improves MKL Consistency to get bit consistent results on repeated identical calculations</param>
public MklLinearAlgebraProvider(bool bitConsistent = false) public MklLinearAlgebraProvider(bool bitConsistent = false)
{ {
@ -52,13 +59,43 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
public override void InitializeVerify() public override void InitializeVerify()
{ {
// TODO: Choose x86 or x64 based on Environment.Is64BitProcess // TODO: Choose x86 or x64 based on Environment.Is64BitProcess
// TODO: call into MKL to verify
int a = 0, b = 0, linearAlgebra = 0;
try
{
a = SafeNativeMethods.query_capability(0);
b = SafeNativeMethods.query_capability(1);
_nativeIX86 = SafeNativeMethods.query_capability(8) > 0;
_nativeX64 = SafeNativeMethods.query_capability(9) > 0;
_nativeIA64 = SafeNativeMethods.query_capability(10) > 0;
_nativeRevision = SafeNativeMethods.query_capability(64);
linearAlgebra = SafeNativeMethods.query_capability(128);
}
catch (BadImageFormatException e)
{
throw new NotSupportedException("MKL Native Provider failed to load. Please verify that the platform matches (x64 vs x32, Windows vs Linux).", e);
}
catch (EntryPointNotFoundException e)
{
// we currently accept this to continue to support the old version for a while.
// however, this is planned to be dropped for the final v3 release at latest.
// TODO: drop return statement and instead fail with the exception below
return;
throw new NotSupportedException("MKL Native Provider does not support capability querying and is therefore not compatible. Try to upgrade to a newer version (1).", e);
}
if (a != 0 || b != -1 || linearAlgebra <=0 || _nativeRevision < 4)
{
throw new NotSupportedException("MKL Native Provider too old or not compatible (2).");
}
} }
public override string ToString() public override string ToString()
{ {
// TODO: query version and platform and add to string return string.Format("Intel MKL ({1}; revision {0})", _nativeRevision, _nativeIX86 ? "x86" : _nativeX64 ? "x64" : _nativeIA64 ? "IA64" : "unknown");
return "Intel MKL";
} }
} }
} }

3
src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs

@ -46,6 +46,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary> /// </summary>
const string DllName = "MathNet.Numerics.MKL.dll"; const string DllName = "MathNet.Numerics.MKL.dll";
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern int query_capability(int capability);
#region BLAS #region BLAS
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]

Loading…
Cancel
Save