Browse Source

Move HintPaths to MklControl/CudaControl/OpenBlasControl

dependabot/nuget/NUnit3TestAdapter-4.2.0
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); static readonly ProviderProbe<IFourierTransformProvider> MklProbe = new ProviderProbe<IFourierTransformProvider>(MklTypeName, AppSwitches.DisableMklNativeProvider);
/// <summary> /// <summary>
/// Optional path to try to load native provider binaries from. /// Optional path to try to load native provider binaries from,
/// If not set, Numerics will fall back to the environment variable /// if the provider specific hint path is not set.
/// `MathNetNumericsFFTProviderPath` or the default probing paths. /// If neither is set, Numerics falls back to the provider specific
/// environment variables, or the default probing paths.
/// </summary> /// </summary>
public static string HintPath { get; set; } 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); static readonly ProviderProbe<ILinearAlgebraProvider> CudaProbe = new ProviderProbe<ILinearAlgebraProvider>(CudaTypeName, AppSwitches.DisableCudaNativeProvider);
/// <summary> /// <summary>
/// Optional path to try to load native provider binaries from. /// Optional path to try to load native provider binaries from,
/// If not set, Numerics will fall back to the environment variable /// if the provider specific hint path is not set.
/// `MathNetNumericsLAProviderPath` or the default probing paths. /// If neither is set, Numerics falls back to the provider specific
/// environment variables, or the default probing paths.
/// </summary> /// </summary>
public static string HintPath { get; set; } 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); static readonly ProviderProbe<ISparseSolverProvider> MklProbe = new ProviderProbe<ISparseSolverProvider>(MklTypeName, AppSwitches.DisableMklNativeProvider);
/// <summary> /// <summary>
/// Optional path to try to load native provider binaries from. /// Optional path to try to load native provider binaries from,
/// If not set, Numerics will fall back to the environment variable /// if the provider specific hint path is not set.
/// `MathNetNumericsSSProviderPath` or the default probing paths. /// If neither is set, Numerics falls back to the provider specific
/// environment variables, or the default probing paths.
/// </summary> /// </summary>
public static string HintPath { get; set; } 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"; 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> /// <summary>
/// Use the OpenBLAS native provider for linear algebra. /// 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. /// Throws if it is not available or failed to initialize, in which case the previous provider is still active.
/// </summary> /// </summary>
public static void UseNativeCUDA() public static void UseNativeCUDA() => CudaLinearAlgebraControl.UseNativeCUDA();
{
CudaLinearAlgebraControl.UseNativeCUDA();
}
/// <summary> /// <summary>
/// Try to use the OpenBLAS native provider for linear algebra. /// 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. /// True if the provider was found and initialized successfully.
/// False if it failed and the previous provider is still active. /// False if it failed and the previous provider is still active.
/// </returns> /// </returns>
public static bool TryUseNativeCUDA() public static bool TryUseNativeCUDA() => CudaLinearAlgebraControl.TryUseNativeCUDA();
{
bool linearAlgebra = CudaLinearAlgebraControl.TryUseNativeCUDA();
return linearAlgebra;
}
} }
} }

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

@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra
{ {
public class CudaLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider> public class CudaLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider>
{ {
const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath"; public static ILinearAlgebraProvider CreateNativeCUDA() => new CudaLinearAlgebraProvider(GetCombinedHintPath());
public static void UseNativeCUDA() => LinearAlgebraControl.Provider = CreateNativeCUDA();
/// <summary> public static bool TryUseNativeCUDA() => LinearAlgebraControl.TryUse(CreateNativeCUDA());
/// 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());
}
static string GetCombinedHintPath() static string GetCombinedHintPath()
{ {
if (!String.IsNullOrEmpty(HintPath)) if (!String.IsNullOrEmpty(CudaControl.HintPath))
{ {
return HintPath; return CudaControl.HintPath;
} }
if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath)) if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath))
@ -76,18 +56,9 @@ namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra
return value; return value;
} }
value = Environment.GetEnvironmentVariable(EnvVarLAProviderPath);
if (!String.IsNullOrEmpty(value))
{
return value;
}
return null; return null;
} }
public ILinearAlgebraProvider CreateProvider() public ILinearAlgebraProvider CreateProvider() => CreateNativeCUDA();
{
return CreateNativeCUDA();
}
} }
} }

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

@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
{ {
public class MklFourierTransformControl : IProviderCreator<IFourierTransformProvider> public class MklFourierTransformControl : IProviderCreator<IFourierTransformProvider>
{ {
const string EnvVarFFTProviderPath = "MathNetNumericsFFTProviderPath"; public static IFourierTransformProvider CreateNativeMKL() => new MklFourierTransformProvider(GetCombinedHintPath());
public static void UseNativeMKL() => FourierTransformControl.Provider = CreateNativeMKL();
/// <summary> public static bool TryUseNativeMKL() => FourierTransformControl.TryUse(CreateNativeMKL());
/// 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());
}
static string GetCombinedHintPath() static string GetCombinedHintPath()
{ {
if (!String.IsNullOrEmpty(HintPath)) if (!String.IsNullOrEmpty(MklControl.HintPath))
{ {
return HintPath; return MklControl.HintPath;
} }
if (!String.IsNullOrEmpty(FourierTransformControl.HintPath)) if (!String.IsNullOrEmpty(FourierTransformControl.HintPath))
@ -76,18 +56,9 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
return value; return value;
} }
value = Environment.GetEnvironmentVariable(EnvVarFFTProviderPath);
if (!String.IsNullOrEmpty(value))
{
return value;
}
return null; return null;
} }
public IFourierTransformProvider CreateProvider() public IFourierTransformProvider CreateProvider() => CreateNativeMKL();
{
return CreateNativeMKL();
}
} }
} }

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

