-
Notifications
You must be signed in to change notification settings - Fork 286
Add TensorPrimitives benchmarks. #3922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
46 changes: 46 additions & 0 deletions
46
src/benchmarks/micro/libraries/System.Numerics.Tensors/Perf_BinaryIntegerTensorPrimitives.cs
This file contains hidden or 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,46 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Extensions; | ||
| using MicroBenchmarks; | ||
|
|
||
| namespace System.Numerics.Tensors.Tests | ||
| { | ||
| [BenchmarkCategory(Categories.Libraries, Categories.SIMD, Categories.JIT)] | ||
| [GenericTypeArguments(typeof(int))] | ||
| public class Perf_BinaryIntegerTensorPrimitives<T> | ||
| where T : unmanaged, IBinaryInteger<T> | ||
| { | ||
| [Params(128, 6 * 512 + 7)] | ||
| public int BufferLength; | ||
|
|
||
| private T[] _source1; | ||
| private T[] _destination; | ||
|
|
||
| [GlobalSetup] | ||
| public void Init() | ||
| { | ||
| _source1 = ValuesGenerator.Array<T>(BufferLength, seed: 42); | ||
| _destination = new T[BufferLength]; | ||
| } | ||
|
|
||
| #region Unary Operations | ||
| [Benchmark] | ||
| public void LeadingZeroCount() => TensorPrimitives.LeadingZeroCount<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void OnesComplement() => TensorPrimitives.OnesComplement<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void PopCount() => TensorPrimitives.PopCount<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void ShiftLeft() => TensorPrimitives.ShiftLeft<T>(_source1, shiftAmount: 3, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void TrailingZeroCount() => TensorPrimitives.TrailingZeroCount<T>(_source1, _destination); | ||
| #endregion | ||
| } | ||
| } |
105 changes: 105 additions & 0 deletions
105
src/benchmarks/micro/libraries/System.Numerics.Tensors/Perf_FloatingPointTensorPrimitives.cs
This file contains hidden or 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,105 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Extensions; | ||
| using MicroBenchmarks; | ||
| using System.Linq; | ||
|
|
||
| namespace System.Numerics.Tensors.Tests | ||
| { | ||
| [BenchmarkCategory(Categories.Libraries, Categories.SIMD, Categories.JIT)] | ||
| [GenericTypeArguments(typeof(float))] | ||
| [GenericTypeArguments(typeof(double))] | ||
| public class Perf_FloatingPointTensorPrimitives<T> | ||
| where T : unmanaged, IFloatingPointIeee754<T> | ||
| { | ||
| [Params(128, 6 * 512 + 7)] | ||
| public int BufferLength; | ||
|
|
||
| private T[] _source1; | ||
| private T[] _source2; | ||
| private T[] _source3; | ||
| private T _scalar1; | ||
| private T[] _ones; | ||
| private T[] _destination; | ||
|
|
||
| [GlobalSetup] | ||
| public void Init() | ||
| { | ||
| _source1 = ValuesGenerator.Array<T>(BufferLength, seed: 42); | ||
| _source2 = ValuesGenerator.Array<T>(BufferLength, seed: 43); | ||
| _source3 = ValuesGenerator.Array<T>(BufferLength, seed: 44); | ||
| _scalar1 = ValuesGenerator.Value<T>(seed: 45); | ||
| _ones = Enumerable.Repeat(T.One, BufferLength).ToArray(); | ||
| _destination = new T[BufferLength]; | ||
| } | ||
|
|
||
| #region Unary Operations | ||
| [Benchmark] | ||
| public void AtanPi() => TensorPrimitives.AtanPi<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Exp() => TensorPrimitives.Exp<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Log() => TensorPrimitives.Log<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Round() => TensorPrimitives.Round<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Sin() => TensorPrimitives.Sin<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Sinh() => TensorPrimitives.Sinh<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Sigmoid() => TensorPrimitives.Sigmoid<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Sqrt() => TensorPrimitives.Sqrt<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Truncate() => TensorPrimitives.Truncate<T>(_source1, _destination); | ||
| #endregion | ||
|
|
||
| #region Binary/Ternary Operations | ||
| [Benchmark] | ||
| public void FusedMultiplyAdd_Vectors() => TensorPrimitives.FusedMultiplyAdd<T>(_source1, _source2, _source3, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void FusedMultiplyAdd_ScalarAddend() => TensorPrimitives.FusedMultiplyAdd(_source1, _scalar1, _source2, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void FusedMultiplyAdd_ScalarMultiplier() => TensorPrimitives.FusedMultiplyAdd(_source1, _source2, _scalar1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Ieee754Remainder_Vector() => TensorPrimitives.Ieee754Remainder<T>(_source1, _source2, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Ieee754Remainder_ScalarDividend() => TensorPrimitives.Ieee754Remainder(_scalar1, _source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Ieee754Remainder_ScalarDivisor() => TensorPrimitives.Ieee754Remainder(_source1, _scalar1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Pow_Vectors() => TensorPrimitives.Pow<T>(_source1, _ones, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Pow_ScalarBase() => TensorPrimitives.Pow(_scalar1, _ones, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Pow_ScalarExponent() => TensorPrimitives.Pow(_source1, T.One, _destination); | ||
| #endregion | ||
|
|
||
| #region Reducers | ||
| [Benchmark] | ||
| public T CosineSimilarity() => TensorPrimitives.CosineSimilarity<T>(_source1, _source2); | ||
|
|
||
| [Benchmark] | ||
| public T Distance() => TensorPrimitives.Distance<T>(_source1, _source2); | ||
| #endregion | ||
| } | ||
| } |
103 changes: 103 additions & 0 deletions
103
src/benchmarks/micro/libraries/System.Numerics.Tensors/Perf_NumberTensorPrimitives.cs
This file contains hidden or 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,103 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Extensions; | ||
| using MicroBenchmarks; | ||
| using System.Linq; | ||
|
|
||
| namespace System.Numerics.Tensors.Tests | ||
| { | ||
| [BenchmarkCategory(Categories.Libraries, Categories.SIMD, Categories.JIT)] | ||
| [GenericTypeArguments(typeof(int))] | ||
| [GenericTypeArguments(typeof(float))] | ||
| [GenericTypeArguments(typeof(double))] | ||
| public class Perf_NumberTensorPrimitives<T> | ||
| where T : INumber<T>, IBitwiseOperators<T, T, T> | ||
| { | ||
| [Params(128, 6 * 512 + 7)] | ||
| public int BufferLength; | ||
|
|
||
| private T[] _source1; | ||
| private T[] _source2; | ||
| private T[] _source3; | ||
| private T _scalar1; | ||
| private T[] _ones; | ||
| private T[] _destination; | ||
|
|
||
| [GlobalSetup] | ||
| public void Init() | ||
| { | ||
| _source1 = ValuesGenerator.Array<T>(BufferLength, seed: 42); | ||
| _source2 = ValuesGenerator.Array<T>(BufferLength, seed: 43); | ||
| _source3 = ValuesGenerator.Array<T>(BufferLength, seed: 44); | ||
| _scalar1 = ValuesGenerator.Value<T>(seed: 45); | ||
| _ones = Enumerable.Repeat(T.One, BufferLength).ToArray(); | ||
| _destination = new T[BufferLength]; | ||
| } | ||
|
|
||
| #region Unary Operations | ||
| [Benchmark] | ||
| public void Abs() => TensorPrimitives.Abs<T>(_source1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Negate() => TensorPrimitives.Abs<T>(_source1, _destination); | ||
eiriktsarpalis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #endregion | ||
|
|
||
| #region Binary/Ternary Operations | ||
| [Benchmark] | ||
| public void Add_Vector() => TensorPrimitives.Add<T>(_source1, _source2, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Add_Scalar() => TensorPrimitives.Add(_source1, _scalar1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void AddMultiply_Vectors() => TensorPrimitives.AddMultiply<T>(_source1, _source2, _source3, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void AddMultiply_ScalarAddend() => TensorPrimitives.AddMultiply(_source1, _scalar1, _source2, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void AddMultiply_ScalarMultiplier() => TensorPrimitives.AddMultiply(_source1, _source2, _scalar1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void BitwiseAnd_Vector() => TensorPrimitives.BitwiseAnd<T>(_source1, _source2, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void BitwiseAnd_Scalar() => TensorPrimitives.BitwiseAnd(_source1, _scalar1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Divide_Vector() => TensorPrimitives.Divide<T>(_source1, _ones, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Divide_Scalar() => TensorPrimitives.Divide(_source1, T.One, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Max_Vector() => TensorPrimitives.Max<T>(_source1, _source2, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void Max_Scalar() => TensorPrimitives.Max(_source1, _scalar1, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void MaxMagnitude_Vector() => TensorPrimitives.MaxMagnitude<T>(_source1, _source2, _destination); | ||
|
|
||
| [Benchmark] | ||
| public void MaxMagnitude_Scalar() => TensorPrimitives.MaxMagnitude(_source1, _scalar1, _destination); | ||
| #endregion | ||
|
|
||
| #region Reducers | ||
| [Benchmark] | ||
| public T Max() => TensorPrimitives.Max<T>(_source1); | ||
|
|
||
| [Benchmark] | ||
| public T SumOfMagnitudes() => TensorPrimitives.SumOfMagnitudes<T>(_ones); | ||
|
|
||
| [Benchmark] | ||
| public T SumOfSquares() => TensorPrimitives.SumOfSquares<T>(_ones); | ||
|
|
||
| [Benchmark] | ||
| public int IndexOfMax() => TensorPrimitives.IndexOfMax<T>(_source1); | ||
| #endregion | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.