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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations