Browse Source

Move HintPaths to MklControl/CudaControl/OpenBlasControl

pull/769/head
Christoph Ruegg 5 years ago
parent
commit
ae7598d261
  1. 7
      src/Numerics/Providers/FourierTransform/FourierTransformControl.cs
  2. 7
      src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs
  3. 7
      src/Numerics/Providers/SparseSolver/SparseSolverControl.cs
  4. 18
      src/Providers.CUDA/CudaControl.cs
  5. 41
      src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraControl.cs
  6. 41
      src/Providers.MKL/FourierTransform/MklFourierTransformControl.cs
  7. 24
      src/Providers.MKL/LinearAlgebra/MklLinearAlgebraControl.cs
  8. 7
      src/Providers.MKL/MklControl.cs
  9. 41
      src/Providers.MKL/SparseSolver/MklSparseSolverControl.cs
  10. 41
      src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraControl.cs
  11. 18
      src/Providers.OpenBLAS/OpenBlasControl.cs

7
src/Numerics/Providers/FourierTransform/FourierTransformControl.cs

@ -42,9 +42,10 @@ namespace MathNet.Numerics.Providers.FourierTransform
static readonly ProviderProbe<IFourierTransformProvider> MklProbe = new ProviderProbe<IFourierTransformProvider>(MklTypeName, AppSwitches.DisableMklNativeProvider);
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsFFTProviderPath` or the default probing paths.
/// Optional path to try to load native provider binaries from,
/// if the provider specific hint path is not set.
/// If neither is set, Numerics falls back to the provider specific
/// environment variables, or the default probing paths.
/// </summary>
public static string HintPath { get; set; }

7
src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs

@ -48,9 +48,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
static readonly ProviderProbe<ILinearAlgebraProvider> CudaProbe = new ProviderProbe<ILinearAlgebraProvider>(CudaTypeName, AppSwitches.DisableCudaNativeProvider);
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsLAProviderPath` or the default probing paths.
/// Optional path to try to load native provider binaries from,
/// if the provider specific hint path is not set.
/// If neither is set, Numerics falls back to the provider specific
/// environment variables, or the default probing paths.
/// </summary>
public static string HintPath { get; set; }

7
src/Numerics/Providers/SparseSolver/SparseSolverControl.cs

@ -42,9 +42,10 @@ namespace MathNet.Numerics.Providers.SparseSolver
static readonly ProviderProbe<ISparseSolverProvider> MklProbe = new ProviderProbe<ISparseSolverProvider>(MklTypeName, AppSwitches.DisableMklNativeProvider);
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsSSProviderPath` or the default probing paths.
/// Optional path to try to load native provider binaries from,
/// if the provider specific hint path is not set.
/// If neither is set, Numerics falls back to the provider specific
/// environment variables, or the default probing paths.
/// </summary>
public static string HintPath { get; set; }

18
src/Providers.CUDA/CudaControl.cs

@ -35,14 +35,18 @@ namespace MathNet.Numerics.Providers.CUDA
{
internal const string EnvVarCUDAProviderPath = "MathNetNumericsCUDAProviderPath";
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsCUDAProviderPath` or the default probing paths.
/// </summary>
public static string HintPath { get; set; }
/// <summary>
/// Use the OpenBLAS native provider for linear algebra.
/// Throws if it is not available or failed to initialize, in which case the previous provider is still active.
/// </summary>
public static void UseNativeCUDA()
{
CudaLinearAlgebraControl.UseNativeCUDA();
}
public static void UseNativeCUDA() => CudaLinearAlgebraControl.UseNativeCUDA();
/// <summary>
/// Try to use the OpenBLAS native provider for linear algebra.
@ -51,10 +55,6 @@ namespace MathNet.Numerics.Providers.CUDA
/// True if the provider was found and initialized successfully.
/// False if it failed and the previous provider is still active.
/// </returns>
public static bool TryUseNativeCUDA()
{
bool linearAlgebra = CudaLinearAlgebraControl.TryUseNativeCUDA();
return linearAlgebra;
}
public static bool TryUseNativeCUDA() => CudaLinearAlgebraControl.TryUseNativeCUDA();
}
}

41
src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraControl.cs

@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra
{
public class CudaLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider>
{
const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath";
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsMKLProviderPath` or the default probing paths.
/// </summary>
public static string HintPath { get; set; }
public static ILinearAlgebraProvider CreateNativeCUDA()
{
return new CudaLinearAlgebraProvider(GetCombinedHintPath());
}
public static void UseNativeCUDA()
{
LinearAlgebraControl.Provider = CreateNativeCUDA();
}
public static bool TryUseNativeCUDA()
{
return LinearAlgebraControl.TryUse(CreateNativeCUDA());
}
public static ILinearAlgebraProvider CreateNativeCUDA() => new CudaLinearAlgebraProvider(GetCombinedHintPath());
public static void UseNativeCUDA() => LinearAlgebraControl.Provider = CreateNativeCUDA();
public static bool TryUseNativeCUDA() => LinearAlgebraControl.TryUse(CreateNativeCUDA());
static string GetCombinedHintPath()
{
if (!String.IsNullOrEmpty(HintPath))
if (!String.IsNullOrEmpty(CudaControl.HintPath))
{
return HintPath;
return CudaControl.HintPath;
}
if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath))
@ -76,18 +56,9 @@ namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra
return value;
}
value = Environment.GetEnvironmentVariable(EnvVarLAProviderPath);
if (!String.IsNullOrEmpty(value))
{
return value;
}
return null;
}
public ILinearAlgebraProvider CreateProvider()
{
return CreateNativeCUDA();
}
public ILinearAlgebraProvider CreateProvider() => CreateNativeCUDA();
}
}

41
src/Providers.MKL/FourierTransform/MklFourierTransformControl.cs

@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
{
public class MklFourierTransformControl : IProviderCreator<IFourierTransformProvider>
{
const string EnvVarFFTProviderPath = "MathNetNumericsFFTProviderPath";
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsMKLProviderPath` or the default probing paths.
/// </summary>
public static string HintPath { get; set; }
public static IFourierTransformProvider CreateNativeMKL()
{
return new MklFourierTransformProvider(GetCombinedHintPath());
}
public static void UseNativeMKL()
{
FourierTransformControl.Provider = CreateNativeMKL();
}
public static bool TryUseNativeMKL()
{
return FourierTransformControl.TryUse(CreateNativeMKL());
}
public static IFourierTransformProvider CreateNativeMKL() => new MklFourierTransformProvider(GetCombinedHintPath());
public static void UseNativeMKL() => FourierTransformControl.Provider = CreateNativeMKL();
public static bool TryUseNativeMKL() => FourierTransformControl.TryUse(CreateNativeMKL());
static string GetCombinedHintPath()
{
if (!String.IsNullOrEmpty(HintPath))
if (!String.IsNullOrEmpty(MklControl.HintPath))
{
return HintPath;
return MklControl.HintPath;
}
if (!String.IsNullOrEmpty(FourierTransformControl.HintPath))
@ -76,18 +56,9 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
return value;
}
value = Environment.GetEnvironmentVariable(EnvVarFFTProviderPath);
if (!String.IsNullOrEmpty(value))
{
return value;
}
return null;
}
public IFourierTransformProvider CreateProvider()
{
return CreateNativeMKL();
}
public IFourierTransformProvider CreateProvider() => CreateNativeMKL();
}
}

24
src/Providers.MKL/LinearAlgebra/MklLinearAlgebraControl.cs

