Search in sources :

Example 6 with FunctionCallGraph

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();
}
Also used : ExternalFunctionStatement(org.apache.sysml.parser.ExternalFunctionStatement) FunctionStatement(org.apache.sysml.parser.FunctionStatement) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) ExternalFunctionStatement(org.apache.sysml.parser.ExternalFunctionStatement) FunctionCallGraph(org.apache.sysml.hops.ipa.FunctionCallGraph) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) ParForStatementBlock(org.apache.sysml.parser.ParForStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) HashSet(java.util.HashSet)

Example 7 with FunctionCallGraph

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

Aggregations

FunctionCallGraph (org.apache.sysml.hops.ipa.FunctionCallGraph)7 HashSet (java.util.HashSet)5 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)5 DMLProgram (org.apache.sysml.parser.DMLProgram)3 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)3 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)3 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)3 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)3 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)3 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)3 CompilerConfig (org.apache.sysml.conf.CompilerConfig)2 ExternalFunctionStatement (org.apache.sysml.parser.ExternalFunctionStatement)2 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)2 FunctionStatement (org.apache.sysml.parser.FunctionStatement)2 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)2 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)2 ParForStatementBlock (org.apache.sysml.parser.ParForStatementBlock)2 StatementBlock (org.apache.sysml.parser.StatementBlock)2 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)2