Search in sources :

Example 91 with Instruction

use of org.apache.sysml.runtime.instructions.Instruction in project incubator-systemml by apache.

the class Recompiler method recompileIfPredicate.

// helper functions for predicate recompile
private static void recompileIfPredicate(IfProgramBlock ipb, IfStatementBlock isb, LocalVariableMap vars, RecompileStatus status, long tid, ResetType resetRecompile) {
    if (isb == null)
        return;
    Hop hops = isb.getPredicateHops();
    if (hops != null) {
        ArrayList<Instruction> tmp = recompileHopsDag(hops, vars, status, true, false, tid);
        ipb.setPredicate(tmp);
        if (ParForProgramBlock.RESET_RECOMPILATION_FLAGs && resetRecompile.isReset()) {
            Hop.resetRecompilationFlag(hops, ExecType.CP, resetRecompile);
            isb.updatePredicateRecompilationFlag();
        }
    }
}
Also used : Hop(org.apache.sysml.hops.Hop) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) SeqInstruction(org.apache.sysml.runtime.instructions.mr.SeqInstruction) RandInstruction(org.apache.sysml.runtime.instructions.mr.RandInstruction)

Example 92 with Instruction

use of org.apache.sysml.runtime.instructions.Instruction in project incubator-systemml by apache.

the class Recompiler method recompile.

/**
 * Core internal primitive for the dynamic recompilation of any DAGs/predicate,
 * including all variants with slightly different configurations.
 *
 * @param sb statement block of DAG, null for predicates
 * @param hops list of DAG root nodes
 * @param vars symbol table
 * @param status recompilation status
 * @param inplace modify DAG in place, otherwise deep copy
 * @param replaceLit replace literals (only applicable on deep copy)
 * @param updateStats update statistics, rewrites, and memory estimates
 * @param forceEt force a given execution type, null for reset
 * @param pred recompile for predicate DAG
 * @param et given execution type
 * @param tid thread id, 0 for main or before worker creation
 * @return modified list of instructions
 */
private static ArrayList<Instruction> recompile(StatementBlock sb, ArrayList<Hop> hops, LocalVariableMap vars, RecompileStatus status, boolean inplace, boolean replaceLit, boolean updateStats, boolean forceEt, boolean pred, ExecType et, long tid) {
    // prepare hops dag for recompile
    if (!inplace) {
        // deep copy hop dag (for non-reversable rewrites)
        hops = deepCopyHopsDag(hops);
    } else {
        // clear existing lops
        Hop.resetVisitStatus(hops);
        for (Hop hopRoot : hops) rClearLops(hopRoot);
    }
    // replace scalar reads with literals
    if (!inplace && replaceLit) {
        Hop.resetVisitStatus(hops);
        for (Hop hopRoot : hops) rReplaceLiterals(hopRoot, vars, false);
    }
    // force exec type (et=null for reset)
    if (forceEt) {
        Hop.resetVisitStatus(hops);
        for (Hop hopRoot : hops) rSetExecType(hopRoot, et);
        Hop.resetVisitStatus(hops);
    }
    // update statistics, rewrites, and mem estimates
    if (updateStats) {
        // refresh matrix characteristics (update stats)
        Hop.resetVisitStatus(hops);
        for (Hop hopRoot : hops) rUpdateStatistics(hopRoot, vars);
        // dynamic hop rewrites
        if (!inplace) {
            _rewriter.get().rewriteHopDAG(hops, null);
            // update stats after rewrites
            Hop.resetVisitStatus(hops);
            for (Hop hopRoot : hops) rUpdateStatistics(hopRoot, vars);
        }
        // refresh memory estimates (based on updated stats,
        // before: init memo table with propagated worst-case estimates,
        // after: extract worst-case estimates from memo table
        Hop.resetVisitStatus(hops);
        MemoTable memo = new MemoTable();
        memo.init(hops, status);
        Hop.resetVisitStatus(hops);
        for (Hop hopRoot : hops) hopRoot.refreshMemEstimates(memo);
        memo.extract(hops, status);
    }
    // codegen if enabled
    if (ConfigurationManager.isCodegenEnabled() && // not on reset
    !(forceEt && et == null) && SpoofCompiler.RECOMPILE_CODEGEN) {
        // create deep copy for in-place
        if (inplace)
            hops = deepCopyHopsDag(hops);
        Hop.resetVisitStatus(hops);
        hops = SpoofCompiler.optimize(hops, (status == null || !status.isInitialCodegen()));
    }
    // construct lops
    Dag<Lop> dag = new Dag<>();
    for (Hop hopRoot : hops) {
        Lop lops = hopRoot.constructLops();
        lops.addToDag(dag);
    }
    // generate runtime instructions (incl piggybacking)
    ArrayList<Instruction> newInst = dag.getJobs(sb, ConfigurationManager.getDMLConfig());
    // defer the explain of instructions after additional modifications
    if (DMLScript.EXPLAIN == ExplainType.RECOMPILE_HOPS) {
        if (pred)
            logExplainPred(hops.get(0), newInst);
        else
            logExplainDAG(sb, hops, newInst);
    }
    return newInst;
}
Also used : Hop(org.apache.sysml.hops.Hop) Dag(org.apache.sysml.lops.compile.Dag) Lop(org.apache.sysml.lops.Lop) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) SeqInstruction(org.apache.sysml.runtime.instructions.mr.SeqInstruction) RandInstruction(org.apache.sysml.runtime.instructions.mr.RandInstruction) MemoTable(org.apache.sysml.hops.MemoTable)