@ -34,15 +34,6 @@ namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
{
public class MklLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider>
{
const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath";
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsMKLProviderPath` or the default probing paths.
/// </summary>
public static string HintPath { get; set; }
public static ILinearAlgebraProvider CreateNativeMKL(
MklConsistency consistency = MklConsistency.Auto,
MklPrecision precision = MklPrecision.Double,
@ -69,9 +60,9 @@ namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
static string GetCombinedHintPath()
{
if (!String.IsNullOrEmpty(HintPath))
if (!String.IsNullOrEmpty(MklControl.HintPath))
{
return HintPath;
return MklControl.HintPath;
}
if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath))
@ -85,18 +76,9 @@ namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
return value;
}
value = Environment.GetEnvironmentVariable(EnvVarLAProviderPath);
if (!String.IsNullOrEmpty(value))
{
return value;
}
return null;
}
public ILinearAlgebraProvider CreateProvider()
{
return CreateNativeMKL();
}
public ILinearAlgebraProvider CreateProvider() => CreateNativeMKL();
}
}

7
src/Providers.MKL/MklControl.cs

@ -37,6 +37,13 @@ namespace MathNet.Numerics.Providers.MKL
{
internal const string EnvVarMKLProviderPath = "MathNetNumericsMKLProviderPath";
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsMKLProviderPath` or the default probing paths.
/// </summary>
public static string HintPath { get; set; }
/// <summary>
/// Use the Intel MKL native provider for linear algebra.
/// Throws if it is not available or failed to initialize, in which case the previous provider is still active.

41
src/Providers.MKL/SparseSolver/MklSparseSolverControl.cs

@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver
{
public class MklSparseSolverControl : IProviderCreator<ISparseSolverProvider>
{
const string EnvVarSSProviderPath = "MathNetNumericsSSProviderPath";
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsMKLProviderPath` or the default probing paths.
/// </summary>
public static string HintPath { get; set; }
public static ISparseSolverProvider CreateNativeMKL()
{
return new MklSparseSolverProvider(GetCombinedHintPath());
}
public static void UseNativeMKL()
{
SparseSolverControl.Provider = CreateNativeMKL();
}
public static bool TryUseNativeMKL()
{
return SparseSolverControl.TryUse(CreateNativeMKL());
}
public static ISparseSolverProvider CreateNativeMKL() => new MklSparseSolverProvider(GetCombinedHintPath());
public static void UseNativeMKL() => SparseSolverControl.Provider = CreateNativeMKL();
public static bool TryUseNativeMKL() => SparseSolverControl.TryUse(CreateNativeMKL());
static string GetCombinedHintPath()
{
if (!String.IsNullOrEmpty(HintPath))
if (!String.IsNullOrEmpty(MklControl.HintPath))
{
return HintPath;
return MklControl.HintPath;
}
if (!String.IsNullOrEmpty(SparseSolverControl.HintPath))
@ -76,18 +56,9 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver
return value;
}
value = Environment.GetEnvironmentVariable(EnvVarSSProviderPath);
if (!String.IsNullOrEmpty(value))
{
return value;
}
return null;
}
public ISparseSolverProvider CreateProvider()
{
return CreateNativeMKL();
}
public ISparseSolverProvider CreateProvider() => CreateNativeMKL();
}
}

41
src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraControl.cs

@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra
{
public class OpenBlasLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider>
{
const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath";
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsMKLProviderPath` or the default probing paths.
/// </summary>
public static string HintPath { get; set; }
public static ILinearAlgebraProvider CreateNativeOpenBLAS()
{
return new OpenBlasLinearAlgebraProvider(GetCombinedHintPath());
}
public static void UseNativeOpenBLAS()
{
LinearAlgebraControl.Provider = CreateNativeOpenBLAS();
}
public static bool TryUseNativeOpenBLAS()
{
return LinearAlgebraControl.TryUse(CreateNativeOpenBLAS());
}
public static ILinearAlgebraProvider CreateNativeOpenBLAS() => new OpenBlasLinearAlgebraProvider(GetCombinedHintPath());
public static void UseNativeOpenBLAS() => LinearAlgebraControl.Provider = CreateNativeOpenBLAS();
public static bool TryUseNativeOpenBLAS() => LinearAlgebraControl.TryUse(CreateNativeOpenBLAS());
static string GetCombinedHintPath()
{
if (!String.IsNullOrEmpty(HintPath))
if (!String.IsNullOrEmpty(OpenBlasControl.HintPath))
{
return HintPath;
return OpenBlasControl.HintPath;
}
if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath))
@ -76,18 +56,9 @@ namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra
return value;
}
value = Environment.GetEnvironmentVariable(EnvVarLAProviderPath);
if (!String.IsNullOrEmpty(value))
{
return value;
}
return null;
}
public ILinearAlgebraProvider CreateProvider()
{
return CreateNativeOpenBLAS();
}
public ILinearAlgebraProvider CreateProvider() => CreateNativeOpenBLAS();
}
}

18
src/Providers.OpenBLAS/OpenBlasControl.cs

@ -35,14 +35,18 @@ namespace MathNet.Numerics.Providers.OpenBLAS
{
internal const string EnvVarOpenBLASProviderPath = "MathNetNumericsOpenBLASProviderPath";
/// <summary>
/// Optional path to try to load native provider binaries from.
/// If not set, Numerics will fall back to the environment variable
/// `MathNetNumericsOpenBLASProviderPath` or the default probing paths.
/// </summary>
public static string HintPath { get; set; }
/// <summary>
/// Use the OpenBLAS native provider for linear algebra.
/// Throws if it is not available or failed to initialize, in which case the previous provider is still active.
/// </summary>
public static void UseNativeOpenBLAS()
{
OpenBlasLinearAlgebraControl.UseNativeOpenBLAS();
}
public static void UseNativeOpenBLAS() => OpenBlasLinearAlgebraControl.UseNativeOpenBLAS();
/// <summary>
/// Try to use the OpenBLAS native provider for linear algebra.
@ -51,10 +55,6 @@ namespace MathNet.Numerics.Providers.OpenBLAS
/// True if the provider was found and initialized successfully.
/// False if it failed and the previous provider is still active.
/// </returns>
public static bool TryUseNativeOpenBLAS()
{
bool linearAlgebra = OpenBlasLinearAlgebraControl.TryUseNativeOpenBLAS();
return linearAlgebra;
}
public static bool TryUseNativeOpenBLAS() => OpenBlasLinearAlgebraControl.TryUseNativeOpenBLAS();
}
}

Loading…
Cancel
Save