Search in sources :

Example 1 with MatrixProcessorInterface

use of jmbench.interfaces.MatrixProcessorInterface in project Java-Matrix-Benchmark by lessthanoptimal.

the class RuntimeEvaluationTest method evaluate.

/**
 * Computes the number of operations per second it takes to run the specified algortihm
 * with the inputs specified in {@link #setupTest()}.
 *
 * @return Number of operations per second.
 */
@Override
public TestResults evaluate() {
    int cycles = 0;
    long numTrials = estimatedTrials;
    if (numTrials <= 0) {
        numTrials = 1;
    }
    // try to purge all temporary data that has yet to be clean up so that the GC won't run
    // while performance is being measured
    runGarbageCollector();
    MatrixProcessorInterface alg = createAlgorithm();
    // see if the operation isn't supported
    if (alg == null) {
        return new RuntimeMeasurement(-1, -1);
    }
    // translate it to nanoseconds
    long goalDuration = this.goalRuntime * 1000000;
    while (true) {
        // nano is more precise than the millisecond timer
        long elapsedTime = alg.process(inputs, outputs, numTrials);
        // System.out.println("  in seconds "+(elapsedTime/1e9));
        if (elapsedTime > goalDuration * 0.9) {
            estimatedTrials = (long) Math.ceil(goalDuration * (double) numTrials / (double) elapsedTime);
            // System.out.println("  elapsedTime = "+elapsedTime);
            return compileResults((double) numTrials / (elapsedTime / 1e9));
        } else {
            // 0.2 seconds
            // if enough time has elapsed use a linear model to predict how many trials it will take
            long oldNumTrials = numTrials;
            numTrials = (long) Math.ceil(goalDuration * (double) numTrials / (double) elapsedTime);
            if (oldNumTrials > numTrials) {
                numTrials = oldNumTrials;
            }
        }
        runGarbageCollector();
        if (cycles++ > 20) {
            throw new RuntimeException("Exceeded the opsPerSecondMax cycles");
        }
    }
}
Also used : MatrixProcessorInterface(jmbench.interfaces.MatrixProcessorInterface)

Example 2 with MatrixProcessorInterface

use of jmbench.interfaces.MatrixProcessorInterface in project Java-Matrix-Benchmark by lessthanoptimal.

the class MemoryTest method evaluate.

@Override
public TestResults evaluate() {
    Random rand = new Random(randomSeed);
    BenchmarkMatrix[] inputs = gen != null ? gen.createInputs(factory, rand, size) : null;
    double[] mod = null;
    if (gen != null) {
        mod = new double[inputs.length];
        for (int i = 0; i < inputs.length; i++) {
            mod[i] = inputs[i].get(0, 0);
        }
    }
    MatrixProcessorInterface operation = createAlgorithm();
    // see if the operation is supported
    if (operation == null) {
        return new Results(-1);
    }
    long start = System.currentTimeMillis();
    // output is null since that might require creating new memory, which isn't strictly part of th test
    operation.process(inputs, null, N);
    long stop = System.currentTimeMillis();
    if (gen != null) {
        for (int i = 0; i < inputs.length; i++) {
            if (mod[i] != inputs[i].get(0, 0))
                throw new RuntimeException("Input modified! Input " + i);
        }
    }
    // the application exits
    synchronized (this) {
        try {
            wait(300);
        } catch (InterruptedException e) {
        }
    }
    return new Results(stop - start);
}
Also used : MatrixProcessorInterface(jmbench.interfaces.MatrixProcessorInterface) Random(java.util.Random) TestResults(jmbench.tools.TestResults) BenchmarkMatrix(jmbench.interfaces.BenchmarkMatrix)

Example 3 with MatrixProcessorInterface

use of jmbench.interfaces.MatrixProcessorInterface in project Java-Matrix-Benchmark by lessthanoptimal.

the class SolverAccuracy method evaluateSolver.

private void evaluateSolver() {
    reason = OutputError.NO_ERROR;
    foundResult = Double.NaN;
    BenchmarkMatrix[] inputsB = new BenchmarkMatrix[2];
    BenchmarkMatrix[] outputB = new BenchmarkMatrix[1];
    inputsB[0] = factory.convertToLib(A);
    inputsB[1] = factory.convertToLib(b);
    MatrixProcessorInterface operation = createAlgorithm();
    if (operation == null) {
        reason = OutputError.NOT_SUPPORTED;
        return;
    }
    try {
        operation.process(inputsB, outputB, 1);
    } catch (DetectedException e) {
        reason = OutputError.DETECTED_FAILURE;
        return;
    } catch (Exception e) {
        addUnexpectedException(e);
        reason = OutputError.UNEXPECTED_EXCEPTION;
        return;
    }
    RowMajorMatrix[] results = new RowMajorMatrix[outputB.length];
    for (int i = 0; i < results.length; i++) results[i] = factory.convertToRowMajor(outputB[i]);
    RowMajorMatrix x = results[0];
    if (RowMajorOps.hasUncountable(x)) {
        reason = OutputError.UNCOUNTABLE;
        return;
    }
    foundResult = StabilityBenchmark.residualErrorMetric(A, x, b);
    if (Double.isNaN(foundResult) || Double.isInfinite(foundResult)) {
        reason = OutputError.LARGE_ERROR;
        return;
    }
}
Also used : DetectedException(jmbench.interfaces.DetectedException) MatrixProcessorInterface(jmbench.interfaces.MatrixProcessorInterface) RowMajorMatrix(jmbench.matrix.RowMajorMatrix) BenchmarkMatrix(jmbench.interfaces.BenchmarkMatrix) DetectedException(jmbench.interfaces.DetectedException)

