use of org.apache.sysml.parser.StatementBlock in project incubator-systemml by apache.
the class ProgramRecompiler method generatePartitialRuntimeProgram.
public static ArrayList<ProgramBlock> generatePartitialRuntimeProgram(Program rtprog, ArrayList<StatementBlock> sbs) {
ArrayList<ProgramBlock> ret = new ArrayList<>();
DMLConfig config = ConfigurationManager.getDMLConfig();
// construct lops from hops if not existing
DMLTranslator dmlt = new DMLTranslator(sbs.get(0).getDMLProg());
for (StatementBlock sb : sbs) {
dmlt.constructLops(sb);
}
// construct runtime program from lops
for (StatementBlock sb : sbs) {
ret.add(dmlt.createRuntimeProgramBlock(rtprog, sb, config));
}
// enhance runtime program by automatic operator fusion
if (ConfigurationManager.isCodegenEnabled() && SpoofCompiler.INTEGRATION == IntegrationType.RUNTIME) {
for (ProgramBlock pb : ret) dmlt.codgenHopsDAG(pb);
}
return ret;
}
use of org.apache.sysml.parser.StatementBlock in project incubator-systemml by apache.
the class Explain method explain.
public static String explain(DMLProgram prog) {
StringBuilder sb = new StringBuilder();
// create header
sb.append("\nPROGRAM\n");
// Explain functions (if exists)
if (prog.hasFunctionStatementBlocks()) {
sb.append("--FUNCTIONS\n");
// show function call graph
sb.append("----FUNCTION CALL GRAPH\n");
sb.append("------MAIN PROGRAM\n");
FunctionCallGraph fgraph = new FunctionCallGraph(prog);
sb.append(explainFunctionCallGraph(fgraph, new HashSet<String>(), null, 3));
// show individual functions
for (String namespace : prog.getNamespaces().keySet()) {
for (String fname : prog.getFunctionStatementBlocks(namespace).keySet()) {
FunctionStatementBlock fsb = prog.getFunctionStatementBlock(namespace, fname);
FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
String fkey = DMLProgram.constructFunctionKey(namespace, fname);
if (fstmt instanceof ExternalFunctionStatement)
sb.append("----EXTERNAL FUNCTION " + fkey + "\n");
else {
sb.append("----FUNCTION " + fkey + " [recompile=" + fsb.isRecompileOnce() + "]\n");
for (StatementBlock current : fstmt.getBody()) sb.append(explainStatementBlock(current, 3));
}
}
}
}
// Explain main program
sb.append("--MAIN PROGRAM\n");
for (StatementBlock sblk : prog.getStatementBlocks()) sb.append(explainStatementBlock(sblk, 2));
return sb.toString();
}
use of org.apache.sysml.parser.StatementBlock in project incubator-systemml by apache.
the class Explain method getHopDAG.
private static StringBuilder getHopDAG(StatementBlock sb, StringBuilder nodes, ArrayList<Integer> lines, boolean withSubgraph) {
StringBuilder builder = new StringBuilder();
if (sb instanceof WhileStatementBlock) {
addSubGraphHeader(builder, withSubgraph);
WhileStatementBlock wsb = (WhileStatementBlock) sb;
String label = null;
if (!wsb.getUpdateInPlaceVars().isEmpty())
label = "WHILE (lines " + wsb.getBeginLine() + "-" + wsb.getEndLine() + ") in-place=" + wsb.getUpdateInPlaceVars().toString() + "";
else
label = "WHILE (lines " + wsb.getBeginLine() + "-" + wsb.getEndLine() + ")";
// TODO: Don't show predicate hops for now
// builder.append(explainHop(wsb.getPredicateHops()));
WhileStatement ws = (WhileStatement) sb.getStatement(0);
for (StatementBlock current : ws.getBody()) builder.append(getHopDAG(current, nodes, lines, withSubgraph));
addSubGraphFooter(builder, withSubgraph, label);
} else if (sb instanceof IfStatementBlock) {
addSubGraphHeader(builder, withSubgraph);
IfStatementBlock ifsb = (IfStatementBlock) sb;
String label = "IF (lines " + ifsb.getBeginLine() + "-" + ifsb.getEndLine() + ")";
// TODO: Don't show predicate hops for now
// builder.append(explainHop(ifsb.getPredicateHops(), level+1));
IfStatement ifs = (IfStatement) sb.getStatement(0);
for (StatementBlock current : ifs.getIfBody()) {
builder.append(getHopDAG(current, nodes, lines, withSubgraph));
addSubGraphFooter(builder, withSubgraph, label);
}
if (!ifs.getElseBody().isEmpty()) {
addSubGraphHeader(builder, withSubgraph);
label = "ELSE (lines " + ifsb.getBeginLine() + "-" + ifsb.getEndLine() + ")";
for (StatementBlock current : ifs.getElseBody()) builder.append(getHopDAG(current, nodes, lines, withSubgraph));
addSubGraphFooter(builder, withSubgraph, label);
}
} else if (sb instanceof ForStatementBlock) {
ForStatementBlock fsb = (ForStatementBlock) sb;
addSubGraphHeader(builder, withSubgraph);
String label = "";
if (sb instanceof ParForStatementBlock) {
if (!fsb.getUpdateInPlaceVars().isEmpty())
label = "PARFOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ") in-place=" + fsb.getUpdateInPlaceVars().toString() + "";
else
label = "PARFOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ")";
} else {
if (!fsb.getUpdateInPlaceVars().isEmpty())
label = "FOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ") in-place=" + fsb.getUpdateInPlaceVars().toString() + "";
else
label = "FOR (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ")";
}
// TODO: Don't show predicate hops for now
// if (fsb.getFromHops() != null)
// builder.append(explainHop(fsb.getFromHops(), level+1));
// if (fsb.getToHops() != null)
// builder.append(explainHop(fsb.getToHops(), level+1));
// if (fsb.getIncrementHops() != null)
// builder.append(explainHop(fsb.getIncrementHops(), level+1));
ForStatement fs = (ForStatement) sb.getStatement(0);
for (StatementBlock current : fs.getBody()) builder.append(getHopDAG(current, nodes, lines, withSubgraph));
addSubGraphFooter(builder, withSubgraph, label);
} else if (sb instanceof FunctionStatementBlock) {
FunctionStatement fsb = (FunctionStatement) sb.getStatement(0);
addSubGraphHeader(builder, withSubgraph);
String label = "Function (lines " + fsb.getBeginLine() + "-" + fsb.getEndLine() + ")";
for (StatementBlock current : fsb.getBody()) builder.append(getHopDAG(current, nodes, lines, withSubgraph));
addSubGraphFooter(builder, withSubgraph, label);
} else {
// For generic StatementBlock
if (sb.requiresRecompilation()) {
addSubGraphHeader(builder, withSubgraph);
}
ArrayList<Hop> hopsDAG = sb.getHops();
if (hopsDAG != null && !hopsDAG.isEmpty()) {
Hop.resetVisitStatus(hopsDAG);
for (Hop hop : hopsDAG) builder.append(getHopDAG(hop, nodes, lines, withSubgraph));
Hop.resetVisitStatus(hopsDAG);
}
if (sb.requiresRecompilation()) {
builder.append("style=filled;\n");
builder.append("color=lightgrey;\n");
String label = "(lines " + sb.getBeginLine() + "-" + sb.getEndLine() + ") [recompile=" + sb.requiresRecompilation() + "]";
addSubGraphFooter(builder, withSubgraph, label);
}
}
return builder;
}
use of org.apache.sysml.parser.StatementBlock in project incubator-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);
}
}
}
use of org.apache.sysml.parser.StatementBlock 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;
}
Aggregations