Search in sources :

Example 1 with UpdateType

use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType in project incubator-systemml by apache.

the class WhileProgramBlock method execute.

public void execute(ExecutionContext ec) throws DMLRuntimeException {
    //execute while loop
    try {
        // prepare update in-place variables
        UpdateType[] flags = prepareUpdateInPlaceVariables(ec, _tid);
        //run loop body until predicate becomes false
        while (executePredicate(ec).getBooleanValue()) {
            //execute all child blocks
            for (int i = 0; i < _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 while program block", e);
    }
    //execute exit instructions
    try {
        executeInstructions(_exitInstructions, ec);
    } catch (Exception e) {
        throw new DMLRuntimeException(printBlockErrorLocation() + "Error executing while exit instructions.", e);
    }
}
Also used : 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 2 with UpdateType

use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType in project incubator-systemml by apache.

the class ForProgramBlock method execute.

@Override
public void execute(ExecutionContext ec) throws DMLRuntimeException {
    // add the iterable predicate variable to the variable set
    String iterVarName = _iterablePredicateVars[0];
    // 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()) && _iterablePredicateVars[3] == null ? new IntObject((from.getLongValue() <= to.getLongValue()) ? 1 : -1) : executePredicateInstructions(3, _incrementInstructions, ec);
    if (//would produce infinite loop
    incr.getLongValue() == 0)
        throw new DMLRuntimeException(this.printBlockErrorLocation() + "Expression for increment of variable '" + iterVarName + "' 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(iterVarName, from, to, incr);
        for (IntObject iterVar : seqIter) {
            //set iteration variable
            ec.setVariable(iterVarName, 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 3 with UpdateType

use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType in project incubator-systemml by apache.

the class RewriteSplitDagUnknownCSVRead method rewriteStatementBlock.

@Override
public ArrayList<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus state) throws HopsException {
    ArrayList<StatementBlock> ret = new ArrayList<StatementBlock>();
    //collect all unknown csv reads hops
    ArrayList<Hop> cand = new ArrayList<Hop>();
    collectCSVReadHopsUnknownSize(sb.get_hops(), cand);
    //split hop dag on demand
    if (!cand.isEmpty()) {
        try {
            //duplicate sb incl live variable sets
            StatementBlock sb1 = new StatementBlock();
            sb1.setDMLProg(sb.getDMLProg());
            sb1.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
            sb1.setLiveIn(new VariableSet());
            sb1.setLiveOut(new VariableSet());
            //move csv reads incl reblock to new statement block
            //(and replace original persistent read with transient read)
            ArrayList<Hop> sb1hops = new ArrayList<Hop>();
            for (Hop c : cand) {
                Hop reblock = c;
                long rlen = reblock.getDim1();
                long clen = reblock.getDim2();
                long nnz = reblock.getNnz();
                UpdateType update = c.getUpdateType();
                long brlen = reblock.getRowsInBlock();
                long bclen = reblock.getColsInBlock();
                //create new transient read
                DataOp tread = new DataOp(reblock.getName(), reblock.getDataType(), reblock.getValueType(), DataOpTypes.TRANSIENTREAD, null, rlen, clen, nnz, update, brlen, bclen);
                HopRewriteUtils.copyLineNumbers(reblock, tread);
                //replace reblock with transient read
                ArrayList<Hop> parents = new ArrayList<Hop>(reblock.getParent());
                for (int i = 0; i < parents.size(); i++) {
                    Hop parent = parents.get(i);
                    HopRewriteUtils.replaceChildReference(parent, reblock, tread);
                }
                //add reblock sub dag to first statement block
                DataOp twrite = new DataOp(reblock.getName(), reblock.getDataType(), reblock.getValueType(), reblock, DataOpTypes.TRANSIENTWRITE, null);
                twrite.setOutputParams(rlen, clen, nnz, update, brlen, bclen);
                HopRewriteUtils.copyLineNumbers(reblock, twrite);
                sb1hops.add(twrite);
                //update live in and out of new statement block (for piggybacking)
                DataIdentifier diVar = sb.variablesRead().getVariable(reblock.getName());
                if (diVar != null) {
                    //var read should always exist because persistent read
                    sb1.liveOut().addVariable(reblock.getName(), new DataIdentifier(diVar));
                    sb.liveIn().addVariable(reblock.getName(), new DataIdentifier(diVar));
                }
            }
            sb1.set_hops(sb1hops);
            sb1.updateRecompilationFlag();
            //statement block with csv reblocks
            ret.add(sb1);
            //statement block with remaining hops
            ret.add(sb);
        } catch (Exception ex) {
            throw new HopsException("Failed to split hops dag for csv read with unknown size.", ex);
        }
        LOG.debug("Applied splitDagUnknownCSVRead.");
    } else //keep original hop dag
    {
        ret.add(sb);
    }
    return ret;
}
Also used : DataIdentifier(org.apache.sysml.parser.DataIdentifier) ArrayList(java.util.ArrayList) Hop(org.apache.sysml.hops.Hop) HopsException(org.apache.sysml.hops.HopsException) UpdateType(org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType) HopsException(org.apache.sysml.hops.HopsException) VariableSet(org.apache.sysml.parser.VariableSet) DataOp(org.apache.sysml.hops.DataOp) StatementBlock(org.apache.sysml.parser.StatementBlock)

Example 4 with UpdateType

use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType in project incubator-systemml by apache.

the class MatrixIndexingCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    String opcode = getOpcode();
    IndexRange ixrange = getIndexRange(ec);
    //get original matrix
    MatrixObject mo = ec.getMatrixObject(input1.getName());
    //right indexing
    if (opcode.equalsIgnoreCase("rangeReIndex")) {
        MatrixBlock resultBlock = null;
        if (//via data partitioning
        mo.isPartitioned())
            resultBlock = mo.readMatrixPartition(ixrange.add(1));
        else //via slicing the in-memory matrix
        {
            //execute right indexing operation
            MatrixBlock matBlock = ec.getMatrixInput(input1.getName());
            resultBlock = matBlock.sliceOperations(ixrange, new MatrixBlock());
            //unpin rhs input
            ec.releaseMatrixInput(input1.getName());
            //ensure correct sparse/dense output representation
            //(memory guarded by release of input)
            resultBlock.examSparsity();
        }
        //unpin output
        ec.setMatrixOutput(output.getName(), resultBlock);
    } else //left indexing
    if (opcode.equalsIgnoreCase("leftIndex")) {
        UpdateType updateType = mo.getUpdateType();
        if (DMLScript.STATISTICS) {
            if (updateType.isInPlace())
                Statistics.incrementTotalLixUIP();
            Statistics.incrementTotalLix();
        }
        MatrixBlock matBlock = ec.getMatrixInput(input1.getName());
        MatrixBlock resultBlock = null;
        if (//MATRIX<-MATRIX
        input2.getDataType() == DataType.MATRIX) {
            MatrixBlock rhsMatBlock = ec.getMatrixInput(input2.getName());
            resultBlock = matBlock.leftIndexingOperations(rhsMatBlock, ixrange, new MatrixBlock(), updateType);
            ec.releaseMatrixInput(input2.getName());
        } else //MATRIX<-SCALAR 
        {
            if (!ixrange.isScalar())
                throw new DMLRuntimeException("Invalid index range of scalar leftindexing: " + ixrange.toString() + ".");
            ScalarObject scalar = ec.getScalarInput(input2.getName(), ValueType.DOUBLE, input2.isLiteral());
            resultBlock = (MatrixBlock) matBlock.leftIndexingOperations(scalar, (int) ixrange.rowStart, (int) ixrange.colStart, new MatrixBlock(), updateType);
        }
        //unpin lhs input
        ec.releaseMatrixInput(input1.getName());
        //ensure correct sparse/dense output representation
        //(memory guarded by release of input)
        resultBlock.examSparsity();
        //unpin output
        ec.setMatrixOutput(output.getName(), resultBlock, updateType);
    } else
        throw new DMLRuntimeException("Invalid opcode (" + opcode + ") encountered in MatrixIndexingCPInstruction.");
}
Also used : IndexRange(org.apache.sysml.runtime.util.IndexRange) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) UpdateType(org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 5 with UpdateType

use of org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType in project incubator-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
	 * @throws DMLRuntimeException if DMLRuntimeException occurs
	 */
public static Object[] parseDataObject(String in) throws DMLRuntimeException {
    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:
                        long value1 = Long.parseLong(valString);
                        dat = new IntObject(name, value1);
                        break;
                    case DOUBLE:
                        double value2 = Double.parseDouble(valString);
                        dat = new DoubleObject(name, value2);
                        break;
                    case BOOLEAN:
                        boolean value3 = Boolean.parseBoolean(valString);
                        dat = new BooleanObject(name, value3);
                        break;
                    case STRING:
                        dat = new StringObject(name, 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);
                MatrixFormatMetaData md = new MatrixFormatMetaData(mc, oin, iin);
                mo.setMetaData(md);
                mo.setVarName(name);
                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 : 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) MatrixFormatMetaData(org.apache.sysml.runtime.matrix.MatrixFormatMetaData) 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) MatrixFormatMetaData(org.apache.sysml.runtime.matrix.MatrixFormatMetaData) 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)

Aggregations

UpdateType (org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType)8 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)5 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)3 ArrayList (java.util.ArrayList)2 DataOp (org.apache.sysml.hops.DataOp)2 Hop (org.apache.sysml.hops.Hop)2 HopsException (org.apache.sysml.hops.HopsException)2 DataIdentifier (org.apache.sysml.parser.DataIdentifier)2 DataType (org.apache.sysml.parser.Expression.DataType)2 ValueType (org.apache.sysml.parser.Expression.ValueType)2 StatementBlock (org.apache.sysml.parser.StatementBlock)2 VariableSet (org.apache.sysml.parser.VariableSet)2 DMLScriptException (org.apache.sysml.runtime.DMLScriptException)2 IntObject (org.apache.sysml.runtime.instructions.cp.IntObject)2 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)2 MatrixFormatMetaData (org.apache.sysml.runtime.matrix.MatrixFormatMetaData)2 InputInfo (org.apache.sysml.runtime.matrix.data.InputInfo)2 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)2 OutputInfo (org.apache.sysml.runtime.matrix.data.OutputInfo)2 HashSet (java.util.HashSet)1