Browse Source

Native Providers: simplify minimum supported revision handling

spatial
Christoph Ruegg 9 years ago
parent
commit
0fd6005af9
  1. 24
      src/Numerics/Providers/Common/Cuda/CudaProvider.cs
  2. 24
      src/Numerics/Providers/Common/Mkl/MklProvider.cs
  3. 24
      src/Numerics/Providers/Common/OpenBlas/OpenBlasProvider.cs
  4. 12
      src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs
  5. 12
      src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs
  6. 13
      src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
  7. 12
      src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs

24
src/Numerics/Providers/Common/Cuda/CudaProvider.cs

@ -47,12 +47,7 @@ namespace MathNet.Numerics.Providers.Common.Cuda
public static bool IsAvailable(string hintPath = null)
{
return IsAvailable(_minimumCompatibleRevision, hintPath);
}
internal static bool IsAvailable(int minRevision, string hintPath)
{
if (_loaded && _nativeRevision >= minRevision)
if (_loaded)
{
return true;
}
@ -67,7 +62,7 @@ namespace MathNet.Numerics.Providers.Common.Cuda
int a = SafeNativeMethods.query_capability(0);
int b = SafeNativeMethods.query_capability(1);
int nativeRevision = SafeNativeMethods.query_capability((int)ProviderConfig.Revision);
return a == 0 && b == -1 && nativeRevision >= minRevision;
return a == 0 && b == -1 && nativeRevision >= _minimumCompatibleRevision;
}
catch
{
@ -75,16 +70,12 @@ namespace MathNet.Numerics.Providers.Common.Cuda
}
}
public static void Load(string hintPath = null)
{
Load(_minimumCompatibleRevision, hintPath);
}
internal static void Load(int minRevision, string hintPath)
/// <returns>Revision</returns>
public static int Load(string hintPath = null)
{
if (_loaded && _nativeRevision >= minRevision)
if (_loaded)
{
return;
return _nativeRevision;
}
int a, b;
@ -113,12 +104,13 @@ namespace MathNet.Numerics.Providers.Common.Cuda
throw new NotSupportedException("Cuda Native Provider does not support capability querying and is therefore not compatible. Consider upgrading to a newer version.", e);
}
if (a != 0 || b != -1 || _nativeRevision < minRevision)
if (a != 0 || b != -1 || _nativeRevision < _minimumCompatibleRevision)
{
throw new NotSupportedException("Cuda Native Provider too old. Consider upgrading to a newer version.");
}
_loaded = true;
return _nativeRevision;
}
public static string Describe()

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

@ -48,12 +48,7 @@ namespace MathNet.Numerics.Providers.Common.Mkl
public static bool IsAvailable(string hintPath = null)
{
return IsAvailable(_minimumCompatibleRevision, hintPath);
}
internal static bool IsAvailable(int minRevision, string hintPath)
{
if (_loaded && _nativeRevision >= minRevision)
if (_loaded)
{
return true;
}
@ -68,7 +63,7 @@ namespace MathNet.Numerics.Providers.Common.Mkl
int a = SafeNativeMethods.query_capability(0);
int b = SafeNativeMethods.query_capability(1);
int nativeRevision = SafeNativeMethods.query_capability((int)ProviderConfig.Revision);
return a == 0 && b == -1 && nativeRevision >= minRevision;
return a == 0 && b == -1 && nativeRevision >= _minimumCompatibleRevision;
}
catch
{
@ -76,16 +71,12 @@ namespace MathNet.Numerics.Providers.Common.Mkl
}
}
public static void Load(string hintPath = null)
{
Load(_minimumCompatibleRevision, hintPath);
}
internal static void Load(int minRevision, string hintPath)
/// <returns>Revision</returns>
internal static int Load(string hintPath = null)
{
if (_loaded && _nativeRevision >= minRevision)
if (_loaded)
{
return;
return _nativeRevision;
}
int a, b;
@ -119,7 +110,7 @@ namespace MathNet.Numerics.Providers.Common.Mkl
throw new NotSupportedException("MKL Native Provider does not support capability querying and is therefore not compatible. Consider upgrading to a newer version.", e);
}
if (a != 0 || b != -1 || _nativeRevision < minRevision)
if (a != 0 || b != -1 || _nativeRevision < _minimumCompatibleRevision)
{
throw new NotSupportedException("MKL Native Provider too old. Consider upgrading to a newer version.");
}
@ -131,6 +122,7 @@ namespace MathNet.Numerics.Providers.Common.Mkl
}
_loaded = true;
return _nativeRevision;
}
internal static void ConfigureThreading()

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

