Search in sources :

Example 26 with ExecType

use of org.apache.sysml.lops.LopProperties.ExecType in project incubator-systemml by apache.

the class WeightedCrossEntropyR method getInstructions.

@Override
public String getInstructions(String input1, String input2, String input3, String input4, String output) {
    StringBuilder sb = new StringBuilder();
    final ExecType et = getExecType();
    sb.append(et);
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(OPCODE);
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(getInputs().get(0).prepInputOperand(input1));
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(getInputs().get(1).prepInputOperand(input2));
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(getInputs().get(2).prepInputOperand(input3));
    sb.append(Lop.OPERAND_DELIMITOR);
    if ((et == ExecType.MR) && (getInputs().get(3).getDataType() == DataType.SCALAR)) {
        sb.append(getInputs().get(3).prepScalarInputOperand(et));
    } else {
        sb.append(getInputs().get(3).prepInputOperand(input4));
    }
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(prepOutputOperand(output));
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(_wcemmType);
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(_cacheU);
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(_cacheV);
    return sb.toString();
}
Also used : ExecType(org.apache.sysml.lops.LopProperties.ExecType)

Example 27 with ExecType

use of org.apache.sysml.lops.LopProperties.ExecType in project incubator-systemml by apache.

the class WeightedDivMM method getInstructions.

/* CP/SPARK instruction generation */
@Override
public String getInstructions(String input1, String input2, String input3, String input4, String output) {
    StringBuilder sb = new StringBuilder();
    final ExecType et = getExecType();
    sb.append(et);
    sb.append(Lop.OPERAND_DELIMITOR);
    if (et == ExecType.CP)
        sb.append(OPCODE_CP);
    else
        sb.append(OPCODE);
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(getInputs().get(0).prepInputOperand(input1));
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(getInputs().get(1).prepInputOperand(input2));
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(getInputs().get(2).prepInputOperand(input3));
    sb.append(Lop.OPERAND_DELIMITOR);
    if ((et == ExecType.MR) && (getInputs().get(3).getDataType() == DataType.SCALAR)) {
        sb.append(getInputs().get(3).prepScalarInputOperand(et));
    } else {
        sb.append(getInputs().get(3).prepInputOperand(input4));
    }
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(prepOutputOperand(output));
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(_weightsType);
    //append degree of parallelism
    if (et == ExecType.CP) {
        sb.append(OPERAND_DELIMITOR);
        sb.append(_numThreads);
    }
    return sb.toString();
}
Also used : ExecType(org.apache.sysml.lops.LopProperties.ExecType)

Example 28 with ExecType

use of org.apache.sysml.lops.LopProperties.ExecType in project incubator-systemml by apache.

the class WeightedDivMMR method getInstructions.

/* CP/SPARK instruction generation */
@Override
public String getInstructions(String input1, String input2, String input3, String input4, String output) {
    StringBuilder sb = new StringBuilder();
    final ExecType et = getExecType();
    sb.append(et);
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(OPCODE);
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(getInputs().get(0).prepInputOperand(input1));
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(getInputs().get(1).prepInputOperand(input2));
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(getInputs().get(2).prepInputOperand(input3));
    sb.append(Lop.OPERAND_DELIMITOR);
    if ((et == ExecType.MR) && (getInputs().get(3).getDataType() == DataType.SCALAR)) {
        sb.append(getInputs().get(3).prepScalarInputOperand(et));
    } else {
        sb.append(getInputs().get(3).prepInputOperand(input4));
    }
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(prepOutputOperand(output));
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(_weightsType);
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(_cacheU);
    sb.append(Lop.OPERAND_DELIMITOR);
    sb.append(_cacheV);
    return sb.toString();
}
Also used : ExecType(org.apache.sysml.lops.LopProperties.ExecType)

Example 29 with ExecType

use of org.apache.sysml.lops.LopProperties.ExecType in project incubator-systemml by apache.

the class TernaryOp method constructLopsCentralMoment.

/**
	 * Method to construct LOPs when op = CENTRAILMOMENT.
	 * 
	 * @throws HopsException if HopsException occurs
	 * @throws LopsException if LopsException occurs
	 */
