use of org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator in project incubator-systemml by apache.
the class MatrixBlock method min.
/**
* Wrapper method for reduceall-min of a matrix.
*
* @return ?
*/
public double min() {
// construct operator
AggregateOperator aop = new AggregateOperator(Double.POSITIVE_INFINITY, Builtin.getBuiltinFnObject("min"));
AggregateUnaryOperator auop = new AggregateUnaryOperator(aop, ReduceAll.getReduceAllFnObject());
// execute operation
MatrixBlock out = new MatrixBlock(1, 1, false);
LibMatrixAgg.aggregateUnaryMatrix(this, out, auop);
return out.quickGetValue(0, 0);
}
use of org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator in project incubator-systemml by apache.
the class BasicUnaryAggregateTest method runUnaryAggregateTest.
private static void runUnaryAggregateTest(SparsityType sptype, ValueType vtype, AggType aggtype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols1, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
// uc group
mb = mb.append(MatrixBlock.seqOperations(0.1, rows - 0.1, 1), new MatrixBlock());
// prepare unary aggregate operator
AggregateUnaryOperator auop = null;
switch(aggtype) {
case SUM:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uak+");
break;
case ROWSUMS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uark+");
break;
case COLSUMS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uack+");
break;
case SUMSQ:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uasqk+");
break;
case ROWSUMSSQ:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarsqk+");
break;
case COLSUMSSQ:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacsqk+");
break;
case MAX:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uamax");
break;
case ROWMAXS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarmax");
break;
case COLMAXS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacmax");
break;
case MIN:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uamin");
break;
case ROWMINS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarmin");
break;
case COLMINS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacmin");
break;
}
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// matrix-vector uncompressed
MatrixBlock ret1 = (MatrixBlock) mb.aggregateUnaryOperations(auop, new MatrixBlock(), 1000, 1000, null, true);
// matrix-vector compressed
MatrixBlock ret2 = (MatrixBlock) cmb.aggregateUnaryOperations(auop, new MatrixBlock(), 1000, 1000, null, true);
// compare result with input
double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
int dim1 = (aggtype == AggType.ROWSUMS || aggtype == AggType.ROWSUMSSQ || aggtype == AggType.ROWMINS || aggtype == AggType.ROWMINS) ? rows : 1;
int dim2 = (aggtype == AggType.COLSUMS || aggtype == AggType.COLSUMSSQ || aggtype == AggType.COLMAXS || aggtype == AggType.COLMINS) ? cols1 : 1;
TestUtils.compareMatrices(d1, d2, dim1, dim2, 0.00000000001);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
use of org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator in project incubator-systemml by apache.
the class LargeParUnaryAggregateTest method runUnaryAggregateTest.
private static void runUnaryAggregateTest(SparsityType sptype, ValueType vtype, AggType aggtype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
// uc group
mb = mb.append(MatrixBlock.seqOperations(0.1, rows - 0.1, 1), new MatrixBlock());
// prepare unary aggregate operator
AggregateUnaryOperator auop = null;
int k = InfrastructureAnalyzer.getLocalParallelism();
switch(aggtype) {
case SUM:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uak+", k);
break;
case ROWSUMS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uark+", k);
break;
case COLSUMS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uack+", k);
break;
case SUMSQ:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uasqk+", k);
break;
case ROWSUMSSQ:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarsqk+", k);
break;
case COLSUMSSQ:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacsqk+", k);
break;
case MAX:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uamax", k);
break;
case ROWMAXS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarmax", k);
break;
case COLMAXS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacmax", k);
break;
case MIN:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uamin", k);
break;
case ROWMINS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarmin", k);
break;
case COLMINS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacmin", k);
break;
}
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// matrix-vector uncompressed
MatrixBlock ret1 = (MatrixBlock) mb.aggregateUnaryOperations(auop, new MatrixBlock(), 1000, 1000, null, true);
// matrix-vector compressed
MatrixBlock ret2 = (MatrixBlock) cmb.aggregateUnaryOperations(auop, new MatrixBlock(), 1000, 1000, null, true);
// compare result with input
double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
int dim1 = (aggtype == AggType.ROWSUMS || aggtype == AggType.ROWSUMSSQ || aggtype == AggType.ROWMINS || aggtype == AggType.ROWMINS) ? rows : 1;
int dim2 = (aggtype == AggType.COLSUMS || aggtype == AggType.COLSUMSSQ || aggtype == AggType.COLMAXS || aggtype == AggType.COLMINS) ? cols + 1 : 1;
TestUtils.compareMatrices(d1, d2, dim1, dim2, 0.000000001);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
use of org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator in project incubator-systemml by apache.
the class ParUnaryAggregateTest method runUnaryAggregateTest.
private static void runUnaryAggregateTest(SparsityType sptype, ValueType vtype, AggType aggtype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols1, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
// uc group
mb = mb.append(MatrixBlock.seqOperations(0.1, rows - 0.1, 1), new MatrixBlock());
// prepare unary aggregate operator
AggregateUnaryOperator auop = null;
int k = InfrastructureAnalyzer.getLocalParallelism();
switch(aggtype) {
case SUM:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uak+", k);
break;
case ROWSUMS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uark+", k);
break;
case COLSUMS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uack+", k);
break;
case SUMSQ:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uasqk+", k);
break;
case ROWSUMSSQ:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarsqk+", k);
break;
case COLSUMSSQ:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacsqk+", k);
break;
case MAX:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uamax", k);
break;
case ROWMAXS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarmax", k);
break;
case COLMAXS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacmax", k);
break;
case MIN:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uamin", k);
break;
case ROWMINS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarmin", k);
break;
case COLMINS:
auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacmin", k);
break;
}
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// matrix-vector uncompressed
MatrixBlock ret1 = (MatrixBlock) mb.aggregateUnaryOperations(auop, new MatrixBlock(), 1000, 1000, null, true);
// matrix-vector compressed
MatrixBlock ret2 = (MatrixBlock) cmb.aggregateUnaryOperations(auop, new MatrixBlock(), 1000, 1000, null, true);
// compare result with input
double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
int dim1 = (aggtype == AggType.ROWSUMS || aggtype == AggType.ROWSUMSSQ || aggtype == AggType.ROWMINS || aggtype == AggType.ROWMINS) ? rows : 1;
int dim2 = (aggtype == AggType.COLSUMS || aggtype == AggType.COLSUMSSQ || aggtype == AggType.COLMAXS || aggtype == AggType.COLMINS) ? cols1 : 1;
TestUtils.compareMatrices(d1, d2, dim1, dim2, 0.00000000001);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
use of org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator in project incubator-systemml by apache.
the class AggregateUnaryGPUInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) {
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(0), 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());
}
}
Aggregations