Search in sources :

Example 16 with Instruction

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

the class ProgramConverter method createDeepCopyInstructionSet.

/**
 * Creates a deep copy of an array of instructions and replaces the placeholders of parworker
 * IDs with the concrete IDs of this parfor instance. This is a helper method uses for generating
 * deep copies of program blocks.
 *
 * @param instSet list of instructions
 * @param pid ?
 * @param IDPrefix ?
 * @param prog runtime program
 * @param fnStack ?
 * @param fnCreated ?
 * @param plain ?
 * @param cpFunctions ?
 * @return list of instructions
 */
public static ArrayList<Instruction> createDeepCopyInstructionSet(ArrayList<Instruction> instSet, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean cpFunctions) {
    ArrayList<Instruction> tmp = new ArrayList<>();
    for (Instruction inst : instSet) {
        if (inst instanceof FunctionCallCPInstruction && cpFunctions) {
            FunctionCallCPInstruction finst = (FunctionCallCPInstruction) inst;
            createDeepCopyFunctionProgramBlock(finst.getNamespace(), finst.getFunctionName(), pid, IDPrefix, prog, fnStack, fnCreated, plain);
        }
        tmp.add(cloneInstruction(inst, pid, plain, cpFunctions));
    }
    return tmp;
}
Also used : FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) ArrayList(java.util.ArrayList) 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 17 with Instruction

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

the class ProgramConverter method createDeepCopyWhileProgramBlock.

public static WhileProgramBlock createDeepCopyWhileProgramBlock(WhileProgramBlock wpb, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) {
    ArrayList<Instruction> predinst = createDeepCopyInstructionSet(wpb.getPredicate(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true);
    WhileProgramBlock tmpPB = new WhileProgramBlock(prog, predinst);
    tmpPB.setStatementBlock(createWhileStatementBlockCopy((WhileStatementBlock) wpb.getStatementBlock(), pid, plain, forceDeepCopy));
    tmpPB.setThreadID(pid);
    tmpPB.setExitInstructions2(createDeepCopyInstructionSet(wpb.getExitInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setChildBlocks(rcreateDeepCopyProgramBlocks(wpb.getChildBlocks(), pid, IDPrefix, fnStack, fnCreated, plain, forceDeepCopy));
    return tmpPB;
}
Also used : 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) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock)

Example 18 with Instruction

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

the class ProgramConverter method parseInstructions.

private static ArrayList<Instruction> parseInstructions(String in, int id) {
    ArrayList<Instruction> insts = new ArrayList<>();
    String lin = in.substring(PARFOR_INST_BEGIN.length(), in.length() - PARFOR_INST_END.length());
    StringTokenizer st = new StringTokenizer(lin, ELEMENT_DELIM);
    while (st.hasMoreTokens()) {
        // Note that at this point only CP instructions and External function instruction can occur
        String instStr = st.nextToken();
        try {
            Instruction tmpinst = CPInstructionParser.parseSingleInstruction(instStr);
            tmpinst = saveReplaceThreadID(tmpinst, CP_ROOT_THREAD_ID, CP_CHILD_THREAD + id);
            insts.add(tmpinst);
        } catch (Exception ex) {
            throw new DMLRuntimeException("Failed to parse instruction: " + instStr, ex);
        }
    }
    return insts;
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) 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) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 19 with Instruction

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

the class GPUInstruction method preprocessInstruction.

@Override
public Instruction preprocessInstruction(ExecutionContext ec) {
    // default preprocess behavior (e.g., debug state)
    Instruction tmp = super.preprocessInstruction(ec);
    // instruction patching
    if (tmp.requiresLabelUpdate()) {
        // update labels only if required
        // note: no exchange of updated instruction as labels might change in the general case
        String updInst = RunMRJobs.updateLabels(tmp.toString(), ec.getVariables());
        tmp = GPUInstructionParser.parseSingleInstruction(updInst);
    }
    return tmp;
}
Also used : Instruction(org.apache.sysml.runtime.instructions.Instruction)

Example 20 with Instruction

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

the class OptTreePlanChecker method checkFunctionNames.

private static void checkFunctionNames(Program prog, DMLProgram dprog, Hop root, ArrayList<Instruction> inst, Set<String> fnStack) {
    // reset visit status of dag
    root.resetVisitStatus();
    // get all function op in this dag
    HashMap<String, FunctionOp> fops = new HashMap<>();
    getAllFunctionOps(root, fops);
    for (Instruction linst : inst) if (linst instanceof FunctionCallCPInstruction) {
        FunctionCallCPInstruction flinst = (FunctionCallCPInstruction) linst;
        String fnamespace = flinst.getNamespace();
        String fname = flinst.getFunctionName();
        String key = DMLProgram.constructFunctionKey(fnamespace, fname);
        // check 1: instruction name equal to hop name
        if (!fops.containsKey(key))
            throw new DMLRuntimeException("Function Check: instruction and hop names differ (" + key + ", " + fops.keySet() + ")");
        // check 2: function exists
        if (!prog.getFunctionProgramBlocks().containsKey(key))
            throw new DMLRuntimeException("Function Check: function does not exits (" + key + ")");
        // check 3: recursive program check
        FunctionProgramBlock fpb = prog.getFunctionProgramBlock(fnamespace, fname);
        FunctionStatementBlock fsb = dprog.getFunctionStatementBlock(fnamespace, fname);
        if (!fnStack.contains(key)) {
            fnStack.add(key);
            checkProgramCorrectness(fpb, fsb, fnStack);
            fnStack.remove(key);
        }
    }
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) HashMap(java.util.HashMap) FunctionOp(org.apache.sysml.hops.FunctionOp) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

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