//[unboundMatrixMultGemm2DArrayTest] public static void Gemm2DArrayTest() { var gpuMultiplication64 = DefaultMatrixMultiplyModuleF64.DefaultInstance; const int wA = 31, hA = 65, wB = 65, hB = 31; const int wC = 65, hC = 65; var rng = new Random(42); var a = Array2D.ofArrayRowMajor(hA, wA, (Enumerable.Repeat(rng, hA * wA).Select((random, i) => random.NextDouble())).ToArray()); var b = Array2D.ofArrayRowMajor(hB, wB, (Enumerable.Repeat(rng, hB * wB).Select((random, i) => random.NextDouble())).ToArray()); var c = Array2D.ofArrayRowMajor(hC, wC, Enumerable.Repeat(0.0, hC * wC).ToArray()); var cpuOutput = MatrixMult.MultiplyMatrix(Array2D.toArrayRowMajor(c), Array2D.toArrayRowMajor(a), Array2D.toArrayRowMajor(b), wA, wB); var gpuOutput = gpuMultiplication64.Mult(Implementation.PrefetchingData, Transpose.NoTranspose, Transpose.NoTranspose, MatrixStorageOrder.RowMajor, 1.0, 0.0, a, b, c); for (var i = 0; i < cpuOutput.ToArray().Length; ++i) { Assert.AreEqual(cpuOutput[i], Array2D.toArrayRowMajor(gpuOutput)[i], 1.0e-12); } }
//[unboundMatrixMultGemm1DArrayTest] public static void Gemm1DArrayTest() { var gpuMultiplication64 = DefaultMatrixMultiplyModuleF64.DefaultInstance; const int wA = 32, hA = 64, wB = 64, hB = 32; const int wC = 64, hC = 64; var rng = new Random(42); var a = (Enumerable.Repeat(rng, hA * wA).Select((random, i) => random.NextDouble())).ToArray(); var b = (Enumerable.Repeat(rng, hB * wB).Select((random, i) => random.NextDouble())).ToArray(); var c = Enumerable.Repeat(0.0, hC * wC).ToArray(); var cpuOutput = MatrixMult.MultiplyMatrix(c, a, b, wA, wB); var gpuOutput = gpuMultiplication64.Mult(Implementation.PrefetchingData, Transpose.NoTranspose, Transpose.NoTranspose, MatrixStorageOrder.RowMajor, wA, wB, 1.0, 0.0, a, b, c); for (var i = 0; i < cpuOutput.Length; ++i) { Assert.AreEqual(cpuOutput[i], gpuOutput[i], 1.0e-12); } }