use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class QuaternarySPInstruction method parseInstruction.
public static QuaternarySPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
// validity check
if (!InstructionUtils.isDistQuaternaryOpcode(opcode)) {
throw new DMLRuntimeException("Quaternary.parseInstruction():: Unknown opcode " + opcode);
}
// instruction parsing
if (// wsloss
WeightedSquaredLoss.OPCODE.equalsIgnoreCase(opcode) || WeightedSquaredLossR.OPCODE.equalsIgnoreCase(opcode)) {
boolean isRed = WeightedSquaredLossR.OPCODE.equalsIgnoreCase(opcode);
// check number of fields (4 inputs, output, type)
if (isRed)
InstructionUtils.checkNumFields(parts, 8);
else
InstructionUtils.checkNumFields(parts, 6);
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand in3 = new CPOperand(parts[3]);
CPOperand in4 = new CPOperand(parts[4]);
CPOperand out = new CPOperand(parts[5]);
WeightsType wtype = WeightsType.valueOf(parts[6]);
// in mappers always through distcache, in reducers through distcache/shuffle
boolean cacheU = isRed ? Boolean.parseBoolean(parts[7]) : true;
boolean cacheV = isRed ? Boolean.parseBoolean(parts[8]) : true;
return new QuaternarySPInstruction(new QuaternaryOperator(wtype), in1, in2, in3, in4, out, cacheU, cacheV, opcode, str);
} else if (// wumm
WeightedUnaryMM.OPCODE.equalsIgnoreCase(opcode) || WeightedUnaryMMR.OPCODE.equalsIgnoreCase(opcode)) {
boolean isRed = WeightedUnaryMMR.OPCODE.equalsIgnoreCase(opcode);
// check number of fields (4 inputs, output, type)
if (isRed)
InstructionUtils.checkNumFields(parts, 8);
else
InstructionUtils.checkNumFields(parts, 6);
String uopcode = parts[1];
CPOperand in1 = new CPOperand(parts[2]);
CPOperand in2 = new CPOperand(parts[3]);
CPOperand in3 = new CPOperand(parts[4]);
CPOperand out = new CPOperand(parts[5]);
WUMMType wtype = WUMMType.valueOf(parts[6]);
// in mappers always through distcache, in reducers through distcache/shuffle
boolean cacheU = isRed ? Boolean.parseBoolean(parts[7]) : true;
boolean cacheV = isRed ? Boolean.parseBoolean(parts[8]) : true;
return new QuaternarySPInstruction(new QuaternaryOperator(wtype, uopcode), in1, in2, in3, null, out, cacheU, cacheV, opcode, str);
} else if (// wdivmm
WeightedDivMM.OPCODE.equalsIgnoreCase(opcode) || WeightedDivMMR.OPCODE.equalsIgnoreCase(opcode)) {
boolean isRed = opcode.startsWith("red");
// check number of fields (4 inputs, output, type)
if (isRed)
InstructionUtils.checkNumFields(parts, 8);
else
InstructionUtils.checkNumFields(parts, 6);
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand in3 = new CPOperand(parts[3]);
CPOperand in4 = new CPOperand(parts[4]);
CPOperand out = new CPOperand(parts[5]);
// in mappers always through distcache, in reducers through distcache/shuffle
boolean cacheU = isRed ? Boolean.parseBoolean(parts[7]) : true;
boolean cacheV = isRed ? Boolean.parseBoolean(parts[8]) : true;
final WDivMMType wt = WDivMMType.valueOf(parts[6]);
QuaternaryOperator qop = (wt.hasScalar() ? new QuaternaryOperator(wt, Double.parseDouble(in4.getName())) : new QuaternaryOperator(wt));
return new QuaternarySPInstruction(qop, in1, in2, in3, in4, out, cacheU, cacheV, opcode, str);
} else // map/redwsigmoid, map/redwcemm
{
boolean isRed = opcode.startsWith("red");
int addInput4 = (opcode.endsWith("wcemm")) ? 1 : 0;
// check number of fields (3 or 4 inputs, output, type)
if (isRed)
InstructionUtils.checkNumFields(parts, 7 + addInput4);
else
InstructionUtils.checkNumFields(parts, 5 + addInput4);
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand in3 = new CPOperand(parts[3]);
CPOperand out = new CPOperand(parts[4 + addInput4]);
// in mappers always through distcache, in reducers through distcache/shuffle
boolean cacheU = isRed ? Boolean.parseBoolean(parts[6 + addInput4]) : true;
boolean cacheV = isRed ? Boolean.parseBoolean(parts[7 + addInput4]) : true;
if (opcode.endsWith("wsigmoid"))
return new QuaternarySPInstruction(new QuaternaryOperator(WSigmoidType.valueOf(parts[5])), in1, in2, in3, null, out, cacheU, cacheV, opcode, str);
else if (opcode.endsWith("wcemm")) {
CPOperand in4 = new CPOperand(parts[4]);
final WCeMMType wt = WCeMMType.valueOf(parts[6]);
QuaternaryOperator qop = (wt.hasFourInputs() ? new QuaternaryOperator(wt, Double.parseDouble(in4.getName())) : new QuaternaryOperator(wt));
return new QuaternarySPInstruction(qop, in1, in2, in3, in4, out, cacheU, cacheV, opcode, str);
}
}
return null;
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class ReblockSPInstruction method parseInstruction.
public static ReblockSPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
if (!opcode.equals("rblk")) {
throw new DMLRuntimeException("Incorrect opcode for ReblockSPInstruction:" + opcode);
}
CPOperand in = new CPOperand(parts[1]);
CPOperand out = new CPOperand(parts[2]);
int brlen = Integer.parseInt(parts[3]);
int bclen = Integer.parseInt(parts[4]);
boolean outputEmptyBlocks = Boolean.parseBoolean(parts[5]);
// no operator for ReblockSPInstruction
Operator op = null;
return new ReblockSPInstruction(op, in, out, brlen, bclen, outputEmptyBlocks, opcode, str);
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class ReorgSPInstruction method parseInstruction.
public static ReorgSPInstruction parseInstruction(String str) {
CPOperand in = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String opcode = InstructionUtils.getOpCode(str);
if (opcode.equalsIgnoreCase("r'")) {
// max 2 operands
parseUnaryInstruction(str, in, out);
return new ReorgSPInstruction(new ReorgOperator(SwapIndex.getSwapIndexFnObject()), in, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rev")) {
// max 2 operands
parseUnaryInstruction(str, in, out);
return new ReorgSPInstruction(new ReorgOperator(RevIndex.getRevIndexFnObject()), in, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rdiag")) {
// max 2 operands
parseUnaryInstruction(str, in, out);
return new ReorgSPInstruction(new ReorgOperator(DiagIndex.getDiagIndexFnObject()), in, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rsort")) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 5, 6);
in.split(parts[1]);
out.split(parts[5]);
CPOperand col = new CPOperand(parts[2]);
CPOperand desc = new CPOperand(parts[3]);
CPOperand ixret = new CPOperand(parts[4]);
boolean bSortIndInMem = false;
if (parts.length > 5)
bSortIndInMem = Boolean.parseBoolean(parts[6]);
return new ReorgSPInstruction(new ReorgOperator(new SortIndex(1, false, false)), in, col, desc, ixret, out, opcode, bSortIndInMem, str);
} else {
throw new DMLRuntimeException("Unknown opcode while parsing a ReorgInstruction: " + str);
}
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class RmmSPInstruction method parseInstruction.
public static RmmSPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
if ("rmm".equals(opcode)) {
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand out = new CPOperand(parts[3]);
return new RmmSPInstruction(null, in1, in2, out, opcode, str);
} else {
throw new DMLRuntimeException("RmmSPInstruction.parseInstruction():: Unknown opcode " + opcode);
}
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class TernarySPInstruction method parseInstruction.
public static TernarySPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
CPOperand operand1 = new CPOperand(parts[1]);
CPOperand operand2 = new CPOperand(parts[2]);
CPOperand operand3 = new CPOperand(parts[3]);
CPOperand outOperand = new CPOperand(parts[4]);
TernaryOperator op = InstructionUtils.parseTernaryOperator(opcode);
return new TernarySPInstruction(op, operand1, operand2, operand3, outOperand, opcode, str);
}
Aggregations