Search in sources :

Example 31 with ScalarObject

use of org.apache.sysml.runtime.instructions.cp.ScalarObject in project systemml by apache.

the class ExternalFunctionInvocationInstruction method verifyAndAttachOutputs.

private void verifyAndAttachOutputs(ExecutionContext ec, PackageFunction fun, CPOperand[] outputs) {
    for (int i = 0; i < outputs.length; i++) {
        CPOperand output = outputs[i];
        switch(fun.getFunctionOutput(i).getType()) {
            case Matrix:
                Matrix m = (Matrix) fun.getFunctionOutput(i);
                MatrixObject newVar = createOutputMatrixObject(m);
                ec.setVariable(output.getName(), newVar);
                break;
            case Scalar:
                Scalar s = (Scalar) fun.getFunctionOutput(i);
                ScalarObject scalarObject = null;
                switch(s.getScalarType()) {
                    case Integer:
                        scalarObject = new IntObject(Long.parseLong(s.getValue()));
                        break;
                    case Double:
                        scalarObject = new DoubleObject(Double.parseDouble(s.getValue()));
                        break;
                    case Boolean:
                        scalarObject = new BooleanObject(Boolean.parseBoolean(s.getValue()));
                        break;
                    case Text:
                        scalarObject = new StringObject(s.getValue());
                        break;
                    default:
                        throw new DMLRuntimeException("Unknown scalar value type '" + s.getScalarType() + "' of output '" + output.getName() + "'.");
                }
                ec.setVariable(output.getName(), scalarObject);
                break;
            default:
                throw new DMLRuntimeException("Unsupported data type: " + fun.getFunctionOutput(i).getType().name());
        }
    }
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) StringObject(org.apache.sysml.runtime.instructions.cp.StringObject) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) BooleanObject(org.apache.sysml.runtime.instructions.cp.BooleanObject) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 32 with ScalarObject

use of org.apache.sysml.runtime.instructions.cp.ScalarObject in project systemml by apache.

the class ScalarMatrixArithmeticGPUInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    GPUStatistics.incrementNoOfExecutedGPUInst();
    CPOperand mat = (_input1.getDataType() == DataType.MATRIX) ? _input1 : _input2;
    CPOperand scalar = (_input1.getDataType() == DataType.MATRIX) ? _input2 : _input1;
    MatrixObject in1 = getMatrixInputForGPUInstruction(ec, mat.getName());
    ScalarObject constant = (ScalarObject) ec.getScalarInput(scalar.getName(), scalar.getValueType(), scalar.isLiteral());
    boolean isTransposed = false;
    int rlen = isTransposed ? (int) in1.getNumColumns() : (int) in1.getNumRows();
    int clen = isTransposed ? (int) in1.getNumRows() : (int) in1.getNumColumns();
    ec.setMetaData(_output.getName(), rlen, clen);
    ScalarOperator sc_op = (ScalarOperator) _optr;
    sc_op = sc_op.setConstant(constant.getDoubleValue());
    LibMatrixCUDA.matrixScalarArithmetic(ec, ec.getGPUContext(0), getExtendedOpcode(), in1, _output.getName(), isTransposed, sc_op);
    ec.releaseMatrixInputForGPUInstruction(mat.getName());
    ec.releaseMatrixOutputForGPUInstruction(_output.getName());
}
Also used : ScalarOperator(org.apache.sysml.runtime.matrix.operators.ScalarOperator) ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand)

Example 33 with ScalarObject

use of org.apache.sysml.runtime.instructions.cp.ScalarObject in project systemml by apache.

the class BinarySPInstruction method processMatrixScalarBinaryInstruction.

protected void processMatrixScalarBinaryInstruction(ExecutionContext ec) {
    SparkExecutionContext sec = (SparkExecutionContext) ec;
    // get input RDD
    String rddVar = (input1.getDataType() == DataType.MATRIX) ? input1.getName() : input2.getName();
    JavaPairRDD<MatrixIndexes, MatrixBlock> in1 = sec.getBinaryBlockRDDHandleForVariable(rddVar);
    // get operator and scalar
    CPOperand scalar = (input1.getDataType() == DataType.MATRIX) ? input2 : input1;
    ScalarObject constant = (ScalarObject) ec.getScalarInput(scalar.getName(), scalar.getValueType(), scalar.isLiteral());
    ScalarOperator sc_op = (ScalarOperator) _optr;
    sc_op = sc_op.setConstant(constant.getDoubleValue());
    // execute scalar matrix arithmetic instruction
    JavaPairRDD<MatrixIndexes, MatrixBlock> out = in1.mapValues(new MatrixScalarUnaryFunction(sc_op));
    // put output RDD handle into symbol table
    updateUnaryOutputMatrixCharacteristics(sec, rddVar, output.getName());
    sec.setRDDHandleForVariable(output.getName(), out);
    sec.addLineageRDD(output.getName(), rddVar);
}
Also used : ScalarOperator(org.apache.sysml.runtime.matrix.operators.ScalarOperator) ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixScalarUnaryFunction(org.apache.sysml.runtime.instructions.spark.functions.MatrixScalarUnaryFunction) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)

Example 34 with ScalarObject

use of org.apache.sysml.runtime.instructions.cp.ScalarObject in project systemml by apache.

the class MatrixMatrixAxpyGPUInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    GPUStatistics.incrementNoOfExecutedGPUInst();
    MatrixObject in1 = getMatrixInputForGPUInstruction(ec, _input1.getName());
    MatrixObject in2 = getMatrixInputForGPUInstruction(ec, _input2.getName());
    ScalarObject scalar = ec.getScalarInput(constant.getName(), constant.getValueType(), constant.isLiteral());
    long rlen1 = in1.getNumRows();
    long clen1 = in1.getNumColumns();
    long rlen2 = in2.getNumRows();
    long clen2 = in2.getNumColumns();
    if (isValidMMOperation(rlen1, rlen2, clen1, clen2) || isValidMVOperation(rlen1, rlen2, clen1, clen2)) {
        ec.setMetaData(_output.getName(), (int) rlen1, (int) clen1);
    } else {
        throw new DMLRuntimeException("Incorrect dimensions of inputs in GPU axpy operation. input1:" + rlen1 + " X " + clen1 + " and input2:" + rlen2 + " X " + clen2);
    }
    LibMatrixCUDA.axpy(ec, ec.getGPUContext(0), getExtendedOpcode(), in1, in2, _output.getName(), multiplier * scalar.getDoubleValue());
    ec.releaseMatrixInputForGPUInstruction(_input1.getName());
    ec.releaseMatrixInputForGPUInstruction(_input2.getName());
    ec.releaseMatrixOutputForGPUInstruction(_output.getName());
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 35 with ScalarObject

use of org.apache.sysml.runtime.instructions.cp.ScalarObject in project systemml by apache.

the class ProgramConverter method serializeDataObject.

public static String serializeDataObject(String key, Data dat) {
    // SCHEMA: <name>|<datatype>|<valuetype>|value
    // (scalars are serialize by value, matrices by filename)
    StringBuilder sb = new StringBuilder();
    // prepare data for serialization
    String name = key;
    DataType datatype = dat.getDataType();
    ValueType valuetype = dat.getValueType();
    String value = null;
    String[] matrixMetaData = null;
    switch(datatype) {
        case SCALAR:
            ScalarObject so = (ScalarObject) dat;
            // name = so.getName();
            value = so.getStringValue();
            break;
        case MATRIX:
            MatrixObject mo = (MatrixObject) dat;
            MetaDataFormat md = (MetaDataFormat) dat.getMetaData();
            MatrixCharacteristics mc = md.getMatrixCharacteristics();
            value = mo.getFileName();
            PartitionFormat partFormat = (mo.getPartitionFormat() != null) ? new PartitionFormat(mo.getPartitionFormat(), mo.getPartitionSize()) : PartitionFormat.NONE;
            matrixMetaData = new String[9];
            matrixMetaData[0] = String.valueOf(mc.getRows());
            matrixMetaData[1] = String.valueOf(mc.getCols());
            matrixMetaData[2] = String.valueOf(mc.getRowsPerBlock());
            matrixMetaData[3] = String.valueOf(mc.getColsPerBlock());
            matrixMetaData[4] = String.valueOf(mc.getNonZeros());
            matrixMetaData[5] = InputInfo.inputInfoToString(md.getInputInfo());
            matrixMetaData[6] = OutputInfo.outputInfoToString(md.getOutputInfo());
            matrixMetaData[7] = String.valueOf(partFormat);
            matrixMetaData[8] = String.valueOf(mo.getUpdateType());
            break;
        default:
            throw new DMLRuntimeException("Unable to serialize datatype " + datatype);
    }
    // serialize data
    sb.append(name);
    sb.append(DATA_FIELD_DELIM);
    sb.append(datatype);
    sb.append(DATA_FIELD_DELIM);
    sb.append(valuetype);
    sb.append(DATA_FIELD_DELIM);
    sb.append(value);
    if (matrixMetaData != null)
        for (int i = 0; i < matrixMetaData.length; i++) {
            sb.append(DATA_FIELD_DELIM);
            sb.append(matrixMetaData[i]);
        }
    return sb.toString();
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) MetaDataFormat(org.apache.sysml.runtime.matrix.MetaDataFormat) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) ValueType(org.apache.sysml.parser.Expression.ValueType) DataType(org.apache.sysml.parser.Expression.DataType) PartitionFormat(org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PartitionFormat) PDataPartitionFormat(org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PDataPartitionFormat) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)42 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)23 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)17 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)14 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)12 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)12 LiteralOp (org.apache.sysml.hops.LiteralOp)11 IntObject (org.apache.sysml.runtime.instructions.cp.IntObject)10 DataOp (org.apache.sysml.hops.DataOp)9 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)9 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)8 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)8 Data (org.apache.sysml.runtime.instructions.cp.Data)7 ArrayList (java.util.ArrayList)6 UnaryOp (org.apache.sysml.hops.UnaryOp)6 BooleanObject (org.apache.sysml.runtime.instructions.cp.BooleanObject)6 StringObject (org.apache.sysml.runtime.instructions.cp.StringObject)6 MetaDataFormat (org.apache.sysml.runtime.matrix.MetaDataFormat)6 ScalarOperator (org.apache.sysml.runtime.matrix.operators.ScalarOperator)6 Hop (org.apache.sysml.hops.Hop)5