-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathPerf_FloatingPointTensorPrimitives.cs
105 lines (81 loc) · 3.82 KB
/
Perf_FloatingPointTensorPrimitives.cs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
}
}