Browse Source

LA: clone managed provider to ManagedReference as benchmark reference

spatial
Christoph Ruegg 9 years ago
parent
commit
f9e4312c6d
  1. 62
      src/Benchmark/LinearAlgebra/DenseVectorAdd.cs
  2. 26
      src/Benchmark/Transforms/FFT.cs
  3. 6
      src/Numerics/Control.cs
  4. 10
      src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs
  5. 2952
      src/Numerics/Providers/LinearAlgebra/ManagedReference/ManagedReferenceLinearAlgebraProvider.Complex.cs
  6. 2955
      src/Numerics/Providers/LinearAlgebra/ManagedReference/ManagedReferenceLinearAlgebraProvider.Complex32.cs
  7. 2859
      src/Numerics/Providers/LinearAlgebra/ManagedReference/ManagedReferenceLinearAlgebraProvider.Double.cs
  8. 2864
      src/Numerics/Providers/LinearAlgebra/ManagedReference/ManagedReferenceLinearAlgebraProvider.Single.cs
  9. 122
      src/Numerics/Providers/LinearAlgebra/ManagedReference/ManagedReferenceLinearAlgebraProvider.cs

62
src/Benchmark/LinearAlgebra/DenseVectorAdd.cs

@ -16,20 +16,20 @@ namespace Benchmark.LinearAlgebra
{
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("CLR x64", RunMode.Default, EnvMode.RyuJitX64)
{
Env = { Runtime = Runtime.Clr, Platform = Platform.X64 }
});
#if NET461
Add(new Job("CLR x86", RunMode.Default, EnvMode.LegacyJitX86)
{
Env = { Runtime = Runtime.Clr, Platform = Platform.X86 }
});
#else
Add(new Job("Core RyuJit x64", RunMode.Default, EnvMode.RyuJitX64)
{
Env = { Runtime = Runtime.Core, Platform = Platform.X64 }
});
{
Env = { Runtime = Runtime.Core, Platform = Platform.X64 }
});
#endif
}
}
@ -37,13 +37,14 @@ namespace Benchmark.LinearAlgebra
public enum ProviderId
{
Managed,
ManagedReference,
NativeMKL,
}
[Params(4, 32, 128, 4096, 524288)]
public int N { get; set; }
[Params(ProviderId.Managed, ProviderId.NativeMKL)]
[Params(ProviderId.Managed, ProviderId.ManagedReference, ProviderId.NativeMKL)]
public ProviderId Provider { get; set; }
//const int Rounds = 1024;
@ -61,6 +62,9 @@ namespace Benchmark.LinearAlgebra
case ProviderId.Managed:
Control.UseManaged();
break;
case ProviderId.ManagedReference:
Control.UseManagedReference();
break;
case ProviderId.NativeMKL:
Control.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High);
break;
@ -72,17 +76,17 @@ namespace Benchmark.LinearAlgebra
_bv = Vector<double>.Build.Dense(_b);
}
[Benchmark(OperationsPerInvoke = 1, Baseline = true)]
public double[] ForLoop()
{
double[] r = new double[_a.Length];
for (int i = 0; i < r.Length; i++)
{
r[i] = _a[i] + _b[i];
}
//[Benchmark(OperationsPerInvoke = 1, Baseline = true)]
//public double[] ForLoop()
//{
// double[] r = new double[_a.Length];
// for (int i = 0; i < r.Length; i++)
// {
// r[i] = _a[i] + _b[i];
// }
return r;
}
// return r;
//}
[Benchmark(OperationsPerInvoke = 1)]
public double[] ProviderAddArrays()
@ -92,10 +96,10 @@ namespace Benchmark.LinearAlgebra
return r;
}
[Benchmark(OperationsPerInvoke = 1)]
public Vector<double> VectorAddOp()
{
return _av + _bv;
}
//[Benchmark(OperationsPerInvoke = 1)]
//public Vector<double> VectorAddOp()
//{
// return _av + _bv;
//}
}
}

26
src/Benchmark/Transforms/FFT.cs

@ -16,20 +16,20 @@ namespace Benchmark.Transforms
{
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("CLR x64", RunMode.Default, EnvMode.RyuJitX64)
{
Env = { Runtime = Runtime.Clr, Platform = Platform.X64 }
});
#if NET461
Add(new Job("CLR x86", RunMode.Default, EnvMode.LegacyJitX86)
{
Env = { Runtime = Runtime.Clr, Platform = Platform.X86 }
});
#else
Add(new Job("Core RyuJit x64", RunMode.Default, EnvMode.RyuJitX64)
{
Env = { Runtime = Runtime.Core, Platform = Platform.X64 }
});
{
Env = { Runtime = Runtime.Core, Platform = Platform.X64 }
});
#endif
}
}

