Search in sources :

Example 1 with ExecutionContext

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

the class GDFEnumOptimizer method optimize.

@Override
public GDFGraph optimize(GDFGraph gdfgraph, Summary summary) throws DMLRuntimeException, HopsException, LopsException {
    Timing time = new Timing(true);
    Program prog = gdfgraph.getRuntimeProgram();
    ExecutionContext ec = ExecutionContextFactory.createContext(prog);
    ArrayList<GDFNode> roots = gdfgraph.getGraphRootNodes();
    //Step 1: baseline costing for branch and bound costs
    double initCosts = Double.MAX_VALUE;
    if (BRANCH_AND_BOUND_PRUNING) {
        initCosts = CostEstimationWrapper.getTimeEstimate(prog, ec);
        initCosts = initCosts * (1 + BRANCH_AND_BOUND_REL_THRES);
    }
    //Step 2: dynamic programming plan generation
    //(finally, pick optimal root plans over all interesting property sets)
    ArrayList<Plan> rootPlans = new ArrayList<Plan>();
    for (GDFNode node : roots) {
        PlanSet ps = enumOpt(node, _memo, initCosts);
        Plan optPlan = ps.getPlanWithMinCosts();
        rootPlans.add(optPlan);
    }
    long enumPlanMismatch = getPlanMismatches();
    //check for final containment of independent roots and pick optimal
    HashMap<Long, Plan> memo = new HashMap<Long, Plan>();
    resetPlanMismatches();
    for (Plan p : rootPlans) rSetRuntimePlanConfig(p, memo);
    long finalPlanMismatch = getPlanMismatches();
    //generate final runtime plan (w/ optimal config)
    Recompiler.recompileProgramBlockHierarchy(prog.getProgramBlocks(), new LocalVariableMap(), 0, false);
    ec = ExecutionContextFactory.createContext(prog);
    double optCosts = CostEstimationWrapper.getTimeEstimate(prog, ec);
    //maintain optimization summary statistics
    summary.setCostsInitial(initCosts);
    summary.setCostsOptimal(optCosts);
    summary.setNumEnumPlans(_enumeratedPlans);
    summary.setNumPrunedInvalidPlans(_prunedInvalidPlans);
    summary.setNumPrunedSuboptPlans(_prunedSuboptimalPlans);
    summary.setNumCompiledPlans(_compiledPlans);
    summary.setNumCostedPlans(_costedPlans);
    summary.setNumEnumPlanMismatch(enumPlanMismatch);
    summary.setNumFinalPlanMismatch(finalPlanMismatch);
    summary.setTimeOptim(time.stop());
    return gdfgraph;
}
Also used : Program(org.apache.sysml.runtime.controlprogram.Program) HashMap(java.util.HashMap) GDFNode(org.apache.sysml.hops.globalopt.gdfgraph.GDFNode) ArrayList(java.util.ArrayList) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) LocalVariableMap(org.apache.sysml.runtime.controlprogram.LocalVariableMap) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)

Example 2 with ExecutionContext

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

the class ScriptExecutorUtils method executeRuntimeProgram.

/**
	 * Execute the runtime program. This involves execution of the program
	 * blocks that make up the runtime program and may involve dynamic
	 * recompilation.
	 * 
	 * @param se
	 *            script executor
	 * @param statisticsMaxHeavyHitters
	 *            maximum number of statistics to print
	 * @throws DMLRuntimeException
	 *             if exception occurs
	 */
public static void executeRuntimeProgram(ScriptExecutor se, int statisticsMaxHeavyHitters) throws DMLRuntimeException {
    Program prog = se.getRuntimeProgram();
    ExecutionContext ec = se.getExecutionContext();
    DMLConfig config = se.getConfig();
    executeRuntimeProgram(prog, ec, config, statisticsMaxHeavyHitters);
}
Also used : Program(org.apache.sysml.runtime.controlprogram.Program) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) DMLConfig(org.apache.sysml.conf.DMLConfig)

Example 3 with ExecutionContext

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

the class ProgramConverter method parseParForBody.

