Search in sources :

Example 46 with DataOp

use of org.apache.sysml.hops.DataOp in project incubator-systemml by apache.

the class GDFEnumOptimizer method costRuntimePlan.

private static double costRuntimePlan(Plan p) throws DMLRuntimeException {
    Program prog = p.getNode().getProgram();
    if (prog == null)
        throw new DMLRuntimeException("Program not available for runtime plan costing.");
    //put data flow configuration into program
    rSetRuntimePlanConfig(p, new HashMap<Long, Plan>());
    double costs = -1;
    if (COST_FULL_PROGRAMS || (p.getNode().getHop() == null || p.getNode().getProgramBlock() == null)) {
        //recompile entire runtime program
        Recompiler.recompileProgramBlockHierarchy(prog.getProgramBlocks(), new LocalVariableMap(), 0, false);
        _compiledPlans++;
        //cost entire runtime program
        ExecutionContext ec = ExecutionContextFactory.createContext(prog);
        costs = CostEstimationWrapper.getTimeEstimate(prog, ec);
    } else {
        Hop currentHop = p.getNode().getHop();
        ProgramBlock pb = p.getNode().getProgramBlock();
        try {
            //keep the old dag roots
            ArrayList<Hop> oldRoots = pb.getStatementBlock().get_hops();
            Hop tmpHop = null;
            if (!(currentHop instanceof DataOp && ((DataOp) currentHop).isWrite())) {
                ArrayList<Hop> newRoots = new ArrayList<Hop>();
                tmpHop = new DataOp("_tmp", currentHop.getDataType(), currentHop.getValueType(), currentHop, DataOpTypes.TRANSIENTWRITE, "tmp");
                //ensure recursive visitstatus reset on recompile
                tmpHop.setVisited();
                newRoots.add(tmpHop);
                pb.getStatementBlock().set_hops(newRoots);
            }
            //recompile modified runtime program
            Recompiler.recompileProgramBlockHierarchy(prog.getProgramBlocks(), new LocalVariableMap(), 0, false);
            _compiledPlans++;
            //cost partial runtime program up to current hop
            ExecutionContext ec = ExecutionContextFactory.createContext(prog);
            costs = CostEstimationWrapper.getTimeEstimate(prog, ec);
            //restore original hop dag
            if (tmpHop != null)
                HopRewriteUtils.removeChildReference(tmpHop, currentHop);
            pb.getStatementBlock().set_hops(oldRoots);
        } catch (HopsException ex) {
            throw new DMLRuntimeException(ex);
        }
    }
    //release forced data flow configuration from program
    rResetRuntimePlanConfig(p, new HashMap<Long, Plan>());
    _costedPlans++;
    return costs;
}
Also used : Program(org.apache.sysml.runtime.controlprogram.Program) Hop(org.apache.sysml.hops.Hop) ArrayList(java.util.ArrayList) HopsException(org.apache.sysml.hops.HopsException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) LocalVariableMap(org.apache.sysml.runtime.controlprogram.LocalVariableMap) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) DataOp(org.apache.sysml.hops.DataOp)

Example 47 with DataOp

use of org.apache.sysml.hops.DataOp in project incubator-systemml by apache.

the class GDFEnumOptimizer method rSetRuntimePlanConfig.

private static void rSetRuntimePlanConfig(Plan p, HashMap<Long, Plan> memo) {
    ExecType CLUSTER = OptimizerUtils.isSparkExecutionMode() ? ExecType.SPARK : ExecType.MR;
    //basic memoization including containment check 
    if (memo.containsKey(p.getNode().getID())) {
        Plan pmemo = memo.get(p.getNode().getID());
        if (!p.getInterestingProperties().equals(pmemo.getInterestingProperties())) {
            //TODO this would require additional cleanup in special cases
            if (_resolve.resolveMismatch(pmemo.getRewriteConfig(), p.getRewriteConfig()))
                memo.put(p.getNode().getID(), p);
            //logging of encounter plan mismatch
            LOG.warn("Configuration mismatch on shared node (" + p.getNode().getHop().getHopID() + "). Falling back to heuristic '" + _resolve.getName() + "'.");
            LOG.warn(p.getInterestingProperties().toString());
            LOG.warn(memo.get(p.getNode().getID()).getInterestingProperties());
            _planMismatches++;
            return;
        }
    }
    //set plan configuration
    Hop hop = p.getNode().getHop();
    if (hop != null) {
        RewriteConfig rc = p.getRewriteConfig();
        //set exec type
        hop.setForcedExecType(rc.getExecType());
        //set blocksizes and reblock
        hop.setRowsInBlock(rc.getBlockSize());
        hop.setColsInBlock(rc.getBlockSize());
        if (//after blocksize update
        rc.getExecType() == CLUSTER) {
            //TODO double check dataop condition - side effect from plan validity
            boolean reblock = HopRewriteUtils.alwaysRequiresReblock(hop) || (hop.hasMatrixInputWithDifferentBlocksizes() && !(hop instanceof DataOp));
            hop.setRequiresReblock(reblock);
        } else
            hop.setRequiresReblock(false);
    }
    //process childs
    if (p.getChilds() != null)
        for (Plan c : p.getChilds()) rSetRuntimePlanConfig(c, memo);
    //memoization (mark as processed)
    memo.put(p.getNode().getID(), p);
}
Also used : Hop(org.apache.sysml.hops.Hop) ExecType(org.apache.sysml.lops.LopProperties.ExecType) DataOp(org.apache.sysml.hops.DataOp)

Aggregations

DataOp (org.apache.sysml.hops.DataOp)47 Hop (org.apache.sysml.hops.Hop)41 LiteralOp (org.apache.sysml.hops.LiteralOp)23 ArrayList (java.util.ArrayList)14 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)10 HopsException (org.apache.sysml.hops.HopsException)9 UnaryOp (org.apache.sysml.hops.UnaryOp)9 StatementBlock (org.apache.sysml.parser.StatementBlock)9 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)9 IndexingOp (org.apache.sysml.hops.IndexingOp)8 HashMap (java.util.HashMap)7 FunctionOp (org.apache.sysml.hops.FunctionOp)7 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)7 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)7 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)7 DataIdentifier (org.apache.sysml.parser.DataIdentifier)6 Data (org.apache.sysml.runtime.instructions.cp.Data)6 BinaryOp (org.apache.sysml.hops.BinaryOp)5 LeftIndexingOp (org.apache.sysml.hops.LeftIndexingOp)5 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)5