Browse Source

Native Providers: MKL provider sets consistency mode first, before querying #488

spatial
Christoph Ruegg 9 years ago
parent
commit
43f77496d5
  1. 61
      src/Numerics/Providers/Common/Mkl/MklProvider.cs
  2. 2
      src/Numerics/Providers/Common/OpenBlas/OpenBlasProvider.cs
  3. 4
      src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs

61
src/Numerics/Providers/Common/Mkl/MklProvider.cs

@ -72,7 +72,18 @@ namespace MathNet.Numerics.Providers.Common.Mkl
}
/// <returns>Revision</returns>
internal static int Load(string hintPath = null)
public static int Load(string hintPath = null)
{
return Load(hintPath, MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High);
}
/// <returns>Revision</returns>
[CLSCompliant(false)]
public static int Load(
string hintPath = null,
MklConsistency consistency = MklConsistency.Auto,
MklPrecision precision = MklPrecision.Double,
MklAccuracy accuracy = MklAccuracy.High)
{
if (_loaded)
{
@ -92,6 +103,19 @@ namespace MathNet.Numerics.Providers.Common.Mkl
_nativeX64 = SafeNativeMethods.query_capability((int)ProviderPlatform.x64) > 0;
_nativeIA64 = SafeNativeMethods.query_capability((int)ProviderPlatform.ia64) > 0;
// set numerical consistency, precision and accuracy modes, if supported
if (SafeNativeMethods.query_capability((int)ProviderConfig.Precision) > 0)
{
SafeNativeMethods.set_consistency_mode((int)consistency);
SafeNativeMethods.set_vml_mode((uint)precision | (uint)accuracy);
}
// set threading settings, if supported
if (SafeNativeMethods.query_capability((int)ProviderConfig.Threading) > 0)
{
SafeNativeMethods.set_max_threads(Control.MaxDegreeOfParallelism);
}
_mklVersion = new Version(
SafeNativeMethods.query_capability((int)ProviderConfig.MklMajorVersion),
SafeNativeMethods.query_capability((int)ProviderConfig.MklMinorVersion),
@ -115,45 +139,10 @@ namespace MathNet.Numerics.Providers.Common.Mkl
throw new NotSupportedException("MKL Native Provider too old. Consider upgrading to a newer version.");
}
// set threading settings, if supported
if (SafeNativeMethods.query_capability((int)ProviderConfig.Threading) > 0)
{
SafeNativeMethods.set_max_threads(Control.MaxDegreeOfParallelism);
}
_loaded = true;
return _nativeRevision;
}
internal static void ConfigureThreading()
{
if (!_loaded)
{
throw new InvalidOperationException();
}
// set threading settings, if supported
if (SafeNativeMethods.query_capability((int)ProviderConfig.Threading) > 0)
{
SafeNativeMethods.set_max_threads(Control.MaxDegreeOfParallelism);
}
}
internal static void ConfigurePrecision(MklConsistency consistency, MklPrecision precision, MklAccuracy accuracy)
{
if (!_loaded)
{
throw new InvalidOperationException();
}
// set numerical consistency, precision and accuracy modes, if supported
if (SafeNativeMethods.query_capability((int)ProviderConfig.Precision) > 0)
{
SafeNativeMethods.set_consistency_mode((int)consistency);
SafeNativeMethods.set_vml_mode((uint)precision | (uint)accuracy);
}
}
/// <summary>
/// Frees memory buffers, caches and handles allocated in or to the provider.
/// Does not unload the provider itself, it is still usable afterwards.

2
src/Numerics/Providers/Common/OpenBlas/OpenBlasProvider.cs

@ -34,7 +34,7 @@ using System.Collections.Generic;
namespace MathNet.Numerics.Providers.Common.OpenBlas
{
internal static class OpenBlasProvider
public static class OpenBlasProvider
{
const int _designTimeRevision = 1;
const int _minimumCompatibleRevision = 1;

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

@ -92,14 +92,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary>
public override void InitializeVerify()
{
int revision = MklProvider.Load(hintPath: _hintPath);
int revision = MklProvider.Load(_hintPath, _consistency, _precision, _accuracy);
if (revision < _minimumCompatibleRevision)
{
throw new NotSupportedException($"MKL Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{_minimumCompatibleRevision} and newer are supported.");
}
MklProvider.ConfigurePrecision(_consistency, _precision, _accuracy);
_linearAlgebraMajor = SafeNativeMethods.query_capability((int)ProviderCapability.LinearAlgebraMajor);
_linearAlgebraMinor = SafeNativeMethods.query_capability((int)ProviderCapability.LinearAlgebraMinor);
_vectorFunctionsMajor = SafeNativeMethods.query_capability((int)ProviderCapability.VectorFunctionsMajor);

Loading…
Cancel
Save