Search in sources :

Example 81 with DataOp

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();
}
Also used : HopsException.check(org.apache.sysml.hops.HopsException.check) HopsException(org.apache.sysml.hops.HopsException) Set(java.util.Set) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) Collectors(java.util.stream.Collectors) Hop(org.apache.sysml.hops.Hop) ArrayList(java.util.ArrayList) FunctionOp(org.apache.sysml.hops.FunctionOp) LiteralOp(org.apache.sysml.hops.LiteralOp) HashSet(java.util.HashSet) DataOp(org.apache.sysml.hops.DataOp) Expression(org.apache.sysml.parser.Expression) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Explain(org.apache.sysml.utils.Explain) Expression(org.apache.sysml.parser.Expression) Hop(org.apache.sysml.hops.Hop) FunctionOp(org.apache.sysml.hops.FunctionOp) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp)

Example 82 with DataOp

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;
}
Also used : Hop(org.apache.sysml.hops.Hop) DataOp(org.apache.sysml.hops.DataOp)

Example 83 with DataOp

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;
}
Also used : AggUnaryOp(org.apache.sysml.hops.AggUnaryOp) UnaryOp(org.apache.sysml.hops.UnaryOp) Hop(org.apache.sysml.hops.Hop) DataOp(org.apache.sysml.hops.DataOp)

Example 84 with DataOp

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;
}
Also used : DataOp(org.apache.sysml.hops.DataOp)

Example 85 with DataOp

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();
}
Also used : ParameterizedBuiltinOp(org.apache.sysml.hops.ParameterizedBuiltinOp) AggBinaryOp(org.apache.sysml.hops.AggBinaryOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp) TernaryOp(org.apache.sysml.hops.TernaryOp)

Aggregations

DataOp (org.apache.sysml.hops.DataOp)86 Hop (org.apache.sysml.hops.Hop)75 LiteralOp (org.apache.sysml.hops.LiteralOp)44 ArrayList (java.util.ArrayList)23 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)20 UnaryOp (org.apache.sysml.hops.UnaryOp)18 StatementBlock (org.apache.sysml.parser.StatementBlock)17 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)17 HopsException (org.apache.sysml.hops.HopsException)16 IndexingOp (org.apache.sysml.hops.IndexingOp)16 HashMap (java.util.HashMap)13 FunctionOp (org.apache.sysml.hops.FunctionOp)13 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)13 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)13 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)12 DataIdentifier (org.apache.sysml.parser.DataIdentifier)11 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)11 Data (org.apache.sysml.runtime.instructions.cp.Data)11 BinaryOp (org.apache.sysml.hops.BinaryOp)9 LeftIndexingOp (org.apache.sysml.hops.LeftIndexingOp)9