use of org.apache.sysml.runtime.instructions.cp.IntObject in project systemml by apache.
the class TaskPartitionerFixedsize method createTasks.
@Override
public List<Task> createTasks() {
LinkedList<Task> tasks = new LinkedList<>();
// range tasks (similar to run-length encoding) make only sense if taskSize>3
TaskType type = (ParForProgramBlock.USE_RANGE_TASKS_IF_USEFUL && _taskSize > 3) ? TaskType.RANGE : TaskType.SET;
long lFrom = _fromVal.getLongValue();
long lTo = _toVal.getLongValue();
long lIncr = _incrVal.getLongValue();
long lfnp1 = _firstnPlus1;
for (long i = lFrom; i <= lTo; ) {
// create new task and add to list of tasks
Task lTask = new Task(_iterVarName, type);
tasks.addLast(lTask);
// correction for static partitioner
int corr = (lfnp1-- > 0) ? 1 : 0;
// (last task might have less)
if (type == TaskType.SET) {
// value based tasks
for (long j = 0; j < _taskSize + corr && i <= lTo; j++, i += lIncr) lTask.addIteration(new IntObject(i));
} else {
// determine end of task
long to = Math.min(i + (_taskSize - 1 + corr) * lIncr, lTo);
// range based tasks
// from
lTask.addIteration(new IntObject(i));
// to
lTask.addIteration(new IntObject(to));
// increment
lTask.addIteration(new IntObject(lIncr));
i = to + lIncr;
}
}
return tasks;
}
use of org.apache.sysml.runtime.instructions.cp.IntObject in project systemml by apache.
the class ExternalFunctionInvocationInstruction method verifyAndAttachOutputs.
private void verifyAndAttachOutputs(ExecutionContext ec, PackageFunction fun, CPOperand[] outputs) {
for (int i = 0; i < outputs.length; i++) {
CPOperand output = outputs[i];
switch(fun.getFunctionOutput(i).getType()) {
case Matrix:
Matrix m = (Matrix) fun.getFunctionOutput(i);
MatrixObject newVar = createOutputMatrixObject(m);
ec.setVariable(output.getName(), newVar);
break;
case Scalar:
Scalar s = (Scalar) fun.getFunctionOutput(i);
ScalarObject scalarObject = null;
switch(s.getScalarType()) {
case Integer:
scalarObject = new IntObject(Long.parseLong(s.getValue()));
break;
case Double:
scalarObject = new DoubleObject(Double.parseDouble(s.getValue()));
break;
case Boolean:
scalarObject = new BooleanObject(Boolean.parseBoolean(s.getValue()));
break;
case Text:
scalarObject = new StringObject(s.getValue());
break;
default:
throw new DMLRuntimeException("Unknown scalar value type '" + s.getScalarType() + "' of output '" + output.getName() + "'.");
}
ec.setVariable(output.getName(), scalarObject);
break;
default:
throw new DMLRuntimeException("Unsupported data type: " + fun.getFunctionOutput(i).getType().name());
}
}
}
use of org.apache.sysml.runtime.instructions.cp.IntObject in project 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 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;
}
use of org.apache.sysml.runtime.instructions.cp.IntObject in project systemml by apache.
the class ProgramBlock method executePredicateInstructions.
protected ScalarObject executePredicateInstructions(ArrayList<Instruction> inst, ValueType retType, ExecutionContext ec) {
// execute all instructions (indexed access required due to debug mode)
int pos = 0;
for (Instruction currInst : inst) {
ec.updateDebugState(pos++);
executeSingleInstruction(currInst, ec);
}
// get scalar return
ScalarObject ret = (ScalarObject) ec.getScalarInput(PRED_VAR, retType, false);
// check and correct scalar ret type (incl save double to int)
if (ret.getValueType() != retType)
switch(retType) {
case BOOLEAN:
ret = new BooleanObject(ret.getBooleanValue());
break;
case INT:
ret = new IntObject(ret.getLongValue());
break;
case DOUBLE:
ret = new DoubleObject(ret.getDoubleValue());
break;
case STRING:
ret = new StringObject(ret.getStringValue());
break;
default:
}
// remove predicate variable
ec.removeVariable(PRED_VAR);
return ret;
}
Aggregations