Search in sources :

Example 1 with CPInstruction

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

the class DMLDebuggerFunctions method printInstructions.

/**
 * Print range of DML program lines interspersed with corresponding runtime instructions
 * @param lines DML script lines of code
 * @param DMLInstMap Mapping between source code line number and corresponding runtime instruction(s)
 * @param range Range of lines of DML code to be displayed
 * @param debug Flag for displaying instructions in debugger test integration
 */
public void printInstructions(String[] lines, TreeMap<Integer, ArrayList<Instruction>> DMLInstMap, IntRange range, boolean debug) {
    // Display instructions with corresponding DML line numbers
    for (int lineNumber = range.getMinimumInteger(); lineNumber <= range.getMaximumInteger(); lineNumber++) {
        System.out.format("line %4d: %s\n", lineNumber, lines[lineNumber - 1]);
        if (DMLInstMap.get(lineNumber) != null) {
            for (Instruction currInst : DMLInstMap.get(lineNumber)) {
                if (currInst instanceof CPInstruction) {
                    if (!debug)
                        System.out.format("\t\t id %4d: %s\n", currInst.getInstID(), prepareInstruction(currInst.toString()));
                    else {
                        String[] instStr = prepareInstruction(currInst.toString()).split(" ");
                        System.out.format("\t\t id %4d: %s %s\n", currInst.getInstID(), instStr[0], instStr[1]);
                    }
                } else if (currInst instanceof MRJobInstruction) {
                    MRJobInstruction currMRInst = (MRJobInstruction) currInst;
                    System.out.format("\t\t id %4d: %s\n", currInst.getInstID(), prepareInstruction(currMRInst.getMRString(debug)));
                } 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 2 with CPInstruction

use of org.apache.sysml.runtime.instructions.cp.CPInstruction 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 3 with CPInstruction

use of org.apache.sysml.runtime.instructions.cp.CPInstruction 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 4 with CPInstruction

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

the class ProgramConverter method cloneInstruction.

public static Instruction cloneInstruction(Instruction oInst, long pid, boolean plain, boolean cpFunctions) {
    Instruction inst = null;
    String tmpString = oInst.toString();
    try {
        if (oInst instanceof CPInstruction || oInst instanceof SPInstruction || oInst instanceof MRInstruction || oInst instanceof GPUInstruction) {
            if (oInst instanceof FunctionCallCPInstruction && cpFunctions) {
                FunctionCallCPInstruction tmp = (FunctionCallCPInstruction) oInst;
                if (!plain) {
                    // safe replacement because target variables might include the function name
                    // note: this is no update-in-place in order to keep the original function name as basis
                    tmpString = tmp.updateInstStringFunctionName(tmp.getFunctionName(), tmp.getFunctionName() + CP_CHILD_THREAD + pid);
                }
            // otherwise: preserve function name
            }
            inst = InstructionParser.parseSingleInstruction(tmpString);
        } else if (oInst instanceof MRJobInstruction) {
            // clone via copy constructor
            inst = new MRJobInstruction((MRJobInstruction) oInst);
        } else
            throw new DMLRuntimeException("Failed to clone instruction: " + oInst);
    } catch (Exception ex) {
        throw new DMLRuntimeException(ex);
    }
    // save replacement of thread id references in instructions
    inst = saveReplaceThreadID(inst, ProgramConverter.CP_ROOT_THREAD_ID, ProgramConverter.CP_CHILD_THREAD + pid);
    return inst;
}
Also used : SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) 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) GPUInstruction(org.apache.sysml.runtime.instructions.gpu.GPUInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) MRInstruction(org.apache.sysml.runtime.instructions.mr.MRInstruction) 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 5 with CPInstruction

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

the class CostEstimator method rGetTimeEstimate.

private double rGetTimeEstimate(ProgramBlock pb, HashMap<String, VarStats> stats, HashSet<String> memoFunc, boolean recursive) {
    double ret = 0;
    if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock tmp = (WhileProgramBlock) pb;
        if (recursive)
            for (ProgramBlock pb2 : tmp.getChildBlocks()) ret += rGetTimeEstimate(pb2, stats, memoFunc, recursive);
        ret *= DEFAULT_NUMITER;
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock tmp = (IfProgramBlock) pb;
        if (recursive) {
            for (ProgramBlock pb2 : tmp.getChildBlocksIfBody()) ret += rGetTimeEstimate(pb2, stats, memoFunc, recursive);
            if (tmp.getChildBlocksElseBody() != null)
                for (ProgramBlock pb2 : tmp.getChildBlocksElseBody()) {
                    ret += rGetTimeEstimate(pb2, stats, memoFunc, recursive);
                    // weighted sum
                    ret /= 2;
                }
        }
    } else if (// includes ParFORProgramBlock
    pb instanceof ForProgramBlock) {
        ForProgramBlock tmp = (ForProgramBlock) pb;
        if (recursive)
            for (ProgramBlock pb2 : tmp.getChildBlocks()) ret += rGetTimeEstimate(pb2, stats, memoFunc, recursive);
        ret *= getNumIterations(stats, tmp);
    } else if (pb instanceof FunctionProgramBlock && // see generic
    !(pb instanceof ExternalFunctionProgramBlock)) {
        FunctionProgramBlock tmp = (FunctionProgramBlock) pb;
        if (recursive)
            for (ProgramBlock pb2 : tmp.getChildBlocks()) ret += rGetTimeEstimate(pb2, stats, memoFunc, recursive);
    } else {
        ArrayList<Instruction> tmp = pb.getInstructions();
        for (Instruction inst : tmp) {
            if (// CP
            inst instanceof CPInstruction) {
                // obtain stats from createvar, cpvar, rmvar, rand
                maintainCPInstVariableStatistics((CPInstruction) inst, stats);
                // extract statistics (instruction-specific)
                Object[] o = extractCPInstStatistics(inst, stats);
                VarStats[] vs = (VarStats[]) o[0];
                String[] attr = (String[]) o[1];
                // if(LOG.isDebugEnabled())
                // LOG.debug(inst);
                // call time estimation for inst
                ret += getCPInstTimeEstimate(inst, vs, attr);
                if (// functions
                inst instanceof FunctionCallCPInstruction) {
                    FunctionCallCPInstruction finst = (FunctionCallCPInstruction) inst;
                    String fkey = DMLProgram.constructFunctionKey(finst.getNamespace(), finst.getFunctionName());
                    // awareness of recursive functions, missing program
                    if (!memoFunc.contains(fkey) && pb.getProgram() != null) {
                        if (LOG.isDebugEnabled())
                            LOG.debug("Begin Function " + fkey);
                        memoFunc.add(fkey);
                        Program prog = pb.getProgram();
                        FunctionProgramBlock fpb = prog.getFunctionProgramBlock(finst.getNamespace(), finst.getFunctionName());
                        ret += rGetTimeEstimate(fpb, stats, memoFunc, recursive);
                        memoFunc.remove(fkey);
                        if (LOG.isDebugEnabled())
                            LOG.debug("End Function " + fkey);
                    }
                }
            } else if (// MR
            inst instanceof MRJobInstruction) {
                // obtain stats for job
                maintainMRJobInstVariableStatistics(inst, stats);
                // extract input statistics
                Object[] o = extractMRJobInstStatistics(inst, stats);
                VarStats[] vs = (VarStats[]) o[0];
                if (LOG.isDebugEnabled())
                    LOG.debug("Begin MRJob type=" + ((MRJobInstruction) inst).getJobType());
                // call time estimation for complex MR inst
                ret += getMRJobInstTimeEstimate(inst, vs, null);
                if (LOG.isDebugEnabled())
                    LOG.debug("End MRJob");
                // cleanup stats for job
                cleanupMRJobVariableStatistics(inst, stats);
            }
        }
    }
    return ret;
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) DMLProgram(org.apache.sysml.parser.DMLProgram) Program(org.apache.sysml.runtime.controlprogram.Program) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ArrayList(java.util.ArrayList) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) MultiReturnBuiltinCPInstruction(org.apache.sysml.runtime.instructions.cp.MultiReturnBuiltinCPInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) DataGenCPInstruction(org.apache.sysml.runtime.instructions.cp.DataGenCPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) MMTSJCPInstruction(org.apache.sysml.runtime.instructions.cp.MMTSJCPInstruction) BinaryCPInstruction(org.apache.sysml.runtime.instructions.cp.BinaryCPInstruction) StringInitCPInstruction(org.apache.sysml.runtime.instructions.cp.StringInitCPInstruction) AggregateUnaryCPInstruction(org.apache.sysml.runtime.instructions.cp.AggregateUnaryCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) AggregateTernaryCPInstruction(org.apache.sysml.runtime.instructions.cp.AggregateTernaryCPInstruction) MRInstruction(org.apache.sysml.runtime.instructions.mr.MRInstruction) UnaryCPInstruction(org.apache.sysml.runtime.instructions.cp.UnaryCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) ParameterizedBuiltinCPInstruction(org.apache.sysml.runtime.instructions.cp.ParameterizedBuiltinCPInstruction) MultiReturnBuiltinCPInstruction(org.apache.sysml.runtime.instructions.cp.MultiReturnBuiltinCPInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) DataGenCPInstruction(org.apache.sysml.runtime.instructions.cp.DataGenCPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) MMTSJCPInstruction(org.apache.sysml.runtime.instructions.cp.MMTSJCPInstruction) BinaryCPInstruction(org.apache.sysml.runtime.instructions.cp.BinaryCPInstruction) StringInitCPInstruction(org.apache.sysml.runtime.instructions.cp.StringInitCPInstruction) AggregateUnaryCPInstruction(org.apache.sysml.runtime.instructions.cp.AggregateUnaryCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) AggregateTernaryCPInstruction(org.apache.sysml.runtime.instructions.cp.AggregateTernaryCPInstruction) UnaryCPInstruction(org.apache.sysml.runtime.instructions.cp.UnaryCPInstruction) ParameterizedBuiltinCPInstruction(org.apache.sysml.runtime.instructions.cp.ParameterizedBuiltinCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject)

