Search in sources :

Example 31 with CNode

use of org.apache.sysml.hops.codegen.cplan.CNode in project systemml by apache.

the class CPlanComparisonTest method testNotEqualUnaryBinaryNodes.

@Test
public void testNotEqualUnaryBinaryNodes() {
    CNode c1 = createCNodeData(DataType.MATRIX);
    CNode c2 = createCNodeData(DataType.SCALAR);
    CNode un1 = new CNodeUnary(c1, UnaryType.ABS);
    CNode bin2 = new CNodeBinary(c1, c2, BinType.DIV);
    Assert.assertNotEquals(un1, bin2);
}
Also used : CNode(org.apache.sysml.hops.codegen.cplan.CNode) CNodeUnary(org.apache.sysml.hops.codegen.cplan.CNodeUnary) CNodeBinary(org.apache.sysml.hops.codegen.cplan.CNodeBinary) Test(org.junit.Test)

Example 32 with CNode

use of org.apache.sysml.hops.codegen.cplan.CNode in project systemml by apache.

the class CPlanComparisonTest method testNotEqualBinaryDAG2.

@Test
public void testNotEqualBinaryDAG2() {
    CNode c1 = createCNodeData(DataType.MATRIX);
    CNode c2 = createCNodeData(DataType.MATRIX);
    CNode c3 = createCNodeData(DataType.MATRIX);
    // DAG 2a: (c1*c2)*c3
    CNode b1a = new CNodeBinary(c1, c2, BinType.MULT);
    CNode b2a = new CNodeBinary(b1a, c3, BinType.MULT);
    // DAG 2b: (c1*c2)*c1
    CNode b1b = new CNodeBinary(c1, c2, BinType.MULT);
    CNode b2b = new CNodeBinary(b1b, c1, BinType.MULT);
    Assert.assertNotEquals(b2a, b2b);
}
Also used : CNode(org.apache.sysml.hops.codegen.cplan.CNode) CNodeBinary(org.apache.sysml.hops.codegen.cplan.CNodeBinary) Test(org.junit.Test)

Example 33 with CNode

use of org.apache.sysml.hops.codegen.cplan.CNode in project systemml by apache.

the class CPlanComparisonTest method testEqualUnaryNodes.

@Test
public void testEqualUnaryNodes() {
    CNode c0 = createCNodeData(DataType.MATRIX);
    CNode c1 = new CNodeUnary(c0, UnaryType.EXP);
    CNode c2 = new CNodeUnary(c0, UnaryType.EXP);
    Assert.assertEquals(c1.hashCode(), c2.hashCode());
    Assert.assertEquals(c1, c2);
}
Also used : CNode(org.apache.sysml.hops.codegen.cplan.CNode) CNodeUnary(org.apache.sysml.hops.codegen.cplan.CNodeUnary) Test(org.junit.Test)

Example 34 with CNode

use of org.apache.sysml.hops.codegen.cplan.CNode in project incubator-systemml by apache.

the class CPlanCSERewriter method eliminateCommonSubexpressions.

public CNodeTpl eliminateCommonSubexpressions(CNodeTpl tpl) {
    // Note: Compared to our traditional common subexpression elimination, on cplans,
    // we don't have any parent references, and hence cannot use a collect-merge approach.
    // In contrast, we exploit the hash signatures of cnodes as used in the plan cache.
    // However, note that these signatures ignore input hops by default (for better plan
    // cache hit rates), but are temporarily set to strict evaluation for this rewrite.
    List<CNode> outputs = (tpl instanceof CNodeMultiAgg) ? ((CNodeMultiAgg) tpl).getOutputs() : Collections.singletonList(tpl.getOutput());
    // step 1: set data nodes to strict comparison
    tpl.resetVisitStatusOutputs();
    for (CNode out : outputs) rSetStrictDataNodeComparision(out, true);
    // step 2: perform common subexpression elimination
    HashMap<CNode, CNode> cseSet = new HashMap<>();
    tpl.resetVisitStatusOutputs();
    for (CNode out : outputs) rEliminateCommonSubexpression(out, cseSet);
    // step 3: reset data nodes to imprecise comparison
    tpl.resetVisitStatusOutputs();
    for (CNode out : outputs) rSetStrictDataNodeComparision(out, false);
    tpl.resetVisitStatusOutputs();
    return tpl;
}
Also used : CNode(org.apache.sysml.hops.codegen.cplan.CNode) HashMap(java.util.HashMap) CNodeMultiAgg(org.apache.sysml.hops.codegen.cplan.CNodeMultiAgg)

Example 35 with CNode

use of org.apache.sysml.hops.codegen.cplan.CNode in project incubator-systemml by apache.

the class CPlanOpRewriter method rFindAndRemoveBinaryMS.

private static void rFindAndRemoveBinaryMS(CNode node, CNodeData mainInput, BinType type, String lit, String replace) {
    for (int i = 0; i < node.getInput().size(); i++) {
        CNode tmp = node.getInput().get(i);
        if (TemplateUtils.isBinary(tmp, type) && tmp.getInput().get(1).isLiteral() && tmp.getInput().get(1).getVarname().equals(lit) && tmp.getInput().get(0) instanceof CNodeData && ((CNodeData) tmp.getInput().get(0)).getHopID() == mainInput.getHopID()) {
            CNodeData cnode = new CNodeData(new LiteralOp(replace));
            cnode.setLiteral(true);
            node.getInput().set(i, cnode);
        } else
            rFindAndRemoveBinaryMS(tmp, mainInput, type, lit, replace);
    }
}
Also used : CNode(org.apache.sysml.hops.codegen.cplan.CNode) CNodeData(org.apache.sysml.hops.codegen.cplan.CNodeData) LiteralOp(org.apache.sysml.hops.LiteralOp)

Aggregations

CNode (org.apache.sysml.hops.codegen.cplan.CNode)64 CNodeBinary (org.apache.sysml.hops.codegen.cplan.CNodeBinary)27 Test (org.junit.Test)26 CNodeUnary (org.apache.sysml.hops.codegen.cplan.CNodeUnary)21 Hop (org.apache.sysml.hops.Hop)19 CNodeData (org.apache.sysml.hops.codegen.cplan.CNodeData)17 CNodeTernary (org.apache.sysml.hops.codegen.cplan.CNodeTernary)16 HashMap (java.util.HashMap)13 Pair (org.apache.sysml.runtime.matrix.data.Pair)11 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 AggBinaryOp (org.apache.sysml.hops.AggBinaryOp)8 MemoTableEntry (org.apache.sysml.hops.codegen.template.CPlanMemoTable.MemoTableEntry)8 CNodeMultiAgg (org.apache.sysml.hops.codegen.cplan.CNodeMultiAgg)7 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)6 BinaryOp (org.apache.sysml.hops.BinaryOp)6 LiteralOp (org.apache.sysml.hops.LiteralOp)6 UnaryOp (org.apache.sysml.hops.UnaryOp)6 CNodeCell (org.apache.sysml.hops.codegen.cplan.CNodeCell)5 CNodeRow (org.apache.sysml.hops.codegen.cplan.CNodeRow)5