Search in sources :

Example 6 with CNodeData

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

the class TemplateUtils method createCNodeData.

public static CNodeData createCNodeData(Hop hop, boolean compileLiterals) {
    CNodeData cdata = new CNodeData(hop);
    cdata.setLiteral(hop instanceof LiteralOp && (compileLiterals || UtilFunctions.isIntegerNumber(((LiteralOp) hop).getStringValue())));
    return cdata;
}
Also used : CNodeData(org.apache.sysml.hops.codegen.cplan.CNodeData) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 7 with CNodeData

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

the class CPlanComparisonTest method testEqualMatrixDataNode.

@Test
public void testEqualMatrixDataNode() {
    Hop data = createDataOp(DataType.MATRIX);
    CNode c1 = new CNodeData(data);
    CNode c2 = new CNodeData(data);
    Assert.assertEquals(c1.hashCode(), c2.hashCode());
    Assert.assertEquals(c1, c2);
}
Also used : CNode(org.apache.sysml.hops.codegen.cplan.CNode) CNodeData(org.apache.sysml.hops.codegen.cplan.CNodeData) Hop(org.apache.sysml.hops.Hop) Test(org.junit.Test)

Example 8 with CNodeData

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

the class TemplateUtils method createCNodeData.

public static CNodeData createCNodeData(Hop hop, boolean compileLiterals) {
    CNodeData cdata = new CNodeData(hop);
    cdata.setLiteral(hop instanceof LiteralOp && (compileLiterals || UtilFunctions.isIntegerNumber(((LiteralOp) hop).getStringValue())));
    return cdata;
}
Also used : CNodeData(org.apache.sysml.hops.codegen.cplan.CNodeData) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 9 with CNodeData

use of org.apache.sysml.hops.codegen.cplan.CNodeData in project 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)

Example 10 with CNodeData

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

the class TemplateMultiAgg method constructCplan.

@Override
public Pair<Hop[], CNodeTpl> constructCplan(Hop hop, CPlanMemoTable memo, boolean compileLiterals) {
    // get all root nodes for multi aggregation
    MemoTableEntry multiAgg = memo.getBest(hop.getHopID(), TemplateType.MAGG);
    ArrayList<Hop> roots = new ArrayList<>();
    for (int i = 0; i < 3; i++) if (multiAgg.isPlanRef(i))
        roots.add(memo._hopRefs.get(multiAgg.input(i)));
    Hop.resetVisitStatus(roots);
    // recursively process required cplan outputs
    HashSet<Hop> inHops = new HashSet<>();
    HashMap<Long, CNode> tmp = new HashMap<>();
    for (// use celltpl cplan construction
    Hop root : // use celltpl cplan construction
    roots) super.rConstructCplan(root, memo, tmp, inHops, compileLiterals);
    Hop.resetVisitStatus(roots);
    // reorder inputs (ensure matrices/vectors come first) and prune literals
    // note: we order by number of cells and subsequently sparsity to ensure
    // that sparse inputs are used as the main input w/o unnecessary conversion
    Hop shared = getSparseSafeSharedInput(roots, inHops);
    Hop[] sinHops = inHops.stream().filter(h -> !(h.getDataType().isScalar() && tmp.get(h.getHopID()).isLiteral())).sorted(new HopInputComparator(shared)).toArray(Hop[]::new);
    // construct template node
    ArrayList<CNode> inputs = new ArrayList<>();
    for (Hop in : sinHops) inputs.add(tmp.get(in.getHopID()));
    ArrayList<CNode> outputs = new ArrayList<>();
    ArrayList<AggOp> aggOps = new ArrayList<>();
    for (Hop root : roots) {
        CNode node = tmp.get(root.getHopID());
        if (// add indexing ops for sideways data inputs
        node instanceof CNodeData && ((CNodeData) inputs.get(0)).getHopID() != ((CNodeData) node).getHopID())
            node = new CNodeUnary(node, (roots.get(0).getDim2() == 1) ? UnaryType.LOOKUP_R : UnaryType.LOOKUP_RC);
        outputs.add(node);
        aggOps.add(TemplateUtils.getAggOp(root));
    }
    CNodeMultiAgg tpl = new CNodeMultiAgg(inputs, outputs);
    tpl.setAggOps(aggOps);
    tpl.setSparseSafe(isSparseSafe(roots, sinHops[0], tpl.getOutputs(), tpl.getAggOps(), true));
    tpl.setRootNodes(roots);
    tpl.setBeginLine(hop.getBeginLine());
    // return cplan instance
    return new Pair<>(sinHops, tpl);
}
Also used : CNodeData(org.apache.sysml.hops.codegen.cplan.CNodeData) HashMap(java.util.HashMap) AggOp(org.apache.sysml.hops.Hop.AggOp) Hop(org.apache.sysml.hops.Hop) ArrayList(java.util.ArrayList) CNode(org.apache.sysml.hops.codegen.cplan.CNode) CNodeUnary(org.apache.sysml.hops.codegen.cplan.CNodeUnary) MemoTableEntry(org.apache.sysml.hops.codegen.template.CPlanMemoTable.MemoTableEntry) CNodeMultiAgg(org.apache.sysml.hops.codegen.cplan.CNodeMultiAgg) HashSet(java.util.HashSet) Pair(org.apache.sysml.runtime.matrix.data.Pair)

Aggregations

CNodeData (org.apache.sysml.hops.codegen.cplan.CNodeData)23 CNode (org.apache.sysml.hops.codegen.cplan.CNode)17 Hop (org.apache.sysml.hops.Hop)13 LiteralOp (org.apache.sysml.hops.LiteralOp)12 CNodeUnary (org.apache.sysml.hops.codegen.cplan.CNodeUnary)8 MemoTableEntry (org.apache.sysml.hops.codegen.template.CPlanMemoTable.MemoTableEntry)8 AggBinaryOp (org.apache.sysml.hops.AggBinaryOp)6 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)6 BinaryOp (org.apache.sysml.hops.BinaryOp)6 UnaryOp (org.apache.sysml.hops.UnaryOp)6 CNodeBinary (org.apache.sysml.hops.codegen.cplan.CNodeBinary)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 CNodeMultiAgg (org.apache.sysml.hops.codegen.cplan.CNodeMultiAgg)5 Pair (org.apache.sysml.runtime.matrix.data.Pair)5 IndexingOp (org.apache.sysml.hops.IndexingOp)4 ParameterizedBuiltinOp (org.apache.sysml.hops.ParameterizedBuiltinOp)4 TernaryOp (org.apache.sysml.hops.TernaryOp)4 CNodeTernary (org.apache.sysml.hops.codegen.cplan.CNodeTernary)4 TernaryType (org.apache.sysml.hops.codegen.cplan.CNodeTernary.TernaryType)4