Search in sources :

Example 16 with ExecutionContext

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

the class GDFEnumOptimizer method costRuntimePlan.

private static double costRuntimePlan(Plan p) throws DMLRuntimeException {
    Program prog = p.getNode().getProgram();
    if (prog == null)
        throw new DMLRuntimeException("Program not available for runtime plan costing.");
    //put data flow configuration into program
    rSetRuntimePlanConfig(p, new HashMap<Long, Plan>());
    double costs = -1;
    if (COST_FULL_PROGRAMS || (p.getNode().getHop() == null || p.getNode().getProgramBlock() == null)) {
        //recompile entire runtime program
        Recompiler.recompileProgramBlockHierarchy(prog.getProgramBlocks(), new LocalVariableMap(), 0, false);
        _compiledPlans++;
        //cost entire runtime program
        ExecutionContext ec = ExecutionContextFactory.createContext(prog);
        costs = CostEstimationWrapper.getTimeEstimate(prog, ec);
    } else {
        Hop currentHop = p.getNode().getHop();
        ProgramBlock pb = p.getNode().getProgramBlock();
        try {
            //keep the old dag roots
            ArrayList<Hop> oldRoots = pb.getStatementBlock().get_hops();
            Hop tmpHop = null;
            if (!(currentHop instanceof DataOp && ((DataOp) currentHop).isWrite())) {
                ArrayList<Hop> newRoots = new ArrayList<Hop>();
                tmpHop = new DataOp("_tmp", currentHop.getDataType(), currentHop.getValueType(), currentHop, DataOpTypes.TRANSIENTWRITE, "tmp");
                //ensure recursive visitstatus reset on recompile
                tmpHop.setVisited();
                newRoots.add(tmpHop);
                pb.getStatementBlock().set_hops(newRoots);
            }
            //recompile modified runtime program
            Recompiler.recompileProgramBlockHierarchy(prog.getProgramBlocks(), new LocalVariableMap(), 0, false);
            _compiledPlans++;
            //cost partial runtime program up to current hop
            ExecutionContext ec = ExecutionContextFactory.createContext(prog);
            costs = CostEstimationWrapper.getTimeEstimate(prog, ec);
            //restore original hop dag
            if (tmpHop != null)
                HopRewriteUtils.removeChildReference(tmpHop, currentHop);
            pb.getStatementBlock().set_hops(oldRoots);
        } catch (HopsException ex) {
            throw new DMLRuntimeException(ex);
        }
    }
    //release forced data flow configuration from program
    rResetRuntimePlanConfig(p, new HashMap<Long, Plan>());
    _costedPlans++;
    return costs;
}
Also used : Program(org.apache.sysml.runtime.controlprogram.Program) Hop(org.apache.sysml.hops.Hop) ArrayList(java.util.ArrayList) HopsException(org.apache.sysml.hops.HopsException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) LocalVariableMap(org.apache.sysml.runtime.controlprogram.LocalVariableMap) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) DataOp(org.apache.sysml.hops.DataOp)

Example 17 with ExecutionContext

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

the class ParForProgramBlock method createParallelWorker.

/**
	 * Creates a new or partially recycled instance of a parallel worker. Therefore the symbol table, and child
	 * program blocks are deep copied. Note that entries of the symbol table are not deep copied because they are replaced 
	 * anyway on the next write. In case of recycling the deep copies of program blocks are recycled from previous 
	 * executions of this parfor.
	 * 
	 * @param pwID parworker id
	 * @param queue task queue
	 * @param ec execution context
	 * @return local parworker
	 * @throws DMLRuntimeException if DMLRuntimeException occurs
	 */
private LocalParWorker createParallelWorker(long pwID, LocalTaskQueue<Task> queue, ExecutionContext ec) throws DMLRuntimeException {
    LocalParWorker pw = null;
    try {
        //create deep copies of required elements child blocks
        ArrayList<ProgramBlock> cpChildBlocks = null;
        HashSet<String> fnNames = new HashSet<String>();
        if (USE_PB_CACHE) {
            if (_pbcache.containsKey(pwID)) {
                cpChildBlocks = _pbcache.get(pwID);
            } else {
                cpChildBlocks = ProgramConverter.rcreateDeepCopyProgramBlocks(_childBlocks, pwID, _IDPrefix, new HashSet<String>(), fnNames, false, false);
                _pbcache.put(pwID, cpChildBlocks);
            }
        } else {
            cpChildBlocks = ProgramConverter.rcreateDeepCopyProgramBlocks(_childBlocks, pwID, _IDPrefix, new HashSet<String>(), fnNames, false, false);
        }
        //deep copy execution context (including prepare parfor update-in-place)
        ExecutionContext cpEc = ProgramConverter.createDeepCopyExecutionContext(ec);
        // and sets it in the ExecutionContext
        if (DMLScript.USE_ACCELERATOR) {
            cpEc.setGPUContext(GPUContextPool.getFromPool());
        }
        //prepare basic update-in-place variables (vars dropped on result merge)
        prepareUpdateInPlaceVariables(cpEc, pwID);
        //copy compiler configuration (for jmlc w/o global config)
        CompilerConfig cconf = ConfigurationManager.getCompilerConfig();
        //create the actual parallel worker
        ParForBody body = new ParForBody(cpChildBlocks, _resultVars, cpEc);
        pw = new LocalParWorker(pwID, queue, body, cconf, MAX_RETRYS_ON_ERROR, _monitor);
        pw.setFunctionNames(fnNames);
    } catch (Exception ex) {
        throw new DMLRuntimeException(ex);
    }
    return pw;
}
Also used : ParForBody(org.apache.sysml.runtime.controlprogram.parfor.ParForBody) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) LocalParWorker(org.apache.sysml.runtime.controlprogram.parfor.LocalParWorker) CompilerConfig(org.apache.sysml.conf.CompilerConfig) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) IOException(java.io.IOException) CacheException(org.apache.sysml.runtime.controlprogram.caching.CacheException) HashSet(java.util.HashSet) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

ExecutionContext (org.apache.sysml.runtime.controlprogram.context.ExecutionContext)17 Program (org.apache.sysml.runtime.controlprogram.Program)6 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)5 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)5 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)5 CompilerConfig (org.apache.sysml.conf.CompilerConfig)4 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 DMLConfig (org.apache.sysml.conf.DMLConfig)3 DMLProgram (org.apache.sysml.parser.DMLProgram)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 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)3 IOException (java.io.IOException)2 DataOp (org.apache.sysml.hops.DataOp)2 HopsException (org.apache.sysml.hops.HopsException)2 ResultVar (org.apache.sysml.parser.ParForStatementBlock.ResultVar)2 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)2