Search in sources :

Example 51 with Lop

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;
}
Also used : MultiThreadedHop(org.apache.sysml.hops.Hop.MultiThreadedHop) Transform(org.apache.sysml.lops.Transform) Lop(org.apache.sysml.lops.Lop)

Example 52 with Lop

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();
}
Also used : MultipleCP(org.apache.sysml.lops.MultipleCP) Lop(org.apache.sysml.lops.Lop) LopsException(org.apache.sysml.lops.LopsException)

Example 53 with Lop

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;
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) Dag(org.apache.sysml.lops.compile.Dag) HopsException(org.apache.sysml.hops.HopsException) Lop(org.apache.sysml.lops.Lop) Instruction(org.apache.sysml.runtime.instructions.Instruction) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp)

Example 54 with Lop

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;
}
Also used : ArrayList(java.util.ArrayList) MultiThreadedHop(org.apache.sysml.hops.Hop.MultiThreadedHop) Hop(org.apache.sysml.hops.Hop) ExecType(org.apache.sysml.lops.LopProperties.ExecType) Lop(org.apache.sysml.lops.Lop) SpoofFused(org.apache.sysml.lops.SpoofFused)

Example 55 with 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);
}
Also used : PMapMult(org.apache.sysml.lops.PMapMult) MapMult(org.apache.sysml.lops.MapMult) Lop(org.apache.sysml.lops.Lop)

Aggregations

Lop (org.apache.sysml.lops.Lop)83 MultiThreadedHop (org.apache.sysml.hops.Hop.MultiThreadedHop)33 ExecType (org.apache.sysml.lops.LopProperties.ExecType)25 Group (org.apache.sysml.lops.Group)20 LopsException (org.apache.sysml.lops.LopsException)20 ArrayList (java.util.ArrayList)16 Aggregate (org.apache.sysml.lops.Aggregate)16 DataPartition (org.apache.sysml.lops.DataPartition)13 Instruction (org.apache.sysml.runtime.instructions.Instruction)13 Data (org.apache.sysml.lops.Data)12 Transform (org.apache.sysml.lops.Transform)12 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)11 RepMat (org.apache.sysml.lops.RepMat)9 Unary (org.apache.sysml.lops.Unary)8 Dag (org.apache.sysml.lops.compile.Dag)8 HashMap (java.util.HashMap)7 Hop (org.apache.sysml.hops.Hop)6 UnaryCP (org.apache.sysml.lops.UnaryCP)6 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)6 RandInstruction (org.apache.sysml.runtime.instructions.mr.RandInstruction)6