-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
727 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...umerics.Benchmarks/TensorAddBenchmarks.cs → ...erics.Tensors.Benchmarks/AddBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...cs.Benchmarks/TensorAddValueBenchmarks.cs → ....Tensors.Benchmarks/AddValueBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/NetFabric.Numerics.Tensors.Benchmarks/NetFabric.Numerics.Tensors.Benchmarks.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
<RootNamespace>NetFabric.Numerics.Tensors.Benchmarks</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\NetFabric.Numerics.Tensors\NetFabric.Numerics.Tensors.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using BenchmarkDotNet.Columns; | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Reports; | ||
using BenchmarkDotNet.Running; | ||
using System.Runtime.Intrinsics; | ||
|
||
var config = DefaultConfig.Instance | ||
.WithSummaryStyle(SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend)) | ||
.HideColumns(Column.EnvironmentVariables, Column.RatioSD, Column.Error) | ||
// .AddDiagnoser(new DisassemblyDiagnoser(new DisassemblyDiagnoserConfig | ||
// (exportGithubMarkdown: true, printInstructionAddresses: false))) | ||
.AddJob(Job.Default.WithId("Scalar") | ||
.WithEnvironmentVariable("DOTNET_EnableHWIntrinsic", "0") | ||
.AsBaseline()); | ||
|
||
if (Vector128.IsHardwareAccelerated) | ||
{ | ||
config = config | ||
.AddJob(Job.Default.WithId("Vector128") | ||
.WithEnvironmentVariable("DOTNET_EnableAVX2", "0") | ||
.WithEnvironmentVariable("DOTNET_EnableAVX512F", "0")); | ||
} | ||
if (Vector256.IsHardwareAccelerated) | ||
{ | ||
config = config | ||
.AddJob(Job.Default.WithId("Vector256") | ||
.WithEnvironmentVariable("DOTNET_EnableAVX512F", "0")); | ||
} | ||
if (Vector512.IsHardwareAccelerated) | ||
{ | ||
config = config | ||
.AddJob(Job.Default.WithId("Vector512")); | ||
} | ||
|
||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); |
4 changes: 2 additions & 2 deletions
4
...umerics.Benchmarks/TensorSumBenchmarks.cs → ...erics.Tensors.Benchmarks/SumBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/NetFabric.Numerics.Tensors.UnitTests/AddMultiplyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System.Linq; | ||
|
||
namespace NetFabric.Numerics.Tensors.UnitTests; | ||
|
||
public class AddMultiplyTests | ||
{ | ||
public static TheoryData<int> AddData | ||
=> new() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37 }; | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Short_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (short)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (short)(value + 1)).ToArray(); | ||
var z = Enumerable.Range(0, count).Select(value => (short)(value + 2)).ToArray(); | ||
var result = new short[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (short)((value + value + 1) * (value + 2))).ToArray(); | ||
|
||
// act | ||
Tensor.AddMultiply<short>(x, y, z, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Int_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => value + 1).ToArray(); | ||
var z = Enumerable.Range(0, count).Select(value => value + 2).ToArray(); | ||
var result = new int[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (value + value + 1) * (value + 2)).ToArray(); | ||
|
||
// act | ||
Tensor.AddMultiply<int>(x, y, z, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Long_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (long)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (long)(value + 1)).ToArray(); | ||
var z = Enumerable.Range(0, count).Select(value => (long)(value + 2)).ToArray(); | ||
var result = new long[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (long)((value + value + 1) * (value + 2))).ToArray(); | ||
|
||
// act | ||
Tensor.AddMultiply<long>(x, y, z, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Float_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (float)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (float)(value + 1)).ToArray(); | ||
var z = Enumerable.Range(0, count).Select(value => (float)(value + 2)).ToArray(); | ||
var result = new float[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (float)((value + value + 1) * (value + 2))).ToArray(); | ||
|
||
// act | ||
Tensor.AddMultiply<float>(x, y, z, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void AddMultiply_Double_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (double)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (double)(value + 1)).ToArray(); | ||
var z = Enumerable.Range(0, count).Select(value => (double)(value + 2)).ToArray(); | ||
var result = new double[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (double)((value + value + 1) * (value + 2))).ToArray(); | ||
|
||
// act | ||
Tensor.AddMultiply<double>(x, y, z, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System.Linq; | ||
|
||
namespace NetFabric.Numerics.Tensors.UnitTests; | ||
|
||
public class AddTests | ||
{ | ||
public static TheoryData<int> AddData | ||
=> new() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37 }; | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Short_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (short)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (short)(value + 1)).ToArray(); | ||
var result = new short[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (short)(value + value + 1)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<short>(x, y, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Int_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => value + 1).ToArray(); | ||
var result = new int[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => value + value + 1).ToArray(); | ||
|
||
// act | ||
Tensor.Add<int>(x, y, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Long_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (long)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (long)(value + 1)).ToArray(); | ||
var result = new long[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (long)(value + value + 1)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<long>(x, y, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Float_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (float)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (float)(value + 1)).ToArray(); | ||
var result = new float[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (float)(value + value + 1)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<float>(x, y, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Double_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (double)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (double)(value + 1)).ToArray(); | ||
var result = new double[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (double)(value + value + 1)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<double>(x, y, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
} |
Oops, something went wrong.