Search in sources :

Example 6 with CNodeUnary

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

the class TemplateUtils method countVectorIntermediates.

public static int countVectorIntermediates(CNode node) {
    if (node.isVisited())
        return 0;
    node.setVisited();
    // compute vector requirements over all inputs
    int ret = 0;
    for (CNode c : node.getInput()) ret += countVectorIntermediates(c);
    // compute vector requirements of current node
    int cntBin = (node instanceof CNodeBinary && ((CNodeBinary) node).getType().isVectorPrimitive() && !((CNodeBinary) node).getType().name().endsWith("_ADD")) ? 1 : 0;
    int cntUn = (node instanceof CNodeUnary && ((CNodeUnary) node).getType().isVectorScalarPrimitive()) ? 1 : 0;
    int cntTn = (node instanceof CNodeTernary && ((CNodeTernary) node).getType().isVectorPrimitive()) ? 1 : 0;
    return ret + cntBin + cntUn + cntTn;
}
Also used : CNode(org.apache.sysml.hops.codegen.cplan.CNode) CNodeTernary(org.apache.sysml.hops.codegen.cplan.CNodeTernary) CNodeUnary(org.apache.sysml.hops.codegen.cplan.CNodeUnary) CNodeBinary(org.apache.sysml.hops.codegen.cplan.CNodeBinary)

Example 7 with CNodeUnary

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

the class TemplateUtils method getMaxVectorIntermediates.

public static int getMaxVectorIntermediates(CNode node) {
    if (node.isVisited())
        return 0;
    int max = 0;
    for (CNode input : node.getInput()) max = Math.max(max, getMaxVectorIntermediates(input));
    max = Math.max(max, (node instanceof CNodeTernary && ((CNodeTernary) node).getType().isVectorPrimitive()) ? 1 : 0);
    max = Math.max(max, (node instanceof CNodeBinary) ? (((CNodeBinary) node).getType().isVectorVectorPrimitive() ? 3 : ((CNodeBinary) node).getType().isVectorScalarPrimitive() ? 2 : ((CNodeBinary) node).getType().isVectorMatrixPrimitive() ? 1 : 0) : 0);
    max = Math.max(max, (node instanceof CNodeUnary && ((CNodeUnary) node).getType().isVectorScalarPrimitive()) ? 2 : 0);
    node.setVisited();
    return max;
}
Also used : CNode(org.apache.sysml.hops.codegen.cplan.CNode) CNodeTernary(org.apache.sysml.hops.codegen.cplan.CNodeTernary) CNodeUnary(org.apache.sysml.hops.codegen.cplan.CNodeUnary) CNodeBinary(org.apache.sysml.hops.codegen.cplan.CNodeBinary)

Example 8 with CNodeUnary

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

Example 9 with CNodeUnary

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

the class CPlanComparisonTest method testNotEqualUnaryTernaryNodes.

@Test
public void testNotEqualUnaryTernaryNodes() {
    CNode c1 = createCNodeData(DataType.MATRIX);
    CNode c2 = createCNodeData(DataType.SCALAR);
    CNode c3 = createCNodeData(DataType.MATRIX);
    CNode un1 = new CNodeUnary(c1, UnaryType.ABS);
    CNode ter2 = new CNodeTernary(c1, c2, c3, TernaryType.PLUS_MULT);
    Assert.assertNotEquals(un1, ter2);
}
Also used : CNode(org.apache.sysml.hops.codegen.cplan.CNode) CNodeTernary(org.apache.sysml.hops.codegen.cplan.CNodeTernary) CNodeUnary(org.apache.sysml.hops.codegen.cplan.CNodeUnary) Test(org.junit.Test)

Example 10 with CNodeUnary

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

Aggregations

CNode (org.apache.sysml.hops.codegen.cplan.CNode)21 CNodeUnary (org.apache.sysml.hops.codegen.cplan.CNodeUnary)21 CNodeBinary (org.apache.sysml.hops.codegen.cplan.CNodeBinary)13 CNodeTernary (org.apache.sysml.hops.codegen.cplan.CNodeTernary)10 Hop (org.apache.sysml.hops.Hop)8 CNodeData (org.apache.sysml.hops.codegen.cplan.CNodeData)8 MemoTableEntry (org.apache.sysml.hops.codegen.template.CPlanMemoTable.MemoTableEntry)8 Test (org.junit.Test)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 IndexingOp (org.apache.sysml.hops.IndexingOp)4 LiteralOp (org.apache.sysml.hops.LiteralOp)4 ParameterizedBuiltinOp (org.apache.sysml.hops.ParameterizedBuiltinOp)4 TernaryOp (org.apache.sysml.hops.TernaryOp)4 TernaryType (org.apache.sysml.hops.codegen.cplan.CNodeTernary.TernaryType)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2