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