Search in sources :

Example 6 with Operator

use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.

the class ReblockInstruction method parseInstruction.

public static ReblockInstruction parseInstruction(String str) {
    Operator op = null;
    byte input, output;
    String[] s = str.split(Instruction.OPERAND_DELIM);
    String[] in1f = s[2].split(Instruction.DATATYPE_PREFIX);
    input = Byte.parseByte(in1f[0]);
    String[] outf = s[3].split(Instruction.DATATYPE_PREFIX);
    output = Byte.parseByte(outf[0]);
    int brlen = Integer.parseInt(s[4]);
    int bclen = Integer.parseInt(s[5]);
    boolean outputEmptyBlocks = Boolean.parseBoolean(s[6]);
    return new ReblockInstruction(op, input, output, brlen, bclen, outputEmptyBlocks, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator)

Example 7 with Operator

use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.

the class GroupedAggregateInstruction method parseInstruction.

public static GroupedAggregateInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionParts(str);
    if (parts.length < 3)
        throw new DMLRuntimeException("the number of fields of instruction " + str + " is less than 2!");
    byte in, out;
    String opcode = parts[0];
    in = Byte.parseByte(parts[1]);
    out = Byte.parseByte(parts[parts.length - 3]);
    boolean weights = Boolean.parseBoolean(parts[parts.length - 2]);
    int ngroups = Integer.parseInt(parts[parts.length - 1]);
    if (!opcode.equalsIgnoreCase("groupedagg")) {
        throw new DMLRuntimeException("Invalid opcode in GroupedAggregateInstruction: " + opcode);
    }
    Operator optr = parseGroupedAggOperator(parts[2], parts[3]);
    return new GroupedAggregateInstruction(optr, in, out, weights, ngroups, str);
}
Also used : CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) Operator(org.apache.sysml.runtime.matrix.operators.Operator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 8 with Operator

use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.

the class ArithmeticBinaryGPUInstruction method parseInstruction.

public static ArithmeticBinaryGPUInstruction parseInstruction(String str) throws DMLRuntimeException {
    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]);
    DataType dt1 = in1.getDataType();
    DataType dt2 = in2.getDataType();
    DataType dt3 = out.getDataType();
    Operator operator = (dt1 != dt2) ? InstructionUtils.parseScalarBinaryOperator(opcode, (dt1 == DataType.SCALAR)) : InstructionUtils.parseBinaryOperator(opcode);
    if (dt1 == DataType.MATRIX && dt2 == DataType.MATRIX && dt3 == DataType.MATRIX) {
        return new MatrixMatrixArithmeticGPUInstruction(operator, in1, in2, out, opcode, str);
    } else if (dt3 == DataType.MATRIX && ((dt1 == DataType.SCALAR && dt2 == DataType.MATRIX) || (dt1 == DataType.MATRIX && dt2 == DataType.SCALAR))) {
        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 9 with Operator

use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.

the class AggregateUnaryGPUInstruction method parseInstruction.

public static AggregateUnaryGPUInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand out = new CPOperand(parts[2]);
    // This follows logic similar to AggregateUnaryCPInstruction.
    // nrow, ncol & length should either read or refresh metadata
    Operator aggop = null;
    if (opcode.equalsIgnoreCase("nrow") || opcode.equalsIgnoreCase("ncol") || opcode.equalsIgnoreCase("length")) {
        throw new DMLRuntimeException("nrow, ncol & length should not be compiled as GPU instructions!");
    } else {
        aggop = InstructionUtils.parseBasicAggregateUnaryOperator(opcode);
    }
    return new AggregateUnaryGPUInstruction(aggop, in1, out, opcode, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 10 with Operator

use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.

the class ParameterizedBuiltinCPInstruction method parseInstruction.

public static ParameterizedBuiltinCPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    // first part is always the opcode
    String opcode = parts[0];
    // last part is always the output
    CPOperand out = new CPOperand(parts[parts.length - 1]);
    // process remaining parts and build a hash map
    HashMap<String, String> paramsMap = constructParameterMap(parts);
    // determine the appropriate value function
    ValueFunction func = null;
    if (opcode.equalsIgnoreCase("cdf")) {
        if (paramsMap.get("dist") == null)
            throw new DMLRuntimeException("Invalid distribution: " + str);
        func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode, paramsMap.get("dist"));
        // Determine appropriate Function Object based on opcode
        return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("invcdf")) {
        if (paramsMap.get("dist") == null)
            throw new DMLRuntimeException("Invalid distribution: " + str);
        func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode, paramsMap.get("dist"));
        // Determine appropriate Function Object based on opcode
        return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("groupedagg")) {
        // check for mandatory arguments
        String fnStr = paramsMap.get("fn");
        if (fnStr == null)
            throw new DMLRuntimeException("Function parameter is missing in groupedAggregate.");
        if (fnStr.equalsIgnoreCase("centralmoment")) {
            if (paramsMap.get("order") == null)
                throw new DMLRuntimeException("Mandatory \"order\" must be specified when fn=\"centralmoment\" in groupedAggregate.");
        }
        Operator op = GroupedAggregateInstruction.parseGroupedAggOperator(fnStr, paramsMap.get("order"));
        return new ParameterizedBuiltinCPInstruction(op, paramsMap, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("rmempty") || opcode.equalsIgnoreCase("replace") || opcode.equalsIgnoreCase("rexpand")) {
        func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
        return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
    } else if (opcode.equals("transform") || opcode.equals("transformapply") || opcode.equals("transformdecode") || opcode.equals("transformmeta")) {
        return new ParameterizedBuiltinCPInstruction(null, paramsMap, out, opcode, str);
    } else if (opcode.equals("toString")) {
        return new ParameterizedBuiltinCPInstruction(null, paramsMap, out, opcode, str);
    } else {
        throw new DMLRuntimeException("Unknown opcode (" + opcode + ") for ParameterizedBuiltin Instruction.");
    }
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) Operator(org.apache.sysml.runtime.matrix.operators.Operator) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

Operator (org.apache.sysml.runtime.matrix.operators.Operator)32 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)20 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)10 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)5 DataType (org.apache.sysml.parser.Expression.DataType)4 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)4 MMTSJType (org.apache.sysml.lops.MMTSJ.MMTSJType)3 IOException (java.io.IOException)2 DataGenMethod (org.apache.sysml.hops.Hop.DataGenMethod)2 VectorType (org.apache.sysml.lops.BinaryM.VectorType)2 CM (org.apache.sysml.runtime.functionobjects.CM)2 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)2 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)2 GroupedAggregateInstruction (org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction)2 WeightedCell (org.apache.sysml.runtime.matrix.data.WeightedCell)2 SimpleOperator (org.apache.sysml.runtime.matrix.operators.SimpleOperator)2 HashMap (java.util.HashMap)1 CacheType (org.apache.sysml.lops.PMMJ.CacheType)1 PDataPartitionFormat (org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PDataPartitionFormat)1 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)1