Skip to content

Commit

Permalink
Randomize memory alignment and diagnose memory in benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed May 2, 2024
1 parent 185a394 commit 19f3ff3
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/NetFabric.Numerics.Tensors.Benchmarks/AddBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class AddBenchmarks
{
short[]? sourceShort, otherShort, resultShort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class AddMultiplyBenchmarks
{
short[]? sourceShort, otherShort, anotherShort, resultShort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class AddValueBenchmarks
{
short[]? sourceShort, resultShort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class CeilingBenchmarks
{
Half[]? sourceHalf, resultHalf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class DegreesToRadiansBenchmarks
{
Half[]? sourceHalf, resultHalf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class FirstGreaterThanBenchmarks
{
short[]? arrayShort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class IndexOfFirstGreaterThanBenchmarks
{
short[]? arrayShort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class IndexOfMinAggregateBenchmarks
{
short[]? arrayShort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class MinAggregateBenchmarks
{
short[]? arrayShort;
Expand Down
2 changes: 2 additions & 0 deletions src/NetFabric.Numerics.Tensors.Benchmarks/MinBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class MinBenchmarks
{
short[]? sourceShort, otherShort, resultShort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class MinMaxAggregateBenchmarks
{
short[]? arrayShort;
Expand Down
2 changes: 2 additions & 0 deletions src/NetFabric.Numerics.Tensors.Benchmarks/NegateBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class NegateBenchmarks
{
short[]? sourceShort, resultShort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class ProductBenchmarks
{
short[]? arrayShort;
Expand Down
2 changes: 2 additions & 0 deletions src/NetFabric.Numerics.Tensors.Benchmarks/SinCosBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class SinCosBenchmarks
{
Half[]? sourceHalf, sinResultHalf, cosResultHalf;
Expand Down
2 changes: 2 additions & 0 deletions src/NetFabric.Numerics.Tensors.Benchmarks/Sum2DBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class Sum2DBenchmarks
{
MyVector2<short>[]? arrayShort;
Expand Down
2 changes: 2 additions & 0 deletions src/NetFabric.Numerics.Tensors.Benchmarks/Sum3DBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class Sum3DBenchmarks
{
MyVector3<short>[]? arrayShort;
Expand Down
2 changes: 2 additions & 0 deletions src/NetFabric.Numerics.Tensors.Benchmarks/Sum4DBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class Sum4DBenchmarks
{
MyVector4<short>[]? arrayShort;
Expand Down
2 changes: 2 additions & 0 deletions src/NetFabric.Numerics.Tensors.Benchmarks/SumBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class SumBenchmarks
{
short[]? arrayShort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NetFabric.Numerics.Tensors.Benchmarks;
[Config(typeof(VectorizationConfig))]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser]
[MemoryRandomization]
public class SumNumberBenchmarks
{
short[]? arrayShort;
Expand Down
5 changes: 2 additions & 3 deletions src/NetFabric.Numerics.Tensors/ApplyBinary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,15 @@ public static void Apply<T1, T2, TResult, TOperator>(ReadOnlySpan<T1> x, ReadOnl
ref var xVectorsRef = ref MemoryMarshal.GetReference(xVectors);
ref var yVectorsRef = ref MemoryMarshal.GetReference(yVectors);
ref var destinationVectorsRef = ref MemoryMarshal.GetReference(destinationVectors);
var indexVector = 0;
for (; indexVector < xVectors.Length; indexVector++)
for (var indexVector = 0; indexVector < xVectors.Length; indexVector++)
{
Unsafe.Add(ref destinationVectorsRef, indexVector) = TOperator.Invoke(
ref Unsafe.Add(ref xVectorsRef, indexVector),
ref Unsafe.Add(ref yVectorsRef, indexVector));
}

// Update the index to the end of the last complete vector.
indexSource = indexVector * Vector<T1>.Count;
indexSource = xVectors.Length * Vector<T1>.Count;
}

// Iterate through the remaining elements.
Expand Down

0 comments on commit 19f3ff3

Please sign in to comment.