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