Search in sources :

Example 1 with SPInstruction

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

the class ProgramConverter method cloneInstruction.

public static Instruction cloneInstruction(Instruction oInst, long pid, boolean plain, boolean cpFunctions) throws DMLRuntimeException {
    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 2 with SPInstruction

use of org.apache.sysml.runtime.instructions.spark.SPInstruction 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(prevLineNum, prevLineNum, -1, -1);
            else
                //minimum instruction line number for this MR job
                currMRInst.setLocation(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(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 3 with SPInstruction

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

the class SPInstructionParser method parseSingleInstruction.

public static SPInstruction parseSingleInstruction(String str) throws DMLRuntimeException {
    if (str == null || str.isEmpty())
        return null;
    SPINSTRUCTION_TYPE cptype = InstructionUtils.getSPType(str);
    if (cptype == null)
        // return null;
        throw new DMLRuntimeException("Invalid SP Instruction Type: " + str);
    SPInstruction spinst = parseSingleInstruction(cptype, str);
    if (spinst == null)
        throw new DMLRuntimeException("Unable to parse instruction: " + str);
    return spinst;
}
Also used : WriteSPInstruction(org.apache.sysml.runtime.instructions.spark.WriteSPInstruction) CheckpointSPInstruction(org.apache.sysml.runtime.instructions.spark.CheckpointSPInstruction) CompressionSPInstruction(org.apache.sysml.runtime.instructions.spark.CompressionSPInstruction) CentralMomentSPInstruction(org.apache.sysml.runtime.instructions.spark.CentralMomentSPInstruction) CpmmSPInstruction(org.apache.sysml.runtime.instructions.spark.CpmmSPInstruction) AggregateTernarySPInstruction(org.apache.sysml.runtime.instructions.spark.AggregateTernarySPInstruction) UaggOuterChainSPInstruction(org.apache.sysml.runtime.instructions.spark.UaggOuterChainSPInstruction) ConvolutionSPInstruction(org.apache.sysml.runtime.instructions.spark.ConvolutionSPInstruction) CovarianceSPInstruction(org.apache.sysml.runtime.instructions.spark.CovarianceSPInstruction) IndexingSPInstruction(org.apache.sysml.runtime.instructions.spark.IndexingSPInstruction) PlusMultSPInstruction(org.apache.sysml.runtime.instructions.spark.PlusMultSPInstruction) Tsmm2SPInstruction(org.apache.sysml.runtime.instructions.spark.Tsmm2SPInstruction) BuiltinBinarySPInstruction(org.apache.sysml.runtime.instructions.spark.BuiltinBinarySPInstruction) RelationalBinarySPInstruction(org.apache.sysml.runtime.instructions.spark.RelationalBinarySPInstruction) BuiltinUnarySPInstruction(org.apache.sysml.runtime.instructions.spark.BuiltinUnarySPInstruction) TernarySPInstruction(org.apache.sysml.runtime.instructions.spark.TernarySPInstruction) PmmSPInstruction(org.apache.sysml.runtime.instructions.spark.PmmSPInstruction) ZipmmSPInstruction(org.apache.sysml.runtime.instructions.spark.ZipmmSPInstruction) MultiReturnParameterizedBuiltinSPInstruction(org.apache.sysml.runtime.instructions.spark.MultiReturnParameterizedBuiltinSPInstruction) ReorgSPInstruction(org.apache.sysml.runtime.instructions.spark.ReorgSPInstruction) RandSPInstruction(org.apache.sysml.runtime.instructions.spark.RandSPInstruction) TsmmSPInstruction(org.apache.sysml.runtime.instructions.spark.TsmmSPInstruction) AppendMSPInstruction(org.apache.sysml.runtime.instructions.spark.AppendMSPInstruction) CumulativeOffsetSPInstruction(org.apache.sysml.runtime.instructions.spark.CumulativeOffsetSPInstruction) QuaternarySPInstruction(org.apache.sysml.runtime.instructions.spark.QuaternarySPInstruction) QuantileSortSPInstruction(org.apache.sysml.runtime.instructions.spark.QuantileSortSPInstruction) AppendGSPInstruction(org.apache.sysml.runtime.instructions.spark.AppendGSPInstruction) RmmSPInstruction(org.apache.sysml.runtime.instructions.spark.RmmSPInstruction) CumulativeAggregateSPInstruction(org.apache.sysml.runtime.instructions.spark.CumulativeAggregateSPInstruction) SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) CastSPInstruction(org.apache.sysml.runtime.instructions.spark.CastSPInstruction) QuantilePickSPInstruction(org.apache.sysml.runtime.instructions.spark.QuantilePickSPInstruction) PMapmmSPInstruction(org.apache.sysml.runtime.instructions.spark.PMapmmSPInstruction) AppendGAlignedSPInstruction(org.apache.sysml.runtime.instructions.spark.AppendGAlignedSPInstruction) BinUaggChainSPInstruction(org.apache.sysml.runtime.instructions.spark.BinUaggChainSPInstruction) MapmmChainSPInstruction(org.apache.sysml.runtime.instructions.spark.MapmmChainSPInstruction) ParameterizedBuiltinSPInstruction(org.apache.sysml.runtime.instructions.spark.ParameterizedBuiltinSPInstruction) MapmmSPInstruction(org.apache.sysml.runtime.instructions.spark.MapmmSPInstruction) MatrixReshapeSPInstruction(org.apache.sysml.runtime.instructions.spark.MatrixReshapeSPInstruction) SpoofSPInstruction(org.apache.sysml.runtime.instructions.spark.SpoofSPInstruction) CSVReblockSPInstruction(org.apache.sysml.runtime.instructions.spark.CSVReblockSPInstruction) ReblockSPInstruction(org.apache.sysml.runtime.instructions.spark.ReblockSPInstruction) AppendRSPInstruction(org.apache.sysml.runtime.instructions.spark.AppendRSPInstruction) ArithmeticBinarySPInstruction(org.apache.sysml.runtime.instructions.spark.ArithmeticBinarySPInstruction) AggregateUnarySPInstruction(org.apache.sysml.runtime.instructions.spark.AggregateUnarySPInstruction) SPINSTRUCTION_TYPE(org.apache.sysml.runtime.instructions.spark.SPInstruction.SPINSTRUCTION_TYPE) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 4 with SPInstruction

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

the class Statistics method getCPHeavyHitterCode.

public static String getCPHeavyHitterCode(Instruction inst) {
    String opcode = null;
    if (inst instanceof MRJobInstruction) {
        MRJobInstruction mrinst = (MRJobInstruction) inst;
        opcode = "MR-Job_" + mrinst.getJobType();
    } else if (inst instanceof SPInstruction) {
        opcode = "SP_" + InstructionUtils.getOpCode(inst.toString());
        if (inst instanceof FunctionCallCPInstruction) {
            FunctionCallCPInstruction extfunct = (FunctionCallCPInstruction) inst;
            opcode = extfunct.getFunctionName();
        }
    } else //CPInstructions
    {
        opcode = InstructionUtils.getOpCode(inst.toString());
        if (inst instanceof FunctionCallCPInstruction) {
            FunctionCallCPInstruction extfunct = (FunctionCallCPInstruction) inst;
            opcode = extfunct.getFunctionName();
        }
    }
    return opcode;
}
Also used : SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)

Example 5 with SPInstruction

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

the class DMLDebuggerProgramInfo method accesBreakpointInstruction.

/**
	 * Access breakpoint instruction at specified line number in set of instructions (if valid)
	 * @param instructions Instructions for current program block
	 * @param lineNumber Location for inserting breakpoint
	 * @param op Breakpoint operation
	 * @param status Current breakpoint status
	 */
private void accesBreakpointInstruction(ArrayList<Instruction> instructions, int lineNumber, int op, BPINSTRUCTION_STATUS status) {
    for (int i = 0; i < instructions.size(); i++) {
        Instruction currInst = instructions.get(i);
        if (op == 0) {
            if (currInst instanceof MRJobInstruction) {
                MRJobInstruction currMRInst = (MRJobInstruction) currInst;
                // Check if current instruction line number correspond to breakpoint line number
                if (currMRInst.findMRInstructions(lineNumber)) {
                    BreakPointInstruction breakpoint = new BreakPointInstruction();
                    breakpoint.setLocation(currInst);
                    breakpoint.setInstID(instID++);
                    breakpoint.setBPInstructionLocation(location);
                    instructions.add(i, breakpoint);
                    DMLBreakpointManager.insertBreakpoint(breakpoint, lineNumber);
                    return;
                }
            } else if (currInst instanceof CPInstruction || currInst instanceof SPInstruction) {
                // Check if current instruction line number correspond to breakpoint line number
                if (currInst.getLineNum() == lineNumber) {
                    BreakPointInstruction breakpoint = new BreakPointInstruction();
                    breakpoint.setLocation(currInst);
                    breakpoint.setInstID(instID++);
                    breakpoint.setBPInstructionLocation(location);
                    instructions.add(i, breakpoint);
                    DMLBreakpointManager.insertBreakpoint(breakpoint, lineNumber);
                    return;
                }
            } else if (currInst instanceof BreakPointInstruction && currInst.getLineNum() == lineNumber) {
                BreakPointInstruction breakpoint = (BreakPointInstruction) currInst;
                breakpoint.setBPInstructionStatus(BPINSTRUCTION_STATUS.ENABLED);
                breakpoint.setBPInstructionLocation(location);
                instructions.set(i, breakpoint);
                DMLBreakpointManager.updateBreakpoint(lineNumber, status);
                return;
            }
        } else {
            // Check if current instruction line number correspond to breakpoint line number
            if (currInst instanceof BreakPointInstruction && currInst.getLineNum() == lineNumber) {
                if (op == 1) {
                    BreakPointInstruction breakpoint = (BreakPointInstruction) currInst;
                    breakpoint.setLocation(currInst);
                    breakpoint.setInstID(currInst.getInstID());
                    breakpoint.setBPInstructionStatus(status);
                    breakpoint.setBPInstructionLocation(location);
                    instructions.set(i, breakpoint);
                    DMLBreakpointManager.updateBreakpoint(lineNumber, status);
                } else {
                    instructions.remove(i);
                    DMLBreakpointManager.removeBreakpoint(lineNumber, status);
                }
                return;
            }
        }
    }
}
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) 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)

