Search in sources :

Example 61 with LocalVariableMap

use of org.apache.sysml.runtime.controlprogram.LocalVariableMap in project systemml by apache.

the class InterProceduralAnalysis method analyzeProgram.

/**
 * Main interface to perform IPA over a given DML program.
 *
 * @param repetitions number of IPA rounds
 */
public void analyzeProgram(int repetitions) {
    // sanity check for valid number of repetitions
    if (repetitions <= 0)
        throw new HopsException("Invalid number of IPA repetitions: " + repetitions);
    // perform number of requested IPA iterations
    FunctionCallSizeInfo lastSizes = null;
    for (int i = 0; i < repetitions; i++) {
        if (LOG.isDebugEnabled())
            LOG.debug("IPA: start IPA iteration " + (i + 1) + "/" + repetitions + ".");
        // get function call size infos to obtain candidates for statistics propagation
        FunctionCallSizeInfo fcallSizes = new FunctionCallSizeInfo(_fgraph);
        if (LOG.isDebugEnabled())
            LOG.debug("IPA: Initial FunctionCallSummary: \n" + fcallSizes);
        // step 1: intra- and inter-procedural
        if (INTRA_PROCEDURAL_ANALYSIS) {
            // get unary dimension-preserving non-candidate functions
            for (String tmp : fcallSizes.getInvalidFunctions()) if (isUnarySizePreservingFunction(_prog.getFunctionStatementBlock(tmp)))
                fcallSizes.addDimsPreservingFunction(tmp);
            if (LOG.isDebugEnabled())
                LOG.debug("IPA: Extended FunctionCallSummary: \n" + fcallSizes);
            // propagate statistics and scalars into functions and across DAGs
            // (callVars used to chain outputs/inputs of multiple functions calls)
            LocalVariableMap callVars = new LocalVariableMap();
            for (// propagate stats into candidates
            StatementBlock sb : // propagate stats into candidates
            _prog.getStatementBlocks()) propagateStatisticsAcrossBlock(sb, callVars, fcallSizes, new HashSet<String>());
        }
        // step 2: apply additional IPA passes
        for (IPAPass pass : _passes) if (pass.isApplicable(_fgraph))
            pass.rewriteProgram(_prog, _fgraph, fcallSizes);
        // early abort without functions or on reached fixpoint
        if (_fgraph.getReachableFunctions().isEmpty() || (lastSizes != null && lastSizes.equals(fcallSizes))) {
            if (LOG.isDebugEnabled())
                LOG.debug("IPA: Early abort after " + (i + 1) + "/" + repetitions + " repetitions due to reached fixpoint.");
            break;
        }
    }
    // cleanup pass: remove unused functions
    FunctionCallGraph graph2 = new FunctionCallGraph(_prog);
    IPAPass rmFuns = new IPAPassRemoveUnusedFunctions();
    if (rmFuns.isApplicable(graph2))
        rmFuns.rewriteProgram(_prog, graph2, null);
}
Also used : LocalVariableMap(org.apache.sysml.runtime.controlprogram.LocalVariableMap) HopsException(org.apache.sysml.hops.HopsException) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) HashSet(java.util.HashSet)

Example 62 with LocalVariableMap

use of org.apache.sysml.runtime.controlprogram.LocalVariableMap in project systemml by apache.

the class InterProceduralAnalysis method isUnarySizePreservingFunction.

private boolean isUnarySizePreservingFunction(FunctionStatementBlock fsb) {
    FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
    // check unary functions over matrices
    boolean ret = (fstmt.getInputParams().size() == 1 && fstmt.getInputParams().get(0).getDataType() == DataType.MATRIX && fstmt.getOutputParams().size() == 1 && fstmt.getOutputParams().get(0).getDataType() == DataType.MATRIX);
    // check size-preserving characteristic
    if (ret) {
        FunctionCallSizeInfo fcallSizes = new FunctionCallSizeInfo(_fgraph, false);
        HashSet<String> fnStack = new HashSet<>();
        LocalVariableMap callVars = new LocalVariableMap();
        // populate input
        MatrixObject mo = createOutputMatrix(7777, 3333, -1);
        callVars.put(fstmt.getInputParams().get(0).getName(), mo);
        // propagate statistics
        for (StatementBlock sbi : fstmt.getBody()) propagateStatisticsAcrossBlock(sbi, callVars, fcallSizes, fnStack);
        // compare output
        MatrixObject mo2 = (MatrixObject) callVars.get(fstmt.getOutputParams().get(0).getName());
        ret &= mo.getNumRows() == mo2.getNumRows() && mo.getNumColumns() == mo2.getNumColumns();
        // reset function
        mo.getMatrixCharacteristics().setDimension(-1, -1);
        for (StatementBlock sbi : fstmt.getBody()) propagateStatisticsAcrossBlock(sbi, callVars, fcallSizes, fnStack);
    }
    return ret;
}
Also used : ExternalFunctionStatement(org.apache.sysml.parser.ExternalFunctionStatement) FunctionStatement(org.apache.sysml.parser.FunctionStatement) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) LocalVariableMap(org.apache.sysml.runtime.controlprogram.LocalVariableMap) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) HashSet(java.util.HashSet)

Example 63 with LocalVariableMap

use of org.apache.sysml.runtime.controlprogram.LocalVariableMap in project systemml by apache.

the class CostEstimationWrapper method getTimeEstimate.

public static double getTimeEstimate(ProgramBlock pb, ExecutionContext ec, boolean recursive) {
    Timing time = new Timing(true);
    HashMap<String, VarStats> stats = new HashMap<>();
    LocalVariableMap vars = (ec != null) ? ec.getVariables() : new LocalVariableMap();
    double costs = _costEstim.getTimeEstimate(pb, vars, stats, recursive);
    LOG.debug("Finished estimation in " + time.stop() + "ms.");
    return costs;
}
Also used : HashMap(java.util.HashMap) LocalVariableMap(org.apache.sysml.runtime.controlprogram.LocalVariableMap) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)

Example 64 with LocalVariableMap

use of org.apache.sysml.runtime.controlprogram.LocalVariableMap in project systemml by apache.

the class CostEstimationWrapper method getTimeEstimate.

public static double getTimeEstimate(Program rtprog, ExecutionContext ec) {
    Timing time = new Timing(true);
    HashMap<String, VarStats> stats = new HashMap<>();
    LocalVariableMap vars = (ec != null) ? ec.getVariables() : new LocalVariableMap();
    double costs = _costEstim.getTimeEstimate(rtprog, vars, stats);
    LOG.debug("Finished estimation in " + time.stop() + "ms.");
    return costs;
}
Also used : HashMap(java.util.HashMap) LocalVariableMap(org.apache.sysml.runtime.controlprogram.LocalVariableMap) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)

Aggregations

LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)64 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)19 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)19 StatementBlock (org.apache.sysml.parser.StatementBlock)19 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)19 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)12 HashSet (java.util.HashSet)11 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)11 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)11 FunctionStatement (org.apache.sysml.parser.FunctionStatement)10 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)10 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)9 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)9 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)9 Path (org.apache.hadoop.fs.Path)8 ExternalFunctionStatement (org.apache.sysml.parser.ExternalFunctionStatement)8 ExecutionContext (org.apache.sysml.runtime.controlprogram.context.ExecutionContext)8 FunctionOp (org.apache.sysml.hops.FunctionOp)7