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