Search in sources :

Example 41 with IntObject

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;
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) TaskType(org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType) LinkedList(java.util.LinkedList)

Example 42 with IntObject

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

Example 43 with IntObject

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());
    }
}
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 44 with IntObject

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;
}
Also used : ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) Hop(org.apache.sysml.hops.Hop) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLScriptException(org.apache.sysml.runtime.DMLScriptException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 45 with IntObject

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

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