public void SpeedTest() { int inwidth = 512, inchannels = 32, outchannels = 63; OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map1D(inchannels, inwidth)); OverflowCheckedTensor gy_tensor = new OverflowCheckedTensor(Shape.Map1D(outchannels, inwidth)); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels)); PointwiseKernelProduct ope = new PointwiseKernelProduct(inwidth, inchannels, outchannels); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(x_tensor, gy_tensor, gw_tensor); ope.Execute(x_tensor, gy_tensor, gw_tensor); ope.Execute(x_tensor, gy_tensor, gw_tensor); ope.Execute(x_tensor, gy_tensor, gw_tensor); sw.Stop(); Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec"); }
public void ExecuteTest() { float max_err = 0; foreach (int batch in new int[] { 1, 2 }) { foreach (int inchannels in new int[] { 1, 2, 3, 4, 5, 10, 15, 20 }) { foreach (int outchannels in new int[] { 7, 13 }) { foreach (int inwidth in new int[] { 8, 9, 13, 17 }) { foreach (int inheight in new int[] { 8, 9, 19, 23 }) { float[] xval = (new float[inwidth * inheight * inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] gyval = (new float[inwidth * inheight * outchannels * batch]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); Map2D x = new Map2D(inchannels, inwidth, inheight, batch, xval); Map2D gy = new Map2D(outchannels, inwidth, inheight, batch, gyval); Filter2D gw = Reference(x, gy); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(inchannels, inwidth, inheight, batch), xval); OverflowCheckedTensor gy_tensor = new OverflowCheckedTensor(Shape.Map2D(outchannels, inwidth, inheight, batch), gyval); OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels)); PointwiseKernelProduct ope = new PointwiseKernelProduct(inwidth, inheight, inchannels, outchannels, batch); ope.Execute(x_tensor, gy_tensor, gw_tensor); float[] gw_expect = gw.ToArray(); float[] gw_actual = gw_tensor.State; CollectionAssert.AreEqual(xval, x_tensor.State); CollectionAssert.AreEqual(gyval, gy_tensor.State); AssertError.Tolerance(gw_expect, gw_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {inchannels},{outchannels},{inwidth},{inheight},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{inwidth},{inheight},{batch}"); } } } } } Console.WriteLine($"maxerr:{max_err}"); }