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());
}
}
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);
}
}
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()));
}
}
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());
}
}
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);
}
}
Aggregations