use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class AppendRSPInstruction method parseInstruction.
public static AppendRSPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 4);
String opcode = parts[0];
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand out = new CPOperand(parts[3]);
boolean cbind = Boolean.parseBoolean(parts[4]);
if (!opcode.equalsIgnoreCase("rappend"))
throw new DMLRuntimeException("Unknown opcode while parsing a MatrixAppendRSPInstruction: " + str);
if (in1.getDataType().isMatrix()) {
return new MatrixAppendRSPInstruction(new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1)), in1, in2, out, cbind, opcode, str);
} else {
return new FrameAppendRSPInstruction(new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1)), in1, in2, out, cbind, opcode, str);
}
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class BinarySPInstruction method parseInstruction.
public static BinarySPInstruction parseInstruction(String str) {
CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String opcode = null;
boolean isBroadcast = false;
VectorType vtype = null;
if (str.startsWith("SPARK" + Lop.OPERAND_DELIMITOR + "map")) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 5);
opcode = parts[0];
in1.split(parts[1]);
in2.split(parts[2]);
out.split(parts[3]);
vtype = VectorType.valueOf(parts[5]);
isBroadcast = true;
} else {
opcode = parseBinaryInstruction(str, in1, in2, out);
}
DataType dt1 = in1.getDataType();
DataType dt2 = in2.getDataType();
Operator operator = InstructionUtils.parseExtendedBinaryOrBuiltinOperator(opcode, in1, in2);
if (dt1 == DataType.MATRIX || dt2 == DataType.MATRIX) {
if (dt1 == DataType.MATRIX && dt2 == DataType.MATRIX) {
if (isBroadcast)
return new BinaryMatrixBVectorSPInstruction(operator, in1, in2, out, vtype, opcode, str);
else
return new BinaryMatrixMatrixSPInstruction(operator, in1, in2, out, opcode, str);
} else
return new BinaryMatrixScalarSPInstruction(operator, in1, in2, out, opcode, str);
}
return null;
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class BuiltinNarySPInstruction method computeOutputMatrixCharacteristics.
private static MatrixCharacteristics computeOutputMatrixCharacteristics(SparkExecutionContext sec, CPOperand[] inputs, boolean cbind) {
MatrixCharacteristics mcIn1 = sec.getMatrixCharacteristics(inputs[0].getName());
MatrixCharacteristics mcOut = new MatrixCharacteristics(0, 0, mcIn1.getRowsPerBlock(), mcIn1.getColsPerBlock(), 0);
for (CPOperand input : inputs) {
MatrixCharacteristics mcIn = sec.getMatrixCharacteristics(input.getName());
updateMatrixCharacteristics(mcIn, mcOut, cbind);
}
return mcOut;
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class BuiltinNarySPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) {
SparkExecutionContext sec = (SparkExecutionContext) ec;
boolean cbind = getOpcode().equals("cbind");
// compute output characteristics
MatrixCharacteristics mcOut = computeOutputMatrixCharacteristics(sec, inputs, cbind);
// get consolidated input via union over shifted and padded inputs
MatrixCharacteristics off = new MatrixCharacteristics(0, 0, mcOut.getRowsPerBlock(), mcOut.getColsPerBlock(), 0);
JavaPairRDD<MatrixIndexes, MatrixBlock> out = null;
for (CPOperand input : inputs) {
MatrixCharacteristics mcIn = sec.getMatrixCharacteristics(input.getName());
JavaPairRDD<MatrixIndexes, MatrixBlock> in = sec.getBinaryBlockRDDHandleForVariable(input.getName()).flatMapToPair(new ShiftMatrix(off, mcIn, cbind)).mapToPair(// just padding
new PadBlocksFunction(mcOut));
out = (out != null) ? out.union(in) : in;
updateMatrixCharacteristics(mcIn, off, cbind);
}
// aggregate partially overlapping blocks w/ single shuffle
int numPartOut = SparkUtils.getNumPreferredPartitions(mcOut);
out = RDDAggregateUtils.mergeByKey(out, numPartOut, false);
// set output RDD and add lineage
sec.getMatrixCharacteristics(output.getName()).set(mcOut);
sec.setRDDHandleForVariable(output.getName(), out);
for (CPOperand input : inputs) sec.addLineageRDD(output.getName(), input.getName());
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class CompressionSPInstruction method parseInstruction.
public static CompressionSPInstruction parseInstruction(String str) {
InstructionUtils.checkNumFields(str, 2);
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
return new CompressionSPInstruction(null, new CPOperand(parts[1]), new CPOperand(parts[2]), parts[0], str);
}
Aggregations