use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class PmmSPInstruction method parseInstruction.
public static PmmSPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = InstructionUtils.getOpCode(str);
if (opcode.equalsIgnoreCase(PMMJ.OPCODE)) {
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand nrow = new CPOperand(parts[3]);
CPOperand out = new CPOperand(parts[4]);
CacheType type = CacheType.valueOf(parts[5]);
AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
return new PmmSPInstruction(aggbin, in1, in2, out, nrow, type, opcode, str);
} else {
throw new DMLRuntimeException("PmmSPInstruction.parseInstruction():: Unknown opcode " + opcode);
}
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class QuantileSortSPInstruction method parseInstruction.
public static QuantileSortSPInstruction parseInstruction(String str) {
CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand in2 = null;
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
if (opcode.equalsIgnoreCase(SortKeys.OPCODE)) {
if (parts.length == 3) {
// Example: sort:mVar1:mVar2 (input=mVar1, output=mVar2)
parseUnaryInstruction(str, in1, out);
return new QuantileSortSPInstruction(new SimpleOperator(null), in1, out, opcode, str);
} else if (parts.length == 4) {
// Example: sort:mVar1:mVar2:mVar3 (input=mVar1, weights=mVar2, output=mVar3)
in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
parseUnaryInstruction(str, in1, in2, out);
return new QuantileSortSPInstruction(new SimpleOperator(null), in1, in2, out, opcode, str);
} else {
throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
}
} else {
throw new DMLRuntimeException("Unknown opcode while parsing a SortSPInstruction: " + str);
}
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class RandSPInstruction method parseInstruction.
public static RandSPInstruction parseInstruction(String str) {
String[] s = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = s[0];
DataGenMethod method = DataGenMethod.INVALID;
if (opcode.equalsIgnoreCase(DataGen.RAND_OPCODE)) {
method = DataGenMethod.RAND;
InstructionUtils.checkNumFields(str, 12);
} else if (opcode.equalsIgnoreCase(DataGen.SEQ_OPCODE)) {
method = DataGenMethod.SEQ;
// 8 operands: rows, cols, rpb, cpb, from, to, incr, outvar
InstructionUtils.checkNumFields(str, 8);
} else if (opcode.equalsIgnoreCase(DataGen.SAMPLE_OPCODE)) {
method = DataGenMethod.SAMPLE;
// 7 operands: range, size, replace, seed, rpb, cpb, outvar
InstructionUtils.checkNumFields(str, 7);
}
Operator op = null;
// output is specified by the last operand
CPOperand out = new CPOperand(s[s.length - 1]);
if (method == DataGenMethod.RAND) {
CPOperand rows = new CPOperand(s[1]);
CPOperand cols = new CPOperand(s[2]);
int rpb = Integer.parseInt(s[3]);
int cpb = Integer.parseInt(s[4]);
double minValue = !s[5].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? Double.valueOf(s[5]).doubleValue() : -1;
double maxValue = !s[6].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? Double.valueOf(s[6]).doubleValue() : -1;
double sparsity = !s[7].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? Double.valueOf(s[7]).doubleValue() : -1;
long seed = !s[8].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? Long.valueOf(s[8]).longValue() : -1;
String dir = s[9];
String pdf = s[10];
String pdfParams = !s[11].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? s[11] : null;
return new RandSPInstruction(op, method, null, out, rows, cols, rpb, cpb, minValue, maxValue, sparsity, seed, dir, pdf, pdfParams, opcode, str);
} else if (method == DataGenMethod.SEQ) {
int rpb = Integer.parseInt(s[3]);
int cpb = Integer.parseInt(s[4]);
CPOperand from = new CPOperand(s[5]);
CPOperand to = new CPOperand(s[6]);
CPOperand incr = new CPOperand(s[7]);
CPOperand in = null;
return new RandSPInstruction(op, method, in, out, null, null, rpb, cpb, from, to, incr, opcode, str);
} else if (method == DataGenMethod.SAMPLE) {
double max = !s[1].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? Double.valueOf(s[1]) : 0;
CPOperand rows = new CPOperand(s[2]);
CPOperand cols = new CPOperand("1", ValueType.INT, DataType.SCALAR);
boolean replace = (!s[3].contains(Lop.VARIABLE_NAME_PLACEHOLDER) && Boolean.valueOf(s[3]));
long seed = Long.parseLong(s[4]);
int rpb = Integer.parseInt(s[5]);
int cpb = Integer.parseInt(s[6]);
return new RandSPInstruction(op, method, null, out, rows, cols, rpb, cpb, max, replace, seed, opcode, str);
} else
throw new DMLRuntimeException("Unrecognized data generation method: " + method);
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class SpoofSPInstruction method parseInstruction.
public static SpoofSPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
// String opcode = parts[0];
ArrayList<CPOperand> inlist = new ArrayList<>();
Class<?> cls = CodegenUtils.getClass(parts[1]);
byte[] classBytes = CodegenUtils.getClassData(parts[1]);
String opcode = parts[0] + CodegenUtils.createInstance(cls).getSpoofType();
for (int i = 2; i < parts.length - 2; i++) inlist.add(new CPOperand(parts[i]));
CPOperand out = new CPOperand(parts[parts.length - 2]);
return new SpoofSPInstruction(cls, classBytes, inlist.toArray(new CPOperand[0]), out, opcode, str);
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class Tsmm2SPInstruction method parseInstruction.
public static Tsmm2SPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
// check supported opcode
if (!opcode.equalsIgnoreCase("tsmm2"))
throw new DMLRuntimeException("Tsmm2SPInstruction.parseInstruction():: Unknown opcode " + opcode);
CPOperand in1 = new CPOperand(parts[1]);
CPOperand out = new CPOperand(parts[2]);
MMTSJType type = MMTSJType.valueOf(parts[3]);
return new Tsmm2SPInstruction(null, in1, out, type, opcode, str);
}
Aggregations