Search in sources :

Example 21 with BinaryOperator

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

the class BinaryInstruction method processInstruction.

@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
    IndexedMatrixValue in1 = cachedValues.getFirst(input1);
    IndexedMatrixValue in2 = cachedValues.getFirst(input2);
    if (in1 == null && in2 == null)
        return;
    // allocate space for the output value
    // try to avoid coping as much as possible
    IndexedMatrixValue out;
    if ((output != input1 && output != input2) || (output == input1 && in1 == null) || (output == input2 && in2 == null))
        out = cachedValues.holdPlace(output, valueClass);
    else
        out = tempValue;
    // if one of the inputs is null, then it is a all zero block
    MatrixIndexes finalIndexes = null;
    if (in1 == null) {
        in1 = zeroInput;
        in1.getValue().reset(in2.getValue().getNumRows(), in2.getValue().getNumColumns());
        finalIndexes = in2.getIndexes();
    } else
        finalIndexes = in1.getIndexes();
    if (in2 == null) {
        in2 = zeroInput;
        in2.getValue().reset(in1.getValue().getNumRows(), in1.getValue().getNumColumns());
    }
    // process instruction
    out.getIndexes().setIndexes(finalIndexes);
    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 : MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)

Example 22 with BinaryOperator

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

the class BinaryMInstruction method parseInstruction.

public static BinaryMInstruction parseInstruction(String str) {
    InstructionUtils.checkNumFields(str, 5);
    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]);
    CacheType ctype = CacheType.valueOf(parts[4]);
    VectorType vtype = VectorType.valueOf(parts[5]);
    BinaryOperator bop = InstructionUtils.parseExtendedBinaryOperator(opcode);
    return new BinaryMInstruction(bop, in1, in2, ctype, vtype, out, str);
}
Also used : VectorType(org.apache.sysml.lops.BinaryM.VectorType) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) CacheType(org.apache.sysml.lops.AppendM.CacheType)

Example 23 with BinaryOperator

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

the class UaggOuterChainInstruction method parseInstruction.

public static UaggOuterChainInstruction parseInstruction(String str) {
    // check number of fields (2/3 inputs, output, type)
    InstructionUtils.checkNumFields(str, 5);
    // parse instruction parts (without exec type)
    String[] parts = InstructionUtils.getInstructionParts(str);
    AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[1]);
    BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[2]);
    byte in1 = Byte.parseByte(parts[3]);
    byte in2 = Byte.parseByte(parts[4]);
    byte out = Byte.parseByte(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 UaggOuterChainInstruction(bop, uaggop, aop, in1, in2, out, str);
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) CorrectionLocationType(org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)

Example 24 with BinaryOperator

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

the class BinarySPInstruction method processMatrixBVectorBinaryInstruction.

protected void processMatrixBVectorBinaryInstruction(ExecutionContext ec, VectorType vtype) {
    SparkExecutionContext sec = (SparkExecutionContext) ec;
    // sanity check dimensions
    checkMatrixMatrixBinaryCharacteristics(sec);
    // get input RDDs
    String rddVar = input1.getName();
    String bcastVar = input2.getName();
    JavaPairRDD<MatrixIndexes, MatrixBlock> in1 = sec.getBinaryBlockRDDHandleForVariable(rddVar);
    PartitionedBroadcast<MatrixBlock> in2 = sec.getBroadcastForVariable(bcastVar);
    MatrixCharacteristics mc1 = sec.getMatrixCharacteristics(rddVar);
    MatrixCharacteristics mc2 = sec.getMatrixCharacteristics(bcastVar);
    BinaryOperator bop = (BinaryOperator) _optr;
    boolean isOuter = (mc1.getRows() > 1 && mc1.getCols() == 1 && mc2.getRows() == 1 && mc2.getCols() > 1);
    // execute map binary operation
    JavaPairRDD<MatrixIndexes, MatrixBlock> out = null;
    if (isOuter) {
        out = in1.flatMapToPair(new OuterVectorBinaryOpFunction(bop, in2));
    } else {
        // default
        // note: we use mappartition in order to preserve partitioning information for
        // binary mv operations where the keys are guaranteed not to change, the reason
        // why we cannot use mapValues is the need for broadcast key lookups.
        // alternative: out = in1.mapToPair(new MatrixVectorBinaryOpFunction(bop, in2, vtype));
        out = in1.mapPartitionsToPair(new MatrixVectorBinaryOpPartitionFunction(bop, in2, vtype), true);
    }
    // set output RDD
    updateBinaryOutputMatrixCharacteristics(sec);
    sec.setRDDHandleForVariable(output.getName(), out);
    sec.addLineageRDD(output.getName(), rddVar);
    sec.addLineageBroadcast(output.getName(), bcastVar);
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) MatrixVectorBinaryOpPartitionFunction(org.apache.sysml.runtime.instructions.spark.functions.MatrixVectorBinaryOpPartitionFunction) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) OuterVectorBinaryOpFunction(org.apache.sysml.runtime.instructions.spark.functions.OuterVectorBinaryOpFunction)

Example 25 with BinaryOperator

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

the class BinaryMatrixMatrixCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    String opcode = getOpcode();
    if (LibCommonsMath.isSupportedMatrixMatrixOperation(opcode)) {
        MatrixBlock solution = LibCommonsMath.matrixMatrixOperations(ec.getMatrixObject(input1.getName()), (MatrixObject) ec.getVariable(input2.getName()), opcode);
        ec.setMatrixOutput(output.getName(), solution, getExtendedOpcode());
        return;
    }
    // Read input matrices
    MatrixBlock inBlock1 = ec.getMatrixInput(input1.getName(), getExtendedOpcode());
    MatrixBlock inBlock2 = ec.getMatrixInput(input2.getName(), getExtendedOpcode());
    // Perform computation using input matrices, and produce the result matrix
    BinaryOperator bop = (BinaryOperator) _optr;
    MatrixBlock retBlock = (MatrixBlock) (inBlock1.binaryOperations(bop, inBlock2, new MatrixBlock()));
    // Release the memory occupied by input matrices
    ec.releaseMatrixInput(input1.getName(), getExtendedOpcode());
    ec.releaseMatrixInput(input2.getName(), getExtendedOpcode());
    // Ensure right dense/sparse output representation (guarded by released input memory)
    if (checkGuardedRepresentationChange(inBlock1, inBlock2, retBlock)) {
        retBlock.examSparsity();
    }
    // Attach result matrix with MatrixObject associated with output_name
    ec.setMatrixOutput(output.getName(), retBlock, getExtendedOpcode());
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator)

Aggregations

BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)34 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)10 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9 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 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)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 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)2 ValueComparisonFunction (org.apache.sysml.runtime.functionobjects.ValueComparisonFunction)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 ScalarOperator (org.apache.sysml.runtime.matrix.operators.ScalarOperator)2 Method (java.lang.reflect.Method)1