Search in sources :

Example 6 with ReduceRow

use of org.apache.sysml.runtime.functionobjects.ReduceRow in project incubator-systemml by apache.

the class AggregateUnaryGPUInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    GPUStatistics.incrementNoOfExecutedGPUInst();
    String opcode = getOpcode();
    // nrow, ncol & length should either read or refresh metadata
    if (opcode.equalsIgnoreCase("nrow") || opcode.equalsIgnoreCase("ncol") || opcode.equalsIgnoreCase("length")) {
        throw new DMLRuntimeException("nrow, ncol & length should not be compiled as GPU instructions!");
    }
    //get inputs
    MatrixObject in1 = getMatrixInputForGPUInstruction(ec, _input1.getName());
    int rlen = (int) in1.getNumRows();
    int clen = (int) in1.getNumColumns();
    IndexFunction indexFunction = ((AggregateUnaryOperator) _optr).indexFn;
    if (indexFunction instanceof ReduceRow) {
        // COL{SUM, MAX...}
        ec.setMetaData(_output.getName(), 1, clen);
    } else if (indexFunction instanceof ReduceCol) {
        // ROW{SUM, MAX,...}
        ec.setMetaData(_output.getName(), rlen, 1);
    }
    LibMatrixCUDA.unaryAggregate(ec, ec.getGPUContext(), getExtendedOpcode(), in1, _output.getName(), (AggregateUnaryOperator) _optr);
    //release inputs/outputs
    ec.releaseMatrixInputForGPUInstruction(_input1.getName());
    // and set in the execution context by invoking the setScalarOutput
    if (indexFunction instanceof ReduceRow || indexFunction instanceof ReduceCol) {
        ec.releaseMatrixOutputForGPUInstruction(_output.getName());
    }
}
Also used : ReduceCol(org.apache.sysml.runtime.functionobjects.ReduceCol) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) IndexFunction(org.apache.sysml.runtime.functionobjects.IndexFunction) AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) ReduceRow(org.apache.sysml.runtime.functionobjects.ReduceRow) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 7 with ReduceRow

use of org.apache.sysml.runtime.functionobjects.ReduceRow in project incubator-systemml by apache.

the class LibMatrixAgg method getAggType.

private static AggType getAggType(AggregateUnaryOperator op) {
    ValueFunction vfn = op.aggOp.increOp.fn;
    IndexFunction ifn = op.indexFn;
    //(kahan) sum / sum squared / trace (for ReduceDiag)
    if (vfn instanceof KahanFunction && (op.aggOp.correctionLocation == CorrectionLocationType.LASTCOLUMN || op.aggOp.correctionLocation == CorrectionLocationType.LASTROW) && (ifn instanceof ReduceAll || ifn instanceof ReduceCol || ifn instanceof ReduceRow || ifn instanceof ReduceDiag)) {
        if (vfn instanceof KahanPlus)
            return AggType.KAHAN_SUM;
        else if (vfn instanceof KahanPlusSq)
            return AggType.KAHAN_SUM_SQ;
    }
    //mean
    if (vfn instanceof Mean && (op.aggOp.correctionLocation == CorrectionLocationType.LASTTWOCOLUMNS || op.aggOp.correctionLocation == CorrectionLocationType.LASTTWOROWS) && (ifn instanceof ReduceAll || ifn instanceof ReduceCol || ifn instanceof ReduceRow)) {
        return AggType.MEAN;
    }
    //variance
    if (vfn instanceof CM && ((CM) vfn).getAggOpType() == AggregateOperationTypes.VARIANCE && (op.aggOp.correctionLocation == CorrectionLocationType.LASTFOURCOLUMNS || op.aggOp.correctionLocation == CorrectionLocationType.LASTFOURROWS) && (ifn instanceof ReduceAll || ifn instanceof ReduceCol || ifn instanceof ReduceRow)) {
        return AggType.VAR;
    }
    //prod
    if (vfn instanceof Multiply && ifn instanceof ReduceAll) {
        return AggType.PROD;
    }
    //min / max
    if (vfn instanceof Builtin && (ifn instanceof ReduceAll || ifn instanceof ReduceCol || ifn instanceof ReduceRow)) {
        BuiltinCode bfcode = ((Builtin) vfn).bFunc;
        switch(bfcode) {
            case MAX:
                return AggType.MAX;
            case MIN:
                return AggType.MIN;
            case MAXINDEX:
                return AggType.MAX_INDEX;
            case MININDEX:
                return AggType.MIN_INDEX;
            //do nothing
            default:
        }
    }
    return AggType.INVALID;
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) ReduceCol(org.apache.sysml.runtime.functionobjects.ReduceCol) ReduceAll(org.apache.sysml.runtime.functionobjects.ReduceAll) Mean(org.apache.sysml.runtime.functionobjects.Mean) ReduceDiag(org.apache.sysml.runtime.functionobjects.ReduceDiag) CM(org.apache.sysml.runtime.functionobjects.CM) ReduceRow(org.apache.sysml.runtime.functionobjects.ReduceRow) IndexFunction(org.apache.sysml.runtime.functionobjects.IndexFunction) BuiltinCode(org.apache.sysml.runtime.functionobjects.Builtin.BuiltinCode) KahanFunction(org.apache.sysml.runtime.functionobjects.KahanFunction) Multiply(org.apache.sysml.runtime.functionobjects.Multiply) KahanPlus(org.apache.sysml.runtime.functionobjects.KahanPlus) KahanPlusSq(org.apache.sysml.runtime.functionobjects.KahanPlusSq) Builtin(org.apache.sysml.runtime.functionobjects.Builtin)