6
src/Numerics/Control.cs

@ -72,6 +72,12 @@ namespace MathNet.Numerics
FourierTransformControl.UseManaged();
}
public static void UseManagedReference()
{
LinearAlgebraControl.UseManagedReference();
FourierTransformControl.UseManaged();
}
/// <summary>
/// Use a specific provider if configured, e.g. using
/// environment variables, or fall back to the best providers.

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

@ -88,6 +88,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
Provider = CreateManaged();
}
internal static ILinearAlgebraProvider CreateManagedReference()
{
return new ManagedReference.ManagedReferenceLinearAlgebraProvider();
}
internal static void UseManagedReference()
{
Provider = CreateManagedReference();
}
#if NATIVE
[CLSCompliant(false)]
public static ILinearAlgebraProvider CreateNativeMKL(

2952
src/Numerics/Providers/LinearAlgebra/ManagedReference/ManagedReferenceLinearAlgebraProvider.Complex.cs

File diff suppressed because it is too large

2955
src/Numerics/Providers/LinearAlgebra/ManagedReference/ManagedReferenceLinearAlgebraProvider.Complex32.cs

File diff suppressed because it is too large

2859
src/Numerics/Providers/LinearAlgebra/ManagedReference/ManagedReferenceLinearAlgebraProvider.Double.cs

File diff suppressed because it is too large

2864
src/Numerics/Providers/LinearAlgebra/ManagedReference/ManagedReferenceLinearAlgebraProvider.Single.cs

File diff suppressed because it is too large

122
src/Numerics/Providers/LinearAlgebra/ManagedReference/ManagedReferenceLinearAlgebraProvider.cs

@ -0,0 +1,122 @@
// <copyright file="ManagedReferenceLinearAlgebraProvider.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
namespace MathNet.Numerics.Providers.LinearAlgebra.ManagedReference
{
internal enum Variation
{
Original,
Experimental
}
/// <summary>
/// The managed linear algebra provider.
/// </summary>
internal partial class ManagedReferenceLinearAlgebraProvider : ILinearAlgebraProvider
{
private readonly Variation _variation;
internal ManagedReferenceLinearAlgebraProvider()
{
_variation = Variation.Experimental;
}
internal ManagedReferenceLinearAlgebraProvider(Variation variation)
{
_variation = variation;
}
/// <summary>
/// Try to find out whether the provider is available, at least in principle.
/// Verification may still fail if available, but it will certainly fail if unavailable.
/// </summary>
public virtual bool IsAvailable()
{
return true;
}
/// <summary>
/// Initialize and verify that the provided is indeed available. If not, fall back to alternatives like the managed provider
/// </summary>
public virtual void InitializeVerify()
{
}
/// <summary>
/// Frees memory buffers, caches and handles allocated in or to the provider.
/// Does not unload the provider itself, it is still usable afterwards.
/// </summary>
public virtual void FreeResources()
{
}
public override string ToString()
{
return "Managed";
}
/// <summary>
/// Assumes that <paramref name="numRows"/> and <paramref name="numCols"/> have already been transposed.
/// </summary>
protected static void GetRow<T>(Transpose transpose, int rowindx, int numRows, int numCols, T[] matrix, T[] row)
{
if (transpose == Transpose.DontTranspose)
{
for (int i = 0; i < numCols; i++)
{
row[i] = matrix[(i * numRows) + rowindx];
}
}
else
{
Array.Copy(matrix, rowindx * numCols, row, 0, numCols);
}
}
/// <summary>
/// Assumes that <paramref name="numRows"/> and <paramref name="numCols"/> have already been transposed.
/// </summary>
protected static void GetColumn<T>(Transpose transpose, int colindx, int numRows, int numCols, T[] matrix, T[] column)
{
if (transpose == Transpose.DontTranspose)
{
Array.Copy(matrix, colindx * numRows, column, 0, numRows);
}
else
{
for (int i = 0; i < numRows; i++)
{
column[i] = matrix[(i * numCols) + colindx];
}
}
}
}
}
Loading…
Cancel
Save