Search in sources :

Example 96 with LiteralOp

use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.

the class Explain method explainHop.

/**
 * Do a post-order traverse through the Hop DAG and explain each Hop
 *
 * @param hop high-level operator
 * @param level offset
 * @return string explanation of Hop DAG
 */
private static String explainHop(Hop hop, int level) {
    if (hop.isVisited() || (!SHOW_LITERAL_HOPS && hop instanceof LiteralOp))
        return "";
    StringBuilder sb = new StringBuilder();
    String offset = createOffset(level);
    for (Hop input : hop.getInput()) sb.append(explainHop(input, level));
    // indentation
    sb.append(offset);
    // hop id
    if (SHOW_DATA_DEPENDENCIES)
        sb.append("(" + hop.getHopID() + ") ");
    // operation string
    sb.append(hop.getOpString());
    // input hop references
    if (SHOW_DATA_DEPENDENCIES) {
        StringBuilder childs = new StringBuilder();
        childs.append(" (");
        boolean childAdded = false;
        for (Hop input : hop.getInput()) if (SHOW_LITERAL_HOPS || !(input instanceof LiteralOp)) {
            childs.append(childAdded ? "," : "");
            childs.append(input.getHopID());
            childAdded = true;
        }
        childs.append(")");
        if (childAdded)
            sb.append(childs.toString());
    }
    // matrix characteristics
    sb.append(" [" + hop.getDim1() + "," + hop.getDim2() + "," + hop.getRowsInBlock() + "," + hop.getColsInBlock() + "," + hop.getNnz());
    if (hop.getUpdateType().isInPlace())
        sb.append("," + hop.getUpdateType().toString().toLowerCase());
    sb.append("]");
    // memory estimates
    sb.append(" [" + showMem(hop.getInputMemEstimate(), false) + "," + showMem(hop.getIntermediateMemEstimate(), false) + "," + showMem(hop.getOutputMemEstimate(), false) + " -> " + showMem(hop.getMemEstimate(), true) + "]");
    // data flow properties
    if (SHOW_DATA_FLOW_PROPERTIES) {
        if (hop.requiresReblock() && hop.requiresCheckpoint())
            sb.append(" [rblk,chkpt]");
        else if (hop.requiresReblock())
            sb.append(" [rblk]");
        else if (hop.requiresCheckpoint())
            sb.append(" [chkpt]");
    }
    // exec type
    if (hop.getExecType() != null)
        sb.append(", " + hop.getExecType());
    sb.append('\n');
    hop.setVisited();
    return sb.toString();
}
Also used : Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 97 with LiteralOp

use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.

the class CPlanComparisonTest method testNotEqualLiteral.

@Test
public void testNotEqualLiteral() {
    CNodeData c1 = new CNodeData(new LiteralOp(7), 0, 0, DataType.SCALAR);
    CNodeData c2 = new CNodeData(new LiteralOp(3), 0, 0, DataType.SCALAR);
    Assert.assertNotEquals(c1.hashCode(), c2.hashCode());
    Assert.assertNotEquals(c1, c2);
    c1.setLiteral(true);
    c2.setLiteral(true);
    Assert.assertNotEquals(c1.hashCode(), c2.hashCode());
    Assert.assertNotEquals(c1, c2);
    c1.setStrictEquals(true);
    c2.setStrictEquals(true);
    Assert.assertNotEquals(c1.hashCode(), c2.hashCode());
    Assert.assertNotEquals(c1, c2);
}
Also used : CNodeData(org.apache.sysml.hops.codegen.cplan.CNodeData) LiteralOp(org.apache.sysml.hops.LiteralOp) Test(org.junit.Test)

Example 98 with LiteralOp

use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.

the class CPlanComparisonTest method testEqualLiteral.

@Test
public void testEqualLiteral() {
    CNodeData c1 = new CNodeData(new LiteralOp(7), 0, 0, DataType.SCALAR);
    CNodeData c2 = new CNodeData(new LiteralOp(7), 0, 0, DataType.SCALAR);
    Assert.assertEquals(c1.hashCode(), c2.hashCode());
    Assert.assertEquals(c1, c2);
    c1.setLiteral(true);
    c2.setLiteral(true);
    Assert.assertEquals(c1.hashCode(), c2.hashCode());
    Assert.assertEquals(c1, c2);
    c1.setStrictEquals(true);
    c2.setStrictEquals(true);
    Assert.assertEquals(c1.hashCode(), c2.hashCode());
    Assert.assertEquals(c1, c2);
}
Also used : CNodeData(org.apache.sysml.hops.codegen.cplan.CNodeData) LiteralOp(org.apache.sysml.hops.LiteralOp) Test(org.junit.Test)

