8 changed files with 318 additions and 0 deletions
@ -0,0 +1,38 @@ |
|||
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00 |
|||
# Visual Studio 2013 |
|||
VisualStudioVersion = 12.0.30723.0 |
|||
MinimumVisualStudioVersion = 10.0.40219.1 |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Performance", "src\Performance\Performance.csproj", "{F2CA84AE-4B7C-46F5-9889-82BC5F9F0F4E}" |
|||
EndProject |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Numerics", "src\Numerics\Numerics.csproj", "{B7CAE5F4-A23F-4438-B5BE-41226618B695}" |
|||
EndProject |
|||
Global |
|||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|||
Debug|Any CPU = Debug|Any CPU |
|||
Release (No MKL)|Any CPU = Release (No MKL)|Any CPU |
|||
Release|Any CPU = Release|Any CPU |
|||
Release-Signed|Any CPU = Release-Signed|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|||
{F2CA84AE-4B7C-46F5-9889-82BC5F9F0F4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{F2CA84AE-4B7C-46F5-9889-82BC5F9F0F4E}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{F2CA84AE-4B7C-46F5-9889-82BC5F9F0F4E}.Release (No MKL)|Any CPU.ActiveCfg = Release (No MKL)|Any CPU |
|||
{F2CA84AE-4B7C-46F5-9889-82BC5F9F0F4E}.Release (No MKL)|Any CPU.Build.0 = Release (No MKL)|Any CPU |
|||
{F2CA84AE-4B7C-46F5-9889-82BC5F9F0F4E}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{F2CA84AE-4B7C-46F5-9889-82BC5F9F0F4E}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{F2CA84AE-4B7C-46F5-9889-82BC5F9F0F4E}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU |
|||
{F2CA84AE-4B7C-46F5-9889-82BC5F9F0F4E}.Release-Signed|Any CPU.Build.0 = Release|Any CPU |
|||
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release (No MKL)|Any CPU.ActiveCfg = Release|Any CPU |
|||
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release (No MKL)|Any CPU.Build.0 = Release|Any CPU |
|||
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release-Signed|Any CPU.ActiveCfg = Release-Signed|Any CPU |
|||
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release-Signed|Any CPU.Build.0 = Release-Signed|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(SolutionProperties) = preSolution |
|||
HideSolutionNode = FALSE |
|||
EndGlobalSection |
|||
EndGlobal |
|||
@ -0,0 +1,113 @@ |
|||
using System; |
|||
using Binarysharp.Benchmark; |
|||
using MathNet.Numerics; |
|||
using MathNet.Numerics.Providers.LinearAlgebra; |
|||
using MathNet.Numerics.Providers.LinearAlgebra.Mkl; |
|||
using MathNet.Numerics.Threading; |
|||
using MathNet.Numerics.LinearAlgebra; |
|||
using MathNet.Numerics.LinearAlgebra.Storage; |
|||
|
|||
namespace Performance.LinearAlgebra |
|||
{ |
|||
public class DenseVectorAdd |
|||
{ |
|||
readonly Vector<double> a; |
|||
readonly Vector<double> b; |
|||
|
|||
readonly ILinearAlgebraProvider managed = new ManagedLinearAlgebraProvider(); |
|||
readonly ILinearAlgebraProvider mkl = new MklLinearAlgebraProvider(); |
|||
|
|||
public DenseVectorAdd(int size) |
|||
{ |
|||
b = Vector<double>.Build.Random(size); |
|||
a = Vector<double>.Build.Random(size); |
|||
|
|||
managed.InitializeVerify(); |
|||
Control.LinearAlgebraProvider = managed; |
|||
|
|||
#if NATIVEMKL
|
|||
mkl.InitializeVerify(); |
|||
Console.WriteLine("MklProvider: {0}", mkl); |
|||
#endif
|
|||
} |
|||
|
|||
[BenchSharkTask("AddOperator")] |
|||
public Vector<double> AddOperator() |
|||
{ |
|||
return a + b; |
|||
} |
|||
|
|||
[BenchSharkTask("Map2")] |
|||
public Vector<double> Map2() |
|||
{ |
|||
return a.Map2((u, v) => u + v, b); |
|||
} |
|||
|
|||
[BenchSharkTask("Loop")] |
|||
public Vector<double> Loop() |
|||
{ |
|||
var aa = ((DenseVectorStorage<double>)a.Storage).Data; |
|||
var ab = ((DenseVectorStorage<double>)b.Storage).Data; |
|||
var ar = new Double[aa.Length]; |
|||
for (int i = 0; i < ar.Length; i++) |
|||
{ |
|||
ar[i] = aa[i] + ab[i]; |
|||
} |
|||
return Vector<double>.Build.Dense(ar); |
|||
} |
|||
|
|||
[BenchSharkTask("ParallelLoop4096")] |
|||
public Vector<double> ParallelLoop4096() |
|||
{ |
|||
var aa = ((DenseVectorStorage<double>)a.Storage).Data; |
|||
var ab = ((DenseVectorStorage<double>)b.Storage).Data; |
|||
var ar = new Double[aa.Length]; |
|||
CommonParallel.For(0, ar.Length, 4096, (u, v) => |
|||
{ |
|||
for (int i = u; i < v; i++) |
|||
{ |
|||
ar[i] = aa[i] + ab[i]; |
|||
} |
|||
}); |
|||
return Vector<double>.Build.Dense(ar); |
|||
} |
|||
|
|||
[BenchSharkTask("ParallelLoop32768")] |
|||
public Vector<double> ParallelLoop32768() |
|||
{ |
|||
var aa = ((DenseVectorStorage<double>)a.Storage).Data; |
|||
var ab = ((DenseVectorStorage<double>)b.Storage).Data; |
|||
var ar = new Double[aa.Length]; |
|||
CommonParallel.For(0, ar.Length, 32768*32, (u, v) => |
|||
{ |
|||
for (int i = u; i < v; i++) |
|||
{ |
|||
ar[i] = aa[i] + ab[i]; |
|||
} |
|||
}); |
|||
return Vector<double>.Build.Dense(ar); |
|||
} |
|||
|
|||
[BenchSharkTask("ManagedProvider")] |
|||
public Vector<double> ManagedProvider() |
|||
{ |
|||
var aa = ((DenseVectorStorage<double>)a.Storage).Data; |
|||
var ab = ((DenseVectorStorage<double>)b.Storage).Data; |
|||
var ar = new Double[aa.Length]; |
|||
managed.AddArrays(aa, ab, ar); |
|||
return Vector<double>.Build.Dense(ar); |
|||
} |
|||
|
|||
#if NATIVEMKL
|
|||
[BenchSharkTask("MklProvider")] |
|||
public Vector<double> MklProvider() |
|||
{ |
|||
var aa = ((DenseVectorStorage<double>)a.Storage).Data; |
|||
var ab = ((DenseVectorStorage<double>)b.Storage).Data; |
|||
var ar = new Double[aa.Length]; |
|||
mkl.AddArrays(aa, ab, ar); |
|||
return Vector<double>.Build.Dense(ar); |
|||
} |
|||
#endif
|
|||
} |
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{F2CA84AE-4B7C-46F5-9889-82BC5F9F0F4E}</ProjectGuid> |
|||
<OutputType>Exe</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Performance</RootNamespace> |
|||
<AssemblyName>Performance</AssemblyName> |
|||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE;NATIVEMKL</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
<PlatformTarget>x64</PlatformTarget> |
|||
</PropertyGroup> |
|||
<PropertyGroup> |
|||
<StartupObject /> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release %28No MKL%29|AnyCPU'"> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<Optimize>true</Optimize> |
|||
<DebugType>pdbonly</DebugType> |
|||
<PlatformTarget>x64</PlatformTarget> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="Benchmark"> |
|||
<HintPath>..\..\packages\BenchShark.1.0.0\lib\Benchmark.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="ConsoleDump"> |
|||
<HintPath>..\..\packages\ConsoleDump.0.6.0.1\lib\net40-Client\ConsoleDump.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Numerics" /> |
|||
<Reference Include="System.Xml.Linq" /> |
|||
<Reference Include="System.Data.DataSetExtensions" /> |
|||
<Reference Include="Microsoft.CSharp" /> |
|||
<Reference Include="System.Data" /> |
|||
<Reference Include="System.Xml" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="LinearAlgebra\DenseVectorAdd.cs" /> |
|||
<Compile Include="Program.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="packages.config" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Numerics\Numerics.csproj"> |
|||
<Project>{b7cae5f4-a23f-4438-b5be-41226618b695}</Project> |
|||
<Name>Numerics</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Content Include="..\..\out\MKL\Windows\x64\libiomp5md.dll"> |
|||
<Link>libiomp5md.dll</Link> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
<Content Include="..\..\out\MKL\Windows\x64\MathNet.Numerics.MKL.dll"> |
|||
<Link>MathNet.Numerics.MKL.dll</Link> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,31 @@ |
|||
using System.Linq; |
|||
using Binarysharp.Benchmark; |
|||
using ConsoleDump; |
|||
|
|||
namespace Performance |
|||
{ |
|||
public class Program |
|||
{ |
|||
public static void Main() |
|||
{ |
|||
Run(new LinearAlgebra.DenseVectorAdd(10000000), 10, "Large"); |
|||
Run(new LinearAlgebra.DenseVectorAdd(100), 10000, "Small"); |
|||
} |
|||
|
|||
static void Run<T>(uint iterations, string suffix = null) where T:new() |
|||
{ |
|||
var bench = new BenchShark(); |
|||
var result = bench.EvaluateDecoratedTasks<T>(iterations); |
|||
var label = string.IsNullOrEmpty(suffix) ? typeof (T).FullName : string.Concat(typeof (T).FullName, ": ", suffix); |
|||
result.FastestEvaluations.Select(x => new { x.Name, x.BestExecutionTime, x.AverageExecutionTime, x.WorstExecutionTime, x.TotalExecutionTime }).Dump(label); |
|||
} |
|||
|
|||
static void Run(object obj, uint iterations, string suffix = null) |
|||
{ |
|||
var bench = new BenchShark(); |
|||
var result = bench.EvaluateDecoratedTasks(obj, iterations); |
|||
var label = string.IsNullOrEmpty(suffix) ? obj.GetType().FullName : string.Concat(obj.GetType().FullName, ": ", suffix); |
|||
result.FastestEvaluations.Select(x => new { x.Name, x.BestExecutionTime, x.AverageExecutionTime, x.WorstExecutionTime, x.TotalExecutionTime }).Dump(label); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("Performance")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Performance")] |
|||
[assembly: AssemblyCopyright("Copyright © 2014")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible
|
|||
// to COM components. If you need to access a type in this assembly from
|
|||
// COM, set the ComVisible attribute to true on that type.
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|||
[assembly: Guid("180a3fd6-72b4-48ac-99d0-c2a590b6834a")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
@ -0,0 +1,5 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="BenchShark" version="1.0.0" targetFramework="net45" /> |
|||
<package id="ConsoleDump" version="0.6.0.1" targetFramework="net45" /> |
|||
</packages> |
|||
Loading…
Reference in new issue