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