예제 #1
0
        public static void TestBinaryBasicValues(BinaryOp op)
        {
            int numValues = op.basicValues.Length;

            if (numValues > 0)
            {
                F64[]    inputs0   = new F64[numValues];
                F64[]    inputs1   = new F64[numValues];
                F64[]    outputs   = new F64[numValues];
                double[] reference = new double[numValues];

                for (int i = 0; i < numValues; i++)
                {
                    F64 i0 = F64.FromDouble(op.basicValues[i].Item1);
                    F64 i1 = F64.FromDouble(op.basicValues[i].Item2);
                    inputs0[i]   = i0;
                    inputs1[i]   = i1;
                    reference[i] = op.refExecute(i0.Double, i1.Double);
                }

                op.arrayExecute(numValues, inputs0, inputs1, outputs);

                Console.WriteLine("{0,-16}                      {1,16} {2,16} {3,16}", op.name, "reference", "result", "error");
                for (int i = 0; i < numValues; i++)
                {
                    double input0 = inputs0[i].Double;
                    double input1 = inputs1[i].Double;
                    double res    = outputs[i].Double;
                    double err    = op.evaluateError(inputs0[i], inputs1[i], outputs[i], reference[i]);
                    Console.WriteLine("{0}, {1} -> {2} {3} {4}", DoubleToString(input0, 16), DoubleToString(input1, 16), DoubleToString(reference[i], 16), DoubleToString(res, 16), DoubleToString(err, 16));
                }
                Console.WriteLine();
            }
        }
예제 #2
0
        public CeilFP64vsDouble()
        {
            ValueGenerator inputGenerator = Input.Uniform(-1.0, 1.0);

            this.doubleArrayInputs = inputGenerator(rnd, BENCHMARK_CHUNK_SIZE);
            this.f64ArrayInputs    = this.doubleArrayInputs.Select(d => F64.FromDouble(d)).ToArray();

            this.doubleArrayOutputs = new double[BENCHMARK_CHUNK_SIZE];
            this.f64ArrayOutputs    = new F64[BENCHMARK_CHUNK_SIZE];
        }
예제 #3
0
        public static PrecisionResult TestUnaryPrecision(UnaryOp op)
        {
            int    numTested  = 0;
            double totalErr   = 0.0;
            double maxErr     = 0.0;
            F64    worstInput = F64.Zero;

            foreach (ValueGenerator inputGenerator in op.inputGenerators)
            {
                F64[] inputs  = inputGenerator(rnd, NUM_PRECISION_TESTS).Select(d => F64.FromDouble(d)).ToArray();
                F64[] outputs = new F64[NUM_PRECISION_TESTS];

                op.arrayExecute(NUM_PRECISION_TESTS, inputs, outputs);

                for (int i = 0; i < NUM_PRECISION_TESTS; i++)
                {
                    double input     = inputs[i].Double;
                    double res       = outputs[i].Double;
                    double reference = op.refExecute(input);

                    if (reference >= ValueBounds.NegMax && reference <= ValueBounds.PosMax)
                    {
                        double err = op.evaluateError(inputs[i], outputs[i], reference);
                        numTested++;
                        totalErr += err;

                        if (err >= maxErr)
                        {
                            maxErr     = Math.Max(maxErr, err);
                            worstInput = inputs[i];
                        }
                    }
                }
            }

            Debug.Assert(numTested > 1000);
            double avgErr  = totalErr / (double)numTested;
            double numBits = -Math.Log(maxErr, 2.0);

            return(new PrecisionResult(avgErr, maxErr, numBits, new[] { worstInput }));
        }
예제 #4
0
        public static BenchmarkResult BenchmarkBinaryOperation(BinaryOp op)
        {
            // \todo [petri] use all generators?
            F64[] inputs0 = op.inputGenerators[0].Item1(rnd, BENCHMARK_CHUNK_SIZE).Select(d => F64.FromDouble(d)).ToArray();
            F64[] inputs1 = op.inputGenerators[0].Item2(rnd, BENCHMARK_CHUNK_SIZE).Select(d => F64.FromDouble(d)).ToArray();
            F64[] outputs = new F64[BENCHMARK_CHUNK_SIZE];

            // Measure execution time.
            double elapsedSeconds = BenchmarkFunction(() =>
            {
                for (int iter = 0; iter < op.numBenchmarkIters; iter++)
                {
                    op.arrayExecute(BENCHMARK_CHUNK_SIZE, inputs0, inputs1, outputs);
                }
            });

            // Return reuslt.
            long   numTotalOps = op.numBenchmarkIters * BENCHMARK_CHUNK_SIZE;
            double opsPerSec   = numTotalOps / elapsedSeconds;

            return(new BenchmarkResult(opsPerSec, elapsedSeconds));
        }