use of org.apache.sysml.runtime.controlprogram.IfProgramBlock in project incubator-systemml by apache.
the class ResourceOptimizer method compileProgram.
private static ArrayList<ProgramBlock> compileProgram(ProgramBlock pb, ArrayList<ProgramBlock> B, double cp, double mr) {
if (pb instanceof FunctionProgramBlock) {
FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
compileProgram(fpb.getChildBlocks(), B, cp, mr);
} else 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);
wpb.setPredicate(inst);
B.add(wpb);
_cntCompilePB++;
}
compileProgram(wpb.getChildBlocks(), B, cp, mr);
} 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);
ipb.setPredicate(inst);
B.add(ipb);
_cntCompilePB++;
}
compileProgram(ipb.getChildBlocksIfBody(), B, cp, mr);
compileProgram(ipb.getChildBlocksElseBody(), B, cp, mr);
} else if (// incl parfor
pb instanceof ForProgramBlock) {
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);
fpb.setFromInstructions(inst);
}
if (sb.getToHops() != null) {
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getToHops(), new LocalVariableMap(), null, false, false, 0);
fpb.setToInstructions(inst);
}
if (sb.getIncrementHops() != null) {
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getIncrementHops(), new LocalVariableMap(), null, false, false, 0);
fpb.setIncrementInstructions(inst);
}
B.add(fpb);
_cntCompilePB++;
}
compileProgram(fpb.getChildBlocks(), B, cp, mr);
} else {
StatementBlock sb = pb.getStatementBlock();
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb, sb.getHops(), new LocalVariableMap(), null, false, false, 0);
pb.setInstructions(inst);
B.add(pb);
_cntCompilePB++;
}
return B;
}
use of org.apache.sysml.runtime.controlprogram.IfProgramBlock 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());
}
}
use of org.apache.sysml.runtime.controlprogram.IfProgramBlock in project systemml by apache.
the class OptTreeConverter method rContainsMRJobInstruction.
public static boolean rContainsMRJobInstruction(ProgramBlock pb, boolean inclFunctions) {
boolean ret = false;
if (pb instanceof WhileProgramBlock) {
WhileProgramBlock tmp = (WhileProgramBlock) pb;
ret = containsMRJobInstruction(tmp.getPredicate(), true, true);
if (ret)
return ret;
for (ProgramBlock pb2 : tmp.getChildBlocks()) {
ret = rContainsMRJobInstruction(pb2, inclFunctions);
if (ret)
return ret;
}
} else if (pb instanceof IfProgramBlock) {
IfProgramBlock tmp = (IfProgramBlock) pb;
ret = containsMRJobInstruction(tmp.getPredicate(), true, true);
if (ret)
return ret;
for (ProgramBlock pb2 : tmp.getChildBlocksIfBody()) {
ret = rContainsMRJobInstruction(pb2, inclFunctions);
if (ret)
return ret;
}
for (ProgramBlock pb2 : tmp.getChildBlocksElseBody()) {
ret = rContainsMRJobInstruction(pb2, inclFunctions);
if (ret)
return ret;
}
} else if (// includes ParFORProgramBlock
pb instanceof ForProgramBlock) {
ForProgramBlock tmp = (ForProgramBlock) pb;
ret = containsMRJobInstruction(tmp.getFromInstructions(), true, true);
ret |= containsMRJobInstruction(tmp.getToInstructions(), true, true);
ret |= containsMRJobInstruction(tmp.getIncrementInstructions(), true, true);
if (ret)
return ret;
for (ProgramBlock pb2 : tmp.getChildBlocks()) {
ret = rContainsMRJobInstruction(pb2, inclFunctions);
if (ret)
return ret;
}
} else if (// includes ExternalFunctionProgramBlock and ExternalFunctionProgramBlockCP)
pb instanceof FunctionProgramBlock) {
// do nothing
} else {
ret = containsMRJobInstruction(pb, true, true) || (inclFunctions && containsFunctionCallInstruction(pb));
}
return ret;
}
use of org.apache.sysml.runtime.controlprogram.IfProgramBlock in project 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 systemml by apache.
the class ResourceOptimizer method compileProgram.
private static ArrayList<ProgramBlock> compileProgram(ProgramBlock pb, ArrayList<ProgramBlock> B, double cp, double mr) {
if (pb instanceof FunctionProgramBlock) {
FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
compileProgram(fpb.getChildBlocks(), B, cp, mr);
} else 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);
wpb.setPredicate(inst);
B.add(wpb);
_cntCompilePB++;
}
compileProgram(wpb.getChildBlocks(), B, cp, mr);
} 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);
ipb.setPredicate(inst);
B.add(ipb);
_cntCompilePB++;
}
compileProgram(ipb.getChildBlocksIfBody(), B, cp, mr);
compileProgram(ipb.getChildBlocksElseBody(), B, cp, mr);
} else if (// incl parfor
pb instanceof ForProgramBlock) {
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);
fpb.setFromInstructions(inst);
}
if (sb.getToHops() != null) {
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getToHops(), new LocalVariableMap(), null, false, false, 0);
fpb.setToInstructions(inst);
}
if (sb.getIncrementHops() != null) {
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getIncrementHops(), new LocalVariableMap(), null, false, false, 0);
fpb.setIncrementInstructions(inst);
}
B.add(fpb);
_cntCompilePB++;
}
compileProgram(fpb.getChildBlocks(), B, cp, mr);
} else {
StatementBlock sb = pb.getStatementBlock();
ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb, sb.getHops(), new LocalVariableMap(), null, false, false, 0);
pb.setInstructions(inst);
B.add(pb);
_cntCompilePB++;
}
return B;
}
Aggregations