////////////////////////////////
// PARSING 
////////////////////////////////
public static ParForBody parseParForBody(String in, int id) throws DMLRuntimeException {
    ParForBody body = new ParForBody();
    //header elimination
    //normalization
    String tmpin = in.replaceAll(NEWLINE, "");
    //remove start/end
    tmpin = tmpin.substring(PARFORBODY_BEGIN.length(), tmpin.length() - PARFORBODY_END.length());
    HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(tmpin, COMPONENTS_DELIM);
    //handle DMLScript UUID (NOTE: set directly in DMLScript)
    //(master UUID is used for all nodes (in order to simply cleanup))
    DMLScript.setUUID(st.nextToken());
    //handle DML config (NOTE: set directly in ConfigurationManager)
    String confStr = st.nextToken();
    JobConf job = ConfigurationManager.getCachedJobConf();
    if (!InfrastructureAnalyzer.isLocalMode(job)) {
        if (confStr != null && !confStr.trim().isEmpty()) {
            DMLConfig dmlconf = DMLConfig.parseDMLConfig(confStr);
            CompilerConfig cconf = OptimizerUtils.constructCompilerConfig(dmlconf);
            ConfigurationManager.setLocalConfig(dmlconf);
            ConfigurationManager.setLocalConfig(cconf);
        }
        //init internal configuration w/ parsed or default config
        ParForProgramBlock.initInternalConfigurations(ConfigurationManager.getDMLConfig());
    }
    //handle additional configs
    String aconfs = st.nextToken();
    parseAndSetAdditionalConfigurations(aconfs);
    //handle program
    String progStr = st.nextToken();
    Program prog = parseProgram(progStr, id);
    //handle result variable names
    String rvarStr = st.nextToken();
    ArrayList<String> rvars = parseStringArrayList(rvarStr);
    body.setResultVarNames(rvars);
    //handle execution context
    String ecStr = st.nextToken();
    ExecutionContext ec = parseExecutionContext(ecStr, prog);
    //handle program blocks
    String spbs = st.nextToken();
    ArrayList<ProgramBlock> pbs = rParseProgramBlocks(spbs, prog, id);
    body.setChildBlocks(pbs);
    body.setEc(ec);
    return body;
}
Also used : DMLConfig(org.apache.sysml.conf.DMLConfig) DMLProgram(org.apache.sysml.parser.DMLProgram) Program(org.apache.sysml.runtime.controlprogram.Program) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) 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) JobConf(org.apache.hadoop.mapred.JobConf) CompilerConfig(org.apache.sysml.conf.CompilerConfig)

Example 4 with ExecutionContext

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

the class ProgramConverter method serializeParForBody.

public static String serializeParForBody(ParForBody body, HashMap<String, byte[]> clsMap) throws DMLRuntimeException {
    ArrayList<ProgramBlock> pbs = body.getChildBlocks();
    ArrayList<String> rVnames = body.getResultVarNames();
    ExecutionContext ec = body.getEc();
    if (pbs.isEmpty())
        return PARFORBODY_BEGIN + PARFORBODY_END;
    Program prog = pbs.get(0).getProgram();
    StringBuilder sb = new StringBuilder();
    sb.append(PARFORBODY_BEGIN);
    sb.append(NEWLINE);
    //handle DMLScript UUID (propagate original uuid for writing to scratch space)
    sb.append(DMLScript.getUUID());
    sb.append(COMPONENTS_DELIM);
    sb.append(NEWLINE);
    //handle DML config
    sb.append(ConfigurationManager.getDMLConfig().serializeDMLConfig());
    sb.append(COMPONENTS_DELIM);
    sb.append(NEWLINE);
    //handle additional configurations
    sb.append(PARFOR_CONF_STATS + "=" + DMLScript.STATISTICS);
    sb.append(COMPONENTS_DELIM);
    sb.append(NEWLINE);
    //handle program
    sb.append(PARFOR_PROG_BEGIN);
    sb.append(NEWLINE);
    sb.append(serializeProgram(prog, pbs, clsMap));
    sb.append(PARFOR_PROG_END);
    sb.append(NEWLINE);
    sb.append(COMPONENTS_DELIM);
    sb.append(NEWLINE);
    //handle result variable names
    sb.append(serializeStringArrayList(rVnames));
    sb.append(COMPONENTS_DELIM);
    //handle execution context
    //note: this includes also the symbol table (serialize only the top-level variable map,
    //      (symbol tables for nested/child blocks are created at parse time, on the remote side)
    sb.append(PARFOR_EC_BEGIN);
    sb.append(serializeExecutionContext(ec));
    sb.append(PARFOR_EC_END);
    sb.append(NEWLINE);
    sb.append(COMPONENTS_DELIM);
    sb.append(NEWLINE);
    //handle program blocks -- ONLY instructions, not variables.
    sb.append(PARFOR_PBS_BEGIN);
    sb.append(NEWLINE);
    sb.append(rSerializeProgramBlocks(pbs, clsMap));
    sb.append(PARFOR_PBS_END);
    sb.append(NEWLINE);
    sb.append(PARFORBODY_END);
    return sb.toString();
}
Also used : ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) DMLProgram(org.apache.sysml.parser.DMLProgram) Program(org.apache.sysml.runtime.controlprogram.Program) 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)

Example 5 with ExecutionContext

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

the class ResourceOptimizer method getProgramCosts.

private static double getProgramCosts(Program prog) throws DMLRuntimeException {
    //we need to cost the entire program in order to take in-memory status into account
    ExecutionContext ec = ExecutionContextFactory.createContext();
    double val = CostEstimationWrapper.getTimeEstimate(prog, ec);
    _cntCostPB++;
    return val;
}
Also used : ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext)

Aggregations

ExecutionContext (org.apache.sysml.runtime.controlprogram.context.ExecutionContext)15 Program (org.apache.sysml.runtime.controlprogram.Program)6 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)5 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)5 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)4 ArrayList (java.util.ArrayList)3 CompilerConfig (org.apache.sysml.conf.CompilerConfig)3 DMLConfig (org.apache.sysml.conf.DMLConfig)3 DMLProgram (org.apache.sysml.parser.DMLProgram)3 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)3 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)3 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)3 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)3 HashSet (java.util.HashSet)2 DataOp (org.apache.sysml.hops.DataOp)2 HopsException (org.apache.sysml.hops.HopsException)2 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)2 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)2 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)2 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)2