using System; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; namespace ComputeSharp.Benchmark { /// /// A that benchmarks a fully connected layer forward pass on both CPU and GPU /// public class FullyConnectedLayerBenchmark { /// /// The number of samples /// private const int Count = 128; /// /// The nummber of rows in the matrix /// private const int N = 100; /// /// The number of columns in the matrix (same as the number of rows in the matrix) /// private const int M = 100; /// /// The number of columns in the matrix /// private const int P = 100; private readonly float[] A; private readonly float[] B; private readonly float[] C; private readonly float[] D; private static readonly Random Random = new Random(); /// /// Creates a new instance /// public FullyConnectedLayerBenchmark() { A = CreateRandomArray(Count * N * M); B = CreateRandomArray(M * P); C = CreateRandomArray(N * P); D = new float[Count * N * P]; } /// /// Creates a new array of the specified size /// /// The size of the new random array to create [Pure] private static float[] CreateRandomArray(int size) { float[] array = new float[size]; ref float r = ref array[0]; for (int i = 0; i < size; i++) { Unsafe.Add(ref r, i) = (float)Random.NextDouble(); } return array; } } }