Example 8 with ReduceRow

use of org.apache.sysml.runtime.functionobjects.ReduceRow in project incubator-systemml by apache.

the class MatrixBlock method uaggouterchainOperations.

public MatrixBlock uaggouterchainOperations(MatrixBlock mbLeft, MatrixBlock mbRight, MatrixBlock mbOut, BinaryOperator bOp, AggregateUnaryOperator uaggOp) throws DMLRuntimeException {
    double[] bv = DataConverter.convertToDoubleVector(mbRight);
    int[] bvi = null;
    //process instruction
    if (LibMatrixOuterAgg.isSupportedUaggOp(uaggOp, bOp)) {
        if ((LibMatrixOuterAgg.isRowIndexMax(uaggOp)) || (LibMatrixOuterAgg.isRowIndexMin(uaggOp))) {
            bvi = LibMatrixOuterAgg.prepareRowIndices(bv.length, bv, bOp, uaggOp);
        } else {
            Arrays.sort(bv);
        }
        int iRows = (uaggOp.indexFn instanceof ReduceCol ? mbLeft.getNumRows() : 2);
        int iCols = (uaggOp.indexFn instanceof ReduceRow ? mbLeft.getNumColumns() : 2);
        if (mbOut == null)
            // Output matrix will be dense matrix most of the time.
            mbOut = new MatrixBlock(iRows, iCols, false);
        else
            mbOut.reset(iRows, iCols, false);
        LibMatrixOuterAgg.aggregateMatrix(mbLeft, mbOut, bv, bvi, bOp, uaggOp);
    } else
        throw new DMLRuntimeException("Unsupported operator for unary aggregate operations.");
    return mbOut;
}
Also used : ReduceCol(org.apache.sysml.runtime.functionobjects.ReduceCol) ReduceRow(org.apache.sysml.runtime.functionobjects.ReduceRow) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 9 with ReduceRow

use of org.apache.sysml.runtime.functionobjects.ReduceRow in project incubator-systemml by apache.

the class MatrixBlock method aggregateTernaryOperations.

public MatrixBlock aggregateTernaryOperations(MatrixBlock m1, MatrixBlock m2, MatrixBlock m3, MatrixBlock ret, AggregateTernaryOperator op, boolean inCP) throws DMLRuntimeException {
    //check input dimensions and operators
    if (m1.rlen != m2.rlen || m1.clen != m2.clen || (m3 != null && (m2.rlen != m3.rlen || m2.clen != m3.clen)))
        throw new DMLRuntimeException("Invalid dimensions for aggregate tertiary (" + m1.rlen + "x" + m1.clen + ", " + m2.rlen + "x" + m2.clen + ", " + m3.rlen + "x" + m3.clen + ").");
    if (!(op.aggOp.increOp.fn instanceof KahanPlus && op.binaryFn instanceof Multiply))
        throw new DMLRuntimeException("Unsupported operator for aggregate tertiary operations.");
    //create output matrix block w/ corrections
    int rl = (op.indexFn instanceof ReduceRow) ? 2 : 1;
    int cl = (op.indexFn instanceof ReduceRow) ? m1.clen : 2;
    if (ret == null)
        ret = new MatrixBlock(rl, cl, false);
    else
        ret.reset(rl, cl, false);
    //execute ternary aggregate function
    if (op.getNumThreads() > 1)
        ret = LibMatrixAgg.aggregateTernary(m1, m2, m3, ret, op, op.getNumThreads());
    else
        ret = LibMatrixAgg.aggregateTernary(m1, m2, m3, ret, op);
    if (op.aggOp.correctionExists && inCP)
        ret.dropLastRowsOrColums(op.aggOp.correctionLocation);
    return ret;
}
Also used : Multiply(org.apache.sysml.runtime.functionobjects.Multiply) KahanPlus(org.apache.sysml.runtime.functionobjects.KahanPlus) ReduceRow(org.apache.sysml.runtime.functionobjects.ReduceRow) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

ReduceRow (org.apache.sysml.runtime.functionobjects.ReduceRow)9 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)8 ReduceCol (org.apache.sysml.runtime.functionobjects.ReduceCol)8 ReduceAll (org.apache.sysml.runtime.functionobjects.ReduceAll)6 KahanPlus (org.apache.sysml.runtime.functionobjects.KahanPlus)5 Builtin (org.apache.sysml.runtime.functionobjects.Builtin)4 CM (org.apache.sysml.runtime.functionobjects.CM)4 KahanPlusSq (org.apache.sysml.runtime.functionobjects.KahanPlusSq)4 Mean (org.apache.sysml.runtime.functionobjects.Mean)4 ReduceDiag (org.apache.sysml.runtime.functionobjects.ReduceDiag)4 IndexFunction (org.apache.sysml.runtime.functionobjects.IndexFunction)3 Multiply (org.apache.sysml.runtime.functionobjects.Multiply)3 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)2 CM_COV_Object (org.apache.sysml.runtime.instructions.cp.CM_COV_Object)2 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)2 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)2 Pointer (jcuda.Pointer)1 BuiltinCode (org.apache.sysml.runtime.functionobjects.Builtin.BuiltinCode)1 KahanFunction (org.apache.sysml.runtime.functionobjects.KahanFunction)1 Plus (org.apache.sysml.runtime.functionobjects.Plus)1