Search in sources :

Example 11 with IntObject

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);
    }
}
Also used : VariableSet(org.apache.sysml.parser.VariableSet) DataIdentifier(org.apache.sysml.parser.DataIdentifier) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) ValueType(org.apache.sysml.parser.Expression.ValueType) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) StringObject(org.apache.sysml.runtime.instructions.cp.StringObject) DataType(org.apache.sysml.parser.Expression.DataType) Data(org.apache.sysml.runtime.instructions.cp.Data) BooleanObject(org.apache.sysml.runtime.instructions.cp.BooleanObject) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 12 with IntObject

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;
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) StringObject(org.apache.sysml.runtime.instructions.cp.StringObject) Instruction(org.apache.sysml.runtime.instructions.Instruction) BooleanObject(org.apache.sysml.runtime.instructions.cp.BooleanObject)

Example 13 with IntObject

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());
    }
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)

Example 14 with IntObject

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;
}
Also used : MetaDataFormat(org.apache.sysml.runtime.matrix.MetaDataFormat) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) ValueType(org.apache.sysml.parser.Expression.ValueType) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) Data(org.apache.sysml.runtime.instructions.cp.Data) PartitionFormat(org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PartitionFormat) PDataPartitionFormat(org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PDataPartitionFormat) UpdateType(org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) OutputInfo(org.apache.sysml.runtime.matrix.data.OutputInfo) StringTokenizer(java.util.StringTokenizer) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) InputInfo(org.apache.sysml.runtime.matrix.data.InputInfo) StringObject(org.apache.sysml.runtime.instructions.cp.StringObject) DataType(org.apache.sysml.parser.Expression.DataType) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) BooleanObject(org.apache.sysml.runtime.instructions.cp.BooleanObject) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) StringObject(org.apache.sysml.runtime.instructions.cp.StringObject) BooleanObject(org.apache.sysml.runtime.instructions.cp.BooleanObject)

Example 15 with IntObject

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();
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) ArrayList(java.util.ArrayList) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) Tuple2(scala.Tuple2)

Aggregations

IntObject (org.apache.sysml.runtime.instructions.cp.IntObject)47 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)19 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)15 BooleanObject (org.apache.sysml.runtime.instructions.cp.BooleanObject)11 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)11 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)11 StringObject (org.apache.sysml.runtime.instructions.cp.StringObject)11 TaskType (org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType)8 Timing (org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)6 Data (org.apache.sysml.runtime.instructions.cp.Data)6 StringTokenizer (java.util.StringTokenizer)5 IOException (java.io.IOException)4 LinkedList (java.util.LinkedList)4 DataType (org.apache.sysml.parser.Expression.DataType)4 ValueType (org.apache.sysml.parser.Expression.ValueType)4 DMLScriptException (org.apache.sysml.runtime.DMLScriptException)4 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)4 UpdateType (org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType)4 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)4 MetaDataFormat (org.apache.sysml.runtime.matrix.MetaDataFormat)4