use of org.apache.sysml.lops.Lop in project incubator-systemml by apache.
the class ReorgOp method constructCPOrSparkSortLop.
private static Lop constructCPOrSparkSortLop(Hop input, Hop by, Hop desc, Hop ixret, ExecType et, boolean bSortIndInMem) throws HopsException, LopsException {
Transform transform1 = new Transform(input.constructLops(), HopsTransf2Lops.get(ReOrgOp.SORT), input.getDataType(), input.getValueType(), et, bSortIndInMem);
for (Hop c : new Hop[] { by, desc, ixret }) {
Lop ltmp = c.constructLops();
transform1.addInput(ltmp);
ltmp.addOutput(transform1);
}
//force order of added lops
transform1.setLevel();
return transform1;
}
use of org.apache.sysml.lops.Lop in project incubator-systemml by apache.
the class MultipleOp method constructLops.
/**
* Construct the corresponding Lops for this Hop
*/
@Override
public Lop constructLops() throws HopsException, LopsException {
// reuse existing lop
if (getLops() != null)
return getLops();
try {
ArrayList<Hop> inHops = getInput();
Lop[] inLops = new Lop[inHops.size()];
for (int i = 0; i < inHops.size(); i++) {
Hop inHop = inHops.get(i);
Lop inLop = inHop.constructLops();
inLops[i] = inLop;
}
MultipleCP.OperationType opType = MultipleOperandOperationHopTypeToLopType.get(multipleOperandOperation);
if (opType == null) {
throw new HopsException("Unknown MultipleCP Lop operation type for MultipleOperandOperation Hop type '" + multipleOperandOperation + "'");
}
MultipleCP multipleCPLop = new MultipleCP(opType, getDataType(), getValueType(), inLops);
setOutputDimensions(multipleCPLop);
setLineNumbers(multipleCPLop);
setLops(multipleCPLop);
} catch (Exception e) {
throw new HopsException(this.printErrorLocation() + "error constructing Lops for MultipleOp Hop -- \n ", e);
}
// add reblock/checkpoint lops if necessary
constructAndSetLopsDataFlowProperties();
return getLops();
}
use of org.apache.sysml.lops.Lop in project incubator-systemml by apache.
the class RewriteConstantFolding method evalScalarOperation.
/**
* In order to (1) prevent unexpected side effects from constant folding and
* (2) for simplicity with regard to arbitrary value type combinations,
* we use the same compilation and runtime for constant folding as we would
* use for actual instruction execution.
*
* @param bop high-level operator
* @return literal op
* @throws LopsException if LopsException occurs
* @throws DMLRuntimeException if DMLRuntimeException occurs
* @throws IOException if IOException occurs
* @throws HopsException if HopsException occurs
*/
private LiteralOp evalScalarOperation(Hop bop) throws LopsException, DMLRuntimeException, IOException, HopsException {
//Timing time = new Timing( true );
DataOp tmpWrite = new DataOp(TMP_VARNAME, bop.getDataType(), bop.getValueType(), bop, DataOpTypes.TRANSIENTWRITE, TMP_VARNAME);
//generate runtime instruction
Dag<Lop> dag = new Dag<Lop>();
//prevent lops reuse
Recompiler.rClearLops(tmpWrite);
//reconstruct lops
Lop lops = tmpWrite.constructLops();
lops.addToDag(dag);
ArrayList<Instruction> inst = dag.getJobs(null, ConfigurationManager.getDMLConfig());
//execute instructions
ExecutionContext ec = getExecutionContext();
ProgramBlock pb = getProgramBlock();
pb.setInstructions(inst);
pb.execute(ec);
//get scalar result (check before invocation) and create literal according
//to observed scalar output type (not hop type) for runtime consistency
ScalarObject so = (ScalarObject) ec.getVariable(TMP_VARNAME);
LiteralOp literal = null;
switch(so.getValueType()) {
case DOUBLE:
literal = new LiteralOp(so.getDoubleValue());
break;
case INT:
literal = new LiteralOp(so.getLongValue());
break;
case BOOLEAN:
literal = new LiteralOp(so.getBooleanValue());
break;
case STRING:
literal = new LiteralOp(so.getStringValue());
break;
default:
throw new HopsException("Unsupported literal value type: " + bop.getValueType());
}
//cleanup
tmpWrite.getInput().clear();
bop.getParent().remove(tmpWrite);
pb.setInstructions(null);
ec.getVariables().removeAll();
//set literal properties (scalar)
HopRewriteUtils.setOutputParametersForScalar(literal);
return literal;
}
use of org.apache.sysml.lops.Lop in project incubator-systemml by apache.
the class SpoofFusedOp method constructLops.
@Override
public Lop constructLops() throws HopsException, LopsException {
if (getLops() != null)
return getLops();
ExecType et = optFindExecType();
ArrayList<Lop> inputs = new ArrayList<Lop>();
for (Hop c : getInput()) inputs.add(c.constructLops());
int k = OptimizerUtils.getConstrainedNumThreads(_numThreads);
SpoofFused lop = new SpoofFused(inputs, getDataType(), getValueType(), _class, k, et);
setOutputDimensions(lop);
setLineNumbers(lop);
setLops(lop);
return lop;
}
use of org.apache.sysml.lops.Lop in project incubator-systemml by apache.
the class AggBinaryOp method constructSparkLopsMapMM.
private void constructSparkLopsMapMM(MMultMethod method) throws LopsException, HopsException {
Lop mapmult = null;
if (isLeftTransposeRewriteApplicable(false, false)) {
mapmult = constructSparkLopsMapMMWithLeftTransposeRewrite();
} else {
// If number of columns is smaller than block size then explicit aggregation is not required.
// i.e., entire matrix multiplication can be performed in the mappers.
boolean needAgg = requiresAggregation(method);
SparkAggType aggtype = getSparkMMAggregationType(needAgg);
_outputEmptyBlocks = !OptimizerUtils.allowsToFilterEmptyBlockOutputs(this);
//core matrix mult
mapmult = new MapMult(getInput().get(0).constructLops(), getInput().get(1).constructLops(), getDataType(), getValueType(), (method == MMultMethod.MAPMM_R), false, _outputEmptyBlocks, aggtype);
}
setOutputDimensions(mapmult);
setLineNumbers(mapmult);
setLops(mapmult);
}
Aggregations