use of org.apache.sysml.hops.ipa.FunctionCallGraph in project incubator-systemml by apache.
the class Explain method explain.
public static String explain(Program rtprog) throws HopsException {
//counts number of instructions
boolean sparkExec = OptimizerUtils.isSparkExecutionMode();
ExplainCounts counts = new ExplainCounts();
countCompiledInstructions(rtprog, counts, !sparkExec, true, sparkExec);
StringBuilder sb = new StringBuilder();
//create header
sb.append("\nPROGRAM ( size CP/" + (sparkExec ? "SP" : "MR") + " = ");
sb.append(counts.numCPInst);
sb.append("/");
sb.append(counts.numJobs);
sb.append(" )\n");
//explain functions (if exists)
Map<String, FunctionProgramBlock> funcMap = rtprog.getFunctionProgramBlocks();
if (funcMap != null && !funcMap.isEmpty()) {
sb.append("--FUNCTIONS\n");
//show function call graph
if (!rtprog.getProgramBlocks().isEmpty() && rtprog.getProgramBlocks().get(0).getStatementBlock() != null) {
sb.append("----FUNCTION CALL GRAPH\n");
sb.append("------MAIN PROGRAM\n");
DMLProgram prog = rtprog.getProgramBlocks().get(0).getStatementBlock().getDMLProg();
FunctionCallGraph fgraph = new FunctionCallGraph(prog);
sb.append(explainFunctionCallGraph(fgraph, new HashSet<String>(), null, 3));
}
//show individual functions
for (Entry<String, FunctionProgramBlock> e : funcMap.entrySet()) {
String fkey = e.getKey();
FunctionProgramBlock fpb = e.getValue();
if (fpb instanceof ExternalFunctionProgramBlock)
sb.append("----EXTERNAL FUNCTION " + fkey + "\n");
else {
sb.append("----FUNCTION " + fkey + " [recompile=" + fpb.isRecompileOnce() + "]\n");
for (ProgramBlock pb : fpb.getChildBlocks()) sb.append(explainProgramBlock(pb, 3));
}
}
}
//explain main program
sb.append("--MAIN PROGRAM\n");
for (ProgramBlock pb : rtprog.getProgramBlocks()) sb.append(explainProgramBlock(pb, 2));
return sb.toString();
}
use of org.apache.sysml.hops.ipa.FunctionCallGraph in project incubator-systemml by apache.
the class PreparedScript method enableFunctionRecompile.
/**
* Enables function recompilation, selectively for the given functions.
* If dynamic recompilation is globally enabled this has no additional
* effect; otherwise the given functions are dynamically recompiled once
* on every entry but not at the granularity of individually last-level
* program blocks. Use this fine-grained recompilation option for important
* functions in small-data scenarios where dynamic recompilation overheads
* might not be amortized.
*
* @param fnamespace function namespace, null for default namespace
* @param fnames function name
*/
public void enableFunctionRecompile(String fnamespace, String... fnames) {
// handle default name space
if (fnamespace == null)
fnamespace = DMLProgram.DEFAULT_NAMESPACE;
// enable dynamic recompilation (note that this does not globally enable
// dynamic recompilation because the program has been compiled already)
CompilerConfig cconf = ConfigurationManager.getCompilerConfig();
cconf.set(ConfigType.ALLOW_DYN_RECOMPILATION, true);
ConfigurationManager.setLocalConfig(cconf);
// build function call graph (to probe for recursive functions)
FunctionCallGraph fgraph = _prog.getProgramBlocks().isEmpty() ? null : new FunctionCallGraph(_prog.getProgramBlocks().get(0).getStatementBlock().getDMLProg());
// enable requested functions for recompile once
for (String fname : fnames) {
String fkey = DMLProgram.constructFunctionKey(fnamespace, fname);
if (fgraph != null && !fgraph.isRecursiveFunction(fkey)) {
FunctionProgramBlock fpb = _prog.getFunctionProgramBlock(fnamespace, fname);
if (fpb != null)
fpb.setRecompileOnce(true);
else
LOG.warn("Failed to enable function recompile for non-existing '" + fkey + "'.");
} else if (fgraph != null) {
LOG.warn("Failed to enable function recompile for recursive '" + fkey + "'.");
}
}
}
use of org.apache.sysml.hops.ipa.FunctionCallGraph in project incubator-systemml by apache.
the class Explain method explain.
public static String explain(Program rtprog, ExplainCounts counts) {
// counts number of instructions
boolean sparkExec = OptimizerUtils.isSparkExecutionMode();
if (counts == null) {
counts = new ExplainCounts();
countCompiledInstructions(rtprog, counts, !sparkExec, true, sparkExec);
}
StringBuilder sb = new StringBuilder();
// create header
sb.append("\nPROGRAM ( size CP/" + (sparkExec ? "SP" : "MR") + " = ");
sb.append(counts.numCPInst);
sb.append("/");
sb.append(counts.numJobs);
sb.append(" )\n");
// explain functions (if exists)
Map<String, FunctionProgramBlock> funcMap = rtprog.getFunctionProgramBlocks();
if (funcMap != null && !funcMap.isEmpty()) {
sb.append("--FUNCTIONS\n");
// show function call graph
if (!rtprog.getProgramBlocks().isEmpty() && rtprog.getProgramBlocks().get(0).getStatementBlock() != null) {
sb.append("----FUNCTION CALL GRAPH\n");
sb.append("------MAIN PROGRAM\n");
DMLProgram prog = rtprog.getProgramBlocks().get(0).getStatementBlock().getDMLProg();
FunctionCallGraph fgraph = new FunctionCallGraph(prog);
sb.append(explainFunctionCallGraph(fgraph, new HashSet<String>(), null, 3));
}
// show individual functions
for (Entry<String, FunctionProgramBlock> e : funcMap.entrySet()) {
String fkey = e.getKey();
FunctionProgramBlock fpb = e.getValue();
if (fpb instanceof ExternalFunctionProgramBlock)
sb.append("----EXTERNAL FUNCTION " + fkey + "\n");
else {
sb.append("----FUNCTION " + fkey + " [recompile=" + fpb.isRecompileOnce() + "]\n");
for (ProgramBlock pb : fpb.getChildBlocks()) sb.append(explainProgramBlock(pb, 3));
}
}
}
// explain main program
sb.append("--MAIN PROGRAM\n");
for (ProgramBlock pb : rtprog.getProgramBlocks()) sb.append(explainProgramBlock(pb, 2));
return sb.toString();
}
use of org.apache.sysml.hops.ipa.FunctionCallGraph in project systemml by apache.
the class Explain method explain.
public static String explain(Program rtprog, ExplainCounts counts) {
// counts number of instructions
boolean sparkExec = OptimizerUtils.isSparkExecutionMode();
if (counts == null) {
counts = new ExplainCounts();
countCompiledInstructions(rtprog, counts, !sparkExec, true, sparkExec);
}
StringBuilder sb = new StringBuilder();
// create header
sb.append("\nPROGRAM ( size CP/" + (sparkExec ? "SP" : "MR") + " = ");
sb.append(counts.numCPInst);
sb.append("/");
sb.append(counts.numJobs);
sb.append(" )\n");
// explain functions (if exists)
Map<String, FunctionProgramBlock> funcMap = rtprog.getFunctionProgramBlocks();
if (funcMap != null && !funcMap.isEmpty()) {
sb.append("--FUNCTIONS\n");
// show function call graph
if (!rtprog.getProgramBlocks().isEmpty() && rtprog.getProgramBlocks().get(0).getStatementBlock() != null) {
sb.append("----FUNCTION CALL GRAPH\n");
sb.append("------MAIN PROGRAM\n");
DMLProgram prog = rtprog.getProgramBlocks().get(0).getStatementBlock().getDMLProg();
FunctionCallGraph fgraph = new FunctionCallGraph(prog);
sb.append(explainFunctionCallGraph(fgraph, new HashSet<String>(), null, 3));
}
// show individual functions
for (Entry<String, FunctionProgramBlock> e : funcMap.entrySet()) {
String fkey = e.getKey();
FunctionProgramBlock fpb = e.getValue();
if (fpb instanceof ExternalFunctionProgramBlock)
sb.append("----EXTERNAL FUNCTION " + fkey + "\n");
else {
sb.append("----FUNCTION " + fkey + " [recompile=" + fpb.isRecompileOnce() + "]\n");
for (ProgramBlock pb : fpb.getChildBlocks()) sb.append(explainProgramBlock(pb, 3));
}
}
}
// explain main program
sb.append("--MAIN PROGRAM\n");
for (ProgramBlock pb : rtprog.getProgramBlocks()) sb.append(explainProgramBlock(pb, 2));
return sb.toString();
}
use of org.apache.sysml.hops.ipa.FunctionCallGraph in project 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();
}
Aggregations