From 71ab1950e6feb71833bc0956940414b40ce62d1d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 5 Jan 2021 16:51:49 +0100 Subject: [PATCH] Added image processing benchmark --- .../Blas/BlasBenchmark.cs | 10 +- .../ComputeSharp.Benchmark.csproj | 14 +++ .../Imaging/ImagingBenchmark.cs | 91 +++++++++++++++++++ 3 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 samples/ComputeSharp.Benchmark/Imaging/ImagingBenchmark.cs diff --git a/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs b/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs index 2f1e91ed..870b1966 100644 --- a/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs +++ b/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs @@ -7,7 +7,7 @@ using BenchmarkDotNet.Engines; namespace ComputeSharp.Benchmark.Blas { /// - /// A that benchmarks the APIs in the class, on both CPU and GPU. + /// A that benchmarks the APIs in the class, on both CPU and GPU. /// [SimpleJob(RunStrategy.Monitoring)] public class BlasBenchmark : IDisposable @@ -105,11 +105,13 @@ namespace ComputeSharp.Benchmark.Blas BufferW = Gpu.Default.AllocateReadOnlyBuffer(W); BufferB = Gpu.Default.AllocateReadOnlyBuffer(B); BufferY = Gpu.Default.AllocateReadWriteBuffer(Y); + + Cpu(); + GpuWithNoTemporaryBuffers(); + GpuWithTemporaryBuffers(); } - /// - /// Clears the memory from the current session. - /// + /// [GlobalCleanup] public void Dispose() { diff --git a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj index 06bb8291..e95049bf 100644 --- a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj +++ b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj @@ -5,8 +5,22 @@ net5.0 + + + + + + + + + + + + + + diff --git a/samples/ComputeSharp.Benchmark/Imaging/ImagingBenchmark.cs b/samples/ComputeSharp.Benchmark/Imaging/ImagingBenchmark.cs new file mode 100644 index 00000000..aa4d4873 --- /dev/null +++ b/samples/ComputeSharp.Benchmark/Imaging/ImagingBenchmark.cs @@ -0,0 +1,91 @@ +using System; +using System.IO; +using System.Reflection; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Engines; +using ComputeSharp.BokehBlur.Processors; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Convolution; +using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32; + +namespace ComputeSharp.Benchmark.Imaging +{ + /// + /// A that benchmarks the image processors against the reference in ImageSharp. + /// + [SimpleJob(RunStrategy.Monitoring)] + [CategoriesColumn] + [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] + public class ImagingBenchmark : IDisposable + { + /// + /// The loaded image. + /// + private Image image; + + /// + /// Initial setup for a benchmarking session. + /// + [GlobalSetup] + public void Setup() + { + string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Imaging", "city.jpg"); + + this.image = Image.Load(path); + + Bokeh_Cpu(); + Bokeh_Gpu(); + Gaussian_Cpu(); + Gaussian_Gpu(); + } + + /// + [GlobalCleanup] + public void Dispose() + { + this.image.Dispose(); + } + + /// + /// Runs a bokeh blur effect on the CPU. + /// + [Benchmark(Baseline = true)] + [BenchmarkCategory("BOKEH")] + public void Bokeh_Cpu() + { + this.image.Mutate(c => c.ApplyProcessor(new BokehBlurProcessor(80, 2, 3))); + } + + /// + /// Runs a bokeh blur effect on the GPU. + /// + [Benchmark] + [BenchmarkCategory("BOKEH")] + public void Bokeh_Gpu() + { + this.image.Mutate(c => c.ApplyProcessor(new HlslBokehBlurProcessor(80, 2, 3))); + } + + /// + /// Runs a gaussian blur effect on the CPU. + /// + [Benchmark(Baseline = true)] + [BenchmarkCategory("GAUSSIAN")] + public void Gaussian_Cpu() + { + this.image.Mutate(c => c.ApplyProcessor(new GaussianBlurProcessor(80))); + } + + /// + /// Runs a gaussian blur effect on the GPU. + /// + [Benchmark] + [BenchmarkCategory("GAUSSIAN")] + public void Gaussian_Gpu() + { + this.image.Mutate(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(80))); + } + } +}