diff --git a/src/Benchmark/LinearAlgebra/DenseMatrixProduct.cs b/src/Benchmark/LinearAlgebra/DenseMatrixProduct.cs index 4d8caaaa..6acf56b3 100644 --- a/src/Benchmark/LinearAlgebra/DenseMatrixProduct.cs +++ b/src/Benchmark/LinearAlgebra/DenseMatrixProduct.cs @@ -1,22 +1,57 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using MathNet.Numerics; using MathNet.Numerics.LinearAlgebra; +using MathNet.Numerics.Providers.Common.Mkl; namespace Benchmark.LinearAlgebra { - - //BenchmarkRunner.Run(config); - //Benchmark(new DenseMatrixProduct(10,100), 100, "10 - 100x100 iterations"); - //Benchmark(new DenseMatrixProduct(25, 100), 100, "25 - 100x100 iterations"); - //Benchmark(new DenseMatrixProduct(50, 10), 100, "50 - 100x10 iterations"); - //Benchmark(new DenseMatrixProduct(100, 10), 100, "100 - 100x10 iterations"); - //Benchmark(new DenseMatrixProduct(250, 1), 10, "250 - 10x1 iterations"); - //Benchmark(new DenseMatrixProduct(500,1), 10, "500 - 10x1 iterations"); - //Benchmark(new DenseMatrixProduct(1000,1), 2, "1000 - 2x1 iterations"); - + [Config(typeof(Config))] public class DenseMatrixProduct { - readonly Dictionary> _data = new Dictionary>(); + class Config : ManualConfig + { + public Config() + { + Add( + new Job("CLR x64", RunMode.Default, EnvMode.RyuJitX64) + { + Env = { Runtime = Runtime.Clr, Platform = Platform.X64 } + }, + new Job("CLR x86", RunMode.Default, EnvMode.LegacyJitX86) + { + Env = { Runtime = Runtime.Clr, Platform = Platform.X86 } + }); +#if !NET461 + Add(new Job("Core RyuJit x64", RunMode.Default, EnvMode.RyuJitX64) + { + Env = { Runtime = Runtime.Core, Platform = Platform.X64 } + }); +#endif + } + } + + public enum ProviderId + { + Managed, + NativeMKLAutoHigh, + NativeMKLAutoLow, + NativeMKLAvx2High, + NativeMKLAvx2Low + } + + //BenchmarkRunner.Run(config); + //Benchmark(new DenseMatrixProduct(10, 100), 100, "10 - 100x100 iterations"); + //Benchmark(new DenseMatrixProduct(25, 100), 100, "25 - 100x100 iterations"); + //Benchmark(new DenseMatrixProduct(50, 10), 100, "50 - 100x10 iterations"); + //Benchmark(new DenseMatrixProduct(100, 10), 100, "100 - 100x10 iterations"); + //Benchmark(new DenseMatrixProduct(250, 1), 10, "250 - 10x1 iterations"); + //Benchmark(new DenseMatrixProduct(500,1), 10, "500 - 10x1 iterations"); + //Benchmark(new DenseMatrixProduct(1000,1), 2, "1000 - 2x1 iterations"); [Params(8, 64, 128)] public int M { get; set; } @@ -24,8 +59,10 @@ namespace Benchmark.LinearAlgebra [Params(8, 64, 128)] public int N { get; set; } - [Params(Provider.Managed, Provider.NativeMKLAutoHigh, Provider.NativeMKLAvx2High)] - public Provider Provider { get; set; } + [Params(ProviderId.Managed, ProviderId.NativeMKLAutoHigh, ProviderId.NativeMKLAvx2High)] + public ProviderId Provider { get; set; } + + readonly Dictionary> _data = new Dictionary>(); public DenseMatrixProduct() { @@ -45,7 +82,24 @@ namespace Benchmark.LinearAlgebra [GlobalSetup] public void Setup() { - Providers.ForceProvider(Provider); + switch (Provider) + { + case ProviderId.Managed: + Control.UseManaged(); + break; + case ProviderId.NativeMKLAutoHigh: + Control.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High); + break; + case ProviderId.NativeMKLAutoLow: + Control.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.Low); + break; + case ProviderId.NativeMKLAvx2High: + Control.UseNativeMKL(MklConsistency.AVX2, MklPrecision.Double, MklAccuracy.High); + break; + case ProviderId.NativeMKLAvx2Low: + Control.UseNativeMKL(MklConsistency.AVX2, MklPrecision.Double, MklAccuracy.Low); + break; + } } [Benchmark(OperationsPerInvoke = 1)] diff --git a/src/Benchmark/Program.cs b/src/Benchmark/Program.cs index 6d97bdc8..6d9d77fd 100644 --- a/src/Benchmark/Program.cs +++ b/src/Benchmark/Program.cs @@ -1,9 +1,6 @@ using System; -using System.Linq; using BenchmarkDotNet.Running; using MathNet.Numerics; -using MathNet.Numerics.Providers.FourierTransform; -using MathNet.Numerics.Providers.LinearAlgebra; namespace Benchmark { @@ -12,11 +9,6 @@ namespace Benchmark public static void Main(string[] args) { Console.WriteLine(Control.Describe()); - foreach (var provider in Enum.GetValues(typeof(Provider)).Cast()) - { - Providers.ForceProvider(provider); - Console.WriteLine($"{provider}: LA={LinearAlgebraControl.Provider}, FFT={FourierTransformControl.Provider}"); - } var switcher = new BenchmarkSwitcher( new[] diff --git a/src/Benchmark/Providers.cs b/src/Benchmark/Providers.cs deleted file mode 100644 index bf399a9e..00000000 --- a/src/Benchmark/Providers.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using MathNet.Numerics; -#if !NETCOREAPP1_1 -using MathNet.Numerics.Providers.Common.Mkl; -#endif - -namespace Benchmark -{ - public enum Provider : int - { - Managed = 0, - NativeMKLAutoHigh = 1, - NativeMKLAutoLow = 2, - NativeMKLAvx2High = 3, - NativeMKLAvx2Low = 4, - //NativeOpenBLAS = 5 - } - - public static class Providers - { - public static void ForceProvider(Provider provider) - { - switch (provider) - { - case Provider.Managed: - Control.UseManaged(); - break; - case Provider.NativeMKLAutoHigh: - Control.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High); - break; - case Provider.NativeMKLAutoLow: - Control.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.Low); - break; - case Provider.NativeMKLAvx2High: - Control.UseNativeMKL(MklConsistency.AVX2, MklPrecision.Double, MklAccuracy.High); - break; - case Provider.NativeMKLAvx2Low: - Control.UseNativeMKL(MklConsistency.AVX2, MklPrecision.Double, MklAccuracy.Low); - break; - //case Provider.NativeOpenBLAS: - // Control.UseNativeOpenBLAS(); - // break; - default: - throw new NotSupportedException($"Provider {provider} not supported."); - } - } - } -} diff --git a/src/Benchmark/Transforms/FFT.cs b/src/Benchmark/Transforms/FFT.cs index 570c9009..6b1b74e3 100644 --- a/src/Benchmark/Transforms/FFT.cs +++ b/src/Benchmark/Transforms/FFT.cs @@ -5,6 +5,7 @@ using BenchmarkDotNet.Environments; using BenchmarkDotNet.Jobs; using MathNet.Numerics; using MathNet.Numerics.IntegralTransforms; +using MathNet.Numerics.Providers.Common.Mkl; namespace Benchmark.Transforms { @@ -33,18 +34,33 @@ namespace Benchmark.Transforms } } + public enum ProviderId + { + Managed, + NativeMKL, + } + [Params(32, 128, 1024)] // 32, 64, 128, 1024, 8192, 65536 public int N { get; set; } - [Params(Provider.Managed, Provider.NativeMKLAutoHigh)] - public Provider Provider { get; set; } + [Params(ProviderId.Managed, ProviderId.NativeMKL)] + public ProviderId Provider { get; set; } Complex[] _data; [GlobalSetup] public void GlobalSetup() { - Providers.ForceProvider(Provider); + switch (Provider) + { + case ProviderId.Managed: + Control.UseManaged(); + break; + case ProviderId.NativeMKL: + Control.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High); + break; + } + var realSinusoidal = Generate.Sinusoidal(N, 32, -2.0, 2.0); var imagSawtooth = Generate.Sawtooth(N, 32, -20.0, 20.0); _data = Generate.Map2(realSinusoidal, imagSawtooth, (r, i) => new Complex(r, i));