use of org.apache.sysml.runtime.controlprogram.ForProgramBlock in project incubator-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 incubator-systemml by apache.
the class Recompiler method recompileProgramBlockInstructions.
/**
* This method does NO full program block recompile (no stats update, no rewrites, no recursion) but
* only regenerates lops and instructions. The primary use case is recompilation after are hop configuration
* changes which allows to preserve statistics (e.g., propagated worst case stats from other program blocks)
* and better performance for recompiling individual program blocks.
*
* @param pb program block
* @throws IOException if IOException occurs
*/
public static void recompileProgramBlockInstructions(ProgramBlock pb) throws IOException {
if (pb instanceof WhileProgramBlock) {
// recompile while predicate instructions
WhileProgramBlock wpb = (WhileProgramBlock) pb;
WhileStatementBlock wsb = (WhileStatementBlock) pb.getStatementBlock();
if (wsb != null && wsb.getPredicateHops() != null)
wpb.setPredicate(recompileHopsDagInstructions(wsb.getPredicateHops()));
} else if (pb instanceof IfProgramBlock) {
// recompile if predicate instructions
IfProgramBlock ipb = (IfProgramBlock) pb;
IfStatementBlock isb = (IfStatementBlock) pb.getStatementBlock();
if (isb != null && isb.getPredicateHops() != null)
ipb.setPredicate(recompileHopsDagInstructions(isb.getPredicateHops()));
} else if (pb instanceof ForProgramBlock) {
// recompile for/parfor predicate instructions
ForProgramBlock fpb = (ForProgramBlock) pb;
ForStatementBlock fsb = (ForStatementBlock) pb.getStatementBlock();
if (fsb != null && fsb.getFromHops() != null)
fpb.setFromInstructions(recompileHopsDagInstructions(fsb.getFromHops()));
if (fsb != null && fsb.getToHops() != null)
fpb.setToInstructions(recompileHopsDagInstructions(fsb.getToHops()));
if (fsb != null && fsb.getIncrementHops() != null)
fpb.setIncrementInstructions(recompileHopsDagInstructions(fsb.getIncrementHops()));
} else {
// recompile last-level program block instructions
StatementBlock sb = pb.getStatementBlock();
if (sb != null && sb.getHops() != null) {
pb.setInstructions(recompileHopsDagInstructions(sb, sb.getHops()));
}
}
}
use of org.apache.sysml.runtime.controlprogram.ForProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method rcreateDeepCopyProgramBlocks.
/**
* This recursively creates a deep copy of program blocks and transparently replaces filenames according to the
* specified parallel worker in order to avoid conflicts between parworkers. This happens recursively in order
* to support arbitrary control-flow constructs within a parfor.
*
* @param childBlocks child program blocks
* @param pid ?
* @param IDPrefix ?
* @param fnStack ?
* @param fnCreated ?
* @param plain if true, full deep copy without id replacement
* @param forceDeepCopy if true, force deep copy
* @return list of program blocks
*/
public static ArrayList<ProgramBlock> rcreateDeepCopyProgramBlocks(ArrayList<ProgramBlock> childBlocks, long pid, int IDPrefix, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) {
ArrayList<ProgramBlock> tmp = new ArrayList<>();
for (ProgramBlock pb : childBlocks) {
Program prog = pb.getProgram();
ProgramBlock tmpPB = null;
if (pb instanceof WhileProgramBlock) {
tmpPB = createDeepCopyWhileProgramBlock((WhileProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
} else if (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)) {
tmpPB = createDeepCopyForProgramBlock((ForProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
} else if (pb instanceof ParForProgramBlock) {
ParForProgramBlock pfpb = (ParForProgramBlock) pb;
if (ParForProgramBlock.ALLOW_NESTED_PARALLELISM)
tmpPB = createDeepCopyParForProgramBlock(pfpb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
else
tmpPB = createDeepCopyForProgramBlock((ForProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
} else if (pb instanceof IfProgramBlock) {
tmpPB = createDeepCopyIfProgramBlock((IfProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
} else // last-level program block
{
// general case use for most PBs
tmpPB = new ProgramBlock(prog);
// for recompile in the master node JVM
tmpPB.setStatementBlock(createStatementBlockCopy(pb.getStatementBlock(), pid, plain, forceDeepCopy));
// tmpPB.setStatementBlock(pb.getStatementBlock());
tmpPB.setThreadID(pid);
}
// copy instructions
tmpPB.setInstructions(createDeepCopyInstructionSet(pb.getInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
// copy symbol table
// tmpPB.setVariables( pb.getVariables() ); //implicit cloning
tmp.add(tmpPB);
}
return tmp;
}
use of org.apache.sysml.runtime.controlprogram.ForProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method createDeepCopyForProgramBlock.
public static ForProgramBlock createDeepCopyForProgramBlock(ForProgramBlock fpb, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) {
ForProgramBlock tmpPB = new ForProgramBlock(prog, fpb.getIterVar());
tmpPB.setStatementBlock(createForStatementBlockCopy((ForStatementBlock) fpb.getStatementBlock(), pid, plain, forceDeepCopy));
tmpPB.setThreadID(pid);
tmpPB.setFromInstructions(createDeepCopyInstructionSet(fpb.getFromInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
tmpPB.setToInstructions(createDeepCopyInstructionSet(fpb.getToInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
tmpPB.setIncrementInstructions(createDeepCopyInstructionSet(fpb.getIncrementInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
tmpPB.setExitInstructions(createDeepCopyInstructionSet(fpb.getExitInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
tmpPB.setChildBlocks(rcreateDeepCopyProgramBlocks(fpb.getChildBlocks(), pid, IDPrefix, fnStack, fnCreated, plain, forceDeepCopy));
return tmpPB;
}
use of org.apache.sysml.runtime.controlprogram.ForProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method rParseForProgramBlock.
private static ForProgramBlock rParseForProgramBlock(String in, Program prog, int id) {
String lin = in.substring(PARFOR_PB_FOR.length(), in.length() - PARFOR_PB_END.length());
HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
// inputs
String iterVar = st.nextToken();
// instructions
ArrayList<Instruction> from = parseInstructions(st.nextToken(), id);
ArrayList<Instruction> to = parseInstructions(st.nextToken(), id);
ArrayList<Instruction> incr = parseInstructions(st.nextToken(), id);
// exit instructions
ArrayList<Instruction> exit = parseInstructions(st.nextToken(), id);
// program blocks
ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, id);
ForProgramBlock fpb = new ForProgramBlock(prog, iterVar);
fpb.setFromInstructions(from);
fpb.setToInstructions(to);
fpb.setIncrementInstructions(incr);
fpb.setExitInstructions(exit);
fpb.setChildBlocks(pbs);
return fpb;
}
Aggregations