Browse Source

Benchmark: simplify, no longer use shared provider management

spatial
Christoph Ruegg 9 years ago
parent
commit
0aa3b551a4
  1. 84
      src/Benchmark/LinearAlgebra/DenseMatrixProduct.cs
  2. 8
      src/Benchmark/Program.cs
  3. 48
      src/Benchmark/Providers.cs
  4. 22
      src/Benchmark/Transforms/FFT.cs

84
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<LinearAlgebra.DenseMatrixProduct>(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<string, Matrix<double>> _data = new Dictionary<string, Matrix<double>>();
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<LinearAlgebra.DenseMatrixProduct>(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<string, Matrix<double>> _data = new Dictionary<string, Matrix<double>>();
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)]

8
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<Provider>())
{
Providers.ForceProvider(provider);
Console.WriteLine($"{provider}: LA={LinearAlgebraControl.Provider}, FFT={FourierTransformControl.Provider}");
}
var switcher = new BenchmarkSwitcher(
new[]

48
src/Benchmark/Providers.cs

@ -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.");
}
}
}
}

22
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));

Loading…
Cancel
Save