From e98a26a806b11b43efd5e53e1d49513057391d85 Mon Sep 17 00:00:00 2001 From: Brian Lui Date: Thu, 30 Aug 2018 16:46:11 -0700 Subject: [PATCH 1/4] Stored all native benchmarks in a new class and cleaned up function names --- .../AvxPerformanceTests.cs | 44 +-- .../NativePerformanceTests.cs | 232 ++++++++++++++ .../SsePerformanceTests.cs | 283 ++---------------- 3 files changed, 286 insertions(+), 273 deletions(-) create mode 100644 test/Microsoft.ML.CpuMath.PerformanceTests/NativePerformanceTests.cs diff --git a/test/Microsoft.ML.CpuMath.PerformanceTests/AvxPerformanceTests.cs b/test/Microsoft.ML.CpuMath.PerformanceTests/AvxPerformanceTests.cs index 2e4b598540..9a27c47553 100644 --- a/test/Microsoft.ML.CpuMath.PerformanceTests/AvxPerformanceTests.cs +++ b/test/Microsoft.ML.CpuMath.PerformanceTests/AvxPerformanceTests.cs @@ -12,135 +12,135 @@ namespace Microsoft.ML.CpuMath.PerformanceTests public class AvxPerformanceTests : PerformanceTests { [Benchmark] - public void ManagedAddScalarUPerf() + public void AddScalarU() { AvxIntrinsics.AddScalarU(DEFAULT_SCALE, new Span(dst, 0, LEN)); } [Benchmark] - public void ManagedScaleUPerf() + public void ScaleU() { AvxIntrinsics.ScaleU(DEFAULT_SCALE, new Span(dst, 0, LEN)); } [Benchmark] - public void ManagedScaleSrcUPerf() + public void ScaleSrcU() { AvxIntrinsics.ScaleSrcU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public void ManagedScaleAddUPerf() + public void ScaleAddU() { AvxIntrinsics.ScaleAddU(DEFAULT_SCALE, DEFAULT_SCALE, new Span(dst, 0, LEN)); } [Benchmark] - public void ManagedAddScaleUPerf() + public void AddScaleU() { AvxIntrinsics.AddScaleU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public void ManagedAddScaleSUPerf() + public void AddScaleSU() { AvxIntrinsics.AddScaleSU(DEFAULT_SCALE, new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); } [Benchmark] - public void ManagedAddScaleCopyUPerf() + public void AddScaleCopyU() { AvxIntrinsics.AddScaleCopyU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN), new Span(result, 0, LEN)); } [Benchmark] - public void ManagedAddUPerf() + public void AddU() { AvxIntrinsics.AddU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public void ManagedAddSUPerf() + public void AddSU() { AvxIntrinsics.AddSU(new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); } [Benchmark] - public void ManagedMulElementWiseUPerf() + public void MulElementWiseU() { AvxIntrinsics.MulElementWiseU(new Span(src1, 0, LEN), new Span(src2, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public float ManagedSumUPerf() + public float SumU() { return AvxIntrinsics.SumU(new Span(src, 0, LEN)); } [Benchmark] - public float ManagedSumSqUPerf() + public float SumSqU() { return AvxIntrinsics.SumSqU(new Span(src, 0, LEN)); } [Benchmark] - public float ManagedSumSqDiffUPerf() + public float SumSqDiffU() { return AvxIntrinsics.SumSqDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); } [Benchmark] - public float ManagedSumAbsUPerf() + public float SumAbsU() { return AvxIntrinsics.SumAbsU(new Span(src, 0, LEN)); } [Benchmark] - public float ManagedSumAbsDiffUPerf() + public float SumAbsDiffU() { return AvxIntrinsics.SumAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); } [Benchmark] - public float ManagedMaxAbsUPerf() + public float MaxAbsU() { return AvxIntrinsics.MaxAbsU(new Span(src, 0, LEN)); } [Benchmark] - public float ManagedMaxAbsDiffUPerf() + public float MaxAbsDiffU() { return AvxIntrinsics.MaxAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); } [Benchmark] - public float ManagedDotUPerf() + public float DotU() { return AvxIntrinsics.DotU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public float ManagedDotSUPerf() + public float DotSU() { return AvxIntrinsics.DotSU(new Span(src), new Span(dst), new Span(idx, 0, IDXLEN)); } [Benchmark] - public float ManagedDist2Perf() + public float Dist2() { return AvxIntrinsics.Dist2(new Span(src, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public void ManagedSdcaL1UpdateUPerf() + public void SdcaL1UpdateU() { AvxIntrinsics.SdcaL1UpdateU(DEFAULT_SCALE, new Span(src, 0, LEN), DEFAULT_SCALE, new Span(dst, 0, LEN), new Span(result, 0, LEN)); } [Benchmark] - public void ManagedSdcaL1UpdateSUPerf() + public void SdcaL1UpdateSU() { AvxIntrinsics.SdcaL1UpdateSU(DEFAULT_SCALE, new Span(src, 0, IDXLEN), new Span(idx, 0, IDXLEN), DEFAULT_SCALE, new Span(dst), new Span(result)); } diff --git a/test/Microsoft.ML.CpuMath.PerformanceTests/NativePerformanceTests.cs b/test/Microsoft.ML.CpuMath.PerformanceTests/NativePerformanceTests.cs new file mode 100644 index 0000000000..b7eb3d233a --- /dev/null +++ b/test/Microsoft.ML.CpuMath.PerformanceTests/NativePerformanceTests.cs @@ -0,0 +1,232 @@ +// 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 System; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Running; +using Microsoft.ML.Runtime.Internal.CpuMath; + +namespace Microsoft.ML.CpuMath.PerformanceTests +{ + public class NativePerformanceTests : PerformanceTests + { + [Benchmark] + public unsafe void AddScalarU() + { + fixed (float* pdst = dst) + { + CpuMathNativeUtils.AddScalarU(DEFAULT_SCALE, pdst, LEN); + } + } + + [Benchmark] + public unsafe void ScaleU() + { + fixed (float* pdst = dst) + { + CpuMathNativeUtils.ScaleU(DEFAULT_SCALE, pdst, LEN); + } + } + + [Benchmark] + public unsafe void ScaleSrcU() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + { + CpuMathNativeUtils.ScaleSrcU(DEFAULT_SCALE, psrc, pdst, LEN); + } + } + + [Benchmark] + public unsafe void ScaleAddU() + { + fixed (float* pdst = dst) + { + CpuMathNativeUtils.ScaleAddU(DEFAULT_SCALE, DEFAULT_SCALE, pdst, LEN); + } + } + + [Benchmark] + public unsafe void AddScaleU() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + { + CpuMathNativeUtils.AddScaleU(DEFAULT_SCALE, psrc, pdst, LEN); + } + } + + [Benchmark] + public unsafe void AddScaleSU() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + fixed (int* pidx = idx) + { + CpuMathNativeUtils.AddScaleSU(DEFAULT_SCALE, psrc, pidx, pdst, IDXLEN); + } + } + + [Benchmark] + public unsafe void AddScaleCopyU() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + fixed (float* pres = result) + { + CpuMathNativeUtils.AddScaleCopyU(DEFAULT_SCALE, psrc, pdst, pres, LEN); + } + } + + [Benchmark] + public unsafe void AddU() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + { + CpuMathNativeUtils.AddU(psrc, pdst, LEN); + } + } + + [Benchmark] + public unsafe void AddSU() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + fixed (int* pidx = idx) + { + CpuMathNativeUtils.AddSU(psrc, pidx, pdst, IDXLEN); + } + } + + [Benchmark] + public unsafe void MulElementWiseU() + { + fixed (float* psrc1 = src1) + fixed (float* psrc2 = src2) + fixed (float* pdst = dst) + { + CpuMathNativeUtils.MulElementWiseU(psrc1, psrc2, pdst, LEN); + } + } + + [Benchmark] + public unsafe float SumU() + { + fixed (float* psrc = src) + { + return CpuMathNativeUtils.SumU(psrc, LEN); + } + } + + [Benchmark] + public unsafe float SumSqU() + { + fixed (float* psrc = src) + { + return CpuMathNativeUtils.SumSqU(psrc, LEN); + } + } + + [Benchmark] + public unsafe float SumSqDiffU() + { + fixed (float* psrc = src) + { + return CpuMathNativeUtils.SumSqDiffU(DEFAULT_SCALE, psrc, LEN); + } + } + + [Benchmark] + public unsafe float SumAbsU() + { + fixed (float* psrc = src) + { + return CpuMathNativeUtils.SumAbsU(psrc, LEN); + } + } + + [Benchmark] + public unsafe float SumAbsDiffU() + { + fixed (float* psrc = src) + { + return CpuMathNativeUtils.SumAbsDiffU(DEFAULT_SCALE, psrc, LEN); + } + } + + [Benchmark] + public unsafe float MaxAbsU() + { + fixed (float* psrc = src) + { + return CpuMathNativeUtils.MaxAbsU(psrc, LEN); + } + } + + [Benchmark] + public unsafe float MaxAbsDiffU() + { + fixed (float* psrc = src) + { + return CpuMathNativeUtils.MaxAbsDiffU(DEFAULT_SCALE, psrc, LEN); + } + } + + [Benchmark] + public unsafe float DotU() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + { + return CpuMathNativeUtils.DotU(psrc, pdst, LEN); + } + } + + [Benchmark] + public unsafe float DotSU() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + fixed (int* pidx = idx) + { + return CpuMathNativeUtils.DotSU(psrc, pdst, pidx, IDXLEN); + } + } + + [Benchmark] + public unsafe float Dist2() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + { + return CpuMathNativeUtils.Dist2(psrc, pdst, LEN); + } + } + + [Benchmark] + public unsafe void SdcaL1UpdateU() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + fixed (float* pres = result) + { + CpuMathNativeUtils.SdcaL1UpdateU(DEFAULT_SCALE, psrc, DEFAULT_SCALE, pdst, pres, LEN); + } + } + + [Benchmark] + public unsafe void SdcaL1UpdateSU() + { + fixed (float* psrc = src) + fixed (float* pdst = dst) + fixed (float* pres = result) + fixed (int* pidx = idx) + { + CpuMathNativeUtils.SdcaL1UpdateSU(DEFAULT_SCALE, psrc, pidx, DEFAULT_SCALE, pdst, pres, IDXLEN); + } + } + } +} diff --git a/test/Microsoft.ML.CpuMath.PerformanceTests/SsePerformanceTests.cs b/test/Microsoft.ML.CpuMath.PerformanceTests/SsePerformanceTests.cs index 3188c64db9..39baaa4553 100644 --- a/test/Microsoft.ML.CpuMath.PerformanceTests/SsePerformanceTests.cs +++ b/test/Microsoft.ML.CpuMath.PerformanceTests/SsePerformanceTests.cs @@ -12,353 +12,134 @@ namespace Microsoft.ML.CpuMath.PerformanceTests public class SsePerformanceTests : PerformanceTests { [Benchmark] - public unsafe void NativeAddScalarUPerf() - { - fixed (float* pdst = dst) - { - CpuMathNativeUtils.AddScalarU(DEFAULT_SCALE, pdst, LEN); - } - } - - [Benchmark] - public void ManagedAddScalarUPerf() + public void AddScalarU() { SseIntrinsics.AddScalarU(DEFAULT_SCALE, new Span(dst, 0, LEN)); } - + [Benchmark] - public unsafe void NativeScaleUPerf() - { - fixed (float* pdst = dst) - { - CpuMathNativeUtils.ScaleU(DEFAULT_SCALE, pdst, LEN); - } - } - - [Benchmark] - public void ManagedScaleUPerf() + public void ScaleU() { SseIntrinsics.ScaleU(DEFAULT_SCALE, new Span(dst, 0, LEN)); } - + [Benchmark] - public unsafe void NativeScaleSrcUPerf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - { - CpuMathNativeUtils.ScaleSrcU(DEFAULT_SCALE, psrc, pdst, LEN); - } - } - - [Benchmark] - public void ManagedScaleSrcUPerf() + public void ScaleSrcU() { SseIntrinsics.ScaleSrcU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public unsafe void NativeScaleAddUPerf() - { - fixed (float* pdst = dst) - { - CpuMathNativeUtils.ScaleAddU(DEFAULT_SCALE, DEFAULT_SCALE, pdst, LEN); - } - } - - [Benchmark] - public void ManagedScaleAddUPerf() + public void ScaleAddU() { SseIntrinsics.ScaleAddU(DEFAULT_SCALE, DEFAULT_SCALE, new Span(dst, 0, LEN)); } - - [Benchmark] - public unsafe void NativeAddScaleUPerf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - { - CpuMathNativeUtils.AddScaleU(DEFAULT_SCALE, psrc, pdst, LEN); - } - } - + [Benchmark] - public void ManagedAddScaleUPerf() + public void AddScaleU() { SseIntrinsics.AddScaleU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public unsafe void NativeAddScaleSUPerf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - fixed (int* pidx = idx) - { - CpuMathNativeUtils.AddScaleSU(DEFAULT_SCALE, psrc, pidx, pdst, IDXLEN); - } - } - - [Benchmark] - public void ManagedAddScaleSUPerf() + public void AddScaleSU() { SseIntrinsics.AddScaleSU(DEFAULT_SCALE, new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); } [Benchmark] - public unsafe void NativeAddScaleCopyUPerf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - fixed (float* pres = result) - { - CpuMathNativeUtils.AddScaleCopyU(DEFAULT_SCALE, psrc, pdst, pres, LEN); - } - } - - [Benchmark] - public void ManagedAddScaleCopyUPerf() + public void AddScaleCopyU() { SseIntrinsics.AddScaleCopyU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN), new Span(result, 0, LEN)); } [Benchmark] - public unsafe void NativeAddUPerf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - { - CpuMathNativeUtils.AddU(psrc, pdst, LEN); - } - } - - [Benchmark] - public void ManagedAddUPerf() + public void AddU() { SseIntrinsics.AddU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public unsafe void NativeAddSUPerf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - fixed (int* pidx = idx) - { - CpuMathNativeUtils.AddSU(psrc, pidx, pdst, IDXLEN); - } - } - - [Benchmark] - public void ManagedAddSUPerf() + public void AddSU() { SseIntrinsics.AddSU(new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); } - - [Benchmark] - public unsafe void NativeMulElementWiseUPerf() - { - fixed (float* psrc1 = src1) - fixed (float* psrc2 = src2) - fixed (float* pdst = dst) - { - CpuMathNativeUtils.MulElementWiseU(psrc1, psrc2, pdst, LEN); - } - } - [Benchmark] - public void ManagedMulElementWiseUPerf() + public void MulElementWiseU() { SseIntrinsics.MulElementWiseU(new Span(src1, 0, LEN), new Span(src2, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public unsafe float NativeSumUPerf() - { - fixed (float* psrc = src) - { - return CpuMathNativeUtils.SumU(psrc, LEN); - } - } - - [Benchmark] - public float ManagedSumUPerf() + public float SumU() { return SseIntrinsics.SumU(new Span(src, 0, LEN)); } [Benchmark] - public unsafe float NativeSumSqUPerf() - { - fixed (float* psrc = src) - { - return CpuMathNativeUtils.SumSqU(psrc, LEN); - } - } - - [Benchmark] - public float ManagedSumSqUPerf() + public float SumSqU() { return SseIntrinsics.SumSqU(new Span(src, 0, LEN)); } - - [Benchmark] - public unsafe float NativeSumSqDiffUPerf() - { - fixed (float* psrc = src) - { - return CpuMathNativeUtils.SumSqDiffU(DEFAULT_SCALE, psrc, LEN); - } - } - + [Benchmark] - public float ManagedSumSqDiffUPerf() + public float SumSqDiffU() { return SseIntrinsics.SumSqDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); } - - [Benchmark] - public unsafe float NativeSumAbsUPerf() - { - fixed (float* psrc = src) - { - return CpuMathNativeUtils.SumAbsU(psrc, LEN); - } - } - + [Benchmark] - public float ManagedSumAbsUPerf() + public float SumAbsU() { return SseIntrinsics.SumAbsU(new Span(src, 0, LEN)); } [Benchmark] - public unsafe float NativeSumAbsDiffUPerf() - { - fixed (float* psrc = src) - { - return CpuMathNativeUtils.SumAbsDiffU(DEFAULT_SCALE, psrc, LEN); - } - } - - [Benchmark] - public float ManagedSumAbsDiffUPerf() + public float SumAbsDiffU() { return SseIntrinsics.SumAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); } - - [Benchmark] - public unsafe float NativeMaxAbsUPerf() - { - fixed (float* psrc = src) - { - return CpuMathNativeUtils.MaxAbsU(psrc, LEN); - } - } - + [Benchmark] - public float ManagedMaxAbsUPerf() + public float MaxAbsU() { return SseIntrinsics.MaxAbsU(new Span(src, 0, LEN)); } - + [Benchmark] - public unsafe float NativeMaxAbsDiffUPerf() - { - fixed (float* psrc = src) - { - return CpuMathNativeUtils.MaxAbsDiffU(DEFAULT_SCALE, psrc, LEN); - } - } - - [Benchmark] - public float ManagedMaxAbsDiffUPerf() + public float MaxAbsDiffU() { return SseIntrinsics.MaxAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); } - - [Benchmark] - public unsafe float NativeDotUPerf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - { - return CpuMathNativeUtils.DotU(psrc, pdst, LEN); - } - } - + [Benchmark] - public float ManagedDotUPerf() + public float DotU() { return SseIntrinsics.DotU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); } - - [Benchmark] - public unsafe float NativeDotSUPerf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - fixed (int* pidx = idx) - { - return CpuMathNativeUtils.DotSU(psrc, pdst, pidx, IDXLEN); - } - } - + [Benchmark] - public float ManagedDotSUPerf() + public float DotSU() { return SseIntrinsics.DotSU(new Span(src), new Span(dst), new Span(idx, 0, IDXLEN)); } - - [Benchmark] - public unsafe float NativeDist2Perf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - { - return CpuMathNativeUtils.Dist2(psrc, pdst, LEN); - } - } - + [Benchmark] - public float ManagedDist2Perf() + public float Dist2() { return SseIntrinsics.Dist2(new Span(src, 0, LEN), new Span(dst, 0, LEN)); } [Benchmark] - public unsafe void NativeSdcaL1UpdateUPerf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - fixed (float* pres = result) - { - CpuMathNativeUtils.SdcaL1UpdateU(DEFAULT_SCALE, psrc, DEFAULT_SCALE, pdst, pres, LEN); - } - } - - [Benchmark] - public void ManagedSdcaL1UpdateUPerf() + public void SdcaL1UpdateU() { SseIntrinsics.SdcaL1UpdateU(DEFAULT_SCALE, new Span(src, 0, LEN), DEFAULT_SCALE, new Span(dst, 0, LEN), new Span(result, 0, LEN)); } [Benchmark] - public unsafe void NativeSdcaL1UpdateSUPerf() - { - fixed (float* psrc = src) - fixed (float* pdst = dst) - fixed (float* pres = result) - fixed (int* pidx = idx) - { - CpuMathNativeUtils.SdcaL1UpdateSU(DEFAULT_SCALE, psrc, pidx, DEFAULT_SCALE, pdst, pres, IDXLEN); - } - } - - [Benchmark] - public void ManagedSdcaL1UpdateSUPerf() + public void SdcaL1UpdateSU() { SseIntrinsics.SdcaL1UpdateSU(DEFAULT_SCALE, new Span(src, 0, IDXLEN), new Span(idx, 0, IDXLEN), DEFAULT_SCALE, new Span(dst), new Span(result)); } From 434cfb3228522bb13f7ac618dcc48e00947b99c7 Mon Sep 17 00:00:00 2001 From: Brian Lui Date: Thu, 30 Aug 2018 16:54:01 -0700 Subject: [PATCH 2/4] Style change: turn braces into one-liners --- .../AvxPerformanceTests.cs | 89 +++++-------------- .../SsePerformanceTests.cs | 88 +++++------------- 2 files changed, 44 insertions(+), 133 deletions(-) diff --git a/test/Microsoft.ML.CpuMath.PerformanceTests/AvxPerformanceTests.cs b/test/Microsoft.ML.CpuMath.PerformanceTests/AvxPerformanceTests.cs index 9a27c47553..b4b1cf65fd 100644 --- a/test/Microsoft.ML.CpuMath.PerformanceTests/AvxPerformanceTests.cs +++ b/test/Microsoft.ML.CpuMath.PerformanceTests/AvxPerformanceTests.cs @@ -13,136 +13,91 @@ public class AvxPerformanceTests : PerformanceTests { [Benchmark] public void AddScalarU() - { - AvxIntrinsics.AddScalarU(DEFAULT_SCALE, new Span(dst, 0, LEN)); - } + => AvxIntrinsics.AddScalarU(DEFAULT_SCALE, new Span(dst, 0, LEN)); [Benchmark] public void ScaleU() - { - AvxIntrinsics.ScaleU(DEFAULT_SCALE, new Span(dst, 0, LEN)); - } + => AvxIntrinsics.ScaleU(DEFAULT_SCALE, new Span(dst, 0, LEN)); [Benchmark] public void ScaleSrcU() - { - AvxIntrinsics.ScaleSrcU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); - } + => AvxIntrinsics.ScaleSrcU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); [Benchmark] public void ScaleAddU() - { - AvxIntrinsics.ScaleAddU(DEFAULT_SCALE, DEFAULT_SCALE, new Span(dst, 0, LEN)); - } + => AvxIntrinsics.ScaleAddU(DEFAULT_SCALE, DEFAULT_SCALE, new Span(dst, 0, LEN)); [Benchmark] public void AddScaleU() - { - AvxIntrinsics.AddScaleU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); - } + => AvxIntrinsics.AddScaleU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); [Benchmark] public void AddScaleSU() - { - AvxIntrinsics.AddScaleSU(DEFAULT_SCALE, new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); - } + => AvxIntrinsics.AddScaleSU(DEFAULT_SCALE, new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); [Benchmark] public void AddScaleCopyU() - { - AvxIntrinsics.AddScaleCopyU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN), new Span(result, 0, LEN)); - } + => AvxIntrinsics.AddScaleCopyU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN), new Span(result, 0, LEN)); [Benchmark] public void AddU() - { - AvxIntrinsics.AddU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); - } + => AvxIntrinsics.AddU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); [Benchmark] public void AddSU() - { - AvxIntrinsics.AddSU(new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); - } - + => AvxIntrinsics.AddSU(new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); [Benchmark] public void MulElementWiseU() - { - AvxIntrinsics.MulElementWiseU(new Span(src1, 0, LEN), new Span(src2, 0, LEN), + => AvxIntrinsics.MulElementWiseU(new Span(src1, 0, LEN), new Span(src2, 0, LEN), new Span(dst, 0, LEN)); - } [Benchmark] public float SumU() - { - return AvxIntrinsics.SumU(new Span(src, 0, LEN)); - } + => AvxIntrinsics.SumU(new Span(src, 0, LEN)); [Benchmark] public float SumSqU() - { - return AvxIntrinsics.SumSqU(new Span(src, 0, LEN)); - } + => AvxIntrinsics.SumSqU(new Span(src, 0, LEN)); [Benchmark] public float SumSqDiffU() - { - return AvxIntrinsics.SumSqDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); - } + => AvxIntrinsics.SumSqDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); [Benchmark] public float SumAbsU() - { - return AvxIntrinsics.SumAbsU(new Span(src, 0, LEN)); - } + => AvxIntrinsics.SumAbsU(new Span(src, 0, LEN)); [Benchmark] public float SumAbsDiffU() - { - return AvxIntrinsics.SumAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); - } + => AvxIntrinsics.SumAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); [Benchmark] public float MaxAbsU() - { - return AvxIntrinsics.MaxAbsU(new Span(src, 0, LEN)); - } + => AvxIntrinsics.MaxAbsU(new Span(src, 0, LEN)); [Benchmark] public float MaxAbsDiffU() - { - return AvxIntrinsics.MaxAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); - } + => AvxIntrinsics.MaxAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); [Benchmark] public float DotU() - { - return AvxIntrinsics.DotU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); - } + => AvxIntrinsics.DotU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); [Benchmark] public float DotSU() - { - return AvxIntrinsics.DotSU(new Span(src), new Span(dst), new Span(idx, 0, IDXLEN)); - } + => AvxIntrinsics.DotSU(new Span(src), new Span(dst), new Span(idx, 0, IDXLEN)); [Benchmark] public float Dist2() - { - return AvxIntrinsics.Dist2(new Span(src, 0, LEN), new Span(dst, 0, LEN)); - } + => AvxIntrinsics.Dist2(new Span(src, 0, LEN), new Span(dst, 0, LEN)); [Benchmark] public void SdcaL1UpdateU() - { - AvxIntrinsics.SdcaL1UpdateU(DEFAULT_SCALE, new Span(src, 0, LEN), DEFAULT_SCALE, new Span(dst, 0, LEN), new Span(result, 0, LEN)); - } + => AvxIntrinsics.SdcaL1UpdateU(DEFAULT_SCALE, new Span(src, 0, LEN), DEFAULT_SCALE, new Span(dst, 0, LEN), new Span(result, 0, LEN)); [Benchmark] public void SdcaL1UpdateSU() - { - AvxIntrinsics.SdcaL1UpdateSU(DEFAULT_SCALE, new Span(src, 0, IDXLEN), new Span(idx, 0, IDXLEN), DEFAULT_SCALE, new Span(dst), new Span(result)); - } + => AvxIntrinsics.SdcaL1UpdateSU(DEFAULT_SCALE, new Span(src, 0, IDXLEN), new Span(idx, 0, IDXLEN), DEFAULT_SCALE, new Span(dst), new Span(result)); } } diff --git a/test/Microsoft.ML.CpuMath.PerformanceTests/SsePerformanceTests.cs b/test/Microsoft.ML.CpuMath.PerformanceTests/SsePerformanceTests.cs index 39baaa4553..21eb840bdc 100644 --- a/test/Microsoft.ML.CpuMath.PerformanceTests/SsePerformanceTests.cs +++ b/test/Microsoft.ML.CpuMath.PerformanceTests/SsePerformanceTests.cs @@ -13,135 +13,91 @@ public class SsePerformanceTests : PerformanceTests { [Benchmark] public void AddScalarU() - { - SseIntrinsics.AddScalarU(DEFAULT_SCALE, new Span(dst, 0, LEN)); - } + => SseIntrinsics.AddScalarU(DEFAULT_SCALE, new Span(dst, 0, LEN)); [Benchmark] public void ScaleU() - { - SseIntrinsics.ScaleU(DEFAULT_SCALE, new Span(dst, 0, LEN)); - } + => SseIntrinsics.ScaleU(DEFAULT_SCALE, new Span(dst, 0, LEN)); [Benchmark] public void ScaleSrcU() - { - SseIntrinsics.ScaleSrcU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); - } + => SseIntrinsics.ScaleSrcU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); [Benchmark] public void ScaleAddU() - { - SseIntrinsics.ScaleAddU(DEFAULT_SCALE, DEFAULT_SCALE, new Span(dst, 0, LEN)); - } + => SseIntrinsics.ScaleAddU(DEFAULT_SCALE, DEFAULT_SCALE, new Span(dst, 0, LEN)); [Benchmark] public void AddScaleU() - { - SseIntrinsics.AddScaleU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); - } + => SseIntrinsics.AddScaleU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN)); [Benchmark] public void AddScaleSU() - { - SseIntrinsics.AddScaleSU(DEFAULT_SCALE, new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); - } + => SseIntrinsics.AddScaleSU(DEFAULT_SCALE, new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); [Benchmark] public void AddScaleCopyU() - { - SseIntrinsics.AddScaleCopyU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN), new Span(result, 0, LEN)); - } + => SseIntrinsics.AddScaleCopyU(DEFAULT_SCALE, new Span(src, 0, LEN), new Span(dst, 0, LEN), new Span(result, 0, LEN)); [Benchmark] public void AddU() - { - SseIntrinsics.AddU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); - } + => SseIntrinsics.AddU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); [Benchmark] public void AddSU() - { - SseIntrinsics.AddSU(new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); - } + => SseIntrinsics.AddSU(new Span(src), new Span(idx, 0, IDXLEN), new Span(dst)); [Benchmark] public void MulElementWiseU() - { - SseIntrinsics.MulElementWiseU(new Span(src1, 0, LEN), new Span(src2, 0, LEN), + => SseIntrinsics.MulElementWiseU(new Span(src1, 0, LEN), new Span(src2, 0, LEN), new Span(dst, 0, LEN)); - } [Benchmark] public float SumU() - { - return SseIntrinsics.SumU(new Span(src, 0, LEN)); - } + => SseIntrinsics.SumU(new Span(src, 0, LEN)); [Benchmark] public float SumSqU() - { - return SseIntrinsics.SumSqU(new Span(src, 0, LEN)); - } + => SseIntrinsics.SumSqU(new Span(src, 0, LEN)); [Benchmark] public float SumSqDiffU() - { - return SseIntrinsics.SumSqDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); - } + => SseIntrinsics.SumSqDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); [Benchmark] public float SumAbsU() - { - return SseIntrinsics.SumAbsU(new Span(src, 0, LEN)); - } + => SseIntrinsics.SumAbsU(new Span(src, 0, LEN)); [Benchmark] public float SumAbsDiffU() - { - return SseIntrinsics.SumAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); - } + => SseIntrinsics.SumAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); [Benchmark] public float MaxAbsU() - { - return SseIntrinsics.MaxAbsU(new Span(src, 0, LEN)); - } + => SseIntrinsics.MaxAbsU(new Span(src, 0, LEN)); [Benchmark] public float MaxAbsDiffU() - { - return SseIntrinsics.MaxAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); - } + => SseIntrinsics.MaxAbsDiffU(DEFAULT_SCALE, new Span(src, 0, LEN)); [Benchmark] public float DotU() - { - return SseIntrinsics.DotU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); - } + => SseIntrinsics.DotU(new Span(src, 0, LEN), new Span(dst, 0, LEN)); [Benchmark] public float DotSU() - { - return SseIntrinsics.DotSU(new Span(src), new Span(dst), new Span(idx, 0, IDXLEN)); - } + => SseIntrinsics.DotSU(new Span(src), new Span(dst), new Span(idx, 0, IDXLEN)); [Benchmark] public float Dist2() - { - return SseIntrinsics.Dist2(new Span(src, 0, LEN), new Span(dst, 0, LEN)); - } + => SseIntrinsics.Dist2(new Span(src, 0, LEN), new Span(dst, 0, LEN)); [Benchmark] public void SdcaL1UpdateU() - { - SseIntrinsics.SdcaL1UpdateU(DEFAULT_SCALE, new Span(src, 0, LEN), DEFAULT_SCALE, new Span(dst, 0, LEN), new Span(result, 0, LEN)); - } + => SseIntrinsics.SdcaL1UpdateU(DEFAULT_SCALE, new Span(src, 0, LEN), DEFAULT_SCALE, new Span(dst, 0, LEN), new Span(result, 0, LEN)); [Benchmark] public void SdcaL1UpdateSU() - { - SseIntrinsics.SdcaL1UpdateSU(DEFAULT_SCALE, new Span(src, 0, IDXLEN), new Span(idx, 0, IDXLEN), DEFAULT_SCALE, new Span(dst), new Span(result)); - } + => SseIntrinsics.SdcaL1UpdateSU(DEFAULT_SCALE, new Span(src, 0, IDXLEN), new Span(idx, 0, IDXLEN), DEFAULT_SCALE, new Span(dst), new Span(result)); } } From 4a15f40caf80bb3f7699d35ef727da1653a32ef3 Mon Sep 17 00:00:00 2001 From: Brian Lui Date: Thu, 30 Aug 2018 16:55:38 -0700 Subject: [PATCH 3/4] Changed ShortRun to Default: run the perf tests longer to give more accurate results --- test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs b/test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs index 77656178c8..e322ae91d2 100644 --- a/test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs +++ b/test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs @@ -13,7 +13,7 @@ public static void Main(string[] args) private static IConfig CreateCustomConfig() => DefaultConfig.Instance - .With(Job.ShortRun + .With(Job.Default .With(InProcessToolchain.Instance)); } } From 469e2a1530c5f03ac4da1a17d78b460bed844634 Mon Sep 17 00:00:00 2001 From: Brian Lui Date: Thu, 30 Aug 2018 17:00:34 -0700 Subject: [PATCH 4/4] Added back necessary usings --- test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs b/test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs index e322ae91d2..9ff474a9a1 100644 --- a/test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs +++ b/test/Microsoft.ML.CpuMath.PerformanceTests/Program.cs @@ -2,6 +2,11 @@ // 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.Configs; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Running; +using BenchmarkDotNet.Toolchains.InProcess; + namespace Microsoft.ML.CpuMath.PerformanceTests { class Program