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());
}
}
}
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());
}
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);
}
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());
}
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();
}
Aggregations