Search in sources :

Example 56 with CPOperand

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

the class ConvolutionSPInstruction method parseInstruction.

public static ConvolutionSPInstruction parseInstruction(String str) {
    CPOperand in = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase("maxpooling") || opcode.equalsIgnoreCase("relu_maxpooling")) {
        InstructionUtils.checkNumFields(parts, 14);
        // stride1, stride2, padding1, padding2
        // input_shape1, input_shape2, input_shape3, input_shape4,
        // filter_shape1, filter_shape2, filter_shape3, filter_shape4, k
        in.split(parts[1]);
        out.split(parts[14]);
        ArrayList<CPOperand> stride = new ArrayList<>();
        ArrayList<CPOperand> padding = new ArrayList<>();
        ArrayList<CPOperand> input_shape = new ArrayList<>();
        ArrayList<CPOperand> filter_shape = new ArrayList<>();
        stride.add(new CPOperand(parts[2]));
        stride.add(new CPOperand(parts[3]));
        padding.add(new CPOperand(parts[4]));
        padding.add(new CPOperand(parts[5]));
        input_shape.add(new CPOperand(parts[6]));
        input_shape.add(new CPOperand(parts[7]));
        input_shape.add(new CPOperand(parts[8]));
        input_shape.add(new CPOperand(parts[9]));
        filter_shape.add(new CPOperand(parts[10]));
        filter_shape.add(new CPOperand(parts[11]));
        filter_shape.add(new CPOperand(parts[12]));
        filter_shape.add(new CPOperand(parts[13]));
        return new ConvolutionSPInstruction(in, out, opcode, str, stride, padding, input_shape, filter_shape);
    } else if (opcode.equalsIgnoreCase("maxpooling_backward") || opcode.equalsIgnoreCase("conv2d") || opcode.equalsIgnoreCase("conv2d_backward_filter") || opcode.equalsIgnoreCase("conv2d_backward_data")) {
        InstructionUtils.checkNumFields(parts, 15);
        // dout, stride1, stride2, padding1, padding2
        // input_shape1, input_shape2, input_shape3, input_shape4,
        // filter_shape1, filter_shape2, filter_shape3, filter_shape4, k
        in.split(parts[1]);
        CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        in2.split(parts[2]);
        out.split(parts[15]);
        ArrayList<CPOperand> stride = new ArrayList<>();
        ArrayList<CPOperand> padding = new ArrayList<>();
        ArrayList<CPOperand> input_shape = new ArrayList<>();
        ArrayList<CPOperand> filter_shape = new ArrayList<>();
        stride.add(new CPOperand(parts[3]));
        stride.add(new CPOperand(parts[4]));
        padding.add(new CPOperand(parts[5]));
        padding.add(new CPOperand(parts[6]));
        input_shape.add(new CPOperand(parts[7]));
        input_shape.add(new CPOperand(parts[8]));
        input_shape.add(new CPOperand(parts[9]));
        input_shape.add(new CPOperand(parts[10]));
        filter_shape.add(new CPOperand(parts[11]));
        filter_shape.add(new CPOperand(parts[12]));
        filter_shape.add(new CPOperand(parts[13]));
        filter_shape.add(new CPOperand(parts[14]));
        return new ConvolutionSPInstruction(in, in2, out, opcode, str, stride, padding, input_shape, filter_shape);
    } else if (opcode.equalsIgnoreCase("conv2d_bias_add")) {
        InstructionUtils.checkNumFields(parts, 16);
        // dout, stride1, stride2, padding1, padding2
        // input_shape1, input_shape2, input_shape3, input_shape4,
        // filter_shape1, filter_shape2, filter_shape3, filter_shape4, k
        in.split(parts[1]);
        CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        in2.split(parts[2]);
        CPOperand in3 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        in3.split(parts[3]);
        out.split(parts[16]);
        ArrayList<CPOperand> stride = new ArrayList<>();
        ArrayList<CPOperand> padding = new ArrayList<>();
        ArrayList<CPOperand> input_shape = new ArrayList<>();
        ArrayList<CPOperand> filter_shape = new ArrayList<>();
        stride.add(new CPOperand(parts[4]));
        stride.add(new CPOperand(parts[5]));
        padding.add(new CPOperand(parts[6]));
        padding.add(new CPOperand(parts[7]));
        input_shape.add(new CPOperand(parts[8]));
        input_shape.add(new CPOperand(parts[9]));
        input_shape.add(new CPOperand(parts[10]));
        input_shape.add(new CPOperand(parts[11]));
        filter_shape.add(new CPOperand(parts[12]));
        filter_shape.add(new CPOperand(parts[13]));
        filter_shape.add(new CPOperand(parts[14]));
        filter_shape.add(new CPOperand(parts[15]));
        return new ConvolutionSPInstruction(in, in2, in3, out, opcode, str, stride, padding, input_shape, filter_shape);
    } else if (opcode.equalsIgnoreCase("bias_add")) {
        InstructionUtils.checkNumFields(parts, 3);
        in.split(parts[1]);
        CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        in2.split(parts[2]);
        out.split(parts[3]);
        return new ConvolutionSPInstruction(in, in2, out, opcode, str);
    } else {
        throw new DMLRuntimeException("Unknown opcode while parsing a ConvolutionCPInstruction: " + str);
    }
}
Also used : ArrayList(java.util.ArrayList) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 57 with CPOperand

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

