Search in sources :

Example 36 with ForProgramBlock

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

the class DMLDebuggerProgramInfo method setProgramBlockInstMap.

/**
 * For each program block, get runtime instructions (if any)
 * @param pb Current program block
 */
private void setProgramBlockInstMap(ProgramBlock pb) {
    if (pb instanceof FunctionProgramBlock) {
        FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
        for (ProgramBlock pbc : fpb.getChildBlocks()) setProgramBlockInstMap(pbc);
    } else if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        this.setInstMap(wpb.getPredicate());
        for (ProgramBlock pbc : wpb.getChildBlocks()) setProgramBlockInstMap(pbc);
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) pb;
        this.setInstMap(ipb.getPredicate());
        for (ProgramBlock pbc : ipb.getChildBlocksIfBody()) setProgramBlockInstMap(pbc);
        if (!ipb.getChildBlocksElseBody().isEmpty()) {
            for (ProgramBlock pbc : ipb.getChildBlocksElseBody()) setProgramBlockInstMap(pbc);
        }
    } else if (// incl parfor
    pb instanceof ForProgramBlock) {
        ForProgramBlock fpb = (ForProgramBlock) pb;
        this.setInstMap(fpb.getFromInstructions());
        this.setInstMap(fpb.getToInstructions());
        this.setInstMap(fpb.getIncrementInstructions());
        for (ProgramBlock pbc : fpb.getChildBlocks()) setProgramBlockInstMap(pbc);
    } else {
        this.setInstMap(pb.getInstructions());
    }
}
Also used : ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) 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) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock)

Example 37 with ForProgramBlock

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

the class DMLDebuggerProgramInfo method accessProgramBlockBreakpoint.

/**
 * Access breakpoint instruction at specified line number in program block (if valid)
 * @param pb Current program block
 * @param lineNumber Location for inserting breakpoint
 * @param op Breakpoint operation
 * @param status Current breakpoint status
 */
private void accessProgramBlockBreakpoint(ProgramBlock pb, int lineNumber, int op, BPINSTRUCTION_STATUS status) {
    if (pb instanceof FunctionProgramBlock) {
        FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
        for (ProgramBlock pbc : fpb.getChildBlocks()) accessProgramBlockBreakpoint(pbc, lineNumber, op, status);
    } else if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        this.accesBreakpointInstruction(wpb.getPredicate(), lineNumber, op, status);
        for (ProgramBlock pbc : wpb.getChildBlocks()) accessProgramBlockBreakpoint(pbc, lineNumber, op, status);
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) pb;
        this.accesBreakpointInstruction(ipb.getPredicate(), lineNumber, op, status);
        for (ProgramBlock pbc : ipb.getChildBlocksIfBody()) accessProgramBlockBreakpoint(pbc, lineNumber, op, status);
        if (!ipb.getChildBlocksElseBody().isEmpty()) {
            for (ProgramBlock pbc : ipb.getChildBlocksElseBody()) accessProgramBlockBreakpoint(pbc, lineNumber, op, status);
        }
    } else if (// incl parfor
    pb instanceof ForProgramBlock) {
        ForProgramBlock fpb = (ForProgramBlock) pb;
        this.accesBreakpointInstruction(fpb.getFromInstructions(), lineNumber, op, status);
        this.accesBreakpointInstruction(fpb.getToInstructions(), lineNumber, op, status);
        this.accesBreakpointInstruction(fpb.getIncrementInstructions(), lineNumber, op, status);
        for (ProgramBlock pbc : fpb.getChildBlocks()) accessProgramBlockBreakpoint(pbc, lineNumber, op, status);
    } else {
        this.accesBreakpointInstruction(pb.getInstructions(), lineNumber, op, status);
    }
}
Also used : ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) 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) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock)

Example 38 with ForProgramBlock

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

the class SpoofCompiler method generateCodeFromProgramBlock.

public static void generateCodeFromProgramBlock(ProgramBlock current) {
    if (current instanceof FunctionProgramBlock) {
        FunctionProgramBlock fsb = (FunctionProgramBlock) current;
        for (ProgramBlock pb : fsb.getChildBlocks()) generateCodeFromProgramBlock(pb);
    } else if (current instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) current;
        WhileStatementBlock wsb = (WhileStatementBlock) wpb.getStatementBlock();
        if (wsb != null && wsb.getPredicateHops() != null)
            wpb.setPredicate(generateCodeFromHopDAGsToInst(wsb.getPredicateHops()));
        for (ProgramBlock sb : wpb.getChildBlocks()) generateCodeFromProgramBlock(sb);
    } else if (current instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) current;
        IfStatementBlock isb = (IfStatementBlock) ipb.getStatementBlock();
        if (isb != null && isb.getPredicateHops() != null)
            ipb.setPredicate(generateCodeFromHopDAGsToInst(isb.getPredicateHops()));
        for (ProgramBlock pb : ipb.getChildBlocksIfBody()) generateCodeFromProgramBlock(pb);
        for (ProgramBlock pb : ipb.getChildBlocksElseBody()) generateCodeFromProgramBlock(pb);
    } else if (// incl parfor
    current instanceof ForProgramBlock) {
        ForProgramBlock fpb = (ForProgramBlock) current;
        ForStatementBlock fsb = (ForStatementBlock) fpb.getStatementBlock();
        if (fsb != null && fsb.getFromHops() != null)
            fpb.setFromInstructions(generateCodeFromHopDAGsToInst(fsb.getFromHops()));
        if (fsb != null && fsb.getToHops() != null)
            fpb.setToInstructions(generateCodeFromHopDAGsToInst(fsb.getToHops()));
        if (fsb != null && fsb.getIncrementHops() != null)
            fpb.setIncrementInstructions(generateCodeFromHopDAGsToInst(fsb.getIncrementHops()));
        for (ProgramBlock pb : fpb.getChildBlocks()) generateCodeFromProgramBlock(pb);
    } else // generic (last-level)
    {
        StatementBlock sb = current.getStatementBlock();
        current.setInstructions(generateCodeFromHopDAGsToInst(sb, sb.getHops()));
    }
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) 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) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) 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) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

Example 39 with ForProgramBlock

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

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

Aggregations

ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)69 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)61 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)61 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)53 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)47 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)43 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)28 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)26 StatementBlock (org.apache.sysml.parser.StatementBlock)26 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)26 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)22 ArrayList (java.util.ArrayList)21 Instruction (org.apache.sysml.runtime.instructions.Instruction)20 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)12 DMLProgram (org.apache.sysml.parser.DMLProgram)10 ParForStatementBlock (org.apache.sysml.parser.ParForStatementBlock)10 Program (org.apache.sysml.runtime.controlprogram.Program)10 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)10 Hop (org.apache.sysml.hops.Hop)9 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9