Search in sources :

Example 31 with CPOperand

use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.

the class CentralMomentSPInstruction method parseInstruction.

public static CentralMomentSPInstruction parseInstruction(String str) {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = null;
    CPOperand in3 = null;
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    // check supported opcode
    if (!opcode.equalsIgnoreCase("cm")) {
        throw new DMLRuntimeException("Unsupported opcode " + opcode);
    }
    if (parts.length == 4) {
        // Example: CP.cm.mVar0.Var1.mVar2; (without weights)
        in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        parseUnaryInstruction(str, in1, in2, out);
    } else if (parts.length == 5) {
        // CP.cm.mVar0.mVar1.Var2.mVar3; (with weights)
        in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        in3 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        parseUnaryInstruction(str, in1, in2, in3, out);
    }
    // Exact order of the central moment MAY NOT be known at compilation time.
    // We first try to parse the second argument as an integer, and if we fail,
    // we simply pass -1 so that getCMAggOpType() picks up AggregateOperationTypes.INVALID.
    // It must be updated at run time in processInstruction() method.
    int cmOrder;
    try {
        if (in3 == null) {
            cmOrder = Integer.parseInt(in2.getName());
        } else {
            cmOrder = Integer.parseInt(in3.getName());
        }
    } catch (NumberFormatException e) {
        // unknown at compilation time
        cmOrder = -1;
    }
    AggregateOperationTypes opType = CMOperator.getCMAggOpType(cmOrder);
    CMOperator cm = new CMOperator(CM.getCMFnObject(opType), opType);
    return new CentralMomentSPInstruction(cm, in1, in2, in3, out, opcode, str);
}
Also used : AggregateOperationTypes(org.apache.sysml.runtime.matrix.operators.CMOperator.AggregateOperationTypes) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 32 with CPOperand

use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.

the class CentralMomentSPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    SparkExecutionContext sec = (SparkExecutionContext) ec;
    // parse 'order' input argument
    CPOperand scalarInput = (input3 == null ? input2 : input3);
    ScalarObject order = ec.getScalarInput(scalarInput.getName(), scalarInput.getValueType(), scalarInput.isLiteral());
    CMOperator cop = ((CMOperator) _optr);
    if (cop.getAggOpType() == AggregateOperationTypes.INVALID) {
        cop.setCMAggOp((int) order.getLongValue());
    }
    // get input
    JavaPairRDD<MatrixIndexes, MatrixBlock> in1 = sec.getBinaryBlockRDDHandleForVariable(input1.getName());
    // process central moment instruction
    CM_COV_Object cmobj = null;
    if (// w/o weights
    input3 == null) {
        cmobj = in1.values().map(new RDDCMFunction(cop)).fold(new CM_COV_Object(), new RDDCMReduceFunction(cop));
    } else // with weights
    {
        JavaPairRDD<MatrixIndexes, MatrixBlock> in2 = sec.getBinaryBlockRDDHandleForVariable(input2.getName());
        cmobj = in1.join(in2).values().map(new RDDCMWeightsFunction(cop)).fold(new CM_COV_Object(), new RDDCMReduceFunction(cop));
    }
    // create scalar output (no lineage information required)
    double val = cmobj.getRequiredResult(_optr);
    ec.setScalarOutput(output.getName(), new DoubleObject(val));
}
Also used : CM_COV_Object(org.apache.sysml.runtime.instructions.cp.CM_COV_Object) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator)

Example 33 with CPOperand

use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.

the class CheckpointSPInstruction method parseInstruction.

public static CheckpointSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 3);
    String opcode = parts[0];
    CPOperand in = new CPOperand(parts[1]);
    CPOperand out = new CPOperand(parts[2]);
    StorageLevel level = StorageLevel.fromString(parts[3]);
    return new CheckpointSPInstruction(null, in, out, level, opcode, str);
}
Also used : CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) StorageLevel(org.apache.spark.storage.StorageLevel)

Example 34 with CPOperand

use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.

the class CpmmSPInstruction method parseInstruction.

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

Example 35 with CPOperand

use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.

the class ExternalFunctionProgramBlock method getOperands.

/**
 * Given a list of parameters as data identifiers, returns an array
 * of instruction operands.
 *
 * @param params list of data identifiers
 * @return operands
 */
protected CPOperand[] getOperands(ArrayList<DataIdentifier> params) {
    CPOperand[] ret = new CPOperand[params.size()];
    for (int i = 0; i < params.size(); i++) {
        DataIdentifier param = params.get(i);
        ret[i] = new CPOperand(param.getName(), param.getValueType(), param.getDataType());
    }
    return ret;
}
Also used : DataIdentifier(org.apache.sysml.parser.DataIdentifier) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand)

Aggregations

CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)77 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)51 Operator (org.apache.sysml.runtime.matrix.operators.Operator)13 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)10 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)7 ReorgOperator (org.apache.sysml.runtime.matrix.operators.ReorgOperator)7 SimpleOperator (org.apache.sysml.runtime.matrix.operators.SimpleOperator)7 ArrayList (java.util.ArrayList)6 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)6 AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)6 BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)6 DataType (org.apache.sysml.parser.Expression.DataType)5 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)5 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)5 SparkAggType (org.apache.sysml.hops.AggBinaryOp.SparkAggType)4 VectorType (org.apache.sysml.lops.BinaryM.VectorType)4 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)4 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)4 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)4 MMTSJType (org.apache.sysml.lops.MMTSJ.MMTSJType)3