Search in sources :

Example 1 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(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();
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) DMLProgram(org.apache.sysml.parser.DMLProgram) FunctionCallGraph(org.apache.sysml.hops.ipa.FunctionCallGraph) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) HashSet(java.util.HashSet)

Example 2 with FunctionCallGraph

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

Example 3 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(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();
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) DMLProgram(org.apache.sysml.parser.DMLProgram) FunctionCallGraph(org.apache.sysml.hops.ipa.FunctionCallGraph) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) HashSet(java.util.HashSet)

Example 4 with FunctionCallGraph

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

Example 5 with FunctionCallGraph

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();
}
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)

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