Search in sources :

Example 26 with ProgramBlock

use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.

the class Explain method explainProgramBlock.

// ////////////
// internal explain RUNTIME
private static String explainProgramBlock(ProgramBlock pb, int level) {
    StringBuilder sb = new StringBuilder();
    String offset = createOffset(level);
    if (pb instanceof FunctionProgramBlock) {
        FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
        for (ProgramBlock pbc : fpb.getChildBlocks()) sb.append(explainProgramBlock(pbc, level + 1));
    } else if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        StatementBlock wsb = pb.getStatementBlock();
        sb.append(offset);
        if (wsb != null && !wsb.getUpdateInPlaceVars().isEmpty())
            sb.append("WHILE (lines " + wpb.getBeginLine() + "-" + wpb.getEndLine() + ") [in-place=" + wsb.getUpdateInPlaceVars().toString() + "]\n");
        else
            sb.append("WHILE (lines " + wpb.getBeginLine() + "-" + wpb.getEndLine() + ")\n");
        sb.append(explainInstructions(wpb.getPredicate(), level + 1));
        for (ProgramBlock pbc : wpb.getChildBlocks()) sb.append(explainProgramBlock(pbc, level + 1));
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) pb;
        sb.append(offset);
        sb.append("IF (lines " + ipb.getBeginLine() + "-" + ipb.getEndLine() + ")\n");
        sb.append(explainInstructions(ipb.getPredicate(), level + 1));
        for (ProgramBlock pbc : ipb.getChildBlocksIfBody()) sb.append(explainProgramBlock(pbc, level + 1));
        if (!ipb.getChildBlocksElseBody().isEmpty()) {
            sb.append(offset);
            sb.append("ELSE\n");
            for (ProgramBlock pbc : ipb.getChildBlocksElseBody()) sb.append(explainProgramBlock(pbc, level + 1));
        }
    } else if (// incl parfor
    pb instanceof ForProgramBlock) {
        ForProgramBlock fpb = (ForProgramBlock) pb;
        StatementBlock fsb = pb.getStatementBlock();
        sb.append(offset);
        if (pb instanceof ParForProgramBlock)
            sb.append("PARFOR (lines " + fpb.getBeginLine() + "-" + fpb.getEndLine() + ")\n");
        else {
            if (fsb != null && !fsb.getUpdateInPlaceVars().isEmpty())
                sb.append("FOR (lines " + fpb.getBeginLine() + "-" + fpb.getEndLine() + ") [in-place=" + fsb.getUpdateInPlaceVars().toString() + "]\n");
            else
                sb.append("FOR (lines " + fpb.getBeginLine() + "-" + fpb.getEndLine() + ")\n");
        }
        sb.append(explainInstructions(fpb.getFromInstructions(), level + 1));
        sb.append(explainInstructions(fpb.getToInstructions(), level + 1));
        sb.append(explainInstructions(fpb.getIncrementInstructions(), level + 1));
        for (ProgramBlock pbc : fpb.getChildBlocks()) sb.append(explainProgramBlock(pbc, level + 1));
    } else {
        sb.append(offset);
        if (pb.getStatementBlock() != null)
            sb.append("GENERIC (lines " + pb.getBeginLine() + "-" + pb.getEndLine() + ") [recompile=" + pb.getStatementBlock().requiresRecompilation() + "]\n");
        else
            sb.append("GENERIC (lines " + pb.getBeginLine() + "-" + pb.getEndLine() + ") \n");
        sb.append(explainInstructions(pb.getInstructions(), level + 1));
    }
    return sb.toString();
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) 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) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) 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) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Example 27 with ProgramBlock

use of org.apache.sysml.runtime.controlprogram.ProgramBlock 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 28 with ProgramBlock

use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.

the class DMLYarnClientProxy method launchDMLYarnAppmaster.

public static boolean launchDMLYarnAppmaster(String dmlScriptStr, DMLConfig conf, String[] allArgs, Program rtprog) throws IOException, DMLRuntimeException {
    boolean ret = false;
    try {
        // optimize resources (and update configuration)
        if (DMLAppMasterUtils.isResourceOptimizerEnabled()) {
            LOG.warn("Optimization level '" + OptimizationLevel.O3_LOCAL_RESOURCE_TIME_MEMORY + "' " + "is still in experimental state and not intended for production use.");
            YarnClusterConfig cc = YarnClusterAnalyzer.getClusterConfig();
            DMLAppMasterUtils.setupRemoteParallelTasks(cc);
            ArrayList<ProgramBlock> pb = DMLAppMasterUtils.getRuntimeProgramBlocks(rtprog);
            ResourceConfig rc = ResourceOptimizer.optimizeResourceConfig(pb, cc, GridEnumType.HYBRID_MEM_EXP_GRID, GridEnumType.HYBRID_MEM_EXP_GRID);
            conf.updateYarnMemorySettings(String.valueOf(YarnOptimizerUtils.toMB(rc.getCPResource())), rc.serialize());
        // alternative: only use the max mr memory for all statement blocks
        // conf.updateYarnMemorySettings(String.valueOf(rc.getCPResource()), String.valueOf(rc.getMaxMRResource()));
        }
        // launch dml yarn app master
        DMLYarnClient yclient = new DMLYarnClient(dmlScriptStr, conf, allArgs);
        ret = yclient.launchDMLYarnAppmaster();
    } catch (NoClassDefFoundError ex) {
        LOG.warn("Failed to instantiate DML yarn client " + "(NoClassDefFoundError: " + ex.getMessage() + "). " + "Resume with default client processing.");
        ret = false;
    }
    return ret;
}
Also used : YarnClusterConfig(org.apache.sysml.yarn.ropt.YarnClusterConfig) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ResourceConfig(org.apache.sysml.yarn.ropt.ResourceConfig)

Example 29 with ProgramBlock

use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.

the class ResourceOptimizer method compileProgram.

private static ArrayList<ProgramBlock> compileProgram(ArrayList<ProgramBlock> prog, ArrayList<ProgramBlock> B, double cp, double mr) {
    if (B == null) {
        // init
        B = new ArrayList<>();
        InfrastructureAnalyzer.setLocalMaxMemory((long) cp);
        InfrastructureAnalyzer.setRemoteMaxMemoryMap((long) mr);
        InfrastructureAnalyzer.setRemoteMaxMemoryReduce((long) mr);
        // dependent on cp, mr
        OptimizerUtils.resetDefaultSize();
    }
    for (ProgramBlock pb : prog) compileProgram(pb, B, cp, mr);
    return B;
}
Also used : 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)

Example 30 with ProgramBlock

use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.

the class ResourceOptimizer method recompileProgramBlocks.

private static void recompileProgramBlocks(ArrayList<ProgramBlock> pbs, long cp, double[][] memo) {
    for (int i = 0; i < pbs.size(); i++) {
        ProgramBlock pb = pbs.get(i);
        long mr = (long) memo[i][0];
        recompileProgramBlock(pb, cp, mr);
    }
}
Also used : 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)

Aggregations

ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)64 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)58 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)56 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)54 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)54 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)38 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)26 ArrayList (java.util.ArrayList)20 Instruction (org.apache.sysml.runtime.instructions.Instruction)18 StatementBlock (org.apache.sysml.parser.StatementBlock)13 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)13 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)11 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)11 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)11 Hop (org.apache.sysml.hops.Hop)10 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)10 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9 Program (org.apache.sysml.runtime.controlprogram.Program)9 DMLProgram (org.apache.sysml.parser.DMLProgram)8 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)7