Search in sources :

Example 1 with AggregateBinaryOperator

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

the class ZipmmSPInstruction method parseInstruction.

public static ZipmmSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase("zipmm")) {
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(parts[3]);
        boolean tRewrite = Boolean.parseBoolean(parts[4]);
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
        return new ZipmmSPInstruction(aggbin, in1, in2, out, tRewrite, opcode, str);
    } else {
        throw new DMLRuntimeException("ZipmmSPInstruction.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)

Example 2 with AggregateBinaryOperator

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

the class PmmSPInstruction method parseInstruction.

public static PmmSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = InstructionUtils.getOpCode(str);
    if (opcode.equalsIgnoreCase(PMMJ.OPCODE)) {
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand nrow = new CPOperand(parts[3]);
        CPOperand out = new CPOperand(parts[4]);
        CacheType type = CacheType.valueOf(parts[5]);
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
        return new PmmSPInstruction(aggbin, in1, in2, out, nrow, type, opcode, str);
    } else {
        throw new DMLRuntimeException("PmmSPInstruction.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) CacheType(org.apache.sysml.lops.MapMult.CacheType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 3 with AggregateBinaryOperator

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

the class CpmmSPInstruction method parseInstruction.

public static CpmmSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase("cpmm")) {
        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);
        SparkAggType aggtype = SparkAggType.valueOf(parts[4]);
        return new CpmmSPInstruction(aggbin, in1, in2, out, aggtype, opcode, str);
    } else {
        throw new DMLRuntimeException("AggregateBinaryInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
}
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)

Example 4 with AggregateBinaryOperator

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

the class AggregateBinaryInstruction method parseInstruction.

public static AggregateBinaryInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionParts(str);
    byte in1, in2, out;
    String opcode = parts[0];
    in1 = Byte.parseByte(parts[1]);
    in2 = Byte.parseByte(parts[2]);
    out = Byte.parseByte(parts[3]);
    if (opcode.equalsIgnoreCase("cpmm") || opcode.equalsIgnoreCase("rmm") || opcode.equalsIgnoreCase(MapMult.OPCODE)) {
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
        AggregateBinaryInstruction inst = new AggregateBinaryInstruction(aggbin, opcode, in1, in2, out, str);
        if (parts.length == 5) {
            inst.setMMCJType(MMCJType.valueOf(parts[4]));
        } else if (parts.length == 6) {
            //mapmm
            inst.setCacheTypeMapMult(CacheType.valueOf(parts[4]));
            inst.setOutputEmptyBlocksMapMult(Boolean.parseBoolean(parts[5]));
        }
        return inst;
    }
    throw new DMLRuntimeException("AggregateBinaryInstruction.parseInstruction():: Unknown opcode " + opcode);
}
Also used : AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 5 with AggregateBinaryOperator

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

the class AggregateBinaryInstruction method processMapMultInstruction.

/**
	 * Helper function to perform map-side matrix-matrix multiplication.
	 * 
	 * @param valueClass matrix value class
	 * @param cachedValues cached value map
	 * @param in1 indexed matrix value 1
	 * @param in2 indexed matrix value 2
	 * @param blockRowFactor ?
	 * @param blockColFactor ?
	 * @throws DMLRuntimeException if DMLRuntimeException occurs
	 */
private void processMapMultInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue in1, IndexedMatrixValue in2, int blockRowFactor, int blockColFactor) throws DMLRuntimeException {
    boolean removeOutput = true;
    if (_cacheType.isRight()) {
        DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input2);
        long in2_cols = dcInput.getNumCols();
        long in2_colBlocks = (long) Math.ceil(((double) in2_cols) / dcInput.getNumColsPerBlock());
        for (int bidx = 1; bidx <= in2_colBlocks; bidx++) {
            // Matrix multiply A[i,k] %*% B[k,bid]
            // Setup input2 block
            IndexedMatrixValue in2Block = dcInput.getDataBlock((int) in1.getIndexes().getColumnIndex(), bidx);
            MatrixValue in2BlockValue = in2Block.getValue();
            MatrixIndexes in2BlockIndex = in2Block.getIndexes();
            //allocate space for the output value
            IndexedMatrixValue out = cachedValues.holdPlace(output, valueClass);
            //process instruction
            OperationsOnMatrixValues.performAggregateBinary(in1.getIndexes(), in1.getValue(), in2BlockIndex, in2BlockValue, out.getIndexes(), out.getValue(), ((AggregateBinaryOperator) optr));
            removeOutput &= (!_outputEmptyBlocks && out.getValue().isEmpty());
        }
    } else {
        DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input1);
        long in1_rows = dcInput.getNumRows();
        long in1_rowsBlocks = (long) Math.ceil(((double) in1_rows) / dcInput.getNumRowsPerBlock());
        for (int bidx = 1; bidx <= in1_rowsBlocks; bidx++) {
            // Matrix multiply A[i,k] %*% B[k,bid]
            // Setup input2 block
            IndexedMatrixValue in1Block = dcInput.getDataBlock(bidx, (int) in2.getIndexes().getRowIndex());
            MatrixValue in1BlockValue = in1Block.getValue();
            MatrixIndexes in1BlockIndex = in1Block.getIndexes();
            //allocate space for the output value
            IndexedMatrixValue out = cachedValues.holdPlace(output, valueClass);
            //process instruction
            OperationsOnMatrixValues.performAggregateBinary(in1BlockIndex, in1BlockValue, in2.getIndexes(), in2.getValue(), out.getIndexes(), out.getValue(), ((AggregateBinaryOperator) optr));
            removeOutput &= (!_outputEmptyBlocks && out.getValue().isEmpty());
        }
    }
    //empty block output filter (enabled by compiler consumer operation is in CP)
    if (removeOutput)
        cachedValues.remove(output);
}
Also used : DistributedCacheInput(org.apache.sysml.runtime.matrix.mapred.DistributedCacheInput) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue) MatrixValue(org.apache.sysml.runtime.matrix.data.MatrixValue) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)

Aggregations

AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)20 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)15 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)10 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)8 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)8 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