Search in sources :

Example 11 with Instruction

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

the class DMLDebuggerFunctions method printRuntimeInstructions.

/**
 * Print range of program runtime instructions
 * @param DMLInstMap Mapping between source code line number and corresponding runtime instruction(s)
 * @param range Range of lines of DML code to be displayed
 */
public void printRuntimeInstructions(TreeMap<Integer, ArrayList<Instruction>> DMLInstMap, IntRange range) {
    // Display instructions
    for (int lineNumber = range.getMinimumInteger(); lineNumber <= range.getMaximumInteger(); lineNumber++) {
        if (DMLInstMap.get(lineNumber) != null) {
            for (Instruction currInst : DMLInstMap.get(lineNumber)) {
                if (currInst instanceof CPInstruction)
                    System.out.format("\t\t id %4d: %s\n", currInst.getInstID(), prepareInstruction(currInst.toString()));
                else if (currInst instanceof MRJobInstruction) {
                    MRJobInstruction currMRInst = (MRJobInstruction) currInst;
                    System.out.format("\t\t id %4d: %s\n", currInst.getInstID(), prepareInstruction(currMRInst.getMRString(false)));
                } else if (currInst instanceof BreakPointInstruction) {
                    BreakPointInstruction currBPInst = (BreakPointInstruction) currInst;
                    System.out.format("\t\t id %4d: %s\n", currInst.getInstID(), currBPInst.toString());
                }
            }
        }
    }
}
Also used : CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) BreakPointInstruction(org.apache.sysml.runtime.instructions.cp.BreakPointInstruction) BreakPointInstruction(org.apache.sysml.runtime.instructions.cp.BreakPointInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction)

Example 12 with Instruction

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

the class DMLDebuggerProgramInfo method setInstMap.

/**
 * For each instruction, generate map with corresponding DML
 * script line number
 * @param instructions Instructions for current program block
 */
private void setInstMap(ArrayList<Instruction> instructions) {
    for (int i = 0; i < instructions.size(); i++) {
        Instruction currInst = instructions.get(i);
        // set instruction unique identifier
        if (currInst.getInstID() == 0) {
            currInst.setInstID(instID++);
        }
        if (currInst instanceof MRJobInstruction) {
            MRJobInstruction currMRInst = (MRJobInstruction) currInst;
            int min = Integer.MAX_VALUE;
            // iterate of MR job instructions to identify minimum line number
            for (Integer lineNumber : currMRInst.getMRJobInstructionsLineNumbers()) {
                if (lineNumber < min)
                    min = lineNumber;
            }
            // set MR job line number
            if (min == 0 || min == Integer.MAX_VALUE)
                // last seen instruction line number
                currMRInst.setLocation(null, prevLineNum, prevLineNum, -1, -1);
            else
                // minimum instruction line number for this MR job
                currMRInst.setLocation(null, min, min, -1, -1);
            // insert current MR instruction into corresponding source code line
            if (!disassembler.containsKey(currMRInst.getLineNum()))
                disassembler.put(currMRInst.getLineNum(), new ArrayList<Instruction>());
            disassembler.get(currMRInst.getLineNum()).add(currMRInst);
        } else if (currInst instanceof CPInstruction || currInst instanceof SPInstruction) {
            // if CP instruction line number is not set, then approximate to last seen line number
            if (currInst.getLineNum() == 0)
                currInst.setLocation(null, prevLineNum, prevLineNum, -1, -1);
            // insert current CP instruction into corresponding source code line
            if (!disassembler.containsKey(currInst.getLineNum()))
                disassembler.put(currInst.getLineNum(), new ArrayList<Instruction>());
            disassembler.get(currInst.getLineNum()).add(currInst);
        } else if (currInst instanceof BreakPointInstruction) {
            BreakPointInstruction currBPInst = (BreakPointInstruction) currInst;
            // insert current BP instruction into corresponding source code line
            if (!disassembler.containsKey(currBPInst.getLineNum()))
                disassembler.put(currBPInst.getLineNum(), new ArrayList<Instruction>());
            disassembler.get(currInst.getLineNum()).add(currBPInst);
        }
        // save instruction's line number as last seen
        if (currInst.getLineNum() != 0)
            prevLineNum = currInst.getLineNum();
    }
}
Also used : SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) BreakPointInstruction(org.apache.sysml.runtime.instructions.cp.BreakPointInstruction) ArrayList(java.util.ArrayList) SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) BreakPointInstruction(org.apache.sysml.runtime.instructions.cp.BreakPointInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction)