@ -34,15 +34,6 @@ namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
{ {
public class MklLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider> 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( public static ILinearAlgebraProvider CreateNativeMKL(
MklConsistency consistency = MklConsistency.Auto, MklConsistency consistency = MklConsistency.Auto,
MklPrecision precision = MklPrecision.Double, MklPrecision precision = MklPrecision.Double,
@ -69,9 +60,9 @@ namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
static string GetCombinedHintPath() static string GetCombinedHintPath()
{ {
if (!String.IsNullOrEmpty(HintPath)) if (!String.IsNullOrEmpty(MklControl.HintPath))
{ {
return HintPath; return MklControl.HintPath;
} }
if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath)) if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath))
@ -85,18 +76,9 @@ namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
return value; return value;
} }
value = Environment.GetEnvironmentVariable(EnvVarLAProviderPath);
if (!String.IsNullOrEmpty(value))
{
return value;
}
return null; return null;
} }
public ILinearAlgebraProvider CreateProvider() public ILinearAlgebraProvider CreateProvider() => CreateNativeMKL();
{
return CreateNativeMKL();
}
} }
} }

7
src/Providers.MKL/MklControl.cs

@ -37,6 +37,13 @@ namespace MathNet.Numerics.Providers.MKL
{ {
internal const string EnvVarMKLProviderPath = "MathNetNumericsMKLProviderPath"; 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> /// <summary>
/// Use the Intel MKL native provider for linear algebra. /// 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. /// 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> public class MklSparseSolverControl : IProviderCreator<ISparseSolverProvider>
{ {
const string EnvVarSSProviderPath = "MathNetNumericsSSProviderPath"; public static ISparseSolverProvider CreateNativeMKL() => new MklSparseSolverProvider(GetCombinedHintPath());
public static void UseNativeMKL() => SparseSolverControl.Provider = CreateNativeMKL();
/// <summary> public static bool TryUseNativeMKL() => SparseSolverControl.TryUse(CreateNativeMKL());
/// 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());
}
static string GetCombinedHintPath() static string GetCombinedHintPath()
{ {
if (!String.IsNullOrEmpty(HintPath)) if (!String.IsNullOrEmpty(MklControl.HintPath))
{ {
return HintPath; return MklControl.HintPath;
} }
if (!String.IsNullOrEmpty(SparseSolverControl.HintPath)) if (!String.IsNullOrEmpty(SparseSolverControl.HintPath))
@ -76,18 +56,9 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver
return value; return value;
} }
value = Environment.GetEnvironmentVariable(EnvVarSSProviderPath);
if (!String.IsNullOrEmpty(value))
{
return value;
}
return null; return null;
} }
public ISparseSolverProvider CreateProvider() public ISparseSolverProvider CreateProvider() => CreateNativeMKL();
{
return CreateNativeMKL();
}
} }
} }

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

@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra
{ {
public class OpenBlasLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider> public class OpenBlasLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider>
{ {
const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath"; public static ILinearAlgebraProvider CreateNativeOpenBLAS() => new OpenBlasLinearAlgebraProvider(GetCombinedHintPath());
public static void UseNativeOpenBLAS() => LinearAlgebraControl.Provider = CreateNativeOpenBLAS();
/// <summary> public static bool TryUseNativeOpenBLAS() => LinearAlgebraControl.TryUse(CreateNativeOpenBLAS());
/// 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());
}
static string GetCombinedHintPath() static string GetCombinedHintPath()
{ {
if (!String.IsNullOrEmpty(HintPath)) if (!String.IsNullOrEmpty(OpenBlasControl.HintPath))
{ {
return HintPath; return OpenBlasControl.HintPath;
} }
if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath)) if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath))
@ -76,18 +56,9 @@ namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra
return value; return value;
} }
value = Environment.GetEnvironmentVariable(EnvVarLAProviderPath);
if (!String.IsNullOrEmpty(value))
{
return value;
}
return null; return null;
} }
public ILinearAlgebraProvider CreateProvider() public ILinearAlgebraProvider CreateProvider() => CreateNativeOpenBLAS();
{
return CreateNativeOpenBLAS();
}
} }
} }

18
src/Providers.OpenBLAS/OpenBlasControl.cs

@ -35,14 +35,18 @@ namespace MathNet.Numerics.Providers.OpenBLAS
{ {
internal const string EnvVarOpenBLASProviderPath = "MathNetNumericsOpenBLASProviderPath"; 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> /// <summary>
/// Use the OpenBLAS native provider for linear algebra. /// 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. /// Throws if it is not available or failed to initialize, in which case the previous provider is still active.
/// </summary> /// </summary>
public static void UseNativeOpenBLAS() public static void UseNativeOpenBLAS() => OpenBlasLinearAlgebraControl.UseNativeOpenBLAS();
{
OpenBlasLinearAlgebraControl.UseNativeOpenBLAS();
}
/// <summary> /// <summary>
/// Try to use the OpenBLAS native provider for linear algebra. /// 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. /// True if the provider was found and initialized successfully.
/// False if it failed and the previous provider is still active. /// False if it failed and the previous provider is still active.
/// </returns> /// </returns>
public static bool TryUseNativeOpenBLAS() public static bool TryUseNativeOpenBLAS() => OpenBlasLinearAlgebraControl.TryUseNativeOpenBLAS();
{
bool linearAlgebra = OpenBlasLinearAlgebraControl.TryUseNativeOpenBLAS();
return linearAlgebra;
}
} }
} }

Loading…
Cancel
Save