public void SpeedTest() { int inchannels = 1024, outchannels = 512; OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels)); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels)); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels)); Dense ope = new Dense(inchannels, outchannels); Stopwatch sw = new Stopwatch(); sw.Start(); ope.Execute(x_tensor, w_tensor, y_tensor); ope.Execute(x_tensor, w_tensor, y_tensor); ope.Execute(x_tensor, w_tensor, y_tensor); ope.Execute(x_tensor, w_tensor, y_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 }) { float[] xval = (new float[inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray(); float[] wval = (new float[inchannels * outchannels]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray(); Map0D x = new Map0D(inchannels, batch, xval); Filter0D w = new Filter0D(inchannels, outchannels, 1, wval); Map0D y = Reference(x, w); OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels, batch), xval); OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels), wval); OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels, batch)); Dense ope = new Dense(inchannels, outchannels, batch); ope.Execute(x_tensor, w_tensor, y_tensor); float[] y_expect = y.ToArray(); float[] y_actual = y_tensor.State; CollectionAssert.AreEqual(xval, x_tensor.State); CollectionAssert.AreEqual(wval, w_tensor.State); AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {inchannels},{outchannels},{batch}"); Console.WriteLine($"pass: {inchannels},{outchannels},{batch}"); } } } Console.WriteLine($"maxerr:{max_err}"); }