From ae7598d261087f2435795f6484c07ec561b9967f Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 16 May 2021 21:31:22 +0200 Subject: [PATCH] Move HintPaths to MklControl/CudaControl/OpenBlasControl --- .../FourierTransformControl.cs | 7 ++-- .../LinearAlgebra/LinearAlgebraControl.cs | 7 ++-- .../SparseSolver/SparseSolverControl.cs | 7 ++-- src/Providers.CUDA/CudaControl.cs | 18 ++++---- .../LinearAlgebra/CudaLinearAlgebraControl.cs | 41 +++---------------- .../MklFourierTransformControl.cs | 41 +++---------------- .../LinearAlgebra/MklLinearAlgebraControl.cs | 24 ++--------- src/Providers.MKL/MklControl.cs | 7 ++++ .../SparseSolver/MklSparseSolverControl.cs | 41 +++---------------- .../OpenBlasLinearAlgebraControl.cs | 41 +++---------------- src/Providers.OpenBLAS/OpenBlasControl.cs | 18 ++++---- 11 files changed, 64 insertions(+), 188 deletions(-) diff --git a/src/Numerics/Providers/FourierTransform/FourierTransformControl.cs b/src/Numerics/Providers/FourierTransform/FourierTransformControl.cs index 5d1e18fb..4d278caf 100644 --- a/src/Numerics/Providers/FourierTransform/FourierTransformControl.cs +++ b/src/Numerics/Providers/FourierTransform/FourierTransformControl.cs @@ -42,9 +42,10 @@ namespace MathNet.Numerics.Providers.FourierTransform static readonly ProviderProbe MklProbe = new ProviderProbe(MklTypeName, AppSwitches.DisableMklNativeProvider); /// - /// 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. /// public static string HintPath { get; set; } diff --git a/src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs b/src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs index c30b583a..d0c67068 100644 --- a/src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs +++ b/src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs @@ -48,9 +48,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra static readonly ProviderProbe CudaProbe = new ProviderProbe(CudaTypeName, AppSwitches.DisableCudaNativeProvider); /// - /// 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. /// public static string HintPath { get; set; } diff --git a/src/Numerics/Providers/SparseSolver/SparseSolverControl.cs b/src/Numerics/Providers/SparseSolver/SparseSolverControl.cs index e36aba2a..b1e5c32e 100644 --- a/src/Numerics/Providers/SparseSolver/SparseSolverControl.cs +++ b/src/Numerics/Providers/SparseSolver/SparseSolverControl.cs @@ -42,9 +42,10 @@ namespace MathNet.Numerics.Providers.SparseSolver static readonly ProviderProbe MklProbe = new ProviderProbe(MklTypeName, AppSwitches.DisableMklNativeProvider); /// - /// 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. /// public static string HintPath { get; set; } diff --git a/src/Providers.CUDA/CudaControl.cs b/src/Providers.CUDA/CudaControl.cs index 9f98b7d9..8fa1ddc8 100644 --- a/src/Providers.CUDA/CudaControl.cs +++ b/src/Providers.CUDA/CudaControl.cs @@ -35,14 +35,18 @@ namespace MathNet.Numerics.Providers.CUDA { internal const string EnvVarCUDAProviderPath = "MathNetNumericsCUDAProviderPath"; + /// + /// 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. + /// + public static string HintPath { get; set; } + /// /// 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. /// - public static void UseNativeCUDA() - { - CudaLinearAlgebraControl.UseNativeCUDA(); - } + public static void UseNativeCUDA() => CudaLinearAlgebraControl.UseNativeCUDA(); /// /// 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. /// - public static bool TryUseNativeCUDA() - { - bool linearAlgebra = CudaLinearAlgebraControl.TryUseNativeCUDA(); - return linearAlgebra; - } + public static bool TryUseNativeCUDA() => CudaLinearAlgebraControl.TryUseNativeCUDA(); } } diff --git a/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraControl.cs b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraControl.cs index 43b008d2..36077a80 100644 --- a/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraControl.cs +++ b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraControl.cs @@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra { public class CudaLinearAlgebraControl : IProviderCreator { - const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath"; - - /// - /// 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. - /// - 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(); } } diff --git a/src/Providers.MKL/FourierTransform/MklFourierTransformControl.cs b/src/Providers.MKL/FourierTransform/MklFourierTransformControl.cs index 216ead6b..f8ad14ce 100644 --- a/src/Providers.MKL/FourierTransform/MklFourierTransformControl.cs +++ b/src/Providers.MKL/FourierTransform/MklFourierTransformControl.cs @@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform { public class MklFourierTransformControl : IProviderCreator { - const string EnvVarFFTProviderPath = "MathNetNumericsFFTProviderPath"; - - /// - /// 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. - /// - 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(); } } diff --git a/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraControl.cs b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraControl.cs index ba473a11..83828ed4 100644 --- a/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraControl.cs +++ b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraControl.cs @@ -34,15 +34,6 @@ namespace MathNet.Numerics.Providers.MKL.LinearAlgebra { public class MklLinearAlgebraControl : IProviderCreator { - const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath"; - - /// - /// 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. - /// - 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(); } } diff --git a/src/Providers.MKL/MklControl.cs b/src/Providers.MKL/MklControl.cs index a6a2023c..0a4c8791 100644 --- a/src/Providers.MKL/MklControl.cs +++ b/src/Providers.MKL/MklControl.cs @@ -37,6 +37,13 @@ namespace MathNet.Numerics.Providers.MKL { internal const string EnvVarMKLProviderPath = "MathNetNumericsMKLProviderPath"; + /// + /// 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. + /// + public static string HintPath { get; set; } + /// /// 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. diff --git a/src/Providers.MKL/SparseSolver/MklSparseSolverControl.cs b/src/Providers.MKL/SparseSolver/MklSparseSolverControl.cs index 0e06b00c..a3c28caf 100644 --- a/src/Providers.MKL/SparseSolver/MklSparseSolverControl.cs +++ b/src/Providers.MKL/SparseSolver/MklSparseSolverControl.cs @@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver { public class MklSparseSolverControl : IProviderCreator { - const string EnvVarSSProviderPath = "MathNetNumericsSSProviderPath"; - - /// - /// 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. - /// - 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(); } } diff --git a/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraControl.cs b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraControl.cs index b22b6355..4e47aa84 100644 --- a/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraControl.cs +++ b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraControl.cs @@ -34,35 +34,15 @@ namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra { public class OpenBlasLinearAlgebraControl : IProviderCreator { - const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath"; - - /// - /// 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. - /// - 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(); } } diff --git a/src/Providers.OpenBLAS/OpenBlasControl.cs b/src/Providers.OpenBLAS/OpenBlasControl.cs index c2b7add5..0726037b 100644 --- a/src/Providers.OpenBLAS/OpenBlasControl.cs +++ b/src/Providers.OpenBLAS/OpenBlasControl.cs @@ -35,14 +35,18 @@ namespace MathNet.Numerics.Providers.OpenBLAS { internal const string EnvVarOpenBLASProviderPath = "MathNetNumericsOpenBLASProviderPath"; + /// + /// 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. + /// + public static string HintPath { get; set; } + /// /// 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. /// - public static void UseNativeOpenBLAS() - { - OpenBlasLinearAlgebraControl.UseNativeOpenBLAS(); - } + public static void UseNativeOpenBLAS() => OpenBlasLinearAlgebraControl.UseNativeOpenBLAS(); /// /// 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. /// - public static bool TryUseNativeOpenBLAS() - { - bool linearAlgebra = OpenBlasLinearAlgebraControl.TryUseNativeOpenBLAS(); - return linearAlgebra; - } + public static bool TryUseNativeOpenBLAS() => OpenBlasLinearAlgebraControl.TryUseNativeOpenBLAS(); } }