Example 13 with Instruction

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

the class ProgramConverter method rParseGenericProgramBlock.

private static ProgramBlock rParseGenericProgramBlock(String in, Program prog, int id) {
    String lin = in.substring(PARFOR_PB_BEGIN.length(), in.length() - PARFOR_PB_END.length());
    StringTokenizer st = new StringTokenizer(lin, COMPONENTS_DELIM);
    ArrayList<Instruction> inst = parseInstructions(st.nextToken(), id);
    ProgramBlock pb = new ProgramBlock(prog);
    pb.setInstructions(inst);
    return pb;
}
Also used : StringTokenizer(java.util.StringTokenizer) 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 14 with Instruction

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

the class ProgramConverter method rFindSerializationCandidates.

private static void rFindSerializationCandidates(ArrayList<ProgramBlock> pbs, HashSet<String> cand) {
    for (ProgramBlock pb : pbs) {
        if (pb instanceof WhileProgramBlock) {
            WhileProgramBlock wpb = (WhileProgramBlock) pb;
            rFindSerializationCandidates(wpb.getChildBlocks(), cand);
        } else if (pb instanceof ForProgramBlock || pb instanceof ParForProgramBlock) {
            ForProgramBlock fpb = (ForProgramBlock) pb;
            rFindSerializationCandidates(fpb.getChildBlocks(), cand);
        } else if (pb instanceof IfProgramBlock) {
            IfProgramBlock ipb = (IfProgramBlock) pb;
            rFindSerializationCandidates(ipb.getChildBlocksIfBody(), cand);
            if (ipb.getChildBlocksElseBody() != null)
                rFindSerializationCandidates(ipb.getChildBlocksElseBody(), cand);
        } else // all generic program blocks
        {
            for (Instruction inst : pb.getInstructions()) if (inst instanceof FunctionCallCPInstruction) {
                FunctionCallCPInstruction fci = (FunctionCallCPInstruction) inst;
                String fkey = DMLProgram.constructFunctionKey(fci.getNamespace(), fci.getFunctionName());
                if (// memoization for multiple calls, recursion
                !cand.contains(fkey)) {
                    // add to candidates
                    cand.add(fkey);
                    // investigate chains of function calls
                    FunctionProgramBlock fpb = pb.getProgram().getFunctionProgramBlock(fci.getNamespace(), fci.getFunctionName());
                    rFindSerializationCandidates(fpb.getChildBlocks(), cand);
                }
            }
        }
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) 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) 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) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Example 15 with Instruction

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

the class ProgramConverter method createDeepCopyIfProgramBlock.

public static IfProgramBlock createDeepCopyIfProgramBlock(IfProgramBlock ipb, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) {
    ArrayList<Instruction> predinst = createDeepCopyInstructionSet(ipb.getPredicate(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true);
    IfProgramBlock tmpPB = new IfProgramBlock(prog, predinst);
    tmpPB.setStatementBlock(createIfStatementBlockCopy((IfStatementBlock) ipb.getStatementBlock(), pid, plain, forceDeepCopy));
    tmpPB.setThreadID(pid);
    tmpPB.setExitInstructions2(createDeepCopyInstructionSet(ipb.getExitInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setChildBlocksIfBody(rcreateDeepCopyProgramBlocks(ipb.getChildBlocksIfBody(), pid, IDPrefix, fnStack, fnCreated, plain, forceDeepCopy));
    tmpPB.setChildBlocksElseBody(rcreateDeepCopyProgramBlocks(ipb.getChildBlocksElseBody(), pid, IDPrefix, fnStack, fnCreated, plain, forceDeepCopy));
    return tmpPB;
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) 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) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

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