Search in sources :

Example 6 with IntObject

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

Example 7 with IntObject

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

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

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);
    }
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) DMLScriptException(org.apache.sysml.runtime.DMLScriptException) UpdateType(org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLScriptException(org.apache.sysml.runtime.DMLScriptException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 10 with IntObject

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

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