Search in sources :

Example 1 with LeftIndexingOp

use of org.apache.sysml.hops.LeftIndexingOp in project incubator-systemml by apache.

the class OptimizerRuleBased method hasOnlyInMemoryResults.

protected boolean hasOnlyInMemoryResults(OptNode n, ArrayList<String> resultVars, LocalVariableMap vars, boolean inLocal) throws DMLRuntimeException {
    boolean ret = true;
    if (n.isLeaf()) {
        String opName = n.getParam(ParamType.OPSTRING);
        //check opstring and exec type
        if (opName.equals(LeftIndexingOp.OPSTRING)) {
            LeftIndexingOp hop = (LeftIndexingOp) OptTreeConverter.getAbstractPlanMapping().getMappedHop(n.getID());
            //check agains set of varname
            String varName = hop.getInput().get(0).getName();
            if (resultVars.contains(varName) && vars.keySet().contains(varName)) {
                //dims of result vars must be known at this point in time
                MatrixObject mo = (MatrixObject) vars.get(hop.getInput().get(0).getName());
                long rows = mo.getNumRows();
                long cols = mo.getNumColumns();
                double memBudget = inLocal ? OptimizerUtils.getLocalMemBudget() : OptimizerUtils.getRemoteMemBudgetMap();
                ret &= isInMemoryResultMerge(rows, cols, memBudget);
            }
        }
    } else {
        for (OptNode c : n.getChilds()) ret &= hasOnlyInMemoryResults(c, resultVars, vars, inLocal);
    }
    return ret;
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) LeftIndexingOp(org.apache.sysml.hops.LeftIndexingOp)

Example 2 with LeftIndexingOp

use of org.apache.sysml.hops.LeftIndexingOp in project incubator-systemml by apache.

the class OptimizerRuleBased method hasResultMRLeftIndexing.

protected boolean hasResultMRLeftIndexing(OptNode n, ArrayList<String> resultVars, LocalVariableMap vars, boolean checkSize) throws DMLRuntimeException {
    boolean ret = false;
    if (n.isLeaf()) {
        String opName = n.getParam(ParamType.OPSTRING);
        //check opstring and exec type
        if (opName != null && opName.equals(LeftIndexingOp.OPSTRING) && n.getExecType() == getRemoteExecType()) {
            LeftIndexingOp hop = (LeftIndexingOp) OptTreeConverter.getAbstractPlanMapping().getMappedHop(n.getID());
            //check agains set of varname
            String varName = hop.getInput().get(0).getName();
            if (resultVars.contains(varName)) {
                ret = true;
                if (checkSize && vars.keySet().contains(varName)) {
                    //dims of result vars must be known at this point in time
                    MatrixObject mo = (MatrixObject) vars.get(hop.getInput().get(0).getName());
                    long rows = mo.getNumRows();
                    long cols = mo.getNumColumns();
                    ret = !isInMemoryResultMerge(rows, cols, OptimizerUtils.getRemoteMemBudgetMap(false));
                }
            }
        }
    } else {
        for (OptNode c : n.getChilds()) ret |= hasResultMRLeftIndexing(c, resultVars, vars, checkSize);
    }
    return ret;
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) LeftIndexingOp(org.apache.sysml.hops.LeftIndexingOp)

Example 3 with LeftIndexingOp

use of org.apache.sysml.hops.LeftIndexingOp in project incubator-systemml by apache.

the class RewriteForLoopVectorization method vectorizeElementwiseBinary.

