use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class ReblockInstruction method parseInstruction.
public static ReblockInstruction parseInstruction(String str) {
Operator op = null;
byte input, output;
String[] s = str.split(Instruction.OPERAND_DELIM);
String[] in1f = s[2].split(Instruction.DATATYPE_PREFIX);
input = Byte.parseByte(in1f[0]);
String[] outf = s[3].split(Instruction.DATATYPE_PREFIX);
output = Byte.parseByte(outf[0]);
int brlen = Integer.parseInt(s[4]);
int bclen = Integer.parseInt(s[5]);
boolean outputEmptyBlocks = Boolean.parseBoolean(s[6]);
return new ReblockInstruction(op, input, output, brlen, bclen, outputEmptyBlocks, str);
}
use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class GroupedAggregateInstruction method parseInstruction.
public static GroupedAggregateInstruction parseInstruction(String str) throws DMLRuntimeException {
String[] parts = InstructionUtils.getInstructionParts(str);
if (parts.length < 3)
throw new DMLRuntimeException("the number of fields of instruction " + str + " is less than 2!");
byte in, out;
String opcode = parts[0];
in = Byte.parseByte(parts[1]);
out = Byte.parseByte(parts[parts.length - 3]);
boolean weights = Boolean.parseBoolean(parts[parts.length - 2]);
int ngroups = Integer.parseInt(parts[parts.length - 1]);
if (!opcode.equalsIgnoreCase("groupedagg")) {
throw new DMLRuntimeException("Invalid opcode in GroupedAggregateInstruction: " + opcode);
}
Operator optr = parseGroupedAggOperator(parts[2], parts[3]);
return new GroupedAggregateInstruction(optr, in, out, weights, ngroups, str);
}
use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class ArithmeticBinaryGPUInstruction method parseInstruction.
public static ArithmeticBinaryGPUInstruction parseInstruction(String str) throws DMLRuntimeException {
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.matrix.operators.Operator in project incubator-systemml by apache.
the class AggregateUnaryGPUInstruction method parseInstruction.
public static AggregateUnaryGPUInstruction parseInstruction(String str) throws DMLRuntimeException {
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.matrix.operators.Operator in project incubator-systemml by apache.
the class ParameterizedBuiltinCPInstruction method parseInstruction.
public static ParameterizedBuiltinCPInstruction parseInstruction(String str) throws DMLRuntimeException {
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("cdf")) {
if (paramsMap.get("dist") == null)
throw new DMLRuntimeException("Invalid distribution: " + str);
func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode, paramsMap.get("dist"));
// Determine appropriate Function Object based on opcode
return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
} else if (opcode.equalsIgnoreCase("invcdf")) {
if (paramsMap.get("dist") == null)
throw new DMLRuntimeException("Invalid distribution: " + str);
func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode, paramsMap.get("dist"));
// Determine appropriate Function Object based on opcode
return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
} else if (opcode.equalsIgnoreCase("groupedagg")) {
// check for mandatory arguments
String fnStr = paramsMap.get("fn");
if (fnStr == null)
throw new DMLRuntimeException("Function parameter is missing in groupedAggregate.");
if (fnStr.equalsIgnoreCase("centralmoment")) {
if (paramsMap.get("order") == null)
throw new DMLRuntimeException("Mandatory \"order\" must be specified when fn=\"centralmoment\" in groupedAggregate.");
}
Operator op = GroupedAggregateInstruction.parseGroupedAggOperator(fnStr, paramsMap.get("order"));
return new ParameterizedBuiltinCPInstruction(op, paramsMap, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rmempty") || opcode.equalsIgnoreCase("replace") || opcode.equalsIgnoreCase("rexpand")) {
func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
} else if (opcode.equals("transform") || opcode.equals("transformapply") || opcode.equals("transformdecode") || opcode.equals("transformmeta")) {
return new ParameterizedBuiltinCPInstruction(null, paramsMap, out, opcode, str);
} else if (opcode.equals("toString")) {
return new ParameterizedBuiltinCPInstruction(null, paramsMap, out, opcode, str);
} else {
throw new DMLRuntimeException("Unknown opcode (" + opcode + ") for ParameterizedBuiltin Instruction.");
}
}
Aggregations