Search in sources :

Example 31 with WhileProgramBlock

use of org.apache.sysml.runtime.controlprogram.WhileProgramBlock in project incubator-systemml by apache.

the class ResourceOptimizer method pruneHasOnlyUnknownMR.

private static boolean pruneHasOnlyUnknownMR(ProgramBlock pb) {
    if (pb instanceof WhileProgramBlock) {
        WhileStatementBlock sb = (WhileStatementBlock) pb.getStatementBlock();
        sb.getPredicateHops().resetVisitStatus();
        return pruneHasOnlyUnknownMR(sb.getPredicateHops());
    } else if (pb instanceof IfProgramBlock) {
        IfStatementBlock sb = (IfStatementBlock) pb.getStatementBlock();
        sb.getPredicateHops().resetVisitStatus();
        return pruneHasOnlyUnknownMR(sb.getPredicateHops());
    } else if (// incl parfor
    pb instanceof ForProgramBlock) {
        ForStatementBlock sb = (ForStatementBlock) pb.getStatementBlock();
        sb.getFromHops().resetVisitStatus();
        sb.getToHops().resetVisitStatus();
        sb.getIncrementHops().resetVisitStatus();
        return pruneHasOnlyUnknownMR(sb.getFromHops()) && pruneHasOnlyUnknownMR(sb.getToHops()) && pruneHasOnlyUnknownMR(sb.getIncrementHops());
    } else // last-level program blocks
    {
        StatementBlock sb = pb.getStatementBlock();
        return pruneHasOnlyUnknownMR(sb.getHops());
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

Example 32 with WhileProgramBlock

use of org.apache.sysml.runtime.controlprogram.WhileProgramBlock in project incubator-systemml by apache.

the class OptimizerRuleBased method rValidateUIPConsumerList.

/* 	
	 * This will validate candidate's consumer list.
	 * 
	 * @param pn:				OpNode of parfor loop
	 * @param uipCandHopHM:		Hashmap of UIPCandidateHop with name as a key.		
	 * @throws DMLRuntimeException
	 */
private void rValidateUIPConsumerList(OptNode pn, HashMap<String, ArrayList<UIPCandidateHop>> uipCandHopHM) throws DMLRuntimeException {
    if (!pn.isLeaf()) {
        if (pn.getNodeType() == OptNode.NodeType.FUNCCALL) {
            Hop hop = (Hop) OptTreeConverter.getAbstractPlanMapping().getMappedHop(pn.getID());
            rValidateUIPConsumerList(hop.getInput(), uipCandHopHM);
            return;
        }
        ProgramBlock pb = (ProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(pn.getID())[1];
        VariableSet varRead = pb.getStatementBlock().variablesRead();
        boolean bUIPCandHopRead = false;
        for (Entry<String, ArrayList<UIPCandidateHop>> entry : uipCandHopHM.entrySet()) {
            ArrayList<UIPCandidateHop> uipCandHopList = entry.getValue();
            if (uipCandHopList != null) {
                for (UIPCandidateHop uipCandHop : uipCandHopList) {
                    ArrayList<Hop> consumerHops = uipCandHop.getConsumerHops();
                    if (consumerHops != null) {
                        // remove candidate from the list.
                        for (Hop consumerHop : consumerHops) {
                            if (varRead.containsVariable(consumerHop.getName())) {
                                bUIPCandHopRead = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
        // As none of the UIP candidates updated in this DAG, no need for further processing within this DAG
        if (!bUIPCandHopRead)
            return;
        for (OptNode optNode : pn.getChilds()) rValidateUIPConsumerList(optNode, uipCandHopHM);
    } else {
        OptTreePlanMappingAbstract map = OptTreeConverter.getAbstractPlanMapping();
        long ppid = map.getMappedParentID(map.getMappedParentID(pn.getID()));
        Object[] o = map.getMappedProg(ppid);
        ProgramBlock pb = (ProgramBlock) o[1];
        if (pb instanceof IfProgramBlock || pb instanceof WhileProgramBlock || //TODO
        (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)))
            rValidateUIPConsumerList(pb, uipCandHopHM);
        long pid = map.getMappedParentID(pn.getID());
        o = map.getMappedProg(pid);
        pb = (ProgramBlock) o[1];
        Hop hop = map.getMappedHop(pn.getID());
        rValidateUIPConsumerList(hop, uipCandHopHM, pb.getStatementBlock().variablesRead());
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) Hop(org.apache.sysml.hops.Hop) MultiThreadedHop(org.apache.sysml.hops.Hop.MultiThreadedHop) ArrayList(java.util.ArrayList) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) VariableSet(org.apache.sysml.parser.VariableSet) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) RDDObject(org.apache.sysml.runtime.instructions.spark.data.RDDObject)

Example 33 with WhileProgramBlock

use of org.apache.sysml.runtime.controlprogram.WhileProgramBlock in project incubator-systemml by apache.

the class OptimizerRuleBased method rGetUIPConsumerList.

/* 	
	 * This will get consumer list for candidate LeftIndexingOp.
	 * 
	 * @param pn:				OpNode of parfor loop
	 * @param uipCandHopHM:		Hashmap of UIPCandidateHop with name as a key.		
	 * @throws DMLRuntimeException
	 */
private void rGetUIPConsumerList(OptNode pn, HashMap<String, ArrayList<UIPCandidateHop>> uipCandHopHM) throws DMLRuntimeException {
    if (!pn.isLeaf()) {
        if (pn.getNodeType() == OptNode.NodeType.FUNCCALL)
            return;
        ProgramBlock pb = (ProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(pn.getID())[1];
        VariableSet varRead = pb.getStatementBlock().variablesRead();
        boolean bUIPCandHopRead = false;
        for (Entry<String, ArrayList<UIPCandidateHop>> entry : uipCandHopHM.entrySet()) {
            String uipCandHopID = entry.getKey();
            if (varRead.containsVariable(uipCandHopID)) {
                bUIPCandHopRead = true;
                break;
            }
        }
        // As none of the UIP candidates updated in this DAG, no need for further processing within this DAG
        if (!bUIPCandHopRead)
            return;
        for (OptNode optNode : pn.getChilds()) rGetUIPConsumerList(optNode, uipCandHopHM);
    } else {
        OptTreePlanMappingAbstract map = OptTreeConverter.getAbstractPlanMapping();
        long ppid = map.getMappedParentID(map.getMappedParentID(pn.getID()));
        Object[] o = map.getMappedProg(ppid);
        ProgramBlock pb = (ProgramBlock) o[1];
        Hop hop = (Hop) OptTreeConverter.getAbstractPlanMapping().getMappedHop(pn.getID());
        rGetUIPConsumerList(hop, uipCandHopHM);
        if (pb instanceof IfProgramBlock || pb instanceof WhileProgramBlock || //TODO
        (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)))
            rGetUIPConsumerList(pb, uipCandHopHM);
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) ArrayList(java.util.ArrayList) Hop(org.apache.sysml.hops.Hop) MultiThreadedHop(org.apache.sysml.hops.Hop.MultiThreadedHop) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) VariableSet(org.apache.sysml.parser.VariableSet) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) RDDObject(org.apache.sysml.runtime.instructions.spark.data.RDDObject)

Example 34 with WhileProgramBlock

use of org.apache.sysml.runtime.controlprogram.WhileProgramBlock in project incubator-systemml by apache.

the class OptimizerRuleBased method rResetVisitStatus.

private void rResetVisitStatus(OptNode pn) throws DMLRuntimeException {
    if (!pn.isLeaf()) {
        if (pn.getNodeType() == OptNode.NodeType.FUNCCALL) {
            Hop hopFunc = (Hop) OptTreeConverter.getAbstractPlanMapping().getMappedHop(pn.getID());
            hopFunc.resetVisitStatus();
            return;
        }
        ProgramBlock pb = (ProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(pn.getID())[1];
        ArrayList<ProgramBlock> childBlocks = null;
        ArrayList<ProgramBlock> elseBlocks = null;
        if (pb instanceof WhileProgramBlock)
            childBlocks = ((WhileProgramBlock) pb).getChildBlocks();
        else if (pb instanceof ForProgramBlock)
            childBlocks = ((ForProgramBlock) pb).getChildBlocks();
        else if (pb instanceof IfProgramBlock) {
            childBlocks = ((IfProgramBlock) pb).getChildBlocksIfBody();
            elseBlocks = ((IfProgramBlock) pb).getChildBlocksElseBody();
        }
        if (childBlocks != null) {
            for (ProgramBlock childBlock : childBlocks) {
                try {
                    Hop.resetVisitStatus(childBlock.getStatementBlock().get_hops());
                } catch (Exception e) {
                    throw new DMLRuntimeException(e);
                }
            }
        }
        if (elseBlocks != null) {
            for (ProgramBlock childBlock : elseBlocks) {
                try {
                    Hop.resetVisitStatus(childBlock.getStatementBlock().get_hops());
                } catch (Exception e) {
                    throw new DMLRuntimeException(e);
                }
            }
        }
        for (OptNode optNode : pn.getChilds()) {
            rResetVisitStatus(optNode);
        }
    } else {
        Hop hop = (Hop) OptTreeConverter.getAbstractPlanMapping().getMappedHop(pn.getID());
        if (hop != null) {
            hop.resetVisitStatus();
        }
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) Hop(org.apache.sysml.hops.Hop) MultiThreadedHop(org.apache.sysml.hops.Hop.MultiThreadedHop) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) HopsException(org.apache.sysml.hops.HopsException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) LopsException(org.apache.sysml.lops.LopsException) LanguageException(org.apache.sysml.parser.LanguageException) IOException(java.io.IOException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 35 with WhileProgramBlock

use of org.apache.sysml.runtime.controlprogram.WhileProgramBlock in project incubator-systemml by apache.

the class GraphBuilder method constructGDFGraph.

@SuppressWarnings("unchecked")
private static void constructGDFGraph(ProgramBlock pb, HashMap<String, GDFNode> roots) throws DMLRuntimeException, HopsException {
    if (pb instanceof FunctionProgramBlock) {
        throw new DMLRuntimeException("FunctionProgramBlocks not implemented yet.");
    } else if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        WhileStatementBlock wsb = (WhileStatementBlock) pb.getStatementBlock();
        //construct predicate node (conceptually sequence of from/to/incr)
        GDFNode pred = constructGDFGraph(wsb.getPredicateHops(), wpb, new HashMap<Long, GDFNode>(), roots);
        HashMap<String, GDFNode> inputs = constructLoopInputNodes(wpb, wsb, roots);
        HashMap<String, GDFNode> lroots = (HashMap<String, GDFNode>) inputs.clone();
        //process childs blocks
        for (ProgramBlock pbc : wpb.getChildBlocks()) constructGDFGraph(pbc, lroots);
        HashMap<String, GDFNode> outputs = constructLoopOutputNodes(wsb, lroots);
        GDFLoopNode lnode = new GDFLoopNode(wpb, pred, inputs, outputs);
        //construct crossblock nodes
        constructLoopOutputCrossBlockNodes(wsb, lnode, outputs, roots, wpb);
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) pb;
        IfStatementBlock isb = (IfStatementBlock) pb.getStatementBlock();
        //construct predicate
        if (isb.getPredicateHops() != null) {
            Hop pred = isb.getPredicateHops();
            roots.put(pred.getName(), constructGDFGraph(pred, ipb, new HashMap<Long, GDFNode>(), roots));
        }
        //construct if and else branch separately
        HashMap<String, GDFNode> ifRoots = (HashMap<String, GDFNode>) roots.clone();
        HashMap<String, GDFNode> elseRoots = (HashMap<String, GDFNode>) roots.clone();
        for (ProgramBlock pbc : ipb.getChildBlocksIfBody()) constructGDFGraph(pbc, ifRoots);
        if (ipb.getChildBlocksElseBody() != null)
            for (ProgramBlock pbc : ipb.getChildBlocksElseBody()) constructGDFGraph(pbc, elseRoots);
        //merge data flow roots (if no else, elseRoots refer to original roots)
        reconcileMergeIfProgramBlockOutputs(ifRoots, elseRoots, roots, ipb);
    } else if (//incl parfor
    pb instanceof ForProgramBlock) {
        ForProgramBlock fpb = (ForProgramBlock) pb;
        ForStatementBlock fsb = (ForStatementBlock) pb.getStatementBlock();
        //construct predicate node (conceptually sequence of from/to/incr)
        GDFNode pred = constructForPredicateNode(fpb, fsb, roots);
        HashMap<String, GDFNode> inputs = constructLoopInputNodes(fpb, fsb, roots);
        HashMap<String, GDFNode> lroots = (HashMap<String, GDFNode>) inputs.clone();
        //process childs blocks
        for (ProgramBlock pbc : fpb.getChildBlocks()) constructGDFGraph(pbc, lroots);
        HashMap<String, GDFNode> outputs = constructLoopOutputNodes(fsb, lroots);
        GDFLoopNode lnode = new GDFLoopNode(fpb, pred, inputs, outputs);
        //construct crossblock nodes
        constructLoopOutputCrossBlockNodes(fsb, lnode, outputs, roots, fpb);
    } else //last-level program block
    {
        StatementBlock sb = pb.getStatementBlock();
        ArrayList<Hop> hops = sb.get_hops();
        if (hops != null) {
            //create new local memo structure for local dag
            HashMap<Long, GDFNode> lmemo = new HashMap<Long, GDFNode>();
            for (Hop hop : hops) {
                //recursively construct GDF graph for hop dag root
                GDFNode root = constructGDFGraph(hop, pb, lmemo, roots);
                if (root == null)
                    throw new HopsException("GDFGraphBuilder: failed to constuct dag root for: " + Explain.explain(hop));
                //create cross block nodes for all transient writes
                if (hop instanceof DataOp && ((DataOp) hop).getDataOpType() == DataOpTypes.TRANSIENTWRITE)
                    root = new GDFCrossBlockNode(hop, pb, root, hop.getName());
                //add GDF root node to global roots 
                roots.put(hop.getName(), root);
            }
        }
    }
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) HashMap(java.util.HashMap) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) Hop(org.apache.sysml.hops.Hop) ArrayList(java.util.ArrayList) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) HopsException(org.apache.sysml.hops.HopsException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) DataOp(org.apache.sysml.hops.DataOp) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

Aggregations

WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)36 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)35 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)35 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)31 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)28 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)21 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)15 ArrayList (java.util.ArrayList)14 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)14 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)14 StatementBlock (org.apache.sysml.parser.StatementBlock)14 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)12 Instruction (org.apache.sysml.runtime.instructions.Instruction)12 Hop (org.apache.sysml.hops.Hop)7 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)7 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)6 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)6 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)5 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)5 MultiThreadedHop (org.apache.sysml.hops.Hop.MultiThreadedHop)4