@ -48,12 +48,7 @@ namespace MathNet.Numerics.Providers.Common.OpenBlas
public static bool IsAvailable(string hintPath = null)
{
return IsAvailable(_minimumCompatibleRevision, hintPath);
}
internal static bool IsAvailable(int minRevision, string hintPath)
{
if (_loaded && _nativeRevision >= minRevision)
if (_loaded)
{
return true;
}
@ -68,7 +63,7 @@ namespace MathNet.Numerics.Providers.Common.OpenBlas
int a = SafeNativeMethods.query_capability(0);
int b = SafeNativeMethods.query_capability(1);
int nativeRevision = SafeNativeMethods.query_capability((int)ProviderConfig.Revision);
return a == 0 && b == -1 && nativeRevision >= minRevision;
return a == 0 && b == -1 && nativeRevision >= _minimumCompatibleRevision;
}
catch
{
@ -76,16 +71,12 @@ namespace MathNet.Numerics.Providers.Common.OpenBlas
}
}
public static void Load(string hintPath = null)
{
Load(_minimumCompatibleRevision, hintPath);
}
internal static void Load(int minRevision, string hintPath)
/// <returns>Revision</returns>
public static int Load(string hintPath = null)
{
if (_loaded && _nativeRevision >= minRevision)
if (_loaded)
{
return;
return _nativeRevision;
}
int a, b;
@ -115,7 +106,7 @@ namespace MathNet.Numerics.Providers.Common.OpenBlas
throw new NotSupportedException("OpenBLAS Native Provider does not support capability querying and is therefore not compatible. Consider upgrading to a newer version.", e);
}
if (a != 0 || b != -1 || _nativeRevision < minRevision)
if (a != 0 || b != -1 || _nativeRevision < _minimumCompatibleRevision)
{
throw new NotSupportedException("OpenBLAS Native Provider too old. Consider upgrading to a newer version.");
}
@ -127,6 +118,7 @@ namespace MathNet.Numerics.Providers.Common.OpenBlas
}
_loaded = true;
return _nativeRevision;
}
internal static void ConfigureThreading()

12
src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs

@ -2,7 +2,7 @@
// Math.NET Numerics, part of the Math.NET Project
// https://numerics.mathdotnet.com
//
// Copyright (c) 2009-2016 Math.NET
// Copyright (c) 2009-2018 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -37,6 +37,8 @@ namespace MathNet.Numerics.Providers.FourierTransform.Mkl
{
internal class MklFourierTransformProvider : IFourierTransformProvider, IDisposable
{
const int _minimumCompatibleRevision = 11;
class Kernel
{
public IntPtr Handle;
@ -61,7 +63,7 @@ namespace MathNet.Numerics.Providers.FourierTransform.Mkl
/// </summary>
public bool IsAvailable()
{
return MklProvider.IsAvailable(minRevision: 11, hintPath: _hintPath);
return MklProvider.IsAvailable(hintPath: _hintPath);
}
/// <summary>
@ -69,7 +71,11 @@ namespace MathNet.Numerics.Providers.FourierTransform.Mkl
/// </summary>
public void InitializeVerify()
{
MklProvider.Load(minRevision: 11, hintPath: _hintPath);
int revision = MklProvider.Load(hintPath: _hintPath);
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.");
}
// we only support exactly one major version, since major version changes imply a breaking change.
int fftMajor = SafeNativeMethods.query_capability((int) ProviderCapability.FourierTransformMajor);

12
src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs

@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2016 Math.NET
// Copyright (c) 2009-2018 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -39,6 +39,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
/// </summary>
internal partial class CudaLinearAlgebraProvider : ManagedLinearAlgebraProvider, IDisposable
{
const int _minimumCompatibleRevision = 1;
readonly string _hintPath;
IntPtr _blasHandle;
IntPtr _solverHandle;
@ -55,7 +57,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
/// </summary>
public override bool IsAvailable()
{
return CudaProvider.IsAvailable(minRevision: 1, hintPath: _hintPath);
return CudaProvider.IsAvailable(hintPath: _hintPath);
}
/// <summary>
@ -64,7 +66,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
/// </summary>
public override void InitializeVerify()
{
CudaProvider.Load(minRevision: 1, hintPath: _hintPath);
int revision = CudaProvider.Load(hintPath: _hintPath);
if (revision < _minimumCompatibleRevision)
{
throw new NotSupportedException($"Cuda Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{_minimumCompatibleRevision} and newer are supported.");
}
int linearAlgebra = SafeNativeMethods.query_capability((int)ProviderCapability.LinearAlgebraMajor);

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

@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2016 Math.NET
// Copyright (c) 2009-2018 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -50,6 +50,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary>
internal partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider
{
const int _minimumCompatibleRevision = 4;
readonly string _hintPath;
readonly MklConsistency _consistency;
readonly MklPrecision _precision;
@ -81,7 +83,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary>
public override bool IsAvailable()
{
return MklProvider.IsAvailable(minRevision: 4, hintPath: _hintPath);
return MklProvider.IsAvailable(hintPath: _hintPath);
}
/// <summary>
@ -90,7 +92,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary>
public override void InitializeVerify()
{
MklProvider.Load(minRevision: 4, hintPath: _hintPath);
int revision = MklProvider.Load(hintPath: _hintPath);
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);

12
src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs

@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2016 Math.NET
// Copyright (c) 2009-2018 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -57,6 +57,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
/// </summary>
internal partial class OpenBlasLinearAlgebraProvider : ManagedLinearAlgebraProvider
{
const int _minimumCompatibleRevision = 1;
readonly string _hintPath;
/// <param name="hintPath">Hint path where to look for the native binaries</param>
@ -71,7 +73,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
/// </summary>
public override bool IsAvailable()
{
return OpenBlasProvider.IsAvailable(minRevision: 1, hintPath: _hintPath);
return OpenBlasProvider.IsAvailable(hintPath: _hintPath);
}
/// <summary>
@ -80,7 +82,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
/// </summary>
public override void InitializeVerify()
{
OpenBlasProvider.Load(minRevision: 1, hintPath: _hintPath);
int revision = OpenBlasProvider.Load(hintPath: _hintPath);
if (revision < _minimumCompatibleRevision)
{
throw new NotSupportedException($"OpenBLAS Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{_minimumCompatibleRevision} and newer are supported.");
}
int linearAlgebra = SafeNativeMethods.query_capability((int)ProviderCapability.LinearAlgebraMajor);

Loading…
Cancel
Save