Aggregations

SPInstruction (org.apache.sysml.runtime.instructions.spark.SPInstruction)5 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)4 Instruction (org.apache.sysml.runtime.instructions.Instruction)3 CPInstruction (org.apache.sysml.runtime.instructions.cp.CPInstruction)3 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)2 BreakPointInstruction (org.apache.sysml.runtime.instructions.cp.BreakPointInstruction)2 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)2 ArrayList (java.util.ArrayList)1 SpoofCPInstruction (org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction)1 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)1 GPUInstruction (org.apache.sysml.runtime.instructions.gpu.GPUInstruction)1 MRInstruction (org.apache.sysml.runtime.instructions.mr.MRInstruction)1 AggregateTernarySPInstruction (org.apache.sysml.runtime.instructions.spark.AggregateTernarySPInstruction)1 AggregateUnarySPInstruction (org.apache.sysml.runtime.instructions.spark.AggregateUnarySPInstruction)1 AppendGAlignedSPInstruction (org.apache.sysml.runtime.instructions.spark.AppendGAlignedSPInstruction)1 AppendGSPInstruction (org.apache.sysml.runtime.instructions.spark.AppendGSPInstruction)1 AppendMSPInstruction (org.apache.sysml.runtime.instructions.spark.AppendMSPInstruction)1 AppendRSPInstruction (org.apache.sysml.runtime.instructions.spark.AppendRSPInstruction)1 ArithmeticBinarySPInstruction (org.apache.sysml.runtime.instructions.spark.ArithmeticBinarySPInstruction)1 BinUaggChainSPInstruction (org.apache.sysml.runtime.instructions.spark.BinUaggChainSPInstruction)1