Search in sources :

Example 16 with AggregateBinaryOperator

use of org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator in project incubator-systemml by apache.

the class LargeMatrixMatrixMultTest method runMatrixVectorMultTest.

private static void runMatrixVectorMultTest(MultType mtype, SparsityType sptype, ValueType vtype, 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);
        }
        boolean right = (mtype == MultType.RIGHT);
        MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
        MatrixBlock vect = DataConverter.convertToMatrixBlock(right ? TestUtils.generateTestMatrix(cols, cols2, -1, 1, 1.0, 3) : TestUtils.generateTestMatrix(cols2, rows, -1, 1, 1.0, 3));
        // compress given matrix block
        CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
        if (compress)
            cmb.compress();
        // matrix-vector uncompressed
        AggregateOperator aop = new AggregateOperator(0, Plus.getPlusFnObject());
        AggregateBinaryOperator abop = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), aop);
        MatrixBlock ret1 = right ? mb.aggregateBinaryOperations(mb, vect, new MatrixBlock(), abop) : vect.aggregateBinaryOperations(vect, mb, new MatrixBlock(), abop);
        // matrix-vector compressed
        MatrixBlock ret2 = right ? cmb.aggregateBinaryOperations(cmb, vect, new MatrixBlock(), abop) : cmb.aggregateBinaryOperations(vect, cmb, new MatrixBlock(), abop);
        // compare result with input
        double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
        double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
        TestUtils.compareMatrices(d1, d2, right ? rows : cols2, right ? cols2 : cols, 0.0000001);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
    }
}
Also used : CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)

Example 17 with AggregateBinaryOperator

use of org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator in project incubator-systemml by apache.

the class AggregateBinaryGPUInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    GPUStatistics.incrementNoOfExecutedGPUInst();
    AggregateBinaryOperator op = (AggregateBinaryOperator) _optr;
    if (!(op.binaryFn instanceof Multiply && op.aggOp.increOp.fn instanceof Plus))
        throw new DMLRuntimeException("Unsupported binary aggregate operation: (" + op.binaryFn + ", " + op.aggOp + ").");
    MatrixObject m1 = getMatrixInputForGPUInstruction(ec, _input1.getName());
    MatrixObject m2 = getMatrixInputForGPUInstruction(ec, _input2.getName());
    // compute matrix multiplication
    int rlen = (int) (_isLeftTransposed ? m1.getNumColumns() : m1.getNumRows());
    int clen = (int) (_isRightTransposed ? m2.getNumRows() : m2.getNumColumns());
    ec.setMetaData(_output.getName(), rlen, clen);
    LibMatrixCuMatMult.matmult(ec, ec.getGPUContext(0), getExtendedOpcode(), m1, m2, _output.getName(), _isLeftTransposed, _isRightTransposed);
    // release inputs/outputs
    ec.releaseMatrixInputForGPUInstruction(_input1.getName());
    ec.releaseMatrixInputForGPUInstruction(_input2.getName());
    ec.releaseMatrixOutputForGPUInstruction(_output.getName());
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) Multiply(org.apache.sysml.runtime.functionobjects.Multiply) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) Plus(org.apache.sysml.runtime.functionobjects.Plus) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 18 with AggregateBinaryOperator

use of org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator in project incubator-systemml by apache.

the class AggregateBinaryGPUInstruction method parseInstruction.

public static AggregateBinaryGPUInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equalsIgnoreCase("ba+*"))
        throw new DMLRuntimeException("AggregateBinaryInstruction.parseInstruction():: Unknown opcode " + opcode);
    InstructionUtils.checkNumFields(parts, 5);
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand in2 = new CPOperand(parts[2]);
    CPOperand out = new CPOperand(parts[3]);
    boolean isLeftTransposed = Boolean.parseBoolean(parts[4]);
    boolean isRightTransposed = Boolean.parseBoolean(parts[5]);
    AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
    AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg, 1);
    return new AggregateBinaryGPUInstruction(aggbin, in1, in2, out, opcode, str, isLeftTransposed, isRightTransposed);
}
Also used : AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 19 with AggregateBinaryOperator

use of org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator in project incubator-systemml by apache.

the class MapmmSPInstruction method parseInstruction.

public static MapmmSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equalsIgnoreCase(MapMult.OPCODE))
        throw new DMLRuntimeException("MapmmSPInstruction.parseInstruction():: Unknown opcode " + opcode);
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand in2 = new CPOperand(parts[2]);
    CPOperand out = new CPOperand(parts[3]);
    CacheType type = CacheType.valueOf(parts[4]);
    boolean outputEmpty = Boolean.parseBoolean(parts[5]);
    SparkAggType aggtype = SparkAggType.valueOf(parts[6]);
    AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
    AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
    return new MapmmSPInstruction(aggbin, in1, in2, out, type, outputEmpty, aggtype, opcode, str);
}
Also used : SparkAggType(org.apache.sysml.hops.AggBinaryOp.SparkAggType) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) CacheType(org.apache.sysml.lops.MapMult.CacheType)

Example 20 with AggregateBinaryOperator

use of org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator in project incubator-systemml by apache.

the class PMapmmSPInstruction method parseInstruction.

public static PMapmmSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(PMapMult.OPCODE)) {
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(parts[3]);
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
        return new PMapmmSPInstruction(aggbin, in1, in2, out, opcode, str);
    } else {
        throw new DMLRuntimeException("PMapmmSPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
}
Also used : AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)21 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)16 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)10 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)10 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)9 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)6 SparkAggType (org.apache.sysml.hops.AggBinaryOp.SparkAggType)2 CacheType (org.apache.sysml.lops.MapMult.CacheType)2 IndexedMatrixValue (org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)2 IOException (java.io.IOException)1 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)1 Multiply (org.apache.sysml.runtime.functionobjects.Multiply)1 Plus (org.apache.sysml.runtime.functionobjects.Plus)1 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)1 MatrixValue (org.apache.sysml.runtime.matrix.data.MatrixValue)1 DistributedCacheInput (org.apache.sysml.runtime.matrix.mapred.DistributedCacheInput)1