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