Search in sources :

Example 1 with CPOperand

use of org.apache.sysml.runtime.instructions.cp.CPOperand 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 CPOperand

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

the class RandSPInstruction method parseInstruction.

public static RandSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] s = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = s[0];
    DataGenMethod method = DataGenMethod.INVALID;
    if (opcode.equalsIgnoreCase(DataGen.RAND_OPCODE)) {
        method = DataGenMethod.RAND;
        InstructionUtils.checkNumFields(str, 12);
    } else if (opcode.equalsIgnoreCase(DataGen.SEQ_OPCODE)) {
        method = DataGenMethod.SEQ;
        // 8 operands: rows, cols, rpb, cpb, from, to, incr, outvar
        InstructionUtils.checkNumFields(str, 8);
    } else if (opcode.equalsIgnoreCase(DataGen.SAMPLE_OPCODE)) {
        method = DataGenMethod.SAMPLE;
        // 7 operands: range, size, replace, seed, rpb, cpb, outvar
        InstructionUtils.checkNumFields(str, 7);
    }
    Operator op = null;
    // output is specified by the last operand
    CPOperand out = new CPOperand(s[s.length - 1]);
    if (method == DataGenMethod.RAND) {
        long rows = -1, cols = -1;
        if (!s[1].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            rows = Double.valueOf(s[1]).longValue();
        }
        if (!s[2].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            cols = Double.valueOf(s[2]).longValue();
        }
        int rpb = Integer.parseInt(s[3]);
        int cpb = Integer.parseInt(s[4]);
        double minValue = -1, maxValue = -1;
        if (!s[5].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            minValue = Double.valueOf(s[5]).doubleValue();
        }
        if (!s[6].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            maxValue = Double.valueOf(s[6]).doubleValue();
        }
        double sparsity = -1;
        if (!s[7].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            sparsity = Double.valueOf(s[7]);
        }
        long seed = DataGenOp.UNSPECIFIED_SEED;
        if (!s[8].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            seed = Long.parseLong(s[8]);
        }
        String dir = s[9];
        String pdf = s[10];
        String pdfParams = s[11];
        return new RandSPInstruction(op, method, null, out, rows, cols, rpb, cpb, minValue, maxValue, sparsity, seed, dir, pdf, pdfParams, opcode, str);
    } else if (method == DataGenMethod.SEQ) {
        // Example Instruction: CP:seq:11:1:1000:1000:1:0:-0.1:scratch_space/_p7932_192.168.1.120//_t0/:mVar1
        long rows = Double.valueOf(s[1]).longValue();
        long cols = Double.valueOf(s[2]).longValue();
        int rpb = Integer.parseInt(s[3]);
        int cpb = Integer.parseInt(s[4]);
        double from, to, incr;
        from = to = incr = Double.NaN;
        if (!s[5].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            from = Double.valueOf(s[5]);
        }
        if (!s[6].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            to = Double.valueOf(s[6]);
        }
        if (!s[7].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            incr = Double.valueOf(s[7]);
        }
        CPOperand in = null;
        return new RandSPInstruction(op, method, in, out, rows, cols, rpb, cpb, from, to, incr, opcode, str);
    } else if (method == DataGenMethod.SAMPLE) {
        // Example Instruction: SPARK:sample:10:100:false:1000:1000:_mVar2·MATRIX·DOUBLE
        double max = 0;
        long rows = 0, cols;
        boolean replace = false;
        if (!s[1].contains(Lop.VARIABLE_NAME_PLACEHOLDER))
            max = Double.valueOf(s[1]);
        if (!s[2].contains(Lop.VARIABLE_NAME_PLACEHOLDER))
            rows = Double.valueOf(s[2]).longValue();
        cols = 1;
        if (!s[3].contains(Lop.VARIABLE_NAME_PLACEHOLDER))
            replace = Boolean.valueOf(s[3]);
        long seed = Long.parseLong(s[4]);
        int rpb = Integer.parseInt(s[5]);
        int cpb = Integer.parseInt(s[6]);
        return new RandSPInstruction(op, method, null, out, rows, cols, rpb, cpb, max, replace, seed, opcode, str);
    } else
        throw new DMLRuntimeException("Unrecognized data generation method: " + method);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DataGenMethod(org.apache.sysml.hops.Hop.DataGenMethod) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 3 with CPOperand

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

the class Tsmm2SPInstruction method parseInstruction.

public static Tsmm2SPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    //check supported opcode 
    if (!opcode.equalsIgnoreCase("tsmm2")) {
        throw new DMLRuntimeException("Tsmm2SPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand out = new CPOperand(parts[2]);
    MMTSJType type = MMTSJType.valueOf(parts[3]);
    return new Tsmm2SPInstruction(null, in1, out, type, opcode, str);
}
Also used : CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) MMTSJType(org.apache.sysml.lops.MMTSJ.MMTSJType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 4 with CPOperand

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

the class QuantileSortSPInstruction method parseInstruction.

public static QuantileSortSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = null;
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(SortKeys.OPCODE)) {
        if (parts.length == 3) {
            // Example: sort:mVar1:mVar2 (input=mVar1, output=mVar2)
            parseUnaryInstruction(str, in1, out);
            return new QuantileSortSPInstruction(new SimpleOperator(null), in1, out, opcode, str);
        } else if (parts.length == 4) {
            // Example: sort:mVar1:mVar2:mVar3 (input=mVar1, weights=mVar2, output=mVar3)
            in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
            parseUnaryInstruction(str, in1, in2, out);
            return new QuantileSortSPInstruction(new SimpleOperator(null), in1, in2, out, opcode, str);
        } else {
            throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
        }
    } else {
        throw new DMLRuntimeException("Unknown opcode while parsing a SortSPInstruction: " + str);
    }
}
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 5 with CPOperand

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

the class SpoofSPInstruction method parseInstruction.

public static SpoofSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    //String opcode = parts[0];
    ArrayList<CPOperand> inlist = new ArrayList<CPOperand>();
    Class<?> cls = CodegenUtils.getClass(parts[1]);
    byte[] classBytes = CodegenUtils.getClassData(parts[1]);
    String opcode = parts[0] + CodegenUtils.createInstance(cls).getSpoofType();
    for (int i = 2; i < parts.length - 2; i++) inlist.add(new CPOperand(parts[i]));
    CPOperand out = new CPOperand(parts[parts.length - 2]);
    return new SpoofSPInstruction(cls, classBytes, inlist.toArray(new CPOperand[0]), out, opcode, str);
}
Also used : ArrayList(java.util.ArrayList) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand)

Aggregations

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