Search in sources :

Example 66 with MatrixBlock

use of org.apache.sysml.runtime.matrix.data.MatrixBlock in project incubator-systemml by apache.

the class QuantileSortCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    // acquire inputs matrices
    MatrixBlock matBlock = ec.getMatrixInput(input1.getName(), getExtendedOpcode());
    MatrixBlock wtBlock = null;
    if (input2 != null) {
        wtBlock = ec.getMatrixInput(input2.getName(), getExtendedOpcode());
    }
    // process core instruction
    MatrixBlock resultBlock = (MatrixBlock) matBlock.sortOperations(wtBlock, new MatrixBlock());
    // release inputs
    ec.releaseMatrixInput(input1.getName(), getExtendedOpcode());
    if (input2 != null)
        ec.releaseMatrixInput(input2.getName(), getExtendedOpcode());
    // set and release output
    ec.setMatrixOutput(output.getName(), resultBlock, getExtendedOpcode());
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock)

Example 67 with MatrixBlock

use of org.apache.sysml.runtime.matrix.data.MatrixBlock in project incubator-systemml by apache.

the class QuaternaryCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    QuaternaryOperator qop = (QuaternaryOperator) _optr;
    MatrixBlock matBlock1 = ec.getMatrixInput(input1.getName(), getExtendedOpcode());
    MatrixBlock matBlock2 = ec.getMatrixInput(input2.getName(), getExtendedOpcode());
    MatrixBlock matBlock3 = ec.getMatrixInput(input3.getName(), getExtendedOpcode());
    MatrixBlock matBlock4 = null;
    if (qop.hasFourInputs()) {
        if (input4.getDataType() == DataType.SCALAR) {
            matBlock4 = new MatrixBlock(1, 1, false);
            final double eps = ec.getScalarInput(input4.getName(), input4.getValueType(), input4.isLiteral()).getDoubleValue();
            matBlock4.quickSetValue(0, 0, eps);
        } else {
            matBlock4 = ec.getMatrixInput(input4.getName(), getExtendedOpcode());
        }
    }
    // core execute
    MatrixBlock out = matBlock1.quaternaryOperations(qop, matBlock2, matBlock3, matBlock4, new MatrixBlock(), _numThreads);
    // release inputs and output
    ec.releaseMatrixInput(input1.getName(), getExtendedOpcode());
    ec.releaseMatrixInput(input2.getName(), getExtendedOpcode());
    ec.releaseMatrixInput(input3.getName(), getExtendedOpcode());
    if (qop.wtype1 != null || qop.wtype4 != null) {
        // wsloss/wcemm
        if ((qop.wtype1 != null && qop.wtype1.hasFourInputs()) || (qop.wtype4 != null && qop.wtype4.hasFourInputs()))
            if (input4.getDataType() == DataType.MATRIX) {
                ec.releaseMatrixInput(input4.getName(), getExtendedOpcode());
            }
        ec.setVariable(output.getName(), new DoubleObject(out.quickGetValue(0, 0)));
    } else {
        // wsigmoid / wdivmm / wumm
        if (qop.wtype3 != null && qop.wtype3.hasFourInputs())
            if (input4.getDataType() == DataType.MATRIX) {
                ec.releaseMatrixInput(input4.getName(), getExtendedOpcode());
            }
        ec.setMatrixOutput(output.getName(), out, getExtendedOpcode());
    }
}
Also used : QuaternaryOperator(org.apache.sysml.runtime.matrix.operators.QuaternaryOperator) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock)

Example 68 with MatrixBlock

use of org.apache.sysml.runtime.matrix.data.MatrixBlock in project incubator-systemml by apache.

the class UnaryMatrixCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    String output_name = output.getName();
    String opcode = getOpcode();
    if (LibCommonsMath.isSupportedUnaryOperation(opcode)) {
        MatrixBlock retBlock = LibCommonsMath.unaryOperations(ec.getMatrixObject(input1.getName()), getOpcode());
        ec.setMatrixOutput(output_name, retBlock, getExtendedOpcode());
    } else {
        UnaryOperator u_op = (UnaryOperator) _optr;
        MatrixBlock inBlock = ec.getMatrixInput(input1.getName(), getExtendedOpcode());
        MatrixBlock retBlock = (MatrixBlock) (inBlock.unaryOperations(u_op, new MatrixBlock()));
        ec.releaseMatrixInput(input1.getName(), getExtendedOpcode());
        // Ensure right dense/sparse output representation (guarded by released input memory)
        if (checkGuardedRepresentationChange(inBlock, retBlock))
            retBlock.examSparsity();
        ec.setMatrixOutput(output_name, retBlock, getExtendedOpcode());
    }
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) UnaryOperator(org.apache.sysml.runtime.matrix.operators.UnaryOperator)

Example 69 with MatrixBlock

use of org.apache.sysml.runtime.matrix.data.MatrixBlock in project incubator-systemml by apache.

the class MatrixIndexingCPFileInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    String opcode = getOpcode();
    IndexRange ixrange = getIndexRange(ec).add(1);
    MatrixObject mo = ec.getMatrixObject(input1.getName());
    if (mo.isPartitioned() && opcode.equalsIgnoreCase(RightIndex.OPCODE)) {
        MetaDataFormat meta = (MetaDataFormat) mo.getMetaData();
        MatrixCharacteristics mc = meta.getMatrixCharacteristics();
        String pfname = mo.getPartitionFileName(ixrange, mc.getRowsPerBlock(), mc.getColsPerBlock());
        if (MapReduceTool.existsFileOnHDFS(pfname)) {
            // create output matrix object
            MatrixObject mobj = new MatrixObject(mo.getValueType(), pfname);
            MatrixCharacteristics mcNew = null;
            switch(mo.getPartitionFormat()) {
                case ROW_WISE:
                    mcNew = new MatrixCharacteristics(1, mc.getCols(), mc.getRowsPerBlock(), mc.getColsPerBlock());
                    break;
                case ROW_BLOCK_WISE_N:
                    mcNew = new MatrixCharacteristics(mo.getPartitionSize(), mc.getCols(), mc.getRowsPerBlock(), mc.getColsPerBlock());
                    break;
                case COLUMN_WISE:
                    mcNew = new MatrixCharacteristics(mc.getRows(), 1, mc.getRowsPerBlock(), mc.getColsPerBlock());
                    break;
                case COLUMN_BLOCK_WISE_N:
                    mcNew = new MatrixCharacteristics(mc.getRows(), mo.getPartitionSize(), mc.getRowsPerBlock(), mc.getColsPerBlock());
                    break;
                default:
                    throw new DMLRuntimeException("Unsupported partition format for CP_FILE " + RightIndex.OPCODE + ": " + mo.getPartitionFormat());
            }
            MetaDataFormat metaNew = new MetaDataFormat(mcNew, meta.getOutputInfo(), meta.getInputInfo());
            mobj.setMetaData(metaNew);
            // put output object into symbol table
            ec.setVariable(output.getName(), mobj);
        } else {
            // will return an empty matrix partition
            MatrixBlock resultBlock = mo.readMatrixPartition(ixrange);
            ec.setMatrixOutput(output.getName(), resultBlock, getExtendedOpcode());
        }
    } else {
        throw new DMLRuntimeException("Invalid opcode or index predicate for MatrixIndexingCPFileInstruction: " + instString);
    }
}
Also used : IndexRange(org.apache.sysml.runtime.util.IndexRange) MetaDataFormat(org.apache.sysml.runtime.matrix.MetaDataFormat) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 70 with MatrixBlock

use of org.apache.sysml.runtime.matrix.data.MatrixBlock in project incubator-systemml by apache.

the class OptimizerRuleBased method rewriteRemoveUnnecessaryCompareMatrix.

// /////
// REWRITE remove compare matrix (for result merge, needs to be invoked before setting result merge)
// /
protected void rewriteRemoveUnnecessaryCompareMatrix(OptNode n, ExecutionContext ec) {
    ParForProgramBlock pfpb = (ParForProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(n.getID())[1];
    ArrayList<ResultVar> cleanedVars = new ArrayList<>();
    ArrayList<ResultVar> resultVars = pfpb.getResultVariables();
    String itervar = pfpb.getIterVar();
    for (ResultVar rvar : resultVars) {
        Data dat = ec.getVariable(rvar._name);
        if (// subject to result merge with compare
        dat instanceof MatrixObject && ((MatrixObject) dat).getNnz() != 0 && // guaranteed no conditional indexing
        n.hasOnlySimpleChilds() && // guaranteed full matrix replace
        rContainsResultFullReplace(n, rvar._name, itervar, (MatrixObject) dat) && // && !pfsb.variablesRead().containsVariable(rvar)                  //never read variable in loop body
        !// never read variable in loop body
        rIsReadInRightIndexing(n, rvar._name) && ((MatrixObject) dat).getNumRows() <= Integer.MAX_VALUE && ((MatrixObject) dat).getNumColumns() <= Integer.MAX_VALUE) {
            // replace existing matrix object with empty matrix
            MatrixObject mo = (MatrixObject) dat;
            ec.cleanupCacheableData(mo);
            ec.setMatrixOutput(rvar._name, new MatrixBlock((int) mo.getNumRows(), (int) mo.getNumColumns(), false), null);
            // keep track of cleaned result variables
            cleanedVars.add(rvar);
        }
    }
    _numEvaluatedPlans++;
    LOG.debug(getOptMode() + " OPT: rewrite 'remove unnecessary compare matrix' - result=" + (!cleanedVars.isEmpty()) + " (" + ProgramConverter.serializeResultVariables(cleanedVars) + ")");
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) ResultVar(org.apache.sysml.parser.ParForStatementBlock.ResultVar) ArrayList(java.util.ArrayList) Data(org.apache.sysml.runtime.instructions.cp.Data) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Aggregations

MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)459 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)142 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)111 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)102 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)48 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)48 IOException (java.io.IOException)44 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)41 ArrayList (java.util.ArrayList)40 Path (org.apache.hadoop.fs.Path)29 FrameBlock (org.apache.sysml.runtime.matrix.data.FrameBlock)24 FileSystem (org.apache.hadoop.fs.FileSystem)23 JavaPairRDD (org.apache.spark.api.java.JavaPairRDD)23 JobConf (org.apache.hadoop.mapred.JobConf)21 Tuple2 (scala.Tuple2)19 SequenceFile (org.apache.hadoop.io.SequenceFile)17 Row (org.apache.spark.sql.Row)14 SparseBlock (org.apache.sysml.runtime.matrix.data.SparseBlock)14 TestConfiguration (org.apache.sysml.test.integration.TestConfiguration)14 IndexedMatrixValue (org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)13