private StatementBlock vectorizeElementwiseBinary(StatementBlock sb, StatementBlock csb, Hop from, Hop to, Hop increment, String itervar) throws HopsException {
    StatementBlock ret = sb;
    //check supported increment values
    if (!(increment instanceof LiteralOp && ((LiteralOp) increment).getDoubleValue() == 1.0)) {
        return ret;
    }
    //check for applicability
    boolean apply = false;
    //row or col
    boolean rowIx = false;
    if (csb.get_hops() != null && csb.get_hops().size() == 1) {
        Hop root = csb.get_hops().get(0);
        if (root.getDataType() == DataType.MATRIX && root.getInput().get(0) instanceof LeftIndexingOp) {
            LeftIndexingOp lix = (LeftIndexingOp) root.getInput().get(0);
            Hop lixlhs = lix.getInput().get(0);
            Hop lixrhs = lix.getInput().get(1);
            if (lixlhs instanceof DataOp && lixrhs instanceof BinaryOp && lixrhs.getInput().get(0) instanceof IndexingOp && lixrhs.getInput().get(1) instanceof IndexingOp && lixrhs.getInput().get(0).getInput().get(0) instanceof DataOp && lixrhs.getInput().get(1).getInput().get(0) instanceof DataOp) {
                IndexingOp rix0 = (IndexingOp) lixrhs.getInput().get(0);
                IndexingOp rix1 = (IndexingOp) lixrhs.getInput().get(1);
                //check for rowwise
                if (lix.getRowLowerEqualsUpper() && rix0.isRowLowerEqualsUpper() && rix1.isRowLowerEqualsUpper() && lix.getInput().get(2).getName().equals(itervar) && rix0.getInput().get(1).getName().equals(itervar) && rix1.getInput().get(1).getName().equals(itervar)) {
                    apply = true;
                    rowIx = true;
                }
                //check for colwise
                if (lix.getColLowerEqualsUpper() && rix0.isColLowerEqualsUpper() && rix1.isColLowerEqualsUpper() && lix.getInput().get(4).getName().equals(itervar) && rix0.getInput().get(3).getName().equals(itervar) && rix1.getInput().get(3).getName().equals(itervar)) {
                    apply = true;
                    rowIx = false;
                }
            }
        }
    }
    //apply rewrite if possible
    if (apply) {
        Hop root = csb.get_hops().get(0);
        LeftIndexingOp lix = (LeftIndexingOp) root.getInput().get(0);
        BinaryOp bop = (BinaryOp) lix.getInput().get(1);
        IndexingOp rix0 = (IndexingOp) bop.getInput().get(0);
        IndexingOp rix1 = (IndexingOp) bop.getInput().get(1);
        int index1 = rowIx ? 2 : 4;
        int index2 = rowIx ? 3 : 5;
        //modify left indexing bounds
        HopRewriteUtils.replaceChildReference(lix, lix.getInput().get(index1), from, index1);
        HopRewriteUtils.replaceChildReference(lix, lix.getInput().get(index2), to, index2);
        //modify both right indexing
        HopRewriteUtils.replaceChildReference(rix0, rix0.getInput().get(index1 - 1), from, index1 - 1);
        HopRewriteUtils.replaceChildReference(rix0, rix0.getInput().get(index2 - 1), to, index2 - 1);
        HopRewriteUtils.replaceChildReference(rix1, rix1.getInput().get(index1 - 1), from, index1 - 1);
        HopRewriteUtils.replaceChildReference(rix1, rix1.getInput().get(index2 - 1), to, index2 - 1);
        updateLeftAndRightIndexingSizes(rowIx, lix, rix0, rix1);
        bop.refreshSizeInformation();
        //after bop update
        lix.refreshSizeInformation();
        ret = csb;
        //ret.liveIn().removeVariable(itervar);
        LOG.debug("Applied vectorizeElementwiseBinaryForLoop.");
    }
    return ret;
}
Also used : IndexingOp(org.apache.sysml.hops.IndexingOp) LeftIndexingOp(org.apache.sysml.hops.LeftIndexingOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) LeftIndexingOp(org.apache.sysml.hops.LeftIndexingOp) BinaryOp(org.apache.sysml.hops.BinaryOp)

Example 4 with LeftIndexingOp

use of org.apache.sysml.hops.LeftIndexingOp in project incubator-systemml by apache.

the class RewriteAlgebraicSimplificationDynamic method fuseLeftIndexingChainToAppend.