Example 4 with MatrixProcessorInterface

use of jmbench.interfaces.MatrixProcessorInterface in project Java-Matrix-Benchmark by lessthanoptimal.

the class SolverOverflow method check.

@Override
public boolean check(int testPoint) {
    // System.out.println("check = "+testPoint);
    double scale = Math.pow(scaling, testPoint);
    RowMajorOps.scale(scale, A, A_scale);
    RowMajorOps.scale(scale, b, b_scale);
    BenchmarkMatrix[] inputsB = new BenchmarkMatrix[2];
    BenchmarkMatrix[] outputB = new BenchmarkMatrix[1];
    inputsB[0] = factory.convertToLib(A_scale);
    inputsB[1] = factory.convertToLib(b_scale);
    MatrixProcessorInterface operation = createAlgorithm();
    if (operation == null) {
        reason = OutputError.NOT_SUPPORTED;
        return false;
    }
    try {
        operation.process(inputsB, outputB, 1);
    } catch (DetectedException e) {
        reason = OutputError.DETECTED_FAILURE;
        return false;
    } catch (Exception e) {
        addUnexpectedException(e);
        reason = OutputError.UNEXPECTED_EXCEPTION;
        return false;
    }
    RowMajorMatrix[] results = new RowMajorMatrix[outputB.length];
    for (int i = 0; i < results.length; i++) results[i] = factory.convertToRowMajor(outputB[i]);
    RowMajorMatrix x = results[0];
    if (RowMajorOps.hasUncountable(x)) {
        reason = OutputError.UNCOUNTABLE;
        return false;
    }
    double error = StabilityBenchmark.residualErrorMetric(A_scale, x, b_scale);
    // was countable, it only become uncountable when computing the error.
    if (Double.isNaN(error) || Double.isInfinite(error) || error > breakingPoint) {
        reason = OutputError.LARGE_ERROR;
        return false;
    }
    System.gc();
    Thread.yield();
    return true;
}
Also used : DetectedException(jmbench.interfaces.DetectedException) MatrixProcessorInterface(jmbench.interfaces.MatrixProcessorInterface) RowMajorMatrix(jmbench.matrix.RowMajorMatrix) BenchmarkMatrix(jmbench.interfaces.BenchmarkMatrix) DetectedException(jmbench.interfaces.DetectedException)

Example 5 with MatrixProcessorInterface

use of jmbench.interfaces.MatrixProcessorInterface in project Java-Matrix-Benchmark by lessthanoptimal.

the class OverflowTestBase method check.

@Override
public boolean check(int testPoint) {
    double scale = Math.pow(scaling, testPoint);
    Ascaled.set(A);
    RowMajorOps.scale(scale, Ascaled);
    RowMajorMatrix[] inputs = new RowMajorMatrix[] { Ascaled };
    BenchmarkMatrix[] inputsB = new BenchmarkMatrix[inputs.length];
    BenchmarkMatrix[] outputB = new BenchmarkMatrix[getNumOutputs()];
    for (int i = 0; i < inputs.length; i++) {
        inputsB[i] = factory.convertToLib(inputs[i]);
    }
    MatrixProcessorInterface operation = createAlgorithm();
    if (operation == null) {
        reason = OutputError.NOT_SUPPORTED;
        return false;
    }
    try {
        operation.process(inputsB, outputB, 1);
    } catch (DetectedException e) {
        reason = OutputError.DETECTED_FAILURE;
        return false;
    } catch (Exception e) {
        addUnexpectedException(e);
        reason = OutputError.UNEXPECTED_EXCEPTION;
        return false;
    }
    RowMajorMatrix[] results = new RowMajorMatrix[outputB.length];
    for (int i = 0; i < results.length; i++) results[i] = factory.convertToRowMajor(outputB[i]);
    for (RowMajorMatrix R : results) {
        if (RowMajorOps.hasUncountable(R)) {
            reason = OutputError.UNCOUNTABLE;
            return false;
        }
    }
    return checkResults(results);
}
Also used : DetectedException(jmbench.interfaces.DetectedException) MatrixProcessorInterface(jmbench.interfaces.MatrixProcessorInterface) RowMajorMatrix(jmbench.matrix.RowMajorMatrix) BenchmarkMatrix(jmbench.interfaces.BenchmarkMatrix) DetectedException(jmbench.interfaces.DetectedException)

Aggregations

MatrixProcessorInterface (jmbench.interfaces.MatrixProcessorInterface)7 BenchmarkMatrix (jmbench.interfaces.BenchmarkMatrix)6 DetectedException (jmbench.interfaces.DetectedException)5 RowMajorMatrix (jmbench.matrix.RowMajorMatrix)5 Random (java.util.Random)1 TestResults (jmbench.tools.TestResults)1