Search in sources :

Example 66 with Instruction

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

the class MLContextUtil method deleteRemoveVariableInstructions.

/**
	 * Recursively traverse program block to delete 'remove variable'
	 * instructions.
	 *
	 * @param pb
	 *            Program block
	 */
private static void deleteRemoveVariableInstructions(ProgramBlock pb) {
    if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        for (ProgramBlock pbc : wpb.getChildBlocks()) deleteRemoveVariableInstructions(pbc);
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) pb;
        for (ProgramBlock pbc : ipb.getChildBlocksIfBody()) deleteRemoveVariableInstructions(pbc);
        for (ProgramBlock pbc : ipb.getChildBlocksElseBody()) deleteRemoveVariableInstructions(pbc);
    } else if (pb instanceof ForProgramBlock) {
        ForProgramBlock fpb = (ForProgramBlock) pb;
        for (ProgramBlock pbc : fpb.getChildBlocks()) deleteRemoveVariableInstructions(pbc);
    } else {
        ArrayList<Instruction> instructions = pb.getInstructions();
        deleteRemoveVariableInstructions(instructions);
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) Instruction(org.apache.sysml.runtime.instructions.Instruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)

Example 67 with Instruction

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

the class ProgramBlock method executeSingleInstruction.

private void executeSingleInstruction(Instruction currInst, ExecutionContext ec) throws DMLRuntimeException {
    try {
        // start time measurement for statistics
        long t0 = (DMLScript.STATISTICS || LOG.isTraceEnabled()) ? System.nanoTime() : 0;
        // pre-process instruction (debug state, inst patching, listeners)
        Instruction tmp = currInst.preprocessInstruction(ec);
        // process actual instruction
        tmp.processInstruction(ec);
        // post-process instruction (debug)
        tmp.postprocessInstruction(ec);
        // maintain aggregate statistics
        if (DMLScript.STATISTICS) {
            Statistics.maintainCPHeavyHitters(tmp.getExtendedOpcode(), System.nanoTime() - t0);
        }
        // optional trace information (instruction and runtime)
        if (LOG.isTraceEnabled()) {
            long t1 = System.nanoTime();
            String time = String.format("%.3f", ((double) t1 - t0) / 1000000000);
            LOG.trace("Instruction: " + tmp + " (executed in " + time + "s).");
        }
        // variables in symbol table (for tracking source of wrong representation)
        if (CHECK_MATRIX_SPARSITY) {
            checkSparsity(tmp, ec.getVariables());
        }
    } catch (Exception e) {
        if (!DMLScript.ENABLE_DEBUG_MODE) {
            if (e instanceof DMLScriptException)
                throw (DMLScriptException) e;
            else
                throw new DMLRuntimeException(this.printBlockErrorLocation() + "Error evaluating instruction: " + currInst.toString(), e);
        } else {
            ec.handleDebugException(e);
        }
    }
}
Also used : DMLScriptException(org.apache.sysml.runtime.DMLScriptException) ComputationCPInstruction(org.apache.sysml.runtime.instructions.cp.ComputationCPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLScriptException(org.apache.sysml.runtime.DMLScriptException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

Instruction (org.apache.sysml.runtime.instructions.Instruction)67 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)44 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)34 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)31 CPInstruction (org.apache.sysml.runtime.instructions.cp.CPInstruction)26 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)19 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)19 ExternalFunctionInvocationInstruction (org.apache.sysml.udf.ExternalFunctionInvocationInstruction)19 ArrayList (java.util.ArrayList)18 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)18 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)18 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)17 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)17 SPInstruction (org.apache.sysml.runtime.instructions.spark.SPInstruction)16 MRInstruction (org.apache.sysml.runtime.instructions.mr.MRInstruction)15 GPUInstruction (org.apache.sysml.runtime.instructions.gpu.GPUInstruction)14 Lop (org.apache.sysml.lops.Lop)13 SpoofCPInstruction (org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction)13 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)12 RandInstruction (org.apache.sysml.runtime.instructions.mr.RandInstruction)10