use of org.apache.sysml.runtime.controlprogram.IfProgramBlock in project incubator-systemml by apache.
the class ResourceConfig method addProgramBlock.
private void addProgramBlock(ProgramBlock pb, long init) {
if (pb instanceof FunctionProgramBlock) {
FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
addProgramBlocks(fpb.getChildBlocks(), init);
} else if (pb instanceof WhileProgramBlock) {
WhileProgramBlock fpb = (WhileProgramBlock) pb;
WhileStatementBlock wsb = (WhileStatementBlock) pb.getStatementBlock();
if (ResourceOptimizer.INCLUDE_PREDICATES && wsb != null && wsb.getPredicateHops() != null)
_mrres.add(init);
addProgramBlocks(fpb.getChildBlocks(), init);
} else if (pb instanceof IfProgramBlock) {
IfProgramBlock fpb = (IfProgramBlock) pb;
IfStatementBlock isb = (IfStatementBlock) pb.getStatementBlock();
if (ResourceOptimizer.INCLUDE_PREDICATES && isb != null && isb.getPredicateHops() != null)
_mrres.add(init);
addProgramBlocks(fpb.getChildBlocksIfBody(), init);
addProgramBlocks(fpb.getChildBlocksElseBody(), init);
} else if (// incl parfor
pb instanceof ForProgramBlock) {
ForProgramBlock fpb = (ForProgramBlock) pb;
ForStatementBlock fsb = (ForStatementBlock) pb.getStatementBlock();
if (ResourceOptimizer.INCLUDE_PREDICATES && fsb != null)
_mrres.add(init);
addProgramBlocks(fpb.getChildBlocks(), init);
} else {
// for objects hash is unique because memory location used
_mrres.add(init);
}
}
use of org.apache.sysml.runtime.controlprogram.IfProgramBlock in project incubator-systemml by apache.
the class ResourceOptimizer method recompileProgramBlock.
private static void recompileProgramBlock(ProgramBlock pb, long cp, long mr) {
// init compiler memory budget
InfrastructureAnalyzer.setLocalMaxMemory(cp);
InfrastructureAnalyzer.setRemoteMaxMemoryMap(mr);
InfrastructureAnalyzer.setRemoteMaxMemoryReduce(mr);
// dependent on cp, mr
OptimizerUtils.resetDefaultSize();
// recompile instructions (incl predicates)
if (pb instanceof WhileProgramBlock) {
WhileProgramBlock wpb = (WhileProgramBlock) pb;
WhileStatementBlock sb = (WhileStatementBlock) pb.getStatementBlock();
if (INCLUDE_PREDICATES && sb != null && sb.getPredicateHops() != null) {
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getPredicateHops(), new LocalVariableMap(), null, false, false, 0);
inst = annotateMRJobInstructions(inst, cp, mr);
wpb.setPredicate(inst);
}
} else if (pb instanceof IfProgramBlock) {
IfProgramBlock ipb = (IfProgramBlock) pb;
IfStatementBlock sb = (IfStatementBlock) ipb.getStatementBlock();
if (INCLUDE_PREDICATES && sb != null && sb.getPredicateHops() != null) {
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getPredicateHops(), new LocalVariableMap(), null, false, false, 0);
inst = annotateMRJobInstructions(inst, cp, mr);
ipb.setPredicate(inst);
}
} else if (pb instanceof ForProgramBlock) {
// incl parfor
ForProgramBlock fpb = (ForProgramBlock) pb;
ForStatementBlock sb = (ForStatementBlock) fpb.getStatementBlock();
if (INCLUDE_PREDICATES && sb != null) {
if (sb.getFromHops() != null) {
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getFromHops(), new LocalVariableMap(), null, false, false, 0);
inst = annotateMRJobInstructions(inst, cp, mr);
fpb.setFromInstructions(inst);
}
if (sb.getToHops() != null) {
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getToHops(), new LocalVariableMap(), null, false, false, 0);
inst = annotateMRJobInstructions(inst, cp, mr);
fpb.setToInstructions(inst);
}
if (sb.getIncrementHops() != null) {
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getIncrementHops(), new LocalVariableMap(), null, false, false, 0);
inst = annotateMRJobInstructions(inst, cp, mr);
fpb.setIncrementInstructions(inst);
}
}
} else {
// last-level program blocks
StatementBlock sb = pb.getStatementBlock();
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb, sb.getHops(), new LocalVariableMap(), null, false, false, 0);
inst = annotateMRJobInstructions(inst, cp, mr);
pb.setInstructions(inst);
}
_cntCompilePB++;
}
use of org.apache.sysml.runtime.controlprogram.IfProgramBlock in project systemml by apache.
the class Explain method countCompiledInstructions.
/**
* Recursively counts the number of compiled MRJob instructions in the
* given runtime program block.
*
* @param pb program block
* @param counts explain countst
* @param MR if true, count Hadoop instructions
* @param CP if true, count CP instructions
* @param SP if true, count Spark instructions
*/
private static void countCompiledInstructions(ProgramBlock pb, ExplainCounts counts, boolean MR, boolean CP, boolean SP) {
if (pb instanceof WhileProgramBlock) {
WhileProgramBlock tmp = (WhileProgramBlock) pb;
countCompiledInstructions(tmp.getPredicate(), counts, MR, CP, SP);
for (ProgramBlock pb2 : tmp.getChildBlocks()) countCompiledInstructions(pb2, counts, MR, CP, SP);
} else if (pb instanceof IfProgramBlock) {
IfProgramBlock tmp = (IfProgramBlock) pb;
countCompiledInstructions(tmp.getPredicate(), counts, MR, CP, SP);
for (ProgramBlock pb2 : tmp.getChildBlocksIfBody()) countCompiledInstructions(pb2, counts, MR, CP, SP);
for (ProgramBlock pb2 : tmp.getChildBlocksElseBody()) countCompiledInstructions(pb2, counts, MR, CP, SP);
} else if (// includes ParFORProgramBlock
pb instanceof ForProgramBlock) {
ForProgramBlock tmp = (ForProgramBlock) pb;
countCompiledInstructions(tmp.getFromInstructions(), counts, MR, CP, SP);
countCompiledInstructions(tmp.getToInstructions(), counts, MR, CP, SP);
countCompiledInstructions(tmp.getIncrementInstructions(), counts, MR, CP, SP);
for (ProgramBlock pb2 : tmp.getChildBlocks()) countCompiledInstructions(pb2, counts, MR, CP, SP);
// additional parfor jobs counted during runtime
} else if (// includes ExternalFunctionProgramBlock and ExternalFunctionProgramBlockCP
pb instanceof FunctionProgramBlock) {
FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
for (ProgramBlock pb2 : fpb.getChildBlocks()) countCompiledInstructions(pb2, counts, MR, CP, SP);
} else {
countCompiledInstructions(pb.getInstructions(), counts, MR, CP, SP);
}
}
use of org.apache.sysml.runtime.controlprogram.IfProgramBlock in project systemml by apache.
the class Explain method explainProgramBlock.
// ////////////
// internal explain RUNTIME
private static String explainProgramBlock(ProgramBlock pb, int level) {
StringBuilder sb = new StringBuilder();
String offset = createOffset(level);
if (pb instanceof FunctionProgramBlock) {
FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
for (ProgramBlock pbc : fpb.getChildBlocks()) sb.append(explainProgramBlock(pbc, level + 1));
} else if (pb instanceof WhileProgramBlock) {
WhileProgramBlock wpb = (WhileProgramBlock) pb;
StatementBlock wsb = pb.getStatementBlock();
sb.append(offset);
if (wsb != null && !wsb.getUpdateInPlaceVars().isEmpty())
sb.append("WHILE (lines " + wpb.getBeginLine() + "-" + wpb.getEndLine() + ") [in-place=" + wsb.getUpdateInPlaceVars().toString() + "]\n");
else
sb.append("WHILE (lines " + wpb.getBeginLine() + "-" + wpb.getEndLine() + ")\n");
sb.append(explainInstructions(wpb.getPredicate(), level + 1));
for (ProgramBlock pbc : wpb.getChildBlocks()) sb.append(explainProgramBlock(pbc, level + 1));
} else if (pb instanceof IfProgramBlock) {
IfProgramBlock ipb = (IfProgramBlock) pb;
sb.append(offset);
sb.append("IF (lines " + ipb.getBeginLine() + "-" + ipb.getEndLine() + ")\n");
sb.append(explainInstructions(ipb.getPredicate(), level + 1));
for (ProgramBlock pbc : ipb.getChildBlocksIfBody()) sb.append(explainProgramBlock(pbc, level + 1));
if (!ipb.getChildBlocksElseBody().isEmpty()) {
sb.append(offset);
sb.append("ELSE\n");
for (ProgramBlock pbc : ipb.getChildBlocksElseBody()) sb.append(explainProgramBlock(pbc, level + 1));
}
} else if (// incl parfor
pb instanceof ForProgramBlock) {
ForProgramBlock fpb = (ForProgramBlock) pb;
StatementBlock fsb = pb.getStatementBlock();
sb.append(offset);
if (pb instanceof ParForProgramBlock)
sb.append("PARFOR (lines " + fpb.getBeginLine() + "-" + fpb.getEndLine() + ")\n");
else {
if (fsb != null && !fsb.getUpdateInPlaceVars().isEmpty())
sb.append("FOR (lines " + fpb.getBeginLine() + "-" + fpb.getEndLine() + ") [in-place=" + fsb.getUpdateInPlaceVars().toString() + "]\n");
else
sb.append("FOR (lines " + fpb.getBeginLine() + "-" + fpb.getEndLine() + ")\n");
}
sb.append(explainInstructions(fpb.getFromInstructions(), level + 1));
sb.append(explainInstructions(fpb.getToInstructions(), level + 1));
sb.append(explainInstructions(fpb.getIncrementInstructions(), level + 1));
for (ProgramBlock pbc : fpb.getChildBlocks()) sb.append(explainProgramBlock(pbc, level + 1));
} else {
sb.append(offset);
if (pb.getStatementBlock() != null)
sb.append("GENERIC (lines " + pb.getBeginLine() + "-" + pb.getEndLine() + ") [recompile=" + pb.getStatementBlock().requiresRecompilation() + "]\n");
else
sb.append("GENERIC (lines " + pb.getBeginLine() + "-" + pb.getEndLine() + ") \n");
sb.append(explainInstructions(pb.getInstructions(), level + 1));
}
return sb.toString();
}
use of org.apache.sysml.runtime.controlprogram.IfProgramBlock in project systemml by apache.
the class GridEnumerationMemory method getMemoryEstimates.
private void getMemoryEstimates(ProgramBlock pb, ArrayList<Long> mem) {
if (pb instanceof FunctionProgramBlock) {
FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
getMemoryEstimates(fpb.getChildBlocks(), mem);
} else if (pb instanceof WhileProgramBlock) {
WhileProgramBlock fpb = (WhileProgramBlock) pb;
getMemoryEstimates(fpb.getChildBlocks(), mem);
} else if (pb instanceof IfProgramBlock) {
IfProgramBlock fpb = (IfProgramBlock) pb;
getMemoryEstimates(fpb.getChildBlocksIfBody(), mem);
getMemoryEstimates(fpb.getChildBlocksElseBody(), mem);
} else if (// incl parfor
pb instanceof ForProgramBlock) {
ForProgramBlock fpb = (ForProgramBlock) pb;
getMemoryEstimates(fpb.getChildBlocks(), mem);
} else {
StatementBlock sb = pb.getStatementBlock();
if (sb != null && sb.getHops() != null) {
Hop.resetVisitStatus(sb.getHops());
for (Hop hop : sb.getHops()) getMemoryEstimates(hop, mem);
}
}
}
Aggregations