Search in sources :

Example 41 with CPOperand

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

the class BuiltinUnaryGPUInstruction method parseInstruction.

public static BuiltinUnaryGPUInstruction 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 = null;
    // print or stop or cumulative aggregates
    if (parts.length == 4) {
        throw new DMLRuntimeException("The instruction is not supported on GPU:" + str);
    } else // 2+1, general case
    {
        InstructionUtils.checkNumFields(str, 2);
        opcode = parts[0];
        in.split(parts[1]);
        out.split(parts[2]);
        if (in.getDataType() == DataType.SCALAR)
            throw new DMLRuntimeException("The instruction is not supported on GPU:" + str);
        else if (in.getDataType() == DataType.MATRIX)
            return new MatrixBuiltinGPUInstruction(null, in, out, opcode, str);
    }
    return null;
}
Also used : CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 42 with CPOperand

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

the class ConvolutionGPUInstruction method parseInstruction.

public static ConvolutionGPUInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if ((opcode.equalsIgnoreCase("conv2d") || opcode.equalsIgnoreCase("conv2d_backward_filter") || opcode.equalsIgnoreCase("conv2d_backward_data"))) {
        InstructionUtils.checkNumFields(parts, 16);
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(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 ConvolutionGPUInstruction(in1, in2, out, opcode, str, stride, padding, input_shape, filter_shape, Double.parseDouble(parts[16]));
    } else if (opcode.equalsIgnoreCase("maxpooling_backward") || opcode.equalsIgnoreCase("avgpooling_backward")) {
        boolean withMaxPoolOut = false;
        if (parts.length == 18) {
            withMaxPoolOut = true;
        } else
            InstructionUtils.checkNumFields(parts, 16);
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand in3 = withMaxPoolOut ? new CPOperand(parts[15]) : null;
        CPOperand out = withMaxPoolOut ? new CPOperand(parts[16]) : new CPOperand(parts[15]);
        double memBudget = withMaxPoolOut ? Double.parseDouble(parts[17]) : Double.parseDouble(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[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 ConvolutionGPUInstruction(in1, in2, in3, out, opcode, str, stride, padding, input_shape, filter_shape, memBudget);
    } else if (opcode.equalsIgnoreCase("conv2d_bias_add")) {
        InstructionUtils.checkNumFields(parts, 17);
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand in3 = new CPOperand(parts[3]);
        CPOperand out = new CPOperand(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 ConvolutionGPUInstruction(in1, in2, in3, out, opcode, str, stride, padding, input_shape, filter_shape, Double.parseDouble(parts[17]));
    } else if (opcode.equalsIgnoreCase("maxpooling") || opcode.equalsIgnoreCase("avgpooling")) {
        InstructionUtils.checkNumFields(parts, 15);
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand out = new CPOperand(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 ConvolutionGPUInstruction(in1, null, out, opcode, str, stride, padding, input_shape, filter_shape, Double.parseDouble(parts[15]));
    } else if (opcode.equalsIgnoreCase("bias_add") || opcode.equalsIgnoreCase("relu_backward") || opcode.equalsIgnoreCase("bias_multiply")) {
        InstructionUtils.checkNumFields(parts, 4);
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(parts[3]);
        return new ConvolutionGPUInstruction(in1, in2, out, opcode, str, Double.parseDouble(parts[4]));
    } else if (opcode.equalsIgnoreCase("channel_sums")) {
        InstructionUtils.checkNumFields(parts, 4);
        CPOperand in = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand in3 = new CPOperand(parts[3]);
        CPOperand out = new CPOperand(parts[4]);
        return new ConvolutionGPUInstruction(in, in2, in3, out, opcode, str, 0);
    } else {
        throw new DMLRuntimeException("Unknown opcode while parsing a ConvolutionGPUInstruction: " + str);
    }
}
Also used : ArrayList(java.util.ArrayList) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 43 with CPOperand

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

the class MMTSJGPUInstruction method parseInstruction.

public static MMTSJGPUInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 3);
    String opcode = parts[0];
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand out = new CPOperand(parts[2]);
    MMTSJType titype = MMTSJType.valueOf(parts[3]);
    if (!opcode.equalsIgnoreCase("tsmm"))
        throw new DMLRuntimeException("Unknown opcode while parsing an MMTSJGPUInstruction: " + str);
    else
        return new MMTSJGPUInstruction(new Operator(true), in1, titype, out, opcode, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) MMTSJType(org.apache.sysml.lops.MMTSJ.MMTSJType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 44 with CPOperand

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

the class MatrixMatrixAxpyGPUInstruction method parseInstruction.

public static MatrixMatrixAxpyGPUInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 4);
    String opcode = parts[0];
    int multiplier = 1;
    if (opcode.equals("-*"))
        multiplier = -1;
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand constant = new CPOperand(parts[2]);
    if (constant.getDataType() != DataType.SCALAR)
        throw new DMLRuntimeException("Expected second operand to be a scalar");
    CPOperand in2 = new CPOperand(parts[3]);
    CPOperand out = new CPOperand(parts[4]);
    DataType dt1 = in1.getDataType();
    DataType dt2 = in2.getDataType();
    DataType dt3 = out.getDataType();
    Operator operator = (dt1 != dt2) ? InstructionUtils.parseScalarBinaryOperator(opcode, (dt1 == DataType.SCALAR)) : InstructionUtils.parseTernaryOperator(opcode);
    if (dt1 == DataType.MATRIX && dt2 == DataType.MATRIX && dt3 == DataType.MATRIX) {
        return new MatrixMatrixAxpyGPUInstruction(operator, in1, constant, multiplier, in2, out, opcode, str);
    } else if (dt3 == DataType.MATRIX && ((dt1 == DataType.SCALAR && dt2 == DataType.MATRIX) || (dt1 == DataType.MATRIX && dt2 == DataType.SCALAR))) {
        throw new DMLRuntimeException("Unsupported GPU PlusMult/MinusMult ArithmeticInstruction.");
    // return new ScalarMatrixArithmeticGPUInstruction(operator, in1, in2, out, opcode, str);
    } else
        throw new DMLRuntimeException("Unsupported GPU ArithmeticInstruction.");
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) DataType(org.apache.sysml.parser.Expression.DataType) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 45 with CPOperand

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

the class RelationalBinaryGPUInstruction method parseInstruction.

public static RelationalBinaryGPUInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 3);
    String opcode = parts[0];
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand in2 = new CPOperand(parts[2]);
    CPOperand out = new CPOperand(parts[3]);
    Expression.DataType dt1 = in1.getDataType();
    Expression.DataType dt2 = in2.getDataType();
    Expression.DataType dt3 = out.getDataType();
    Operator operator = (dt1 != dt2) ? InstructionUtils.parseScalarBinaryOperator(opcode, (dt1 == Expression.DataType.SCALAR)) : InstructionUtils.parseBinaryOperator(opcode);
    if (dt1 == Expression.DataType.MATRIX && dt2 == Expression.DataType.MATRIX && dt3 == Expression.DataType.MATRIX) {
        return new MatrixMatrixRelationalBinaryGPUInstruction(operator, in1, in2, out, opcode, str);
    } else if (dt3 == Expression.DataType.MATRIX && ((dt1 == Expression.DataType.SCALAR && dt2 == Expression.DataType.MATRIX) || (dt1 == Expression.DataType.MATRIX && dt2 == Expression.DataType.SCALAR))) {
        return new ScalarMatrixRelationalBinaryGPUInstruction(operator, in1, in2, out, opcode, str);
    } else
        throw new DMLRuntimeException("Unsupported GPU RelationalBinaryGPUInstruction.");
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) Expression(org.apache.sysml.parser.Expression) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) 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