Search in sources :

Example 1 with BinaryOperator

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

the class UaggOuterChainSPInstruction method parseInstruction.

public static UaggOuterChainSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(UAggOuterChain.OPCODE)) {
        AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[1]);
        BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[2]);
        CPOperand in1 = new CPOperand(parts[3]);
        CPOperand in2 = new CPOperand(parts[4]);
        CPOperand out = new CPOperand(parts[5]);
        //derive aggregation operator from unary operator
        String aopcode = InstructionUtils.deriveAggregateOperatorOpcode(parts[1]);
        CorrectionLocationType corrLoc = InstructionUtils.deriveAggregateOperatorCorrectionLocation(parts[1]);
        String corrExists = (corrLoc != CorrectionLocationType.NONE) ? "true" : "false";
        AggregateOperator aop = InstructionUtils.parseAggregateOperator(aopcode, corrExists, corrLoc.toString());
        return new UaggOuterChainSPInstruction(bop, uaggop, aop, in1, in2, out, opcode, str);
    } else {
        throw new DMLRuntimeException("UaggOuterChainSPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) CorrectionLocationType(org.apache.sysml.lops.PartialAggregate.CorrectionLocationType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 2 with BinaryOperator

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

the class BinaryInstruction method parseInstruction.

public static BinaryInstruction parseInstruction(String str) throws DMLRuntimeException {
    InstructionUtils.checkNumFields(str, 3);
    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]);
    BinaryOperator bop = InstructionUtils.parseBinaryOperator(opcode);
    if (bop != null)
        return new BinaryInstruction(bop, in1, in2, out, str);
    else
        return null;
}
Also used : BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator)

Example 3 with BinaryOperator

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

the class BinaryMInstruction method processInstruction.

@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) throws DMLRuntimeException {
    ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input1);
    if (blkList == null)
        return;
    for (IndexedMatrixValue in1 : blkList) {
        //allocate space for the output value
        //try to avoid coping as much as possible
        IndexedMatrixValue out;
        if ((output != input1 && output != input2))
            out = cachedValues.holdPlace(output, valueClass);
        else
            out = tempValue;
        //get second 
        DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input2);
        IndexedMatrixValue in2 = null;
        if (_vectorType == VectorType.COL_VECTOR)
            in2 = dcInput.getDataBlock((int) in1.getIndexes().getRowIndex(), 1);
        else
            //_vectorType == VectorType.ROW_VECTOR
            in2 = dcInput.getDataBlock(1, (int) in1.getIndexes().getColumnIndex());
        //process instruction
        out.getIndexes().setIndexes(in1.getIndexes());
        OperationsOnMatrixValues.performBinaryIgnoreIndexes(in1.getValue(), in2.getValue(), out.getValue(), ((BinaryOperator) optr));
        //put the output value in the cache
        if (out == tempValue)
            cachedValues.add(output, out);
    }
}
Also used : DistributedCacheInput(org.apache.sysml.runtime.matrix.mapred.DistributedCacheInput) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)

Example 4 with BinaryOperator

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

the class BinUaggChainInstruction method parseInstruction.

public static BinUaggChainInstruction parseInstruction(String str) throws DMLRuntimeException {
    //check number of fields (2/3 inputs, output, type)
    InstructionUtils.checkNumFields(str, 4);
    //parse instruction parts (without exec type)
    String[] parts = InstructionUtils.getInstructionParts(str);
    BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[1]);
    AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[2]);
    byte in1 = Byte.parseByte(parts[3]);
    byte out = Byte.parseByte(parts[4]);
    return new BinUaggChainInstruction(bop, uaggop, in1, out, str);
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator)

Example 5 with BinaryOperator

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

the class BinarySPInstruction method processMatrixMatrixBinaryInstruction.

/**
	 * Common binary matrix-matrix process instruction
	 * 
	 * @param ec execution context
	 * @throws DMLRuntimeException if DMLRuntimeException occurs
	 */
protected void processMatrixMatrixBinaryInstruction(ExecutionContext ec) throws DMLRuntimeException {
    SparkExecutionContext sec = (SparkExecutionContext) ec;
    //sanity check dimensions
    checkMatrixMatrixBinaryCharacteristics(sec);
    // Get input RDDs
    String rddVar1 = input1.getName();
    String rddVar2 = input2.getName();
    JavaPairRDD<MatrixIndexes, MatrixBlock> in1 = sec.getBinaryBlockRDDHandleForVariable(rddVar1);
    JavaPairRDD<MatrixIndexes, MatrixBlock> in2 = sec.getBinaryBlockRDDHandleForVariable(rddVar2);
    MatrixCharacteristics mc1 = sec.getMatrixCharacteristics(rddVar1);
    MatrixCharacteristics mc2 = sec.getMatrixCharacteristics(rddVar2);
    BinaryOperator bop = (BinaryOperator) _optr;
    //vector replication if required (mv or outer operations)
    boolean rowvector = (mc2.getRows() == 1 && mc1.getRows() > 1);
    long numRepLeft = getNumReplicas(mc1, mc2, true);
    long numRepRight = getNumReplicas(mc1, mc2, false);
    if (numRepLeft > 1)
        in1 = in1.flatMapToPair(new ReplicateVectorFunction(false, numRepLeft));
    if (numRepRight > 1)
        in2 = in2.flatMapToPair(new ReplicateVectorFunction(rowvector, numRepRight));
    //execute binary operation
    JavaPairRDD<MatrixIndexes, MatrixBlock> out = in1.join(in2).mapValues(new MatrixMatrixBinaryOpFunction(bop));
    //set output RDD
    updateBinaryOutputMatrixCharacteristics(sec);
    sec.setRDDHandleForVariable(output.getName(), out);
    sec.addLineageRDD(output.getName(), rddVar1);
    sec.addLineageRDD(output.getName(), rddVar2);
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) ReplicateVectorFunction(org.apache.sysml.runtime.instructions.spark.functions.ReplicateVectorFunction) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) MatrixMatrixBinaryOpFunction(org.apache.sysml.runtime.instructions.spark.functions.MatrixMatrixBinaryOpFunction) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics)

Aggregations

BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)30 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)8 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)8 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)5 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)5 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)4 CorrectionLocationType (org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)3 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)3 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)3 RightScalarOperator (org.apache.sysml.runtime.matrix.operators.RightScalarOperator)3 VectorType (org.apache.sysml.lops.BinaryM.VectorType)2 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)2 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)2 ValueFunctionWithConstant (org.apache.sysml.runtime.functionobjects.ValueFunctionWithConstant)2 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)2 IndexedMatrixValue (org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)2 AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)2 Pointer (jcuda.Pointer)1 CacheType (org.apache.sysml.lops.AppendM.CacheType)1 ValueType (org.apache.sysml.parser.Expression.ValueType)1