private static void TestForward(NetworkLayerBase cpu, NetworkLayerBase gpu, int samples) { Tensor x = CreateRandomTensor(samples, cpu.InputInfo.Size); cpu.Forward(x, out Tensor z_cpu, out Tensor a_cpu); gpu.Forward(x, out Tensor z_gpu, out Tensor a_gpu); Assert.IsTrue(z_cpu.ContentEquals(z_gpu)); Assert.IsTrue(a_cpu.ContentEquals(a_gpu)); Tensor.Free(x, z_cpu, a_cpu, z_gpu, a_gpu); }
private static unsafe void TestForward(NetworkLayerBase cpu, NetworkLayerBase gpu, float[,] x) { fixed(float *px = x) { Tensor.Reshape(px, x.GetLength(0), x.GetLength(1), out Tensor xt); cpu.Forward(xt, out Tensor z_cpu, out Tensor a_cpu); gpu.Forward(xt, out Tensor z_gpu, out Tensor a_gpu); Assert.IsTrue(z_cpu.ContentEquals(z_gpu)); Assert.IsTrue(a_cpu.ContentEquals(a_gpu)); z_cpu.Free(); a_cpu.Free(); z_gpu.Free(); a_gpu.Free(); } }