Example 93 with Instruction

use of org.apache.sysml.runtime.instructions.Instruction in project incubator-systemml by apache.

the class ProgramConverter method rParseForProgramBlock.

private static ForProgramBlock rParseForProgramBlock(String in, Program prog, int id) {
    String lin = in.substring(PARFOR_PB_FOR.length(), in.length() - PARFOR_PB_END.length());
    HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
    // inputs
    String iterVar = st.nextToken();
    // instructions
    ArrayList<Instruction> from = parseInstructions(st.nextToken(), id);
    ArrayList<Instruction> to = parseInstructions(st.nextToken(), id);
    ArrayList<Instruction> incr = parseInstructions(st.nextToken(), id);
    // exit instructions
    ArrayList<Instruction> exit = parseInstructions(st.nextToken(), id);
    // program blocks
    ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, id);
    ForProgramBlock fpb = new ForProgramBlock(prog, iterVar);
    fpb.setFromInstructions(from);
    fpb.setToInstructions(to);
    fpb.setIncrementInstructions(incr);
    fpb.setExitInstructions(exit);
    fpb.setChildBlocks(pbs);
    return fpb;
}
Also used : 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) GPUInstruction(org.apache.sysml.runtime.instructions.gpu.GPUInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) MRInstruction(org.apache.sysml.runtime.instructions.mr.MRInstruction)

Example 94 with Instruction

use of org.apache.sysml.runtime.instructions.Instruction in project incubator-systemml by apache.

the class ProgramConverter method serializeInstructions.

@SuppressWarnings("all")
private static String serializeInstructions(ArrayList<Instruction> inst, HashMap<String, byte[]> clsMap) {
    StringBuilder sb = new StringBuilder();
    int count = 0;
    for (Instruction linst : inst) {
        // check that only cp instruction are transmitted
        if (!(linst instanceof CPInstruction || linst instanceof ExternalFunctionInvocationInstruction))
            throw new DMLRuntimeException(NOT_SUPPORTED_MR_INSTRUCTION + " " + linst.getClass().getName() + "\n" + linst);
        // obtain serialized version of generated classes
        if (linst instanceof SpoofCPInstruction) {
            Class<?> cla = ((SpoofCPInstruction) linst).getOperatorClass();
            clsMap.put(cla.getName(), CodegenUtils.getClassData(cla.getName()));
        }
        if (count > 0)
            sb.append(ELEMENT_DELIM);
        sb.append(checkAndReplaceLiterals(linst.toString()));
        count++;
    }
    return sb.toString();
}
Also used : CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) GPUInstruction(org.apache.sysml.runtime.instructions.gpu.GPUInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) MRInstruction(org.apache.sysml.runtime.instructions.mr.MRInstruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 95 with Instruction

use of org.apache.sysml.runtime.instructions.Instruction in project incubator-systemml by apache.

the class ProgramConverter method rParseWhileProgramBlock.

private static WhileProgramBlock rParseWhileProgramBlock(String in, Program prog, int id) {
    String lin = in.substring(PARFOR_PB_WHILE.length(), in.length() - PARFOR_PB_END.length());
    HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
    // predicate instructions
    ArrayList<Instruction> inst = parseInstructions(st.nextToken(), id);
    // exit instructions
    ArrayList<Instruction> exit = parseInstructions(st.nextToken(), id);
    // program blocks
    ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, id);
    WhileProgramBlock wpb = new WhileProgramBlock(prog, inst);
    wpb.setExitInstructions2(exit);
    wpb.setChildBlocks(pbs);
    return wpb;
}
Also used : 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) GPUInstruction(org.apache.sysml.runtime.instructions.gpu.GPUInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) MRInstruction(org.apache.sysml.runtime.instructions.mr.MRInstruction)

Aggregations

Instruction (org.apache.sysml.runtime.instructions.Instruction)132 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)90 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)60 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)60 CPInstruction (org.apache.sysml.runtime.instructions.cp.CPInstruction)56 ArrayList (java.util.ArrayList)40 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)35 ExternalFunctionInvocationInstruction (org.apache.sysml.udf.ExternalFunctionInvocationInstruction)35 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)33 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)33 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)33 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)33 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)32 SPInstruction (org.apache.sysml.runtime.instructions.spark.SPInstruction)32 MRInstruction (org.apache.sysml.runtime.instructions.mr.MRInstruction)30 GPUInstruction (org.apache.sysml.runtime.instructions.gpu.GPUInstruction)28 SpoofCPInstruction (org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction)26 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)24 Lop (org.apache.sysml.lops.Lop)23 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)19