use of org.apache.sysml.parser.ForStatementBlock in project incubator-systemml by apache.
the class InterProceduralAnalysis method rRemoveConstantBinaryOp.
private void rRemoveConstantBinaryOp(StatementBlock sb, HashMap<String, Hop> mOnes) throws HopsException {
if (sb instanceof IfStatementBlock) {
IfStatementBlock isb = (IfStatementBlock) sb;
IfStatement istmt = (IfStatement) isb.getStatement(0);
for (StatementBlock c : istmt.getIfBody()) rRemoveConstantBinaryOp(c, mOnes);
if (istmt.getElseBody() != null)
for (StatementBlock c : istmt.getElseBody()) rRemoveConstantBinaryOp(c, mOnes);
} else if (sb instanceof WhileStatementBlock) {
WhileStatementBlock wsb = (WhileStatementBlock) sb;
WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
for (StatementBlock c : wstmt.getBody()) rRemoveConstantBinaryOp(c, mOnes);
} else if (sb instanceof ForStatementBlock) {
ForStatementBlock fsb = (ForStatementBlock) sb;
ForStatement fstmt = (ForStatement) fsb.getStatement(0);
for (StatementBlock c : fstmt.getBody()) rRemoveConstantBinaryOp(c, mOnes);
} else {
if (sb.get_hops() != null) {
Hop.resetVisitStatus(sb.get_hops());
for (Hop hop : sb.get_hops()) rRemoveConstantBinaryOp(hop, mOnes);
}
}
}
use of org.apache.sysml.parser.ForStatementBlock in project incubator-systemml by apache.
the class ProgramConverter method createForStatementBlockCopy.
public static ForStatementBlock createForStatementBlockCopy(ForStatementBlock sb, long pid, boolean plain, boolean forceDeepCopy) throws DMLRuntimeException {
ForStatementBlock ret = null;
try {
if (ConfigurationManager.getCompilerConfigFlag(ConfigType.ALLOW_PARALLEL_DYN_RECOMPILATION) && sb != null && (Recompiler.requiresRecompilation(sb.getFromHops()) || Recompiler.requiresRecompilation(sb.getToHops()) || Recompiler.requiresRecompilation(sb.getIncrementHops()) || forceDeepCopy)) {
ret = (sb instanceof ParForStatementBlock) ? new ParForStatementBlock() : new ForStatementBlock();
//create new statement (shallow copy livein/liveout for recompile, line numbers for explain)
ret.setDMLProg(sb.getDMLProg());
ret.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
ret.setLiveIn(sb.liveIn());
ret.setLiveOut(sb.liveOut());
ret.setUpdatedVariables(sb.variablesUpdated());
ret.setReadVariables(sb.variablesRead());
ret.setUpdateInPlaceVars(sb.getUpdateInPlaceVars());
//shallow copy child statements
ret.setStatements(sb.getStatements());
//deep copy predicate hops dag for concurrent recompile
if (sb.requiresFromRecompilation()) {
Hop hops = Recompiler.deepCopyHopsDag(sb.getFromHops());
ret.setFromHops(hops);
}
if (sb.requiresToRecompilation()) {
Hop hops = Recompiler.deepCopyHopsDag(sb.getToHops());
ret.setToHops(hops);
}
if (sb.requiresIncrementRecompilation()) {
Hop hops = Recompiler.deepCopyHopsDag(sb.getIncrementHops());
ret.setIncrementHops(hops);
}
ret.updatePredicateRecompilationFlags();
} else {
ret = sb;
}
} catch (Exception ex) {
throw new DMLRuntimeException(ex);
}
return ret;
}
use of org.apache.sysml.parser.ForStatementBlock 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) throws DMLRuntimeException {
ForProgramBlock tmpPB = new ForProgramBlock(prog, fpb.getIterablePredicateVars());
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.parser.ForStatementBlock in project incubator-systemml by apache.
the class ProgramRecompiler method replaceConstantScalarVariables.
public static void replaceConstantScalarVariables(StatementBlock sb, LocalVariableMap vars) throws DMLRuntimeException, HopsException {
if (sb instanceof IfStatementBlock) {
IfStatementBlock isb = (IfStatementBlock) sb;
IfStatement is = (IfStatement) sb.getStatement(0);
replacePredicateLiterals(isb.getPredicateHops(), vars);
for (StatementBlock lsb : is.getIfBody()) replaceConstantScalarVariables(lsb, vars);
for (StatementBlock lsb : is.getElseBody()) replaceConstantScalarVariables(lsb, vars);
} else if (sb instanceof WhileStatementBlock) {
WhileStatementBlock wsb = (WhileStatementBlock) sb;
WhileStatement ws = (WhileStatement) sb.getStatement(0);
replacePredicateLiterals(wsb.getPredicateHops(), vars);
for (StatementBlock lsb : ws.getBody()) replaceConstantScalarVariables(lsb, vars);
} else if (//for or parfor
sb instanceof ForStatementBlock) {
ForStatementBlock fsb = (ForStatementBlock) sb;
ForStatement fs = (ForStatement) fsb.getStatement(0);
replacePredicateLiterals(fsb.getFromHops(), vars);
replacePredicateLiterals(fsb.getToHops(), vars);
replacePredicateLiterals(fsb.getIncrementHops(), vars);
for (StatementBlock lsb : fs.getBody()) replaceConstantScalarVariables(lsb, vars);
} else //last level block
{
ArrayList<Hop> hops = sb.get_hops();
if (hops != null) {
//replace constant literals
Hop.resetVisitStatus(hops);
for (Hop hopRoot : hops) Recompiler.rReplaceLiterals(hopRoot, vars, true);
}
}
}
use of org.apache.sysml.parser.ForStatementBlock 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) throws DMLRuntimeException, HopsException, LopsException, IOException {
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.get_hops(), new LocalVariableMap(), null, false, false, 0);
pb.setInstructions(inst);
B.add(pb);
_cntCompilePB++;
}
return B;
}
Aggregations