Example 99 with LiteralOp

use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.

the class PlanSelectionFuseCostBased method rGetComputeCosts.

private static void rGetComputeCosts(Hop current, HashSet<Long> partition, HashMap<Long, Double> computeCosts) {
    if (computeCosts.containsKey(current.getHopID()))
        return;
    //recursively process children
    for (Hop c : current.getInput()) rGetComputeCosts(c, partition, computeCosts);
    //get costs for given hop
    double costs = 1;
    if (current instanceof UnaryOp) {
        switch(((UnaryOp) current).getOp()) {
            case ABS:
            case ROUND:
            case CEIL:
            case FLOOR:
            case SIGN:
            case SELP:
                costs = 1;
                break;
            case SPROP:
            case SQRT:
                costs = 2;
                break;
            case EXP:
                costs = 18;
                break;
            case SIGMOID:
                costs = 21;
                break;
            case LOG:
            case LOG_NZ:
                costs = 32;
                break;
            case NCOL:
            case NROW:
            case PRINT:
            case CAST_AS_BOOLEAN:
            case CAST_AS_DOUBLE:
            case CAST_AS_INT:
            case CAST_AS_MATRIX:
            case CAST_AS_SCALAR:
                costs = 1;
                break;
            case SIN:
                costs = 18;
                break;
            case COS:
                costs = 22;
                break;
            case TAN:
                costs = 42;
                break;
            case ASIN:
                costs = 93;
                break;
            case ACOS:
                costs = 103;
                break;
            case ATAN:
                costs = 40;
                break;
            case CUMSUM:
            case CUMMIN:
            case CUMMAX:
            case CUMPROD:
                costs = 1;
                break;
            default:
                LOG.warn("Cost model not " + "implemented yet for: " + ((UnaryOp) current).getOp());
        }
    } else if (current instanceof BinaryOp) {
        switch(((BinaryOp) current).getOp()) {
            case MULT:
            case PLUS:
            case MINUS:
            case MIN:
            case MAX:
            case AND:
            case OR:
            case EQUAL:
            case NOTEQUAL:
            case LESS:
            case LESSEQUAL:
            case GREATER:
            case GREATEREQUAL:
            case CBIND:
            case RBIND:
                costs = 1;
                break;
            case INTDIV:
                costs = 6;
                break;
            case MODULUS:
                costs = 8;
                break;
            case DIV:
                costs = 22;
                break;
            case LOG:
            case LOG_NZ:
                costs = 32;
                break;
            case POW:
                costs = (HopRewriteUtils.isLiteralOfValue(current.getInput().get(1), 2) ? 1 : 16);
                break;
            case MINUS_NZ:
            case MINUS1_MULT:
                costs = 2;
                break;
            case CENTRALMOMENT:
                int type = (int) (current.getInput().get(1) instanceof LiteralOp ? HopRewriteUtils.getIntValueSafe((LiteralOp) current.getInput().get(1)) : 2);
                switch(type) {
                    //count
                    case 0:
                        costs = 1;
                        break;
                    //mean
                    case 1:
                        costs = 8;
                        break;
                    //cm2
                    case 2:
                        costs = 16;
                        break;
                    //cm3
                    case 3:
                        costs = 31;
                        break;
                    //cm4
                    case 4:
                        costs = 51;
                        break;
                    //variance
                    case 5:
                        costs = 16;
                        break;
                }
                break;
            case COVARIANCE:
                costs = 23;
                break;
            default:
                LOG.warn("Cost model not " + "implemented yet for: " + ((BinaryOp) current).getOp());
        }
    } else if (current instanceof TernaryOp) {
        switch(((TernaryOp) current).getOp()) {
            case PLUS_MULT:
            case MINUS_MULT:
                costs = 2;
                break;
            case CTABLE:
                costs = 3;
                break;
            case CENTRALMOMENT:
                int type = (int) (current.getInput().get(1) instanceof LiteralOp ? HopRewriteUtils.getIntValueSafe((LiteralOp) current.getInput().get(1)) : 2);
                switch(type) {
                    //count
                    case 0:
                        costs = 2;
                        break;
                    //mean
                    case 1:
                        costs = 9;
                        break;
                    //cm2
                    case 2:
                        costs = 17;
                        break;
                    //cm3
                    case 3:
                        costs = 32;
                        break;
                    //cm4
                    case 4:
                        costs = 52;
                        break;
                    //variance
                    case 5:
                        costs = 17;
                        break;
                }
                break;
            case COVARIANCE:
                costs = 23;
                break;
            default:
                LOG.warn("Cost model not " + "implemented yet for: " + ((TernaryOp) current).getOp());
        }
    } else if (current instanceof ParameterizedBuiltinOp) {
        costs = 1;
    } else if (current instanceof IndexingOp) {
        costs = 1;
    } else if (current instanceof ReorgOp) {
        costs = 1;
    } else if (current instanceof AggBinaryOp) {
        //matrix vector
        costs = 2;
    } else if (current instanceof AggUnaryOp) {
        switch(((AggUnaryOp) current).getOp()) {
            case SUM:
                costs = 4;
                break;
            case SUM_SQ:
                costs = 5;
                break;
            case MIN:
            case MAX:
                costs = 1;
                break;
            default:
                LOG.warn("Cost model not " + "implemented yet for: " + ((AggUnaryOp) current).getOp());
        }
    }
    computeCosts.put(current.getHopID(), costs);
}
Also used : ParameterizedBuiltinOp(org.apache.sysml.hops.ParameterizedBuiltinOp) AggUnaryOp(org.apache.sysml.hops.AggUnaryOp) UnaryOp(org.apache.sysml.hops.UnaryOp) IndexingOp(org.apache.sysml.hops.IndexingOp) AggUnaryOp(org.apache.sysml.hops.AggUnaryOp) AggBinaryOp(org.apache.sysml.hops.AggBinaryOp) Hop(org.apache.sysml.hops.Hop) ReorgOp(org.apache.sysml.hops.ReorgOp) LiteralOp(org.apache.sysml.hops.LiteralOp) AggBinaryOp(org.apache.sysml.hops.AggBinaryOp) BinaryOp(org.apache.sysml.hops.BinaryOp) TernaryOp(org.apache.sysml.hops.TernaryOp)