private void constructLopsCentralMoment() throws HopsException, LopsException {
    if (_op != OpOp3.CENTRALMOMENT)
        throw new HopsException("Unexpected operation: " + _op + ", expecting " + OpOp3.CENTRALMOMENT);
    ExecType et = optFindExecType();
    if (et == ExecType.MR) {
        CombineBinary combine = CombineBinary.constructCombineLop(OperationTypes.PreCentralMoment, getInput().get(0).constructLops(), getInput().get(1).constructLops(), DataType.MATRIX, getValueType());
        combine.getOutputParameters().setDimensions(getInput().get(0).getDim1(), getInput().get(0).getDim2(), getInput().get(0).getRowsInBlock(), getInput().get(0).getColsInBlock(), getInput().get(0).getNnz());
        CentralMoment cm = new CentralMoment(combine, getInput().get(2).constructLops(), DataType.MATRIX, getValueType(), et);
        cm.getOutputParameters().setDimensions(1, 1, 0, 0, -1);
        setLineNumbers(cm);
        UnaryCP unary1 = new UnaryCP(cm, HopsOpOp1LopsUS.get(OpOp1.CAST_AS_SCALAR), getDataType(), getValueType());
        unary1.getOutputParameters().setDimensions(0, 0, 0, 0, -1);
        setLineNumbers(unary1);
        setLops(unary1);
    } else //CP / SPARK
    {
        CentralMoment cm = new CentralMoment(getInput().get(0).constructLops(), getInput().get(1).constructLops(), getInput().get(2).constructLops(), getDataType(), getValueType(), et);
        cm.getOutputParameters().setDimensions(0, 0, 0, 0, -1);
        setLineNumbers(cm);
        setLops(cm);
    }
}
Also used : CombineBinary(org.apache.sysml.lops.CombineBinary) CentralMoment(org.apache.sysml.lops.CentralMoment) ExecType(org.apache.sysml.lops.LopProperties.ExecType) UnaryCP(org.apache.sysml.lops.UnaryCP)

Example 30 with ExecType

use of org.apache.sysml.lops.LopProperties.ExecType in project incubator-systemml by apache.

the class TernaryOp method constructLopsCtable.

/**
	 * Method to construct LOPs when op = CTABLE.
	 * 
	 * @throws HopsException if HopsException occurs
	 * @throws LopsException if LopsException occurs
	 */
