Search in sources :

Example 36 with CPOperand

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

the class ExternalFunctionProgramBlock method createInstructions.

/**
 * method to create instructions
 */
protected void createInstructions() {
    _inst = new ArrayList<>();
    // unblock all input matrices
    block2CellInst = getBlock2CellInstructions(getInputParams(), _unblockedFileNames);
    // assemble information provided through keyvalue pairs
    String className = _otherParams.get(ExternalFunctionStatement.CLASS_NAME);
    String configFile = _otherParams.get(ExternalFunctionStatement.CONFIG_FILE);
    // class name cannot be null, however, configFile and execLocation can be null
    if (className == null)
        throw new RuntimeException(this.printBlockErrorLocation() + ExternalFunctionStatement.CLASS_NAME + " not provided!");
    // assemble input and output operands
    CPOperand[] inputs = getOperands(getInputParams());
    CPOperand[] outputs = getOperands(getOutputParams());
    // generate instruction
    PackageFunction fun = createFunctionObject(className, configFile);
    ExternalFunctionInvocationInstruction einst = new ExternalFunctionInvocationInstruction(inputs, outputs, fun, _baseDir, InputInfo.TextCellInputInfo);
    verifyFunctionInputsOutputs(fun, inputs, outputs);
    if (getInputParams().size() > 0)
        einst.setLocation(getInputParams().get(0));
    else if (getOutputParams().size() > 0)
        einst.setLocation(getOutputParams().get(0));
    else
        einst.setLocation(getFilename(), _beginLine, _endLine, _beginColumn, _endColumn);
    _inst.add(einst);
    // block output matrices
    cell2BlockInst = getCell2BlockInstructions(getOutputParams(), _blockedFileNames);
}
Also used : ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) PackageFunction(org.apache.sysml.udf.PackageFunction)

Example 37 with CPOperand

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

the class ExternalFunctionProgramBlockCP method createInstructions.

@Override
protected void createInstructions() {
    _inst = new ArrayList<>();
    // assemble information provided through keyvalue pairs
    String className = _otherParams.get(ExternalFunctionStatement.CLASS_NAME);
    String configFile = _otherParams.get(ExternalFunctionStatement.CONFIG_FILE);
    // class name cannot be null, however, configFile and execLocation can be null
    if (className == null)
        throw new RuntimeException(this.printBlockErrorLocation() + ExternalFunctionStatement.CLASS_NAME + " not provided!");
    // assemble input and output param strings
    CPOperand[] inputs = getOperands(getInputParams());
    CPOperand[] outputs = getOperands(getOutputParams());
    // generate instruction
    PackageFunction fun = createFunctionObject(className, configFile);
    ExternalFunctionInvocationInstruction einst = new ExternalFunctionInvocationInstruction(inputs, outputs, fun, _baseDir, InputInfo.BinaryBlockInputInfo);
    verifyFunctionInputsOutputs(fun, inputs, outputs);
    _inst.add(einst);
}
Also used : ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) PackageFunction(org.apache.sysml.udf.PackageFunction)

Example 38 with CPOperand

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

the class ExternalFunctionInvocationInstruction method getInputObjects.

@SuppressWarnings("incomplete-switch")
private ArrayList<FunctionParameter> getInputObjects(CPOperand[] inputs, LocalVariableMap vars) {
    ArrayList<FunctionParameter> ret = new ArrayList<>();
    for (CPOperand input : inputs) {
        switch(input.getDataType()) {
            case MATRIX:
                MatrixObject mobj = (MatrixObject) vars.get(input.getName());
                ret.add(new Matrix(mobj, getMatrixValueType(input.getValueType())));
                break;
            case SCALAR:
                ScalarObject so = (ScalarObject) vars.get(input.getName());
                ret.add(new Scalar(getScalarValueType(input.getValueType()), so.getStringValue()));
                break;
            case OBJECT:
                ret.add(new BinaryObject(vars.get(input.getName())));
                break;
        }
    }
    return ret;
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) ArrayList(java.util.ArrayList) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand)

Example 39 with CPOperand

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

the class AggregateBinaryGPUInstruction method parseInstruction.

public static AggregateBinaryGPUInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equalsIgnoreCase("ba+*"))
        throw new DMLRuntimeException("AggregateBinaryInstruction.parseInstruction():: Unknown opcode " + opcode);
    InstructionUtils.checkNumFields(parts, 5);
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand in2 = new CPOperand(parts[2]);
    CPOperand out = new CPOperand(parts[3]);
    boolean isLeftTransposed = Boolean.parseBoolean(parts[4]);
    boolean isRightTransposed = Boolean.parseBoolean(parts[5]);
    AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
    AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg, 1);
    return new AggregateBinaryGPUInstruction(aggbin, in1, in2, out, opcode, str, isLeftTransposed, isRightTransposed);
}
Also used : AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 40 with CPOperand

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

the class BuiltinBinaryGPUInstruction method parseInstruction.

public static BuiltinBinaryGPUInstruction parseInstruction(String str) {
    CPOperand in1 = new CPOperand("", Expression.ValueType.UNKNOWN, Expression.DataType.UNKNOWN);
    CPOperand in2 = new CPOperand("", Expression.ValueType.UNKNOWN, Expression.DataType.UNKNOWN);
    CPOperand out = new CPOperand("", Expression.ValueType.UNKNOWN, Expression.DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 3);
    String opcode = parts[0];
    in1.split(parts[1]);
    in2.split(parts[2]);
    out.split(parts[3]);
    // check for valid data type of output
    if ((in1.getDataType() == Expression.DataType.MATRIX || in2.getDataType() == Expression.DataType.MATRIX) && out.getDataType() != Expression.DataType.MATRIX)
        throw new DMLRuntimeException("Element-wise matrix operations between variables " + in1.getName() + " and " + in2.getName() + " must produce a matrix, which " + out.getName() + " is not");
    // Determine appropriate Function Object based on opcode
    ValueFunction func = Builtin.getBuiltinFnObject(opcode);
    boolean isMatrixMatrix = in1.getDataType() == Expression.DataType.MATRIX && in2.getDataType() == Expression.DataType.MATRIX;
    boolean isMatrixScalar = (in1.getDataType() == Expression.DataType.MATRIX && in2.getDataType() == Expression.DataType.SCALAR) || (in1.getDataType() == Expression.DataType.SCALAR && in2.getDataType() == Expression.DataType.MATRIX);
    if (in1.getDataType() == Expression.DataType.SCALAR && in2.getDataType() == Expression.DataType.SCALAR)
        throw new DMLRuntimeException("GPU : Unsupported GPU builtin operations on 2 scalars");
    else if (isMatrixMatrix && opcode.equals("solve"))
        return new MatrixMatrixBuiltinGPUInstruction(new BinaryOperator(func), in1, in2, out, opcode, str, 2);
    else if (isMatrixScalar && (opcode.equals("min") || opcode.equals("max")))
        return new ScalarMatrixBuiltinGPUInstruction(new BinaryOperator(func), in1, in2, out, opcode, str, 2);
    else
        throw new DMLRuntimeException("GPU : Unsupported GPU builtin operations on a matrix and a scalar:" + opcode);
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) 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