Search in sources :

Example 66 with CPOperand

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

the class QuaternarySPInstruction method parseInstruction.

public static QuaternarySPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    // validity check
    if (!InstructionUtils.isDistQuaternaryOpcode(opcode)) {
        throw new DMLRuntimeException("Quaternary.parseInstruction():: Unknown opcode " + opcode);
    }
    // instruction parsing
    if (// wsloss
    WeightedSquaredLoss.OPCODE.equalsIgnoreCase(opcode) || WeightedSquaredLossR.OPCODE.equalsIgnoreCase(opcode)) {
        boolean isRed = WeightedSquaredLossR.OPCODE.equalsIgnoreCase(opcode);
        // check number of fields (4 inputs, output, type)
        if (isRed)
            InstructionUtils.checkNumFields(parts, 8);
        else
            InstructionUtils.checkNumFields(parts, 6);
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand in3 = new CPOperand(parts[3]);
        CPOperand in4 = new CPOperand(parts[4]);
        CPOperand out = new CPOperand(parts[5]);
        WeightsType wtype = WeightsType.valueOf(parts[6]);
        // in mappers always through distcache, in reducers through distcache/shuffle
        boolean cacheU = isRed ? Boolean.parseBoolean(parts[7]) : true;
        boolean cacheV = isRed ? Boolean.parseBoolean(parts[8]) : true;
        return new QuaternarySPInstruction(new QuaternaryOperator(wtype), in1, in2, in3, in4, out, cacheU, cacheV, opcode, str);
    } else if (// wumm
    WeightedUnaryMM.OPCODE.equalsIgnoreCase(opcode) || WeightedUnaryMMR.OPCODE.equalsIgnoreCase(opcode)) {
        boolean isRed = WeightedUnaryMMR.OPCODE.equalsIgnoreCase(opcode);
        // check number of fields (4 inputs, output, type)
        if (isRed)
            InstructionUtils.checkNumFields(parts, 8);
        else
            InstructionUtils.checkNumFields(parts, 6);
        String uopcode = parts[1];
        CPOperand in1 = new CPOperand(parts[2]);
        CPOperand in2 = new CPOperand(parts[3]);
        CPOperand in3 = new CPOperand(parts[4]);
        CPOperand out = new CPOperand(parts[5]);
        WUMMType wtype = WUMMType.valueOf(parts[6]);
        // in mappers always through distcache, in reducers through distcache/shuffle
        boolean cacheU = isRed ? Boolean.parseBoolean(parts[7]) : true;
        boolean cacheV = isRed ? Boolean.parseBoolean(parts[8]) : true;
        return new QuaternarySPInstruction(new QuaternaryOperator(wtype, uopcode), in1, in2, in3, null, out, cacheU, cacheV, opcode, str);
    } else if (// wdivmm
    WeightedDivMM.OPCODE.equalsIgnoreCase(opcode) || WeightedDivMMR.OPCODE.equalsIgnoreCase(opcode)) {
        boolean isRed = opcode.startsWith("red");
        // check number of fields (4 inputs, output, type)
        if (isRed)
            InstructionUtils.checkNumFields(parts, 8);
        else
            InstructionUtils.checkNumFields(parts, 6);
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand in3 = new CPOperand(parts[3]);
        CPOperand in4 = new CPOperand(parts[4]);
        CPOperand out = new CPOperand(parts[5]);
        // in mappers always through distcache, in reducers through distcache/shuffle
        boolean cacheU = isRed ? Boolean.parseBoolean(parts[7]) : true;
        boolean cacheV = isRed ? Boolean.parseBoolean(parts[8]) : true;
        final WDivMMType wt = WDivMMType.valueOf(parts[6]);
        QuaternaryOperator qop = (wt.hasScalar() ? new QuaternaryOperator(wt, Double.parseDouble(in4.getName())) : new QuaternaryOperator(wt));
        return new QuaternarySPInstruction(qop, in1, in2, in3, in4, out, cacheU, cacheV, opcode, str);
    } else // map/redwsigmoid, map/redwcemm
    {
        boolean isRed = opcode.startsWith("red");
        int addInput4 = (opcode.endsWith("wcemm")) ? 1 : 0;
        // check number of fields (3 or 4 inputs, output, type)
        if (isRed)
            InstructionUtils.checkNumFields(parts, 7 + addInput4);
        else
            InstructionUtils.checkNumFields(parts, 5 + addInput4);
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand in3 = new CPOperand(parts[3]);
        CPOperand out = new CPOperand(parts[4 + addInput4]);
        // in mappers always through distcache, in reducers through distcache/shuffle
        boolean cacheU = isRed ? Boolean.parseBoolean(parts[6 + addInput4]) : true;
        boolean cacheV = isRed ? Boolean.parseBoolean(parts[7 + addInput4]) : true;
        if (opcode.endsWith("wsigmoid"))
            return new QuaternarySPInstruction(new QuaternaryOperator(WSigmoidType.valueOf(parts[5])), in1, in2, in3, null, out, cacheU, cacheV, opcode, str);
        else if (opcode.endsWith("wcemm")) {
            CPOperand in4 = new CPOperand(parts[4]);
            final WCeMMType wt = WCeMMType.valueOf(parts[6]);
            QuaternaryOperator qop = (wt.hasFourInputs() ? new QuaternaryOperator(wt, Double.parseDouble(in4.getName())) : new QuaternaryOperator(wt));
            return new QuaternarySPInstruction(qop, in1, in2, in3, in4, out, cacheU, cacheV, opcode, str);
        }
    }
    return null;
}
Also used : QuaternaryOperator(org.apache.sysml.runtime.matrix.operators.QuaternaryOperator) WDivMMType(org.apache.sysml.lops.WeightedDivMM.WDivMMType) WCeMMType(org.apache.sysml.lops.WeightedCrossEntropy.WCeMMType) WeightsType(org.apache.sysml.lops.WeightedSquaredLoss.WeightsType) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) WUMMType(org.apache.sysml.lops.WeightedUnaryMM.WUMMType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 67 with CPOperand

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

the class ReblockSPInstruction method parseInstruction.

public static ReblockSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equals("rblk")) {
        throw new DMLRuntimeException("Incorrect opcode for ReblockSPInstruction:" + opcode);
    }
    CPOperand in = new CPOperand(parts[1]);
    CPOperand out = new CPOperand(parts[2]);
    int brlen = Integer.parseInt(parts[3]);
    int bclen = Integer.parseInt(parts[4]);
    boolean outputEmptyBlocks = Boolean.parseBoolean(parts[5]);
    // no operator for ReblockSPInstruction
    Operator op = null;
    return new ReblockSPInstruction(op, in, out, brlen, bclen, outputEmptyBlocks, opcode, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 68 with CPOperand

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

the class ReorgSPInstruction method parseInstruction.

public static ReorgSPInstruction parseInstruction(String str) {
    CPOperand in = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String opcode = InstructionUtils.getOpCode(str);
    if (opcode.equalsIgnoreCase("r'")) {
        // max 2 operands
        parseUnaryInstruction(str, in, out);
        return new ReorgSPInstruction(new ReorgOperator(SwapIndex.getSwapIndexFnObject()), in, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("rev")) {
        // max 2 operands
        parseUnaryInstruction(str, in, out);
        return new ReorgSPInstruction(new ReorgOperator(RevIndex.getRevIndexFnObject()), in, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("rdiag")) {
        // max 2 operands
        parseUnaryInstruction(str, in, out);
        return new ReorgSPInstruction(new ReorgOperator(DiagIndex.getDiagIndexFnObject()), in, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("rsort")) {
        String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
        InstructionUtils.checkNumFields(parts, 5, 6);
        in.split(parts[1]);
        out.split(parts[5]);
        CPOperand col = new CPOperand(parts[2]);
        CPOperand desc = new CPOperand(parts[3]);
        CPOperand ixret = new CPOperand(parts[4]);
        boolean bSortIndInMem = false;
        if (parts.length > 5)
            bSortIndInMem = Boolean.parseBoolean(parts[6]);
        return new ReorgSPInstruction(new ReorgOperator(new SortIndex(1, false, false)), in, col, desc, ixret, out, opcode, bSortIndInMem, str);
    } else {
        throw new DMLRuntimeException("Unknown opcode while parsing a ReorgInstruction: " + str);
    }
}
Also used : SortIndex(org.apache.sysml.runtime.functionobjects.SortIndex) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 69 with CPOperand

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

the class RmmSPInstruction method parseInstruction.

public static RmmSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if ("rmm".equals(opcode)) {
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(parts[3]);
        return new RmmSPInstruction(null, in1, in2, out, opcode, str);
    } else {
        throw new DMLRuntimeException("RmmSPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
}
Also used : CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 70 with CPOperand

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

the class TernarySPInstruction method parseInstruction.

public static TernarySPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    CPOperand operand1 = new CPOperand(parts[1]);
    CPOperand operand2 = new CPOperand(parts[2]);
    CPOperand operand3 = new CPOperand(parts[3]);
    CPOperand outOperand = new CPOperand(parts[4]);
    TernaryOperator op = InstructionUtils.parseTernaryOperator(opcode);
    return new TernarySPInstruction(op, operand1, operand2, operand3, outOperand, opcode, str);
}
Also used : TernaryOperator(org.apache.sysml.runtime.matrix.operators.TernaryOperator) 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