use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.
the class TaskPartitioner method normalizePredicate.
/**
* Normalizes the (from, to, incr) predicate to a predicate w/
* positive increment.
*/
private void normalizePredicate() {
// check for positive increment
if (_incrVal.getLongValue() >= 0)
return;
long lfrom = _fromVal.getLongValue();
long lto = _toVal.getLongValue();
long lincr = _incrVal.getLongValue();
_fromVal = new IntObject(lfrom - ((lfrom - lto) / lincr * lincr));
_toVal = new IntObject(lfrom);
_incrVal = new IntObject(-1 * lincr);
}
use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.
the class ParWorker method executeRangeTask.
private void executeRangeTask(Task task) {
// monitoring start
Timing time1 = null, time2 = null;
if (_monitor) {
time1 = new Timing(true);
time2 = new Timing(true);
}
// core execution
List<IntObject> tmp = task.getIterations();
String lVarName = task.getVarName();
long lFrom = tmp.get(0).getLongValue();
long lTo = tmp.get(1).getLongValue();
long lIncr = tmp.get(2).getLongValue();
for (long i = lFrom; i <= lTo; i += lIncr) {
// set index values
_ec.setVariable(lVarName, new IntObject(i));
// for each program block
for (ProgramBlock pb : _childBlocks) pb.execute(_ec);
_numIters++;
if (_monitor)
StatisticMonitor.putPWStat(_workerID, Stat.PARWRK_ITER_T, time1.stop());
}
_numTasks++;
// monitoring end
if (_monitor) {
StatisticMonitor.putPWStat(_workerID, Stat.PARWRK_TASKSIZE, task.size());
StatisticMonitor.putPWStat(_workerID, Stat.PARWRK_TASK_T, time2.stop());
}
}
use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.
the class ParWorker method executeSetTask.
private void executeSetTask(Task task) {
// monitoring start
Timing time1 = null, time2 = null;
if (_monitor) {
time1 = new Timing(true);
time2 = new Timing(true);
}
// core execution
// foreach iteration in task, execute iteration body
String lVarName = task.getVarName();
for (IntObject indexVal : task.getIterations()) {
// System.out.println(" EXECUTE ITERATION: "+indexVal.getName()+"="+indexVal.getIntValue());
// set index values
_ec.setVariable(lVarName, indexVal);
// for each program block
for (ProgramBlock pb : _childBlocks) pb.execute(_ec);
_numIters++;
if (_monitor)
StatisticMonitor.putPWStat(_workerID, Stat.PARWRK_ITER_T, time1.stop());
}
_numTasks++;
// monitoring end
if (_monitor) {
StatisticMonitor.putPWStat(_workerID, Stat.PARWRK_TASKSIZE, task.size());
StatisticMonitor.putPWStat(_workerID, Stat.PARWRK_TASK_T, time2.stop());
}
}
use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.
the class ForProgramBlock method execute.
@Override
public void execute(ExecutionContext ec) {
// evaluate from, to, incr only once (assumption: known at for entry)
IntObject from = executePredicateInstructions(1, _fromInstructions, ec);
IntObject to = executePredicateInstructions(2, _toInstructions, ec);
IntObject incr = (_incrementInstructions == null || _incrementInstructions.isEmpty()) ? new IntObject((from.getLongValue() <= to.getLongValue()) ? 1 : -1) : executePredicateInstructions(3, _incrementInstructions, ec);
if (// would produce infinite loop
incr.getLongValue() == 0)
throw new DMLRuntimeException(printBlockErrorLocation() + "Expression for increment " + "of variable '" + _iterPredVar + "' must evaluate to a non-zero value.");
// execute for loop
try {
// prepare update in-place variables
UpdateType[] flags = prepareUpdateInPlaceVariables(ec, _tid);
// run for loop body for each instance of predicate sequence
SequenceIterator seqIter = new SequenceIterator(from, to, incr);
for (IntObject iterVar : seqIter) {
// set iteration variable
ec.setVariable(_iterPredVar, iterVar);
// execute all child blocks
for (int i = 0; i < this._childBlocks.size(); i++) {
ec.updateDebugState(i);
_childBlocks.get(i).execute(ec);
}
}
// reset update-in-place variables
resetUpdateInPlaceVariableFlags(ec, flags);
} catch (DMLScriptException e) {
// propagate stop call
throw e;
} catch (Exception e) {
throw new DMLRuntimeException(printBlockErrorLocation() + "Error evaluating for program block", e);
}
// execute exit instructions
try {
executeInstructions(_exitInstructions, ec);
} catch (Exception e) {
throw new DMLRuntimeException(printBlockErrorLocation() + "Error evaluating for exit instructions", e);
}
}
use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.
the class ForProgramBlock method executePredicateInstructions.
protected IntObject executePredicateInstructions(int pos, ArrayList<Instruction> instructions, ExecutionContext ec) {
ScalarObject tmp = null;
IntObject ret = null;
try {
if (_sb != null) {
if (// set program block specific remote memory
DMLScript.isActiveAM())
DMLAppMasterUtils.setupProgramBlockRemoteMaxMemory(this);
ForStatementBlock fsb = (ForStatementBlock) _sb;
Hop predHops = null;
boolean recompile = false;
if (pos == 1) {
predHops = fsb.getFromHops();
recompile = fsb.requiresFromRecompilation();
} else if (pos == 2) {
predHops = fsb.getToHops();
recompile = fsb.requiresToRecompilation();
} else if (pos == 3) {
predHops = fsb.getIncrementHops();
recompile = fsb.requiresIncrementRecompilation();
}
tmp = (IntObject) executePredicate(instructions, predHops, recompile, ValueType.INT, ec);
} else
tmp = (IntObject) executePredicate(instructions, null, false, ValueType.INT, ec);
} catch (Exception ex) {
String predNameStr = null;
if (pos == 1)
predNameStr = "from";
else if (pos == 2)
predNameStr = "to";
else if (pos == 3)
predNameStr = "increment";
throw new DMLRuntimeException(this.printBlockErrorLocation() + "Error evaluating '" + predNameStr + "' predicate", ex);
}
// final check of resulting int object (guaranteed to be non-null, see executePredicate)
if (tmp instanceof IntObject)
ret = (IntObject) tmp;
else
// downcast to int if necessary
ret = new IntObject(tmp.getLongValue());
return ret;
}
Aggregations