use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.
the class ParForProgramBlock method createEmptyUnscopedVariables.
/**
* Create empty matrix objects and scalars for all unscoped vars
* (created within the parfor).
*
* NOTE: parfor gives no guarantees on the values of those objects - hence
* we return -1 for sclars and empty matrix objects.
*
* @param out local variable map
* @param sb statement block
*/
private static void createEmptyUnscopedVariables(LocalVariableMap out, StatementBlock sb) {
VariableSet updated = sb.variablesUpdated();
VariableSet livein = sb.liveIn();
// for all vars IN <updated> AND NOT IN <livein>
for (String var : updated.getVariableNames()) if (!livein.containsVariable(var)) {
// create empty output
DataIdentifier dat = updated.getVariable(var);
DataType datatype = dat.getDataType();
ValueType valuetype = dat.getValueType();
Data dataObj = null;
switch(datatype) {
case SCALAR:
switch(valuetype) {
case BOOLEAN:
dataObj = new BooleanObject(false);
break;
case INT:
dataObj = new IntObject(-1);
break;
case DOUBLE:
dataObj = new DoubleObject(-1d);
break;
case STRING:
dataObj = new StringObject("-1");
break;
default:
throw new DMLRuntimeException("Value type not supported: " + valuetype);
}
break;
case MATRIX:
case FRAME:
// because metadata (e.g., outputinfo) not known at this place.
break;
case UNKNOWN:
break;
default:
throw new DMLRuntimeException("Data type not supported: " + datatype);
}
if (dataObj != null)
out.put(var, dataObj);
}
}
use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-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;
}
use of org.apache.sysml.runtime.instructions.cp.IntObject in project 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 systemml by apache.
the class ProgramConverter method parseDataObject.
/**
* NOTE: MRJobConfiguration cannot be used for the general case because program blocks and
* related symbol tables can be hierarchically structured.
*
* @param in data object as string
* @return array of objects
*/
public static Object[] parseDataObject(String in) {
Object[] ret = new Object[2];
StringTokenizer st = new StringTokenizer(in, DATA_FIELD_DELIM);
String name = st.nextToken();
DataType datatype = DataType.valueOf(st.nextToken());
ValueType valuetype = ValueType.valueOf(st.nextToken());
String valString = st.hasMoreTokens() ? st.nextToken() : "";
Data dat = null;
switch(datatype) {
case SCALAR:
{
switch(valuetype) {
case INT:
dat = new IntObject(Long.parseLong(valString));
break;
case DOUBLE:
dat = new DoubleObject(Double.parseDouble(valString));
break;
case BOOLEAN:
dat = new BooleanObject(Boolean.parseBoolean(valString));
break;
case STRING:
dat = new StringObject(valString);
break;
default:
throw new DMLRuntimeException("Unable to parse valuetype " + valuetype);
}
break;
}
case MATRIX:
{
MatrixObject mo = new MatrixObject(valuetype, valString);
long rows = Long.parseLong(st.nextToken());
long cols = Long.parseLong(st.nextToken());
int brows = Integer.parseInt(st.nextToken());
int bcols = Integer.parseInt(st.nextToken());
long nnz = Long.parseLong(st.nextToken());
InputInfo iin = InputInfo.stringToInputInfo(st.nextToken());
OutputInfo oin = OutputInfo.stringToOutputInfo(st.nextToken());
PartitionFormat partFormat = PartitionFormat.valueOf(st.nextToken());
UpdateType inplace = UpdateType.valueOf(st.nextToken());
MatrixCharacteristics mc = new MatrixCharacteristics(rows, cols, brows, bcols, nnz);
MetaDataFormat md = new MetaDataFormat(mc, oin, iin);
mo.setMetaData(md);
if (partFormat._dpf != PDataPartitionFormat.NONE)
mo.setPartitioned(partFormat._dpf, partFormat._N);
mo.setUpdateType(inplace);
dat = mo;
break;
}
default:
throw new DMLRuntimeException("Unable to parse datatype " + datatype);
}
ret[0] = name;
ret[1] = dat;
return ret;
}
use of org.apache.sysml.runtime.instructions.cp.IntObject in project systemml by apache.
the class RemoteDPParForSparkWorker method call.
@Override
public Iterator<Tuple2<Long, String>> call(Iterator<Tuple2<Long, Iterable<Writable>>> arg0) throws Exception {
ArrayList<Tuple2<Long, String>> ret = new ArrayList<>();
// lazy parworker initialization
configureWorker(TaskContext.get().taskAttemptId());
// process all matrix partitions of this data partition
MatrixBlock partition = null;
while (arg0.hasNext()) {
Tuple2<Long, Iterable<Writable>> larg = arg0.next();
// collect input partition (check via equals because oinfo deserialized instance)
if (_oinfo.equals(OutputInfo.BinaryBlockOutputInfo))
partition = collectBinaryBlock(larg._2(), partition);
else
partition = collectBinaryCellInput(larg._2());
// update in-memory matrix partition
MatrixObject mo = _ec.getMatrixObject(_inputVar);
mo.setInMemoryPartition(partition);
// create tasks for input data
Task lTask = new Task(_iterVar, TaskType.SET);
lTask.addIteration(new IntObject(larg._1()));
// execute program
long numIter = getExecutedIterations();
super.executeTask(lTask);
// maintain accumulators
_aTasks.add(1);
_aIters.add((int) (getExecutedIterations() - numIter));
}
// write output if required (matrix indexed write)
ArrayList<String> tmp = RemoteParForUtils.exportResultVariables(_workerID, _ec.getVariables(), _resultVars);
for (String val : tmp) ret.add(new Tuple2<>(_workerID, val));
return ret.iterator();
}
Aggregations