Aggregations

CPInstruction (org.apache.sysml.runtime.instructions.cp.CPInstruction)24 Instruction (org.apache.sysml.runtime.instructions.Instruction)18 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)18 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)16 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)10 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)10 BreakPointInstruction (org.apache.sysml.runtime.instructions.cp.BreakPointInstruction)8 SPInstruction (org.apache.sysml.runtime.instructions.spark.SPInstruction)8 ArrayList (java.util.ArrayList)6 Data (org.apache.sysml.lops.Data)6 Lop (org.apache.sysml.lops.Lop)6 SpoofCPInstruction (org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction)6 MRInstruction (org.apache.sysml.runtime.instructions.mr.MRInstruction)6 LopsException (org.apache.sysml.lops.LopsException)4 AggregateTernaryCPInstruction (org.apache.sysml.runtime.instructions.cp.AggregateTernaryCPInstruction)4 AggregateUnaryCPInstruction (org.apache.sysml.runtime.instructions.cp.AggregateUnaryCPInstruction)4 BinaryCPInstruction (org.apache.sysml.runtime.instructions.cp.BinaryCPInstruction)4 DataGenCPInstruction (org.apache.sysml.runtime.instructions.cp.DataGenCPInstruction)4 MMTSJCPInstruction (org.apache.sysml.runtime.instructions.cp.MMTSJCPInstruction)4 MultiReturnBuiltinCPInstruction (org.apache.sysml.runtime.instructions.cp.MultiReturnBuiltinCPInstruction)4