use of org.apache.sysml.hops.ipa.FunctionCallGraph 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.hops.ipa.FunctionCallGraph in project 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 + "'.");
}
}
}
Aggregations