Example 100 with LiteralOp

use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.

the class InterProceduralAnalysis method rRemoveConstantBinaryOp.

private void rRemoveConstantBinaryOp(Hop hop, HashMap<String, Hop> mOnes) {
    if (hop.isVisited())
        return;
    if (hop instanceof BinaryOp && ((BinaryOp) hop).getOp() == OpOp2.MULT && !((BinaryOp) hop).isOuterVectorOperator() && hop.getInput().get(0).getDataType() == DataType.MATRIX && hop.getInput().get(1) instanceof DataOp && mOnes.containsKey(hop.getInput().get(1).getName())) {
        //replace matrix of ones with literal 1 (later on removed by
        //algebraic simplification rewrites; otherwise more complex
        //recursive processing of childs and rewiring required)
        HopRewriteUtils.removeChildReferenceByPos(hop, hop.getInput().get(1), 1);
        HopRewriteUtils.addChildReference(hop, new LiteralOp(1), 1);
    }
    //recursively process child nodes
    for (Hop c : hop.getInput()) rRemoveConstantBinaryOp(c, mOnes);
    hop.setVisited();
}
Also used : Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp) BinaryOp(org.apache.sysml.hops.BinaryOp)

Aggregations

LiteralOp (org.apache.sysml.hops.LiteralOp)102 Hop (org.apache.sysml.hops.Hop)88 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)30 BinaryOp (org.apache.sysml.hops.BinaryOp)27 AggBinaryOp (org.apache.sysml.hops.AggBinaryOp)25 UnaryOp (org.apache.sysml.hops.UnaryOp)24 DataOp (org.apache.sysml.hops.DataOp)23 IndexingOp (org.apache.sysml.hops.IndexingOp)17 ArrayList (java.util.ArrayList)13 DataGenOp (org.apache.sysml.hops.DataGenOp)13 LeftIndexingOp (org.apache.sysml.hops.LeftIndexingOp)12 HashMap (java.util.HashMap)11 DataIdentifier (org.apache.sysml.parser.DataIdentifier)10 ReorgOp (org.apache.sysml.hops.ReorgOp)9 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)9 HopsException (org.apache.sysml.hops.HopsException)8 ParameterizedBuiltinOp (org.apache.sysml.hops.ParameterizedBuiltinOp)8 StatementBlock (org.apache.sysml.parser.StatementBlock)8 TernaryOp (org.apache.sysml.hops.TernaryOp)7 CNodeData (org.apache.sysml.hops.codegen.cplan.CNodeData)6