private Hop fuseLeftIndexingChainToAppend(Hop parent, Hop hi, int pos) {
    boolean applied = false;
    //pattern1: X[,1]=A; X[,2]=B -> X=cbind(A,B); matrix / frame
    if (//first lix 
    hi instanceof LeftIndexingOp && HopRewriteUtils.isFullColumnIndexing((LeftIndexingOp) hi) && //second lix	
    hi.getInput().get(0) instanceof LeftIndexingOp && HopRewriteUtils.isFullColumnIndexing((LeftIndexingOp) hi.getInput().get(0)) && //first lix is single consumer
    hi.getInput().get(0).getParent().size() == 1 && //two column matrix
    hi.getInput().get(0).getInput().get(0).getDim2() == 2) {
        //rhs matrix
        Hop input2 = hi.getInput().get(1);
        //cl=cu
        Hop pred2 = hi.getInput().get(4);
        //lhs matrix
        Hop input1 = hi.getInput().get(0).getInput().get(1);
        //cl=cu
        Hop pred1 = hi.getInput().get(0).getInput().get(4);
        if (pred1 instanceof LiteralOp && HopRewriteUtils.getDoubleValueSafe((LiteralOp) pred1) == 1 && pred2 instanceof LiteralOp && HopRewriteUtils.getDoubleValueSafe((LiteralOp) pred2) == 2 && input1.getDataType() != DataType.SCALAR && input2.getDataType() != DataType.SCALAR) {
            //create new cbind operation and rewrite inputs
            BinaryOp bop = HopRewriteUtils.createBinary(input1, input2, OpOp2.CBIND);
            HopRewriteUtils.replaceChildReference(parent, hi, bop, pos);
            hi = bop;
            applied = true;
        }
    }
    //pattern1: X[1,]=A; X[2,]=B -> X=rbind(A,B)
    if (//first lix 
    !applied && hi instanceof LeftIndexingOp && HopRewriteUtils.isFullRowIndexing((LeftIndexingOp) hi) && //second lix	
    hi.getInput().get(0) instanceof LeftIndexingOp && HopRewriteUtils.isFullRowIndexing((LeftIndexingOp) hi.getInput().get(0)) && //first lix is single consumer
    hi.getInput().get(0).getParent().size() == 1 && //two column matrix
    hi.getInput().get(0).getInput().get(0).getDim1() == 2) {
        //rhs matrix
        Hop input2 = hi.getInput().get(1);
        //rl=ru
        Hop pred2 = hi.getInput().get(2);
        //lhs matrix
        Hop input1 = hi.getInput().get(0).getInput().get(1);
        //rl=ru
        Hop pred1 = hi.getInput().get(0).getInput().get(2);
        if (pred1 instanceof LiteralOp && HopRewriteUtils.getDoubleValueSafe((LiteralOp) pred1) == 1 && pred2 instanceof LiteralOp && HopRewriteUtils.getDoubleValueSafe((LiteralOp) pred2) == 2 && input1.getDataType() != DataType.SCALAR && input2.getDataType() != DataType.SCALAR) {
            //create new cbind operation and rewrite inputs
            BinaryOp bop = HopRewriteUtils.createBinary(input1, input2, OpOp2.RBIND);
            HopRewriteUtils.replaceChildReference(parent, hi, bop, pos);
            hi = bop;
            applied = true;
            LOG.debug("Applied fuseLeftIndexingChainToAppend2 (line " + hi.getBeginLine() + ")");
        }
    }
    return hi;
}
Also used : Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp) LeftIndexingOp(org.apache.sysml.hops.LeftIndexingOp) AggBinaryOp(org.apache.sysml.hops.AggBinaryOp) BinaryOp(org.apache.sysml.hops.BinaryOp)

Example 5 with LeftIndexingOp

use of org.apache.sysml.hops.LeftIndexingOp in project incubator-systemml by apache.

the class RewriteAlgebraicSimplificationDynamic method removeUnnecessaryLeftIndexing.

private Hop removeUnnecessaryLeftIndexing(Hop parent, Hop hi, int pos) {
    if (//left indexing op
    hi instanceof LeftIndexingOp) {
        //rhs matrix/frame
        Hop input = hi.getInput().get(1);
        if (//equal dims
        HopRewriteUtils.isEqualSize(hi, input)) {
            //equal dims of left indexing input and output -> no need for indexing
            //remove unnecessary right indexing				
            HopRewriteUtils.replaceChildReference(parent, hi, input, pos);
            HopRewriteUtils.cleanupUnreferenced(hi);
            hi = input;
            LOG.debug("Applied removeUnnecessaryLeftIndexing");
        }
    }
    return hi;
}
Also used : Hop(org.apache.sysml.hops.Hop) LeftIndexingOp(org.apache.sysml.hops.LeftIndexingOp)

Aggregations

LeftIndexingOp (org.apache.sysml.hops.LeftIndexingOp)11 Hop (org.apache.sysml.hops.Hop)9 LiteralOp (org.apache.sysml.hops.LiteralOp)6 DataOp (org.apache.sysml.hops.DataOp)4 IndexingOp (org.apache.sysml.hops.IndexingOp)4 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)3 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)3 StatementBlock (org.apache.sysml.parser.StatementBlock)3 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)3 ArrayList (java.util.ArrayList)2 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)2 BinaryOp (org.apache.sysml.hops.BinaryOp)2 UnaryOp (org.apache.sysml.hops.UnaryOp)2 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)2 AggBinaryOp (org.apache.sysml.hops.AggBinaryOp)1 FunctionOp (org.apache.sysml.hops.FunctionOp)1 MultiThreadedHop (org.apache.sysml.hops.Hop.MultiThreadedHop)1 ReorgOp (org.apache.sysml.hops.ReorgOp)1