Search in sources :

Example 1 with VectorType

use of org.apache.sysml.lops.BinaryM.VectorType in project incubator-systemml by apache.

the class RelationalBinarySPInstruction method parseInstruction.

public static RelationalBinarySPInstruction parseInstruction(String str) throws DMLRuntimeException {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String opcode = null;
    boolean isBroadcast = false;
    VectorType vtype = null;
    if (str.startsWith("SPARK" + Lop.OPERAND_DELIMITOR + "map")) {
        String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
        InstructionUtils.checkNumFields(parts, 5);
        opcode = parts[0];
        in1.split(parts[1]);
        in2.split(parts[2]);
        out.split(parts[3]);
        vtype = VectorType.valueOf(parts[5]);
        isBroadcast = true;
    } else {
        InstructionUtils.checkNumFields(str, 3);
        opcode = parseBinaryInstruction(str, in1, in2, out);
    }
    DataType dt1 = in1.getDataType();
    DataType dt2 = in2.getDataType();
    Operator operator = (dt1 != dt2) ? InstructionUtils.parseScalarBinaryOperator(opcode, (dt1 == DataType.SCALAR)) : InstructionUtils.parseExtendedBinaryOperator(opcode);
    if (dt1 == DataType.MATRIX || dt2 == DataType.MATRIX) {
        if (dt1 == DataType.MATRIX && dt2 == DataType.MATRIX) {
            if (isBroadcast)
                return new MatrixBVectorRelationalSPInstruction(operator, in1, in2, out, vtype, opcode, str);
            else
                return new MatrixMatrixRelationalSPInstruction(operator, in1, in2, out, opcode, str);
        } else
            return new MatrixScalarRelationalSPInstruction(operator, in1, in2, out, opcode, str);
    }
    return null;
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) VectorType(org.apache.sysml.lops.BinaryM.VectorType) DataType(org.apache.sysml.parser.Expression.DataType) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand)

Example 2 with VectorType

use of org.apache.sysml.lops.BinaryM.VectorType in project incubator-systemml by apache.

the class BuiltinBinarySPInstruction method parseInstruction.

public static BuiltinBinarySPInstruction parseInstruction(String str) throws DMLRuntimeException {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String opcode = null;
    boolean isBroadcast = false;
    VectorType vtype = null;
    ValueFunction func = null;
    if (//map builtin function
    str.startsWith("SPARK" + Lop.OPERAND_DELIMITOR + "map")) {
        String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
        InstructionUtils.checkNumFields(parts, 5);
        opcode = parts[0];
        in1.split(parts[1]);
        in2.split(parts[2]);
        out.split(parts[3]);
        func = Builtin.getBuiltinFnObject(opcode.substring(3));
        vtype = VectorType.valueOf(parts[5]);
        isBroadcast = true;
    } else //default builtin function
    {
        opcode = parseBinaryInstruction(str, in1, in2, out);
        func = Builtin.getBuiltinFnObject(opcode);
    }
    //sanity check value function
    if (func == null)
        throw new DMLRuntimeException("Failed to create builtin value function for opcode: " + opcode);
    // Determine appropriate Function Object based on opcode			
    if (//MATRIX-SCALAR
    in1.getDataType() != in2.getDataType()) {
        return new MatrixScalarBuiltinSPInstruction(new RightScalarOperator(func, 0), in1, in2, out, opcode, str);
    } else //MATRIX-MATRIX 
    {
        if (isBroadcast)
            return new MatrixBVectorBuiltinSPInstruction(new BinaryOperator(func), in1, in2, out, vtype, opcode, str);
        else
            return new MatrixMatrixBuiltinSPInstruction(new BinaryOperator(func), in1, in2, out, opcode, str);
    }
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) VectorType(org.apache.sysml.lops.BinaryM.VectorType) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) RightScalarOperator(org.apache.sysml.runtime.matrix.operators.RightScalarOperator) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 3 with VectorType

use of org.apache.sysml.lops.BinaryM.VectorType in project incubator-systemml by apache.

the class ArithmeticBinarySPInstruction method parseInstruction.

public static ArithmeticBinarySPInstruction parseInstruction(String str) throws DMLRuntimeException {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String opcode = null;
    boolean isBroadcast = false;
    VectorType vtype = null;
    if (str.startsWith("SPARK" + Lop.OPERAND_DELIMITOR + "map")) {
        String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
        InstructionUtils.checkNumFields(parts, 5);
        opcode = parts[0];
        in1.split(parts[1]);
        in2.split(parts[2]);
        out.split(parts[3]);
        vtype = VectorType.valueOf(parts[5]);
        isBroadcast = true;
    } else {
        opcode = parseBinaryInstruction(str, in1, in2, out);
    }
    // Arithmetic operations must be performed on DOUBLE or INT
    DataType dt1 = in1.getDataType();
    DataType dt2 = in2.getDataType();
    Operator operator = (dt1 != dt2) ? InstructionUtils.parseScalarBinaryOperator(opcode, (dt1 == DataType.SCALAR)) : InstructionUtils.parseExtendedBinaryOperator(opcode);
    if (dt1 == DataType.MATRIX || dt2 == DataType.MATRIX) {
        if (dt1 == DataType.MATRIX && dt2 == DataType.MATRIX) {
            if (isBroadcast)
                return new MatrixBVectorArithmeticSPInstruction(operator, in1, in2, out, vtype, opcode, str);
            else
                return new MatrixMatrixArithmeticSPInstruction(operator, in1, in2, out, opcode, str);
        } else
            return new MatrixScalarArithmeticSPInstruction(operator, in1, in2, out, opcode, str);
    }
    return null;
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) VectorType(org.apache.sysml.lops.BinaryM.VectorType) DataType(org.apache.sysml.parser.Expression.DataType) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand)

Example 4 with VectorType

use of org.apache.sysml.lops.BinaryM.VectorType in project incubator-systemml by apache.

the class BinaryMInstruction method parseInstruction.

public static BinaryMInstruction parseInstruction(String str) throws DMLRuntimeException {
    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)

Aggregations

VectorType (org.apache.sysml.lops.BinaryM.VectorType)4 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)3 DataType (org.apache.sysml.parser.Expression.DataType)2 BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)2 Operator (org.apache.sysml.runtime.matrix.operators.Operator)2 CacheType (org.apache.sysml.lops.AppendM.CacheType)1 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)1 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)1 RightScalarOperator (org.apache.sysml.runtime.matrix.operators.RightScalarOperator)1