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);
}
}
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);
}
}
}
Aggregations