Search in sources :

Example 56 with ProgramBlock

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

the class ResourceOptimizer method initGlobalMemoTable.

private static double[][] initGlobalMemoTable(ArrayList<ProgramBlock> B, ArrayList<ProgramBlock> Bp, double[][] lmemo, double min) {
    // allocate memo structure
    int len = B.size();
    // lenp<=len
    int lenp = Bp.size();
    double[][] memo = new double[len][2];
    // init with min resources
    for (int i = 0; i < len; i++) {
        memo[i][0] = min;
        memo[i][1] = -1;
    }
    // overwrite existing values
    int j = 0;
    for (int i = 0; i < len && j < lenp; i++) {
        ProgramBlock pb = B.get(i);
        if (pb != Bp.get(j))
            continue;
        // map local memo entry
        memo[i][0] = lmemo[j][0];
        memo[i][1] = -1;
        j++;
    }
    return memo;
}
Also used : 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)

Example 57 with ProgramBlock

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

the class OptimizerRuleBased method rewriteNestedParallelism.

///////
//REWRITE enable nested parallelism
///
@SuppressWarnings("all")
protected boolean rewriteNestedParallelism(OptNode n, double M, boolean flagLIX) throws DMLRuntimeException {
    boolean nested = false;
    if (APPLY_REWRITE_NESTED_PARALLELISM && // if not applied left indexing rewrite	
    !flagLIX && // at least exploit all nodes
    _N >= _rnk && // only for 1D problems, otherwise potentially bad load balance
    !n.hasNestedParallelism(false) && // only if we can exploit full local parallelism in the map task JVM memory
    M * _lkmaxCP <= _rm) {
        //modify tree
        ArrayList<OptNode> tmpOld = n.getChilds();
        OptNode nest = new OptNode(NodeType.PARFOR, ExecType.CP);
        ArrayList<OptNode> tmpNew = new ArrayList<OptNode>();
        tmpNew.add(nest);
        n.setChilds(tmpNew);
        nest.setChilds(tmpOld);
        //modify rtprog
        long id = n.getID();
        ParForProgramBlock pfpb = (ParForProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(id)[1];
        ArrayList<ProgramBlock> tmpPBOld = pfpb.getChildBlocks();
        //create new program block structure and modify parameters (from, to, incr, types,)
        //from, to stay original
        String[] iterVars = pfpb.getIterablePredicateVars();
        //itervar, incr stay original
        String[] iterVars2 = iterVars.clone();
        int outIncr = (int) Math.ceil(((double) _N) / _rnk);
        // already checked for uniqueness in ParForStatementBlock
        iterVars[0] = ParForStatementBlock.INTERAL_FN_INDEX_ROW;
        iterVars[3] = String.valueOf(outIncr);
        //sub start
        iterVars2[1] = ParForStatementBlock.INTERAL_FN_INDEX_ROW;
        iterVars2[2] = null;
        HashMap<String, String> params = pfpb.getParForParams();
        HashMap<String, String> params2 = (HashMap<String, String>) params.clone();
        ParForProgramBlock pfpb2 = new ParForProgramBlock(pfpb.getProgram(), iterVars2, params2);
        OptTreeConverter.getAbstractPlanMapping().putProgMapping(null, pfpb2, nest);
        ArrayList<ProgramBlock> tmpPBNew = new ArrayList<ProgramBlock>();
        tmpPBNew.add(pfpb2);
        pfpb.setChildBlocks(tmpPBNew);
        pfpb.setIterablePredicateVars(iterVars);
        pfpb.setIncrementInstructions(new ArrayList<Instruction>());
        pfpb.setExecMode(PExecMode.REMOTE_MR);
        pfpb2.setChildBlocks(tmpPBOld);
        pfpb2.setResultVariables(pfpb.getResultVariables());
        pfpb2.setFromInstructions(new ArrayList<Instruction>());
        pfpb2.setToInstructions(ProgramRecompiler.createNestedParallelismToInstructionSet(ParForStatementBlock.INTERAL_FN_INDEX_ROW, String.valueOf(outIncr - 1)));
        pfpb2.setIncrementInstructions(new ArrayList<Instruction>());
        pfpb2.setExecMode(PExecMode.LOCAL);
        nested = true;
    }
    _numEvaluatedPlans++;
    LOG.debug(getOptMode() + " OPT: rewrite 'enable nested parallelism' - result=" + nested);
    return nested;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Instruction(org.apache.sysml.runtime.instructions.Instruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) 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)

Example 58 with ProgramBlock

use of org.apache.sysml.runtime.controlprogram.ProgramBlock 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 59 with ProgramBlock

use of org.apache.sysml.runtime.controlprogram.ProgramBlock 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 60 with ProgramBlock

use of org.apache.sysml.runtime.controlprogram.ProgramBlock 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)

Aggregations

ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)64 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)58 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)56 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)54 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)54 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)38 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)26 ArrayList (java.util.ArrayList)20 Instruction (org.apache.sysml.runtime.instructions.Instruction)18 StatementBlock (org.apache.sysml.parser.StatementBlock)13 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)13 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)11 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)11 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)11 Hop (org.apache.sysml.hops.Hop)10 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)10 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9 Program (org.apache.sysml.runtime.controlprogram.Program)9 DMLProgram (org.apache.sysml.parser.DMLProgram)8 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)7