Search in sources :

Example 66 with FunctionProgramBlock

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;
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) DMLProgram(org.apache.sysml.parser.DMLProgram) Program(org.apache.sysml.runtime.controlprogram.Program)

Example 67 with FunctionProgramBlock

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);
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) HashSet(java.util.HashSet)

Example 68 with FunctionProgramBlock

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 + "'.");
        }
    }
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) FunctionCallGraph(org.apache.sysml.hops.ipa.FunctionCallGraph) CompilerConfig(org.apache.sysml.conf.CompilerConfig)

Aggregations

FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)68 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)54 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)52 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)52 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)46 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)34 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)33 ArrayList (java.util.ArrayList)22 StatementBlock (org.apache.sysml.parser.StatementBlock)20 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)18 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)18 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)18 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)16 Instruction (org.apache.sysml.runtime.instructions.Instruction)15 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)12 DMLProgram (org.apache.sysml.parser.DMLProgram)11 Program (org.apache.sysml.runtime.controlprogram.Program)11 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)10 HashSet (java.util.HashSet)9 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)9