use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock in project systemml by apache.
the class ProgramConverter method parseProgram.
public static Program parseProgram(String in, int id) {
String lin = in.substring(PARFOR_PROG_BEGIN.length(), in.length() - PARFOR_PROG_END.length()).trim();
Program prog = new Program();
HashMap<String, FunctionProgramBlock> fc = parseFunctionProgramBlocks(lin, prog, id);
for (Entry<String, FunctionProgramBlock> e : fc.entrySet()) {
String[] keypart = e.getKey().split(Program.KEY_DELIM);
String namespace = keypart[0];
String name = keypart[1];
prog.addFunctionProgramBlock(namespace, name, e.getValue());
}
return prog;
}
use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock in project systemml by apache.
the class JMLCUtils method cleanupRuntimeProgram.
/**
* Removes rmvar instructions that would remove any of the given outputs.
* This is important for keeping registered outputs after the program terminates.
*
* @param prog the DML/PyDML program
* @param outputs registered output variables
*/
public static void cleanupRuntimeProgram(Program prog, String[] outputs) {
Map<String, FunctionProgramBlock> funcMap = prog.getFunctionProgramBlocks();
HashSet<String> blacklist = new HashSet<>(Arrays.asList(outputs));
if (funcMap != null && !funcMap.isEmpty()) {
for (Entry<String, FunctionProgramBlock> e : funcMap.entrySet()) {
FunctionProgramBlock fpb = e.getValue();
for (ProgramBlock pb : fpb.getChildBlocks()) rCleanupRuntimeProgram(pb, blacklist);
}
}
for (ProgramBlock pb : prog.getProgramBlocks()) rCleanupRuntimeProgram(pb, blacklist);
}
use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock 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