Search in sources :

Example 16 with CPOperand

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

the class ParameterizedBuiltinCPFileInstruction method parseInstruction.

public static ParameterizedBuiltinCPFileInstruction parseInstruction(String str) {
    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("rmempty")) {
        func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
        return new ParameterizedBuiltinCPFileInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
    } else {
        throw new DMLRuntimeException("Unknown opcode (" + opcode + ") for ParameterizedBuiltin Instruction.");
    }
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 17 with CPOperand

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

the class AggregateUnaryGPUInstruction method parseInstruction.

public static AggregateUnaryGPUInstruction parseInstruction(String str) {
    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 18 with CPOperand

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

the class ArithmeticBinaryGPUInstruction method parseInstruction.

public static ArithmeticBinaryGPUInstruction 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]);
    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 19 with CPOperand

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

the class MatrixAppendGPUInstruction method parseInstruction.

public static MatrixAppendGPUInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 5);
    String opcode = parts[0];
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand in2 = new CPOperand(parts[2]);
    @SuppressWarnings("unused") CPOperand in3 = new CPOperand(parts[3]);
    CPOperand out = new CPOperand(parts[4]);
    boolean cbind = Boolean.parseBoolean(parts[5]);
    AppendCPInstruction.AppendType type = (in1.getDataType() != Expression.DataType.MATRIX && in1.getDataType() != Expression.DataType.FRAME) ? AppendCPInstruction.AppendType.STRING : cbind ? AppendCPInstruction.AppendType.CBIND : AppendCPInstruction.AppendType.RBIND;
    if (in1.getDataType() != Expression.DataType.MATRIX || in2.getDataType() != Expression.DataType.MATRIX) {
        throw new DMLRuntimeException("GPU : Error in internal state - Append was called on data other than matrices");
    }
    if (!opcode.equalsIgnoreCase("append"))
        throw new DMLRuntimeException("Unknown opcode while parsing a AppendCPInstruction: " + str);
    Operator op = new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1));
    return new MatrixAppendGPUInstruction(op, in1, in2, out, type, opcode, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) AppendCPInstruction(org.apache.sysml.runtime.instructions.cp.AppendCPInstruction) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 20 with CPOperand

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

the class MatrixIndexingGPUInstruction method parseInstruction.

public static MatrixIndexingGPUInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(RightIndex.OPCODE)) {
        if (parts.length == 7) {
            CPOperand in, rl, ru, cl, cu, out;
            in = new CPOperand(parts[1]);
            rl = new CPOperand(parts[2]);
            ru = new CPOperand(parts[3]);
            cl = new CPOperand(parts[4]);
            cu = new CPOperand(parts[5]);
            out = new CPOperand(parts[6]);
            if (in.getDataType() == DataType.MATRIX)
                return new MatrixIndexingGPUInstruction(new SimpleOperator(null), in, rl, ru, cl, cu, out, opcode, str);
            else
                throw new DMLRuntimeException("Can index only on Matrices in GPU");
        } else {
            throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
        }
    } else if (opcode.equalsIgnoreCase(LeftIndex.OPCODE)) {
        if (parts.length == 8) {
            CPOperand lhsInput, rhsInput, rl, ru, cl, cu, out;
            lhsInput = new CPOperand();
            rhsInput = new CPOperand();
            rl = new CPOperand();
            ru = new CPOperand();
            cl = new CPOperand();
            cu = new CPOperand();
            out = new CPOperand();
            lhsInput.split(parts[1]);
            rhsInput.split(parts[2]);
            rl.split(parts[3]);
            ru.split(parts[4]);
            cl.split(parts[5]);
            cu.split(parts[6]);
            out.split(parts[7]);
            if (lhsInput.getDataType() == DataType.MATRIX)
                return new MatrixIndexingGPUInstruction(new SimpleOperator(null), lhsInput, rhsInput, rl, ru, cl, cu, out, opcode, str);
            else
                throw new DMLRuntimeException("Can index only on Matrices in GPU");
        } else {
            throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
        }
    } else {
        throw new DMLRuntimeException("Unknown opcode while parsing a MatrixIndexingGPUInstruction: " + 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)

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