the class CovarianceSPInstruction method parseInstruction.

public static CovarianceSPInstruction parseInstruction(String str) {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in3 = null;
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equalsIgnoreCase("cov")) {
        throw new DMLRuntimeException("CovarianceCPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
    COVOperator cov = new COVOperator(COV.getCOMFnObject());
    if (parts.length == 4) {
        // CP.cov.mVar0.mVar1.mVar2
        parseBinaryInstruction(str, in1, in2, out);
        return new CovarianceSPInstruction(cov, in1, in2, out, opcode, str);
    } else if (parts.length == 5) {
        // CP.cov.mVar0.mVar1.mVar2.mVar3
        in3 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        parseBinaryInstruction(str, in1, in2, in3, out);
        return new CovarianceSPInstruction(cov, in1, in2, in3, out, opcode, str);
    } else {
        throw new DMLRuntimeException("Invalid number of arguments in Instruction: " + str);
    }
}
Also used : COVOperator(org.apache.sysml.runtime.matrix.operators.COVOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 58 with CPOperand

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

the class CtableSPInstruction method parseInstruction.

public static CtableSPInstruction parseInstruction(String inst) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(inst);
    InstructionUtils.checkNumFields(parts, 7);
    String opcode = parts[0];
    // handle opcode
    if (!(opcode.equalsIgnoreCase("ctable") || opcode.equalsIgnoreCase("ctableexpand"))) {
        throw new DMLRuntimeException("Unexpected opcode in TertiarySPInstruction: " + inst);
    }
    boolean isExpand = opcode.equalsIgnoreCase("ctableexpand");
    // handle operands
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand in2 = new CPOperand(parts[2]);
    CPOperand in3 = new CPOperand(parts[3]);
    // handle known dimension information
    String[] dim1Fields = parts[4].split(Instruction.LITERAL_PREFIX);
    String[] dim2Fields = parts[5].split(Instruction.LITERAL_PREFIX);
    CPOperand out = new CPOperand(parts[6]);
    boolean ignoreZeros = Boolean.parseBoolean(parts[7]);
    // ctable does not require any operator, so we simply pass-in a dummy operator with null functionobject
    return new CtableSPInstruction(new SimpleOperator(null), in1, in2, in3, out, dim1Fields[0], Boolean.parseBoolean(dim1Fields[1]), dim2Fields[0], Boolean.parseBoolean(dim2Fields[1]), isExpand, ignoreZeros, opcode, inst);
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 59 with CPOperand

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

the class CumulativeAggregateSPInstruction method parseInstruction.

public static CumulativeAggregateSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 2);
    String opcode = parts[0];
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand out = new CPOperand(parts[2]);
    AggregateUnaryOperator aggun = InstructionUtils.parseCumulativeAggregateUnaryOperator(opcode);
    return new CumulativeAggregateSPInstruction(aggun, in1, out, opcode, str);
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand)

Example 60 with CPOperand

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

the class IndexingSPInstruction method parseInstruction.

public static IndexingSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(RightIndex.OPCODE)) {
        if (parts.length == 8) {
            CPOperand in = new CPOperand(parts[1]);
            CPOperand rl = new CPOperand(parts[2]);
            CPOperand ru = new CPOperand(parts[3]);
            CPOperand cl = new CPOperand(parts[4]);
            CPOperand cu = new CPOperand(parts[5]);
            CPOperand out = new CPOperand(parts[6]);
            SparkAggType aggtype = SparkAggType.valueOf(parts[7]);
            if (in.getDataType() == DataType.MATRIX)
                return new MatrixIndexingSPInstruction(new SimpleOperator(null), in, rl, ru, cl, cu, out, aggtype, opcode, str);
            else
                return new FrameIndexingSPInstruction(new SimpleOperator(null), in, rl, ru, cl, cu, out, aggtype, opcode, str);
        } else {
            throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
        }
    } else if (opcode.equalsIgnoreCase(LeftIndex.OPCODE) || opcode.equalsIgnoreCase("mapLeftIndex")) {
        if (parts.length == 9) {
            CPOperand lhsInput = new CPOperand(parts[1]);
            CPOperand rhsInput = new CPOperand(parts[2]);
            CPOperand rl = new CPOperand(parts[3]);
            CPOperand ru = new CPOperand(parts[4]);
            CPOperand cl = new CPOperand(parts[5]);
            CPOperand cu = new CPOperand(parts[6]);
            CPOperand out = new CPOperand(parts[7]);
            LixCacheType lixtype = LixCacheType.valueOf(parts[8]);
            if (lhsInput.getDataType() == DataType.MATRIX)
                return new MatrixIndexingSPInstruction(new SimpleOperator(null), lhsInput, rhsInput, rl, ru, cl, cu, out, lixtype, opcode, str);
            else
                return new FrameIndexingSPInstruction(new SimpleOperator(null), lhsInput, rhsInput, rl, ru, cl, cu, out, opcode, str);
        } else {
            throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
        }
    } else {
        throw new DMLRuntimeException("Unknown opcode while parsing a IndexingSPInstruction: " + str);
    }
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) SparkAggType(org.apache.sysml.hops.AggBinaryOp.SparkAggType) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) LixCacheType(org.apache.sysml.lops.LeftIndex.LixCacheType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

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