use of org.apache.sysml.hops.DataOp in project systemml by apache.
the class HopDagValidator method rValidateHop.
private static void rValidateHop(final Hop hop, final ValidatorState state) {
final long id = hop.getHopID();
// check visit status
final boolean seen = !state.seen.add(id);
if (seen != hop.isVisited()) {
String parentIDs = hop.getParent().stream().map(h -> Long.toString(h.getHopID())).collect(Collectors.joining(", "));
check(false, hop, parentIDs, seen);
}
// we saw the Hop previously, no need to re-validate
if (seen)
return;
// check parent linking
for (Hop parent : hop.getParent()) check(parent.getInput().contains(hop), hop, "not properly linked to its parent pid=%d %s", parent.getHopID(), parent.getClass().getName());
final ArrayList<Hop> input = hop.getInput();
final Expression.DataType dt = hop.getDataType();
final Expression.ValueType vt = hop.getValueType();
// check child linking
for (Hop child : input) check(child.getParent().contains(hop), hop, "not properly linked to its child cid=%d %s", child.getHopID(), child.getClass().getName());
// check empty children (other variable-length Hops must have at least one child)
if (input.isEmpty())
check(hop instanceof DataOp || hop instanceof FunctionOp || hop instanceof LiteralOp, hop, "is not a dataop/functionop/literal but has no children");
// check Hop has a legal arity (number of children)
hop.checkArity();
// check Matrix data type Hops must have Double Value type
if (dt == Expression.DataType.MATRIX)
check(vt == Expression.ValueType.DOUBLE || vt == Expression.ValueType.INT, hop, "has Matrix type but Value Type %s is not DOUBLE", vt);
// recursively process children
for (Hop child : input) rValidateHop(child, state);
hop.setVisited();
}
use of org.apache.sysml.hops.DataOp in project systemml by apache.
the class HopRewriteUtils method hasOnlyWriteParents.
public static boolean hasOnlyWriteParents(Hop hop, boolean inclTransient, boolean inclPersistent) {
boolean ret = true;
ArrayList<Hop> parents = hop.getParent();
for (Hop p : parents) {
if (inclTransient && inclPersistent)
ret &= (p instanceof DataOp && (((DataOp) p).getDataOpType() == DataOpTypes.TRANSIENTWRITE || ((DataOp) p).getDataOpType() == DataOpTypes.PERSISTENTWRITE));
else if (inclTransient)
ret &= (p instanceof DataOp && ((DataOp) p).getDataOpType() == DataOpTypes.TRANSIENTWRITE);
else if (inclPersistent)
ret &= (p instanceof DataOp && ((DataOp) p).getDataOpType() == DataOpTypes.PERSISTENTWRITE);
}
return ret;
}
use of org.apache.sysml.hops.DataOp in project systemml by apache.
the class HopRewriteUtils method rContainsRead.
public static boolean rContainsRead(Hop root, String var, boolean includeMetaOp) {
if (root.isVisited())
return false;
boolean ret = false;
// handle leaf node for variable
if (root instanceof DataOp && ((DataOp) root).isRead() && root.getName().equals(var)) {
boolean onlyMetaOp = true;
if (!includeMetaOp) {
for (Hop p : root.getParent()) {
onlyMetaOp &= (p instanceof UnaryOp && (((UnaryOp) p).getOp() == OpOp1.NROW || ((UnaryOp) p).getOp() == OpOp1.NCOL));
}
ret = !onlyMetaOp;
} else
ret = true;
}
// recursively process childs
for (Hop c : root.getInput()) ret |= rContainsRead(c, var, includeMetaOp);
root.setVisited();
return ret;
}
use of org.apache.sysml.hops.DataOp in project systemml by apache.
the class HopRewriteUtils method createDataOp.
public static DataOp createDataOp(String name, Hop input, DataOpTypes type) {
DataOp dop = new DataOp(name, input.getDataType(), input.getValueType(), input, type, null);
dop.setOutputBlocksizes(input.getRowsInBlock(), input.getColsInBlock());
copyLineNumbers(input, dop);
dop.refreshSizeInformation();
return dop;
}
use of org.apache.sysml.hops.DataOp in project systemml by apache.
the class RewriteSplitDagDataDependentOperators method rCollectDataDependentOperators.
private void rCollectDataDependentOperators(Hop hop, ArrayList<Hop> cand) {
if (hop.isVisited())
return;
// prevent unnecessary dag split (dims known or no consumer operations)
boolean noSplitRequired = (hop.dimsKnown() || HopRewriteUtils.hasOnlyWriteParents(hop, true, true));
boolean investigateChilds = true;
// #1 removeEmpty
if (hop instanceof ParameterizedBuiltinOp && ((ParameterizedBuiltinOp) hop).getOp() == ParamBuiltinOp.RMEMPTY && !noSplitRequired && !(hop.getParent().size() == 1 && hop.getParent().get(0) instanceof TernaryOp && ((TernaryOp) hop.getParent().get(0)).isMatrixIgnoreZeroRewriteApplicable())) {
ParameterizedBuiltinOp pbhop = (ParameterizedBuiltinOp) hop;
cand.add(pbhop);
investigateChilds = false;
// keep interesting consumer information, flag hops accordingly
boolean noEmptyBlocks = true;
boolean onlyPMM = true;
boolean diagInput = pbhop.isTargetDiagInput();
for (Hop p : hop.getParent()) {
// list of operators without need for empty blocks to be extended as needed
noEmptyBlocks &= (p instanceof AggBinaryOp && hop == p.getInput().get(0) || HopRewriteUtils.isUnary(p, OpOp1.NROW));
onlyPMM &= (p instanceof AggBinaryOp && hop == p.getInput().get(0));
}
pbhop.setOutputEmptyBlocks(!noEmptyBlocks);
if (onlyPMM && diagInput) {
if (ConfigurationManager.isDynamicRecompilation())
pbhop.setOutputPermutationMatrix(true);
for (Hop p : hop.getParent()) ((AggBinaryOp) p).setHasLeftPMInput(true);
}
}
// #2 ctable with unknown dims
if (HopRewriteUtils.isTernary(hop, OpOp3.CTABLE) && // dims not provided
hop.getInput().size() < 4 && !noSplitRequired) {
cand.add(hop);
investigateChilds = false;
// keep interesting consumer information, flag hops accordingly
boolean onlyPMM = true;
for (Hop p : hop.getParent()) {
onlyPMM &= (p instanceof AggBinaryOp && hop == p.getInput().get(0));
}
if (onlyPMM && HopRewriteUtils.isBasic1NSequence(hop.getInput().get(0)))
hop.setOutputEmptyBlocks(false);
}
// #3 orderby childs computed in same DAG
if (HopRewriteUtils.isReorg(hop, ReOrgOp.SORT)) {
// params 'decreasing' / 'indexreturn'
for (int i = 2; i <= 3; i++) {
Hop c = hop.getInput().get(i);
if (!(c instanceof LiteralOp || c instanceof DataOp)) {
cand.add(c);
c.setVisited();
investigateChilds = false;
}
}
}
// #4 second-order eval function
if (HopRewriteUtils.isNary(hop, OpOpN.EVAL) && !noSplitRequired) {
cand.add(hop);
investigateChilds = false;
}
// otherwise, processed by recursive rule application)
if (investigateChilds && hop.getInput() != null)
for (Hop c : hop.getInput()) rCollectDataDependentOperators(c, cand);
hop.setVisited();
}
Aggregations