diff --git a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj index f93e3c60..bfb20336 100644 --- a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj +++ b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj @@ -5,10 +5,6 @@ netcoreapp3.0 - - - - diff --git a/samples/ComputeSharp.Benchmark/FullyConnectedLayerBenchmark.cs b/samples/ComputeSharp.Benchmark/FullyConnectedLayerBenchmark.cs index d78499ed..3f1488a3 100644 --- a/samples/ComputeSharp.Benchmark/FullyConnectedLayerBenchmark.cs +++ b/samples/ComputeSharp.Benchmark/FullyConnectedLayerBenchmark.cs @@ -17,17 +17,17 @@ namespace ComputeSharp.Benchmark /// /// The nummber of rows in the matrix /// - private const int N = 100; + private const int N = 128; /// /// The number of columns in the matrix (same as the number of rows in the matrix) /// - private const int M = 100; + private const int M = 128; /// /// The number of columns in the matrix /// - private const int P = 100; + private const int P = 128; /// /// The input tensor @@ -81,5 +81,15 @@ namespace ComputeSharp.Benchmark return array; } + + /// + /// Runs a fully connected forward operation on the CPU + /// + public void Cpu() => Dnn.FullyConnectedForwardCpu(C, N, M, P, X, W, B, Y); + + /// + /// Runs a fully connected forward operation on the GPU + /// + public void Gpu() => Dnn.FullyConnectedForwardGpu(C, N, M, P, X, W, B, Y); } } diff --git a/samples/ComputeSharp.Benchmark/Program.cs b/samples/ComputeSharp.Benchmark/Program.cs index 1bfa2a7a..d7d613f9 100644 --- a/samples/ComputeSharp.Benchmark/Program.cs +++ b/samples/ComputeSharp.Benchmark/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; namespace ComputeSharp.Benchmark { @@ -6,7 +7,30 @@ namespace ComputeSharp.Benchmark { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + var benchmark = new FullyConnectedLayerBenchmark(); + benchmark.Gpu(); // Warmup + return; + + Stopwatch timer = new Stopwatch(); + TimeSpan cpuTime = TimeSpan.Zero, gpuTime = TimeSpan.Zero; + + for (int i = 0; i < 10; i++) + { + benchmark.Cpu(); + cpuTime += timer.Elapsed; + Console.WriteLine($"CPU: {timer.Elapsed:g}"); + timer.Restart(); + benchmark.Gpu(); + gpuTime += timer.Elapsed; + Console.WriteLine($"GPU: {timer.Elapsed:g}"); + timer.Restart(); + } + + Console.WriteLine("======== AVERAGE ========"); + Console.WriteLine($"CPU: {cpuTime:g}"); + Console.WriteLine($"GPU: {gpuTime:g}"); + + Console.ReadKey(); } } }