private void constructLopsCtable() throws HopsException, LopsException {
    if (_op != OpOp3.CTABLE)
        throw new HopsException("Unexpected operation: " + _op + ", expecting " + OpOp3.CTABLE);
    /*
		 * We must handle three different cases: case1 : all three
		 * inputs are vectors (e.g., F=ctable(A,B,W)) case2 : two
		 * vectors and one scalar (e.g., F=ctable(A,B)) case3 : one
		 * vector and two scalars (e.g., F=ctable(A))
		 */
    // identify the particular case
    // F=ctable(A,B,W)
    DataType dt1 = getInput().get(0).getDataType();
    DataType dt2 = getInput().get(1).getDataType();
    DataType dt3 = getInput().get(2).getDataType();
    Ternary.OperationTypes tertiaryOpOrig = Ternary.findCtableOperationByInputDataTypes(dt1, dt2, dt3);
    // Compute lops for all inputs
    Lop[] inputLops = new Lop[getInput().size()];
    for (int i = 0; i < getInput().size(); i++) {
        inputLops[i] = getInput().get(i).constructLops();
    }
    ExecType et = optFindExecType();
    //reset reblock requirement (see MR ctable / construct lops)
    setRequiresReblock(false);
    if (et == ExecType.CP || et == ExecType.SPARK) {
        //for CP we support only ctable expand left
        Ternary.OperationTypes tertiaryOp = isSequenceRewriteApplicable(true) ? Ternary.OperationTypes.CTABLE_EXPAND_SCALAR_WEIGHT : tertiaryOpOrig;
        boolean ignoreZeros = false;
        if (isMatrixIgnoreZeroRewriteApplicable()) {
            //table - rmempty - rshape
            ignoreZeros = true;
            inputLops[0] = ((ParameterizedBuiltinOp) getInput().get(0)).getTargetHop().getInput().get(0).constructLops();
            inputLops[1] = ((ParameterizedBuiltinOp) getInput().get(1)).getTargetHop().getInput().get(0).constructLops();
        }
        Ternary tertiary = new Ternary(inputLops, tertiaryOp, getDataType(), getValueType(), ignoreZeros, et);
        tertiary.getOutputParameters().setDimensions(_dim1, _dim2, getRowsInBlock(), getColsInBlock(), -1);
        tertiary.setAllPositions(this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
        //force blocked output in CP (see below), otherwise binarycell
        if (et == ExecType.SPARK) {
            tertiary.getOutputParameters().setDimensions(_dim1, _dim2, -1, -1, -1);
            setRequiresReblock(true);
        } else
            tertiary.getOutputParameters().setDimensions(_dim1, _dim2, getRowsInBlock(), getColsInBlock(), -1);
        //tertiary opt, w/o reblock in CP
        setLops(tertiary);
    } else //MR
    {
        //for MR we support both ctable expand left and right
        Ternary.OperationTypes tertiaryOp = isSequenceRewriteApplicable() ? Ternary.OperationTypes.CTABLE_EXPAND_SCALAR_WEIGHT : tertiaryOpOrig;
        Group group1 = null, group2 = null, group3 = null, group4 = null;
        group1 = new Group(inputLops[0], Group.OperationTypes.Sort, getDataType(), getValueType());
        group1.getOutputParameters().setDimensions(getDim1(), getDim2(), getRowsInBlock(), getColsInBlock(), getNnz());
        group1.setAllPositions(this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
        Ternary tertiary = null;
        // create "group" lops for MATRIX inputs
        switch(tertiaryOp) {
            case CTABLE_TRANSFORM:
                // F = ctable(A,B,W)
                group2 = new Group(inputLops[1], Group.OperationTypes.Sort, getDataType(), getValueType());
                group2.getOutputParameters().setDimensions(getDim1(), getDim2(), getRowsInBlock(), getColsInBlock(), getNnz());
                group2.setAllPositions(this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
                group3 = new Group(inputLops[2], Group.OperationTypes.Sort, getDataType(), getValueType());
                group3.getOutputParameters().setDimensions(getDim1(), getDim2(), getRowsInBlock(), getColsInBlock(), getNnz());
                group3.setAllPositions(this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
                if (inputLops.length == 3)
                    tertiary = new Ternary(new Lop[] { group1, group2, group3 }, tertiaryOp, getDataType(), getValueType(), et);
                else
                    // output dimensions are given
                    tertiary = new Ternary(new Lop[] { group1, group2, group3, inputLops[3], inputLops[4] }, tertiaryOp, getDataType(), getValueType(), et);
                break;
            case CTABLE_TRANSFORM_SCALAR_WEIGHT:
                // F = ctable(A,B) or F = ctable(A,B,1)
                group2 = new Group(inputLops[1], Group.OperationTypes.Sort, getDataType(), getValueType());
                group2.getOutputParameters().setDimensions(getDim1(), getDim2(), getRowsInBlock(), getColsInBlock(), getNnz());
                group2.setAllPositions(this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
                if (inputLops.length == 3)
                    tertiary = new Ternary(new Lop[] { group1, group2, inputLops[2] }, tertiaryOp, getDataType(), getValueType(), et);
                else
                    tertiary = new Ternary(new Lop[] { group1, group2, inputLops[2], inputLops[3], inputLops[4] }, tertiaryOp, getDataType(), getValueType(), et);
                break;
            case CTABLE_EXPAND_SCALAR_WEIGHT:
                // F=ctable(seq(1,N),A) or F = ctable(seq,A,1)
                //left 1, right 0 (index of input data)
                int left = isSequenceRewriteApplicable(true) ? 1 : 0;
                Group group = new Group(getInput().get(left).constructLops(), Group.OperationTypes.Sort, getDataType(), getValueType());
                group.getOutputParameters().setDimensions(getDim1(), getDim2(), getRowsInBlock(), getColsInBlock(), getNnz());
                if (inputLops.length == 3)
                    tertiary = new Ternary(new Lop[] { //matrix
                    group, //weight
                    getInput().get(2).constructLops(), //left
                    new LiteralOp(left).constructLops() }, tertiaryOp, getDataType(), getValueType(), et);
                else
                    tertiary = new Ternary(new Lop[] { //getInput().get(1).constructLops(), //matrix
                    group, //weight
                    getInput().get(2).constructLops(), //left
                    new LiteralOp(left).constructLops(), inputLops[3], inputLops[4] }, tertiaryOp, getDataType(), getValueType(), et);
                break;
            case CTABLE_TRANSFORM_HISTOGRAM:
                // F=ctable(A,1) or F = ctable(A,1,1)
                if (inputLops.length == 3)
                    tertiary = new Ternary(new Lop[] { group1, getInput().get(1).constructLops(), getInput().get(2).constructLops() }, tertiaryOp, getDataType(), getValueType(), et);
                else
                    tertiary = new Ternary(new Lop[] { group1, getInput().get(1).constructLops(), getInput().get(2).constructLops(), inputLops[3], inputLops[4] }, tertiaryOp, getDataType(), getValueType(), et);
                break;
            case CTABLE_TRANSFORM_WEIGHTED_HISTOGRAM:
                // F=ctable(A,1,W)
                group3 = new Group(getInput().get(2).constructLops(), Group.OperationTypes.Sort, getDataType(), getValueType());
                group3.getOutputParameters().setDimensions(getDim1(), getDim2(), getRowsInBlock(), getColsInBlock(), getNnz());
                group3.setAllPositions(this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
                if (inputLops.length == 3)
                    tertiary = new Ternary(new Lop[] { group1, getInput().get(1).constructLops(), group3 }, tertiaryOp, getDataType(), getValueType(), et);
                else
                    tertiary = new Ternary(new Lop[] { group1, getInput().get(1).constructLops(), group3, inputLops[3], inputLops[4] }, tertiaryOp, getDataType(), getValueType(), et);
                break;
            default:
                throw new HopsException("Invalid ternary operator type: " + _op);
        }
        // output dimensions are not known at compilation time
        tertiary.getOutputParameters().setDimensions(_dim1, _dim2, (_dimInputsPresent ? getRowsInBlock() : -1), (_dimInputsPresent ? getColsInBlock() : -1), -1);
        setLineNumbers(tertiary);
        Lop lctable = tertiary;
        if (!(_disjointInputs || tertiaryOp == Ternary.OperationTypes.CTABLE_EXPAND_SCALAR_WEIGHT)) {
            //no need for aggregation if (1) input indexed disjoint	or one side is sequence	w/ 1 increment
            group4 = new Group(tertiary, Group.OperationTypes.Sort, getDataType(), getValueType());
            group4.getOutputParameters().setDimensions(_dim1, _dim2, (_dimInputsPresent ? getRowsInBlock() : -1), (_dimInputsPresent ? getColsInBlock() : -1), -1);
            group4.setAllPositions(this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
            Aggregate agg1 = new Aggregate(group4, HopsAgg2Lops.get(AggOp.SUM), getDataType(), getValueType(), ExecType.MR);
            agg1.getOutputParameters().setDimensions(_dim1, _dim2, (_dimInputsPresent ? getRowsInBlock() : -1), (_dimInputsPresent ? getColsInBlock() : -1), -1);
            agg1.setAllPositions(this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
            // kahamSum is used for aggregation but inputs do not have
            // correction values
            agg1.setupCorrectionLocation(CorrectionLocationType.NONE);
            lctable = agg1;
        }
        setLops(lctable);
        // to introduce reblock lop since table itself outputs in blocked format if dims known.
        if (!dimsKnown() && !_dimInputsPresent) {
            setRequiresReblock(true);
        }
    }
}
Also used : Group(org.apache.sysml.lops.Group) Ternary(org.apache.sysml.lops.Ternary) CombineTernary(org.apache.sysml.lops.CombineTernary) Lop(org.apache.sysml.lops.Lop) DataType(org.apache.sysml.parser.Expression.DataType) ExecType(org.apache.sysml.lops.LopProperties.ExecType) Aggregate(org.apache.sysml.lops.Aggregate)

Aggregations

ExecType (org.apache.sysml.lops.LopProperties.ExecType)58 Lop (org.apache.sysml.lops.Lop)24 MultiThreadedHop (org.apache.sysml.hops.Hop.MultiThreadedHop)13 Group (org.apache.sysml.lops.Group)12 Aggregate (org.apache.sysml.lops.Aggregate)10 LopsException (org.apache.sysml.lops.LopsException)8 DataPartition (org.apache.sysml.lops.DataPartition)6 SortKeys (org.apache.sysml.lops.SortKeys)6 UnaryCP (org.apache.sysml.lops.UnaryCP)6 CombineUnary (org.apache.sysml.lops.CombineUnary)5 PickByCount (org.apache.sysml.lops.PickByCount)5 ArrayList (java.util.ArrayList)4 CombineBinary (org.apache.sysml.lops.CombineBinary)4 HashMap (java.util.HashMap)3 Data (org.apache.sysml.lops.Data)3 PartialAggregate (org.apache.sysml.lops.PartialAggregate)3 SparkAggType (org.apache.sysml.hops.AggBinaryOp.SparkAggType)2 DataOp (org.apache.sysml.hops.DataOp)2 Hop (org.apache.sysml.hops.Hop)2 OperationTypes (org.apache.sysml.lops.Aggregate.OperationTypes)2